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