2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package com.android.systemui.keyguard;
19 import android.app.Service;
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;
25 import android.os.Process;
26 import android.util.Log;
28 import com.android.internal.policy.IKeyguardDrawnCallback;
29 import com.android.internal.policy.IKeyguardExitCallback;
30 import com.android.internal.policy.IKeyguardService;
31 import com.android.internal.policy.IKeyguardStateCallback;
32 import com.android.systemui.SystemUIApplication;
34 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
36 public class KeyguardService extends Service {
37 static final String TAG = "KeyguardService";
38 static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;
40 private KeyguardViewMediator mKeyguardViewMediator;
43 public void onCreate() {
44 ((SystemUIApplication) getApplication()).startServicesIfNeeded();
45 mKeyguardViewMediator =
46 ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class);
50 public IBinder onBind(Intent intent) {
54 void checkPermission() {
55 // Avoid deadlock by avoiding calling back into the system process.
56 if (Binder.getCallingUid() == Process.SYSTEM_UID) return;
58 // Otherwise,explicitly check for caller permission ...
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);
66 private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() {
68 @Override // Binder interface
69 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
71 mKeyguardViewMediator.addStateMonitorCallback(callback);
74 @Override // Binder interface
75 public void verifyUnlock(IKeyguardExitCallback callback) {
77 mKeyguardViewMediator.verifyUnlock(callback);
80 @Override // Binder interface
81 public void keyguardDone(boolean authenticated, boolean wakeup) {
83 // TODO: Remove wakeup
84 mKeyguardViewMediator.keyguardDone(authenticated);
87 @Override // Binder interface
88 public void setOccluded(boolean isOccluded) {
90 mKeyguardViewMediator.setOccluded(isOccluded);
93 @Override // Binder interface
94 public void dismiss() {
96 mKeyguardViewMediator.dismiss();
99 @Override // Binder interface
100 public void onDreamingStarted() {
102 mKeyguardViewMediator.onDreamingStarted();
105 @Override // Binder interface
106 public void onDreamingStopped() {
108 mKeyguardViewMediator.onDreamingStopped();
111 @Override // Binder interface
112 public void onStartedGoingToSleep(int reason) {
114 mKeyguardViewMediator.onStartedGoingToSleep(reason);
117 @Override // Binder interface
118 public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
120 mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered);
123 @Override // Binder interface
124 public void onStartedWakingUp() {
126 mKeyguardViewMediator.onStartedWakingUp();
129 @Override // Binder interface
130 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
132 mKeyguardViewMediator.onScreenTurningOn(callback);
135 @Override // Binder interface
136 public void onScreenTurnedOn() {
138 mKeyguardViewMediator.onScreenTurnedOn();
141 @Override // Binder interface
142 public void onScreenTurnedOff() {
144 mKeyguardViewMediator.onScreenTurnedOff();
147 @Override // Binder interface
148 public void setKeyguardEnabled(boolean enabled) {
150 mKeyguardViewMediator.setKeyguardEnabled(enabled);
153 @Override // Binder interface
154 public void onSystemReady() {
156 mKeyguardViewMediator.onSystemReady();
159 @Override // Binder interface
160 public void doKeyguardTimeout(Bundle options) {
162 mKeyguardViewMediator.doKeyguardTimeout(options);
165 @Override // Binder interface
166 public void setCurrentUser(int userId) {
168 mKeyguardViewMediator.setCurrentUser(userId);
172 public void onBootCompleted() {
174 mKeyguardViewMediator.onBootCompleted();
178 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
180 mKeyguardViewMediator.startKeyguardExitAnimation(startTime, fadeoutDuration);
184 public void onActivityDrawn() {
186 mKeyguardViewMediator.onActivityDrawn();