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; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 26 | import android.util.Log; |
| 27 | import android.view.MotionEvent; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 28 | |
| 29 | import com.android.internal.policy.IKeyguardExitCallback; |
| 30 | import com.android.internal.policy.IKeyguardService; |
| 31 | import com.android.internal.policy.IKeyguardServiceConstants; |
| 32 | import com.android.internal.policy.IKeyguardShowCallback; |
| 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 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 69 | private boolean mIsOccluded; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 70 | |
| 71 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 72 | public boolean isShowing() { |
| 73 | return mKeyguardViewMediator.isShowing(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 77 | public boolean isSecure() { |
| 78 | return mKeyguardViewMediator.isSecure(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 82 | public boolean isShowingAndNotOccluded() { |
| 83 | return mKeyguardViewMediator.isShowingAndNotOccluded(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 87 | public boolean isInputRestricted() { |
| 88 | return mKeyguardViewMediator.isInputRestricted(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 92 | public void verifyUnlock(IKeyguardExitCallback callback) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 93 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 94 | mKeyguardViewMediator.verifyUnlock(callback); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 98 | public void keyguardDone(boolean authenticated, boolean wakeup) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 99 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 100 | mKeyguardViewMediator.keyguardDone(authenticated, wakeup); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 104 | public int setOccluded(boolean isOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 105 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 106 | synchronized (this) { |
| 107 | int result; |
| 108 | if (isOccluded && mKeyguardViewMediator.isShowing() |
| 109 | && !mIsOccluded) { |
| 110 | result = IKeyguardServiceConstants |
| 111 | .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS; |
| 112 | } else if (!isOccluded && mKeyguardViewMediator.isShowing() |
| 113 | && mIsOccluded) { |
| 114 | result = IKeyguardServiceConstants |
| 115 | .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS; |
| 116 | } else { |
| 117 | result = IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_NONE; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 118 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 119 | if (mIsOccluded != isOccluded) { |
| 120 | mKeyguardViewMediator.setOccluded(isOccluded); |
| 121 | |
| 122 | // Cache the value so we always have a fresh view in whether Keyguard is occluded. |
| 123 | // If we would just call mKeyguardViewMediator.isOccluded(), this might be stale |
| 124 | // because that value gets updated in another thread. |
| 125 | mIsOccluded = isOccluded; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 126 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 127 | return result; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 128 | } |
| 129 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 130 | |
| 131 | @Override |
| 132 | public void dismiss() { |
| 133 | checkPermission(); |
| 134 | mKeyguardViewMediator.dismiss(); |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public void onDreamingStarted() { |
| 139 | checkPermission(); |
| 140 | mKeyguardViewMediator.onDreamingStarted(); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public void onDreamingStopped() { |
| 145 | checkPermission(); |
| 146 | mKeyguardViewMediator.onDreamingStopped(); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onScreenTurnedOff(int reason) { |
| 151 | checkPermission(); |
| 152 | mKeyguardViewMediator.onScreenTurnedOff(reason); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public void onScreenTurnedOn(IKeyguardShowCallback callback) { |
| 157 | checkPermission(); |
| 158 | mKeyguardViewMediator.onScreenTurnedOn(callback); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void setKeyguardEnabled(boolean enabled) { |
| 163 | checkPermission(); |
| 164 | mKeyguardViewMediator.setKeyguardEnabled(enabled); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public boolean isDismissable() { |
| 169 | return mKeyguardViewMediator.isDismissable(); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void onSystemReady() { |
| 174 | checkPermission(); |
| 175 | mKeyguardViewMediator.onSystemReady(); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void doKeyguardTimeout(Bundle options) { |
| 180 | checkPermission(); |
| 181 | mKeyguardViewMediator.doKeyguardTimeout(options); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void setCurrentUser(int userId) { |
| 186 | checkPermission(); |
| 187 | mKeyguardViewMediator.setCurrentUser(userId); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void showAssistant() { |
| 192 | checkPermission(); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void dispatch(MotionEvent event) { |
| 197 | checkPermission(); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void launchCamera() { |
| 202 | checkPermission(); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onBootCompleted() { |
| 207 | checkPermission(); |
| 208 | mKeyguardViewMediator.onBootCompleted(); |
| 209 | } |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 210 | |
| 211 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 212 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 213 | checkPermission(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 214 | mKeyguardViewMediator.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 215 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 216 | |
| 217 | @Override |
| 218 | public void onActivityDrawn() { |
| 219 | checkPermission(); |
| 220 | mKeyguardViewMediator.onActivityDrawn(); |
| 221 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 222 | }; |
| 223 | } |
| 224 | |