KeyguardService.java revision c0b676dcc23baedb12946c3470d9fa9b02cb39e0
1/* 2 * Copyright (C) 2013 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 17package com.android.keyguard; 18 19import java.io.FileDescriptor; 20import java.io.PrintWriter; 21 22import android.app.Service; 23import android.content.Intent; 24import static android.content.pm.PackageManager.PERMISSION_GRANTED; 25 26import android.os.Binder; 27import android.os.Bundle; 28import android.os.Debug; 29import android.os.IBinder; 30import android.util.Log; 31 32import com.android.internal.policy.IKeyguardService; 33import com.android.internal.policy.IKeyguardExitCallback; 34import com.android.internal.policy.IKeyguardShowCallback; 35import com.android.internal.widget.LockPatternUtils; 36 37public class KeyguardService extends Service { 38 static final String TAG = "KeyguardService"; 39 static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD; 40 private KeyguardViewMediator mKeyguardViewMediator; 41 42 @Override 43 public void onCreate() { 44 if (mKeyguardViewMediator == null) { 45 mKeyguardViewMediator = new KeyguardViewMediator( 46 KeyguardService.this, new LockPatternUtils(KeyguardService.this)); 47 } 48 Log.v(TAG, "onCreate()"); 49 } 50 51 @Override 52 public IBinder onBind(Intent intent) { 53 return mBinder; 54 } 55 56 @Override 57 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 58 // TODO 59 } 60 61 void checkPermission() { 62 if (getBaseContext().checkCallingOrSelfPermission(PERMISSION) != PERMISSION_GRANTED) { 63 Log.w(TAG, "Caller needs permission '" + PERMISSION + "' to call " + Debug.getCaller()); 64 throw new SecurityException("Access denied to process: " + Binder.getCallingPid() 65 + ", must have permission " + PERMISSION); 66 } 67 } 68 69 private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() { 70 public boolean isShowing() { 71 return mKeyguardViewMediator.isShowing(); 72 } 73 public boolean isSecure() { 74 return mKeyguardViewMediator.isSecure(); 75 } 76 public boolean isShowingAndNotHidden() { 77 return mKeyguardViewMediator.isShowingAndNotHidden(); 78 } 79 public boolean isInputRestricted() { 80 return mKeyguardViewMediator.isInputRestricted(); 81 } 82 public void verifyUnlock(IKeyguardExitCallback callback) { 83 mKeyguardViewMediator.verifyUnlock(callback); 84 } 85 public void keyguardDone(boolean authenticated, boolean wakeup) { 86 checkPermission(); 87 mKeyguardViewMediator.keyguardDone(authenticated, wakeup); 88 } 89 public void setHidden(boolean isHidden) { 90 checkPermission(); 91 mKeyguardViewMediator.setHidden(isHidden); 92 } 93 public void dismiss() { 94 mKeyguardViewMediator.dismiss(); 95 } 96 public void onWakeKeyWhenKeyguardShowing(int keyCode) { 97 checkPermission(); 98 mKeyguardViewMediator.onWakeKeyWhenKeyguardShowing(keyCode); 99 } 100 public void onWakeMotionWhenKeyguardShowing() { 101 checkPermission(); 102 mKeyguardViewMediator.onWakeMotionWhenKeyguardShowing(); 103 } 104 public void onDreamingStarted() { 105 checkPermission(); 106 mKeyguardViewMediator.onDreamingStarted(); 107 } 108 public void onDreamingStopped() { 109 checkPermission(); 110 mKeyguardViewMediator.onDreamingStopped(); 111 } 112 public void onScreenTurnedOff(int reason) { 113 checkPermission(); 114 mKeyguardViewMediator.onScreenTurnedOff(reason); 115 } 116 public void onScreenTurnedOn(IKeyguardShowCallback callback) { 117 checkPermission(); 118 mKeyguardViewMediator.onScreenTurnedOn(callback); 119 } 120 public void setKeyguardEnabled(boolean enabled) { 121 checkPermission(); 122 mKeyguardViewMediator.setKeyguardEnabled(enabled); 123 } 124 public boolean isDismissable() { 125 return mKeyguardViewMediator.isDismissable(); 126 } 127 public void onSystemReady() { 128 checkPermission(); 129 mKeyguardViewMediator.onSystemReady(); 130 } 131 public void doKeyguardTimeout(Bundle options) { 132 checkPermission(); 133 mKeyguardViewMediator.doKeyguardTimeout(options); 134 } 135 public void setCurrentUser(int userId) { 136 checkPermission(); 137 mKeyguardViewMediator.setCurrentUser(userId); 138 } 139 public void showAssistant() { 140 checkPermission(); 141 mKeyguardViewMediator.showAssistant(); 142 } 143 }; 144 145} 146 147