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; |
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; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 30 | import com.android.internal.policy.IKeyguardShowCallback; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 31 | import com.android.internal.policy.IKeyguardStateCallback; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 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 | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 44 | ((SystemUIApplication) getApplication()).startServicesIfNeeded(); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 45 | mKeyguardViewMediator = |
| 46 | ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public IBinder onBind(Intent intent) { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 51 | return mBinder; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void checkPermission() { |
Jim Miller | 96afb6f | 2014-11-14 17:56:27 -0800 | [diff] [blame] | 55 | // Avoid deadlock by avoiding calling back into the system process. |
| 56 | if (Binder.getCallingUid() == Process.SYSTEM_UID) return; |
| 57 | |
| 58 | // Otherwise,explicitly check for caller permission ... |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 59 | if (getBaseContext().checkCallingOrSelfPermission(PERMISSION) != PERMISSION_GRANTED) { |
| 60 | Log.w(TAG, "Caller needs permission '" + PERMISSION + "' to call " + Debug.getCaller()); |
| 61 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 62 | + ", must have permission " + PERMISSION); |
| 63 | } |
| 64 | } |
| 65 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 66 | private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() { |
| 67 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 68 | @Override // Binder interface |
| 69 | public void addStateMonitorCallback(IKeyguardStateCallback callback) { |
| 70 | checkPermission(); |
| 71 | mKeyguardViewMediator.addStateMonitorCallback(callback); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 74 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 75 | public void verifyUnlock(IKeyguardExitCallback callback) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 76 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 77 | mKeyguardViewMediator.verifyUnlock(callback); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 80 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 81 | public void keyguardDone(boolean authenticated, boolean wakeup) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 82 | checkPermission(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 83 | mKeyguardViewMediator.keyguardDone(authenticated, wakeup); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 86 | @Override // Binder interface |
| 87 | public void setOccluded(boolean isOccluded) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 88 | checkPermission(); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 89 | mKeyguardViewMediator.setOccluded(isOccluded); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 90 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 91 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 92 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 93 | public void dismiss() { |
| 94 | checkPermission(); |
| 95 | mKeyguardViewMediator.dismiss(); |
| 96 | } |
| 97 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 98 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 99 | public void onDreamingStarted() { |
| 100 | checkPermission(); |
| 101 | mKeyguardViewMediator.onDreamingStarted(); |
| 102 | } |
| 103 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 104 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 105 | public void onDreamingStopped() { |
| 106 | checkPermission(); |
| 107 | mKeyguardViewMediator.onDreamingStopped(); |
| 108 | } |
| 109 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 110 | @Override // Binder interface |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame^] | 111 | public void onStartedGoingToSleep(int reason) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 112 | checkPermission(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame^] | 113 | mKeyguardViewMediator.onStartedGoingToSleep(reason); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 116 | @Override // Binder interface |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame^] | 117 | public void onFinishedGoingToSleep(int reason) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 118 | checkPermission(); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame^] | 119 | mKeyguardViewMediator.onFinishedGoingToSleep(reason); |
| 120 | } |
| 121 | |
| 122 | @Override // Binder interface |
| 123 | public void onStartedWakingUp(IKeyguardShowCallback callback) { |
| 124 | checkPermission(); |
| 125 | mKeyguardViewMediator.onStartedWakingUp(callback); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 128 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 129 | public void setKeyguardEnabled(boolean enabled) { |
| 130 | checkPermission(); |
| 131 | mKeyguardViewMediator.setKeyguardEnabled(enabled); |
| 132 | } |
| 133 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 134 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 135 | public void onSystemReady() { |
| 136 | checkPermission(); |
| 137 | mKeyguardViewMediator.onSystemReady(); |
| 138 | } |
| 139 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 140 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 141 | public void doKeyguardTimeout(Bundle options) { |
| 142 | checkPermission(); |
| 143 | mKeyguardViewMediator.doKeyguardTimeout(options); |
| 144 | } |
| 145 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 146 | @Override // Binder interface |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 147 | public void setCurrentUser(int userId) { |
| 148 | checkPermission(); |
| 149 | mKeyguardViewMediator.setCurrentUser(userId); |
| 150 | } |
| 151 | |
| 152 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 153 | public void onBootCompleted() { |
| 154 | checkPermission(); |
| 155 | mKeyguardViewMediator.onBootCompleted(); |
| 156 | } |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 157 | |
| 158 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 159 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 160 | checkPermission(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 161 | mKeyguardViewMediator.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 162 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 163 | |
| 164 | @Override |
| 165 | public void onActivityDrawn() { |
| 166 | checkPermission(); |
| 167 | mKeyguardViewMediator.onActivityDrawn(); |
| 168 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 169 | }; |
| 170 | } |
| 171 | |