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.os.Trace;
27 import android.util.Log;
29 import com.android.internal.policy.IKeyguardDrawnCallback;
30 import com.android.internal.policy.IKeyguardExitCallback;
31 import com.android.internal.policy.IKeyguardService;
32 import com.android.internal.policy.IKeyguardStateCallback;
33 import com.android.systemui.SystemUIApplication;
35 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
37 public class KeyguardService extends Service {
38 static final String TAG = "KeyguardService";
39 static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;
41 private KeyguardViewMediator mKeyguardViewMediator;
44 public void onCreate() {
45 ((SystemUIApplication) getApplication()).startServicesIfNeeded();
46 mKeyguardViewMediator =
47 ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class);
51 public IBinder onBind(Intent intent) {
55 void checkPermission() {
56 // Avoid deadlock by avoiding calling back into the system process.
57 if (Binder.getCallingUid() == Process.SYSTEM_UID) return;
59 // Otherwise,explicitly check for caller permission ...
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);
67 private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() {
69 @Override // Binder interface
70 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
72 mKeyguardViewMediator.addStateMonitorCallback(callback);
75 @Override // Binder interface
76 public void verifyUnlock(IKeyguardExitCallback callback) {
77 Trace.beginSection("KeyguardService.mBinder#verifyUnlock");
79 mKeyguardViewMediator.verifyUnlock(callback);
83 @Override // Binder interface
84 public void keyguardDone(boolean authenticated, boolean wakeup) {
85 Trace.beginSection("KeyguardService.mBinder#keyguardDone");
87 // TODO: Remove wakeup
88 mKeyguardViewMediator.keyguardDone(authenticated);
92 @Override // Binder interface
93 public void setOccluded(boolean isOccluded) {
94 Trace.beginSection("KeyguardService.mBinder#setOccluded");
96 mKeyguardViewMediator.setOccluded(isOccluded);
100 @Override // Binder interface
101 public void dismiss(boolean allowWhileOccluded) {
103 mKeyguardViewMediator.dismiss(allowWhileOccluded);
106 @Override // Binder interface
107 public void onDreamingStarted() {
109 mKeyguardViewMediator.onDreamingStarted();
112 @Override // Binder interface
113 public void onDreamingStopped() {
115 mKeyguardViewMediator.onDreamingStopped();
118 @Override // Binder interface
119 public void onStartedGoingToSleep(int reason) {
121 mKeyguardViewMediator.onStartedGoingToSleep(reason);
124 @Override // Binder interface
125 public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
127 mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered);
130 @Override // Binder interface
131 public void onStartedWakingUp() {
132 Trace.beginSection("KeyguardService.mBinder#onStartedWakingUp");
134 mKeyguardViewMediator.onStartedWakingUp();
138 @Override // Binder interface
139 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
140 Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn");
142 mKeyguardViewMediator.onScreenTurningOn(callback);
146 @Override // Binder interface
147 public void onScreenTurnedOn() {
148 Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn");
150 mKeyguardViewMediator.onScreenTurnedOn();
154 @Override // Binder interface
155 public void onScreenTurnedOff() {
157 mKeyguardViewMediator.onScreenTurnedOff();
160 @Override // Binder interface
161 public void setKeyguardEnabled(boolean enabled) {
163 mKeyguardViewMediator.setKeyguardEnabled(enabled);
166 @Override // Binder interface
167 public void onSystemReady() {
168 Trace.beginSection("KeyguardService.mBinder#onSystemReady");
170 mKeyguardViewMediator.onSystemReady();
174 @Override // Binder interface
175 public void doKeyguardTimeout(Bundle options) {
177 mKeyguardViewMediator.doKeyguardTimeout(options);
180 @Override // Binder interface
181 public void setCurrentUser(int userId) {
183 mKeyguardViewMediator.setCurrentUser(userId);
187 public void onBootCompleted() {
189 mKeyguardViewMediator.onBootCompleted();
193 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
194 Trace.beginSection("KeyguardService.mBinder#startKeyguardExitAnimation");
196 mKeyguardViewMediator.startKeyguardExitAnimation(startTime, fadeoutDuration);
201 public void onActivityDrawn() {
203 mKeyguardViewMediator.onActivityDrawn();