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.server.policy.keyguard; 18 19import android.content.Context; 20import android.os.Bundle; 21import android.os.IBinder; 22import android.os.RemoteException; 23import android.util.Slog; 24 25import com.android.internal.policy.IKeyguardDismissCallback; 26import com.android.internal.policy.IKeyguardDrawnCallback; 27import com.android.internal.policy.IKeyguardExitCallback; 28import com.android.internal.policy.IKeyguardService; 29import com.android.internal.policy.IKeyguardStateCallback; 30 31import java.io.PrintWriter; 32 33/** 34 * A wrapper class for KeyguardService. It implements IKeyguardService to ensure the interface 35 * remains consistent. 36 * 37 */ 38public class KeyguardServiceWrapper implements IKeyguardService { 39 private KeyguardStateMonitor mKeyguardStateMonitor; 40 private IKeyguardService mService; 41 private String TAG = "KeyguardServiceWrapper"; 42 43 public KeyguardServiceWrapper(Context context, IKeyguardService service, 44 KeyguardStateMonitor.StateCallback callback) { 45 mService = service; 46 mKeyguardStateMonitor = new KeyguardStateMonitor(context, service, callback); 47 } 48 49 @Override // Binder interface 50 public void verifyUnlock(IKeyguardExitCallback callback) { 51 try { 52 mService.verifyUnlock(callback); 53 } catch (RemoteException e) { 54 Slog.w(TAG , "Remote Exception", e); 55 } 56 } 57 58 @Override // Binder interface 59 public void setOccluded(boolean isOccluded, boolean animate) { 60 try { 61 mService.setOccluded(isOccluded, animate); 62 } catch (RemoteException e) { 63 Slog.w(TAG , "Remote Exception", e); 64 } 65 } 66 67 @Override 68 public void addStateMonitorCallback(IKeyguardStateCallback callback) { 69 try { 70 mService.addStateMonitorCallback(callback); 71 } catch (RemoteException e) { 72 Slog.w(TAG , "Remote Exception", e); 73 } 74 } 75 76 @Override // Binder interface 77 public void dismiss(IKeyguardDismissCallback callback) { 78 try { 79 mService.dismiss(callback); 80 } catch (RemoteException e) { 81 Slog.w(TAG , "Remote Exception", e); 82 } 83 } 84 85 @Override // Binder interface 86 public void onDreamingStarted() { 87 try { 88 mService.onDreamingStarted(); 89 } catch (RemoteException e) { 90 Slog.w(TAG , "Remote Exception", e); 91 } 92 } 93 94 @Override // Binder interface 95 public void onDreamingStopped() { 96 try { 97 mService.onDreamingStopped(); 98 } catch (RemoteException e) { 99 Slog.w(TAG , "Remote Exception", e); 100 } 101 } 102 103 @Override 104 public void onStartedGoingToSleep(int reason) { 105 try { 106 mService.onStartedGoingToSleep(reason); 107 } catch (RemoteException e) { 108 Slog.w(TAG , "Remote Exception", e); 109 } 110 } 111 112 @Override 113 public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) { 114 try { 115 mService.onFinishedGoingToSleep(reason, cameraGestureTriggered); 116 } catch (RemoteException e) { 117 Slog.w(TAG , "Remote Exception", e); 118 } 119 } 120 121 @Override 122 public void onStartedWakingUp() { 123 try { 124 mService.onStartedWakingUp(); 125 } catch (RemoteException e) { 126 Slog.w(TAG , "Remote Exception", e); 127 } 128 } 129 130 @Override 131 public void onScreenTurningOn(IKeyguardDrawnCallback callback) { 132 try { 133 mService.onScreenTurningOn(callback); 134 } catch (RemoteException e) { 135 Slog.w(TAG , "Remote Exception", e); 136 } 137 } 138 139 @Override 140 public void onScreenTurnedOn() { 141 try { 142 mService.onScreenTurnedOn(); 143 } catch (RemoteException e) { 144 Slog.w(TAG , "Remote Exception", e); 145 } 146 } 147 148 @Override 149 public void onScreenTurnedOff() { 150 try { 151 mService.onScreenTurnedOff(); 152 } catch (RemoteException e) { 153 Slog.w(TAG , "Remote Exception", e); 154 } 155 } 156 157 @Override // Binder interface 158 public void setKeyguardEnabled(boolean enabled) { 159 try { 160 mService.setKeyguardEnabled(enabled); 161 } catch (RemoteException e) { 162 Slog.w(TAG , "Remote Exception", e); 163 } 164 } 165 166 @Override // Binder interface 167 public void onSystemReady() { 168 try { 169 mService.onSystemReady(); 170 } catch (RemoteException e) { 171 Slog.w(TAG , "Remote Exception", e); 172 } 173 } 174 175 @Override // Binder interface 176 public void doKeyguardTimeout(Bundle options) { 177 try { 178 mService.doKeyguardTimeout(options); 179 } catch (RemoteException e) { 180 Slog.w(TAG , "Remote Exception", e); 181 } 182 } 183 184 @Override // Binder interface 185 public void setSwitchingUser(boolean switching) { 186 try { 187 mService.setSwitchingUser(switching); 188 } catch (RemoteException e) { 189 Slog.w(TAG , "Remote Exception", e); 190 } 191 } 192 193 @Override // Binder interface 194 public void setCurrentUser(int userId) { 195 mKeyguardStateMonitor.setCurrentUser(userId); 196 try { 197 mService.setCurrentUser(userId); 198 } catch (RemoteException e) { 199 Slog.w(TAG , "Remote Exception", e); 200 } 201 } 202 203 @Override // Binder interface 204 public void onBootCompleted() { 205 try { 206 mService.onBootCompleted(); 207 } catch (RemoteException e) { 208 Slog.w(TAG , "Remote Exception", e); 209 } 210 } 211 212 @Override // Binder interface 213 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 214 try { 215 mService.startKeyguardExitAnimation(startTime, fadeoutDuration); 216 } catch (RemoteException e) { 217 Slog.w(TAG , "Remote Exception", e); 218 } 219 } 220 221 @Override 222 public void onShortPowerPressedGoHome() { 223 try { 224 mService.onShortPowerPressedGoHome(); 225 } catch (RemoteException e) { 226 Slog.w(TAG , "Remote Exception", e); 227 } 228 } 229 230 @Override // Binder interface 231 public IBinder asBinder() { 232 return mService.asBinder(); 233 } 234 235 public boolean isShowing() { 236 return mKeyguardStateMonitor.isShowing(); 237 } 238 239 public boolean isTrusted() { 240 return mKeyguardStateMonitor.isTrusted(); 241 } 242 243 public boolean hasLockscreenWallpaper() { 244 return mKeyguardStateMonitor.hasLockscreenWallpaper(); 245 } 246 247 public boolean isSecure(int userId) { 248 return mKeyguardStateMonitor.isSecure(userId); 249 } 250 251 public boolean isInputRestricted() { 252 return mKeyguardStateMonitor.isInputRestricted(); 253 } 254 255 public void dump(String prefix, PrintWriter pw) { 256 mKeyguardStateMonitor.dump(prefix, pw); 257 } 258}