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