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 | |
| 19 | import com.android.internal.policy.IKeyguardExitCallback; |
| 20 | import com.android.internal.policy.IKeyguardService; |
| 21 | import com.android.internal.policy.IKeyguardServiceConstants; |
| 22 | import com.android.internal.policy.IKeyguardShowCallback; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 23 | import com.android.internal.widget.LockPatternUtils; |
| 24 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
| 25 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
| 26 | import com.android.systemui.statusbar.phone.StatusBarWindowManager; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 27 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 28 | import android.app.Service; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 29 | import android.content.Intent; |
| 30 | import android.os.Binder; |
| 31 | import android.os.Bundle; |
| 32 | import android.os.Debug; |
| 33 | import android.os.IBinder; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 34 | import android.util.Log; |
| 35 | import android.view.MotionEvent; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 36 | import android.view.ViewGroup; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 37 | |
| 38 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 39 | |
| 40 | public class KeyguardService extends Service { |
| 41 | static final String TAG = "KeyguardService"; |
| 42 | static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD; |
| 43 | |
| 44 | public static final String ACTION_STATUS_BAR_BIND = "action.status_bar_bind"; |
| 45 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 46 | private KeyguardViewMediator mKeyguardViewMediator; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 47 | |
| 48 | @Override |
| 49 | public void onCreate() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 50 | LockPatternUtils lockPatternUtils = new LockPatternUtils(this); |
| 51 | mKeyguardViewMediator = new KeyguardViewMediator(this, lockPatternUtils); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public IBinder onBind(Intent intent) { |
| 56 | if (ACTION_STATUS_BAR_BIND.equals(intent.getAction())) { |
| 57 | return mKeyguardStatusBarBinder; |
| 58 | } else { |
| 59 | return mBinder; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void checkPermission() { |
| 64 | if (getBaseContext().checkCallingOrSelfPermission(PERMISSION) != PERMISSION_GRANTED) { |
| 65 | Log.w(TAG, "Caller needs permission '" + PERMISSION + "' to call " + Debug.getCaller()); |
| 66 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 67 | + ", must have permission " + PERMISSION); |
| 68 | } |
| 69 | } |
| 70 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 71 | private final KeyguardStatusBarBinder mKeyguardStatusBarBinder = new KeyguardStatusBarBinder() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 72 | |
| 73 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 74 | public void registerStatusBar(PhoneStatusBar phoneStatusBar, ViewGroup container, |
| 75 | StatusBarWindowManager statusBarWindowManager) { |
| 76 | mKeyguardViewMediator.registerStatusBar(phoneStatusBar, container, |
| 77 | statusBarWindowManager); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 78 | } |
| 79 | }; |
| 80 | |
| 81 | private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() { |
| 82 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 83 | private boolean mIsOccluded; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 84 | |
| 85 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 86 | public boolean isShowing() { |
| 87 | return mKeyguardViewMediator.isShowing(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 91 | public boolean isSecure() { |
| 92 | return mKeyguardViewMediator.isSecure(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 96 | public boolean isShowingAndNotOccluded() { |
| 97 | return mKeyguardViewMediator.isShowingAndNotOccluded(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 101 | public boolean isInputRestricted() { |
| 102 | return mKeyguardViewMediator.isInputRestricted(); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 106 | public void verifyUnlock(IKeyguardExitCallback callback) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 107 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 108 | mKeyguardViewMediator.verifyUnlock(callback); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 112 | public void keyguardDone(boolean authenticated, boolean wakeup) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 113 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 114 | mKeyguardViewMediator.keyguardDone(authenticated, wakeup); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 118 | public int setOccluded(boolean isOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 119 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 120 | synchronized (this) { |
| 121 | int result; |
| 122 | if (isOccluded && mKeyguardViewMediator.isShowing() |
| 123 | && !mIsOccluded) { |
| 124 | result = IKeyguardServiceConstants |
| 125 | .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS; |
| 126 | } else if (!isOccluded && mKeyguardViewMediator.isShowing() |
| 127 | && mIsOccluded) { |
| 128 | result = IKeyguardServiceConstants |
| 129 | .KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS; |
| 130 | } else { |
| 131 | result = IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_NONE; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 132 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 133 | if (mIsOccluded != isOccluded) { |
| 134 | mKeyguardViewMediator.setOccluded(isOccluded); |
| 135 | |
| 136 | // Cache the value so we always have a fresh view in whether Keyguard is occluded. |
| 137 | // If we would just call mKeyguardViewMediator.isOccluded(), this might be stale |
| 138 | // because that value gets updated in another thread. |
| 139 | mIsOccluded = isOccluded; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 140 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 141 | return result; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 142 | } |
| 143 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame^] | 144 | |
| 145 | @Override |
| 146 | public void dismiss() { |
| 147 | checkPermission(); |
| 148 | mKeyguardViewMediator.dismiss(); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public void onDreamingStarted() { |
| 153 | checkPermission(); |
| 154 | mKeyguardViewMediator.onDreamingStarted(); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void onDreamingStopped() { |
| 159 | checkPermission(); |
| 160 | mKeyguardViewMediator.onDreamingStopped(); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onScreenTurnedOff(int reason) { |
| 165 | checkPermission(); |
| 166 | mKeyguardViewMediator.onScreenTurnedOff(reason); |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void onScreenTurnedOn(IKeyguardShowCallback callback) { |
| 171 | checkPermission(); |
| 172 | mKeyguardViewMediator.onScreenTurnedOn(callback); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void setKeyguardEnabled(boolean enabled) { |
| 177 | checkPermission(); |
| 178 | mKeyguardViewMediator.setKeyguardEnabled(enabled); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public boolean isDismissable() { |
| 183 | return mKeyguardViewMediator.isDismissable(); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void onSystemReady() { |
| 188 | checkPermission(); |
| 189 | mKeyguardViewMediator.onSystemReady(); |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void doKeyguardTimeout(Bundle options) { |
| 194 | checkPermission(); |
| 195 | mKeyguardViewMediator.doKeyguardTimeout(options); |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public void setCurrentUser(int userId) { |
| 200 | checkPermission(); |
| 201 | mKeyguardViewMediator.setCurrentUser(userId); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void showAssistant() { |
| 206 | checkPermission(); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void dispatch(MotionEvent event) { |
| 211 | checkPermission(); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public void launchCamera() { |
| 216 | checkPermission(); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void onBootCompleted() { |
| 221 | checkPermission(); |
| 222 | mKeyguardViewMediator.onBootCompleted(); |
| 223 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 224 | }; |
| 225 | } |
| 226 | |