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