Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.keyguard; |
| 18 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 19 | import android.app.Service; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.os.Binder; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.Debug; |
| 24 | import android.os.IBinder; |
Jim Miller | 96afb6f | 2014-11-14 17:56:27 -0800 | [diff] [blame] | 25 | import android.os.Process; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 26 | import android.os.Trace; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 27 | import android.util.Log; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 28 | |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 29 | import com.android.internal.policy.IKeyguardDrawnCallback; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 30 | import com.android.internal.policy.IKeyguardExitCallback; |
| 31 | import com.android.internal.policy.IKeyguardService; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 32 | import com.android.internal.policy.IKeyguardStateCallback; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 33 | import com.android.systemui.SystemUIApplication; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 34 | |
| 35 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 36 | |
| 37 | public class KeyguardService extends Service { |
| 38 | static final String TAG = "KeyguardService"; |
| 39 | static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD; |
| 40 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 41 | private KeyguardViewMediator mKeyguardViewMediator; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 42 | |
| 43 | @Override |
| 44 | public void onCreate() { |
Jorim Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 45 | ((SystemUIApplication) getApplication()).startServicesIfNeeded(); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 46 | mKeyguardViewMediator = |
| 47 | ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public IBinder onBind(Intent intent) { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 52 | return mBinder; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void checkPermission() { |
Jim Miller | 96afb6f | 2014-11-14 17:56:27 -0800 | [diff] [blame] | 56 | // Avoid deadlock by avoiding calling back into the system process. |
| 57 | if (Binder.getCallingUid() == Process.SYSTEM_UID) return; |
| 58 | |
| 59 | // Otherwise,explicitly check for caller permission ... |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 60 | if (getBaseContext().checkCallingOrSelfPermission(PERMISSION) != PERMISSION_GRANTED) { |
| 61 | Log.w(TAG, "Caller needs permission '" + PERMISSION + "' to call " + Debug.getCaller()); |
| 62 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 63 | + ", must have permission " + PERMISSION); |
| 64 | } |
| 65 | } |
| 66 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 67 | private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() { |
| 68 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 69 | @Override // Binder interface |
| 70 | public void addStateMonitorCallback(IKeyguardStateCallback callback) { |
| 71 | checkPermission(); |
| 72 | mKeyguardViewMediator.addStateMonitorCallback(callback); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 75 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 76 | public void verifyUnlock(IKeyguardExitCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 77 | Trace.beginSection("KeyguardService.mBinder#verifyUnlock"); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 78 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 79 | mKeyguardViewMediator.verifyUnlock(callback); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 80 | Trace.endSection(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 83 | @Override // Binder interface |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 84 | public void setOccluded(boolean isOccluded, boolean animate) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 85 | Trace.beginSection("KeyguardService.mBinder#setOccluded"); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 86 | checkPermission(); |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 87 | mKeyguardViewMediator.setOccluded(isOccluded, animate); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 88 | Trace.endSection(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 89 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 90 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 91 | @Override // Binder interface |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 92 | public void dismiss(boolean allowWhileOccluded) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 93 | checkPermission(); |
Adrian Roos | d88eb26 | 2016-08-04 14:50:48 -0700 | [diff] [blame] | 94 | mKeyguardViewMediator.dismiss(allowWhileOccluded); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 97 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 98 | public void onDreamingStarted() { |
| 99 | checkPermission(); |
| 100 | mKeyguardViewMediator.onDreamingStarted(); |
| 101 | } |
| 102 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 103 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 104 | public void onDreamingStopped() { |
| 105 | checkPermission(); |
| 106 | mKeyguardViewMediator.onDreamingStopped(); |
| 107 | } |
| 108 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 109 | @Override // Binder interface |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 110 | public void onStartedGoingToSleep(int reason) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 111 | checkPermission(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 112 | mKeyguardViewMediator.onStartedGoingToSleep(reason); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 115 | @Override // Binder interface |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 116 | public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 117 | checkPermission(); |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 118 | mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override // Binder interface |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 122 | public void onStartedWakingUp() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 123 | Trace.beginSection("KeyguardService.mBinder#onStartedWakingUp"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 124 | checkPermission(); |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 125 | mKeyguardViewMediator.onStartedWakingUp(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 126 | Trace.endSection(); |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override // Binder interface |
| 130 | public void onScreenTurningOn(IKeyguardDrawnCallback callback) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 131 | Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn"); |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 132 | checkPermission(); |
| 133 | mKeyguardViewMediator.onScreenTurningOn(callback); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 134 | Trace.endSection(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 137 | @Override // Binder interface |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 138 | public void onScreenTurnedOn() { |
Adrian Roos | e9d8272 | 2016-11-08 14:05:03 -0800 | [diff] [blame] | 139 | Trace.beginSection("KeyguardService.mBinder#onScreenTurnedOn"); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 140 | checkPermission(); |
| 141 | mKeyguardViewMediator.onScreenTurnedOn(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 142 | Trace.endSection(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override // Binder interface |
| 146 | public void onScreenTurnedOff() { |
| 147 | checkPermission(); |
| 148 | mKeyguardViewMediator.onScreenTurnedOff(); |
| 149 | } |
| 150 | |
| 151 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 152 | public void setKeyguardEnabled(boolean enabled) { |
| 153 | checkPermission(); |
| 154 | mKeyguardViewMediator.setKeyguardEnabled(enabled); |
| 155 | } |
| 156 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 157 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 158 | public void onSystemReady() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 159 | Trace.beginSection("KeyguardService.mBinder#onSystemReady"); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 160 | checkPermission(); |
| 161 | mKeyguardViewMediator.onSystemReady(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 162 | Trace.endSection(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 165 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 166 | public void doKeyguardTimeout(Bundle options) { |
| 167 | checkPermission(); |
| 168 | mKeyguardViewMediator.doKeyguardTimeout(options); |
| 169 | } |
| 170 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 171 | @Override // Binder interface |
Evan Rosky | 1839645 | 2016-07-27 15:19:37 -0700 | [diff] [blame] | 172 | public void setSwitchingUser(boolean switching) { |
| 173 | checkPermission(); |
| 174 | mKeyguardViewMediator.setSwitchingUser(switching); |
| 175 | } |
| 176 | |
| 177 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 178 | public void setCurrentUser(int userId) { |
| 179 | checkPermission(); |
| 180 | mKeyguardViewMediator.setCurrentUser(userId); |
| 181 | } |
| 182 | |
| 183 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 184 | public void onBootCompleted() { |
| 185 | checkPermission(); |
| 186 | mKeyguardViewMediator.onBootCompleted(); |
| 187 | } |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 188 | |
| 189 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 190 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 191 | Trace.beginSection("KeyguardService.mBinder#startKeyguardExitAnimation"); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 192 | checkPermission(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 193 | mKeyguardViewMediator.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 194 | Trace.endSection(); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 195 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 196 | }; |
| 197 | } |
| 198 | |