19431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna/*
2dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller * Copyright (C) 2012 The Android Open Source Project
39431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna *
49431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * Licensed under the Apache License, Version 2.0 (the "License");
59431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * you may not use this file except in compliance with the License.
69431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * You may obtain a copy of the License at
79431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna *
89431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna *      http://www.apache.org/licenses/LICENSE-2.0
99431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna *
109431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * Unless required by applicable law or agreed to in writing, software
119431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * distributed under the License is distributed on an "AS IS" BASIS,
129431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * See the License for the specific language governing permissions and
149431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna * limitations under the License.
159431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna */
169431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
17dcb3d84b82cc2448d04e73359a716581bfb657dbJim Millerpackage com.android.internal.policy.impl.keyguard;
189431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
199431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport com.android.internal.policy.IFaceLockCallback;
209431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport com.android.internal.policy.IFaceLockInterface;
219431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport com.android.internal.widget.LockPatternUtils;
229431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
233223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonnaimport android.app.admin.DevicePolicyManager;
249431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.content.ComponentName;
259431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.content.Context;
269431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.content.Intent;
279431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.content.ServiceConnection;
289431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.os.Handler;
299431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.os.IBinder;
3022001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonnaimport android.os.Looper;
319431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.os.Message;
32acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Rossimport android.os.PowerManager;
339431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.os.RemoteException;
349431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.util.Log;
359431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonnaimport android.view.View;
369431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
373223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonnapublic class FaceUnlock implements BiometricSensorUnlock, Handler.Callback {
389431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
399431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private static final boolean DEBUG = false;
409431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private static final String TAG = "FULLockscreen";
419431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
429431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private final Context mContext;
43ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    private final LockPatternUtils mLockPatternUtils;
449431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
45ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // TODO: is mServiceRunning needed or can we just use mIsRunning or check if mService is null?
46ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    private boolean mServiceRunning = false;
47257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    // TODO: now that the code has been restructure to do almost all operations from a handler, this
48257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    // lock may no longer be necessary.
49ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    private final Object mServiceRunningLock = new Object();
509431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private IFaceLockInterface mService;
519431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private boolean mBoundToService = false;
52ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    private View mFaceUnlockView;
539431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
549431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private Handler mHandler;
5561413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    private final int MSG_SERVICE_CONNECTED = 0;
5661413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    private final int MSG_SERVICE_DISCONNECTED = 1;
5761413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    private final int MSG_UNLOCK = 2;
5861413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    private final int MSG_CANCEL = 3;
5961413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    private final int MSG_REPORT_FAILED_ATTEMPT = 4;
60667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna    private final int MSG_POKE_WAKELOCK = 5;
619431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
62ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // TODO: This was added for the purpose of adhering to what the biometric interface expects
63ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // the isRunning() function to return.  However, it is probably not necessary to have both
64ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // mRunning and mServiceRunning.  I'd just rather wait to change that logic.
65257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    private volatile boolean mIsRunning = false;
669431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
67ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // So the user has a consistent amount of time when brought to the backup method from Face
68ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    // Unlock
699431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private final int BACKUP_LOCK_TIMEOUT = 5000;
709431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
71dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller    KeyguardSecurityCallback mKeyguardScreenCallback;
729431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
73257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
74257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Stores some of the structures that Face Unlock will need to access and creates the handler
75257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * will be used to execute messages on the UI thread.
76257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
77000464ac012471d301c6e48a8228291519915e17Jim Miller    public FaceUnlock(Context context) {
789431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        mContext = context;
79dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller        mLockPatternUtils = new LockPatternUtils(context);
809431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        mHandler = new Handler(this);
819431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
829431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
83000464ac012471d301c6e48a8228291519915e17Jim Miller    public void setKeyguardCallback(KeyguardSecurityCallback keyguardScreenCallback) {
84000464ac012471d301c6e48a8228291519915e17Jim Miller        mKeyguardScreenCallback = keyguardScreenCallback;
85000464ac012471d301c6e48a8228291519915e17Jim Miller    }
86000464ac012471d301c6e48a8228291519915e17Jim Miller
87ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
88ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * Stores and displays the view that Face Unlock is allowed to draw within.
89ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * TODO: since the layout object will eventually be shared by multiple biometric unlock
90ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * methods, we will have to add our other views (background, cancel button) here.
91ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
92ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    public void initializeView(View biometricUnlockView) {
93257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        Log.d(TAG, "initializeView()");
94ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        mFaceUnlockView = biometricUnlockView;
95ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    }
96ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna
97ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
98ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * Indicates whether Face Unlock is currently running.
99ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
1003223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    public boolean isRunning() {
101ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        return mIsRunning;
1023223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    }
1033223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna
104ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
10561413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett     * Dismisses face unlock and goes to the backup lock
106ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
10761413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett    public void stopAndShowBackup() {
10861413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett        if (DEBUG) Log.d(TAG, "stopAndShowBackup()");
10961413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett        mHandler.sendEmptyMessage(MSG_CANCEL);
1103223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    }
1113223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna
112ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
113ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * Binds to the Face Unlock service.  Face Unlock will be started when the bind completes.  The
114257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Face Unlock view is displayed to hide the backup lock while the service is starting up.
11522001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna     * Called on the UI thread.
116ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
117ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    public boolean start() {
118257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "start()");
11922001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna        if (mHandler.getLooper() != Looper.myLooper()) {
12022001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna            Log.e(TAG, "start() called off of the UI thread");
12122001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna        }
12222001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna
123ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        if (mIsRunning) {
124ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            Log.w(TAG, "start() called when already running");
125ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        }
126ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna
127ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        if (!mBoundToService) {
1284b4b954ddf34af51576441f0e3eca6d19150aadaAmith Yamasani            Log.d(TAG, "Binding to Face Unlock service for user="
1294b4b954ddf34af51576441f0e3eca6d19150aadaAmith Yamasani                    + mLockPatternUtils.getCurrentUser());
130ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            mContext.bindService(new Intent(IFaceLockInterface.class.getName()),
131ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    mConnection,
132ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    Context.BIND_AUTO_CREATE,
133ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    mLockPatternUtils.getCurrentUser());
134ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            mBoundToService = true;
135ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        } else {
136ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            Log.w(TAG, "Attempt to bind to Face Unlock when already bound");
137ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        }
138ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna
139ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        mIsRunning = true;
140ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        return true;
141ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    }
142ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna
143ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
14422001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna     * Stops Face Unlock and unbinds from the service.  Called on the UI thread.
145ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
1463223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    public boolean stop() {
147257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "stop()");
14822001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna        if (mHandler.getLooper() != Looper.myLooper()) {
149a71984f3da47c6e6e3164c170735362a3222d3adJim Miller            Log.e(TAG, "stop() called from non-UI thread");
15022001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna        }
15122001c1f96984655f7205ecbc93dd982c47b4e97Brian Colonna
152025fb93e3e5518b7db5fec049d285cfb2d28a074Steven Ross        // Clearing any old service connected messages.
153025fb93e3e5518b7db5fec049d285cfb2d28a074Steven Ross        mHandler.removeMessages(MSG_SERVICE_CONNECTED);
154025fb93e3e5518b7db5fec049d285cfb2d28a074Steven Ross
155ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        boolean mWasRunning = mIsRunning;
1561108a2cb412b054cc9e4acc48182c46c45180c0cDanielle Millett
157c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        stopUi();
158c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna
159c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        if (mBoundToService) {
160c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            if (mService != null) {
161c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                try {
162ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    mService.unregisterCallback(mFaceUnlockCallback);
163c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                } catch (RemoteException e) {
164c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                    // Not much we can do
1653223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna                }
1669431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna            }
167257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            Log.d(TAG, "Unbinding from Face Unlock service");
168c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            mContext.unbindService(mConnection);
169c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            mBoundToService = false;
170c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        } else {
171c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            // This is usually not an error when this happens.  Sometimes we will tell it to
172c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            // unbind multiple times because it's called from both onWindowFocusChanged and
173c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            // onDetachedFromWindow.
174ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            if (DEBUG) Log.d(TAG, "Attempt to unbind from Face Unlock when not bound");
1759431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
176ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        mIsRunning = false;
177ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        return mWasRunning;
1789431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
1799431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
1803223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    /**
181ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * Frees up resources used by Face Unlock and stops it if it is still running.
1823223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna     */
1833223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    public void cleanUp() {
184257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "cleanUp()");
1853223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna        if (mService != null) {
1863223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna            try {
187ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                mService.unregisterCallback(mFaceUnlockCallback);
1883223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna            } catch (RemoteException e) {
1893223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna                // Not much we can do
1903223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna            }
1913223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna            stopUi();
1923223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna            mService = null;
1939431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
1943223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    }
1953223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna
196ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
197ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     * Returns the Device Policy Manager quality for Face Unlock, which is BIOMETRIC_WEAK.
198ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
1993223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    public int getQuality() {
2003223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna        return DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
2019431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
2029431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
203ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
204257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Handles messages such that everything happens on the UI thread in a deterministic order.
205257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Calls from the Face Unlock service come from binder threads.  Calls from lockscreen typically
206257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * come from the UI thread.  This makes sure there are no race conditions between those calls.
207ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
2089431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    public boolean handleMessage(Message msg) {
2099431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        switch (msg.what) {
210257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_SERVICE_CONNECTED:
211257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                handleServiceConnected();
212257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
213257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_SERVICE_DISCONNECTED:
214257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                handleServiceDisconnected();
215257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
216257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_UNLOCK:
217257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                handleUnlock();
218257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
219257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_CANCEL:
220257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                handleCancel();
221257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
222257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_REPORT_FAILED_ATTEMPT:
223257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                handleReportFailedAttempt();
224257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
225257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            case MSG_POKE_WAKELOCK:
226dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez                handlePokeWakelock(msg.arg1);
227257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                break;
228257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            default:
229257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                Log.e(TAG, "Unhandled message");
230257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                return false;
2319431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
2329431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        return true;
2339431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
2349431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
235ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
236257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Tells the service to start its UI via an AIDL interface.  Called when the
237257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * onServiceConnected() callback is received.
238257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
239257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    void handleServiceConnected() {
240c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        Log.d(TAG, "handleServiceConnected()");
241c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna
242c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        // It is possible that an unbind has occurred in the time between the bind and when this
243c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        // function is reached.  If an unbind has already occurred, proceeding on to call startUi()
244c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        // can result in a fatal error.  Note that the onServiceConnected() callback is
245c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        // asynchronous, so this possibility would still exist if we executed this directly in
246c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        // onServiceConnected() rather than using a handler.
247c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        if (!mBoundToService) {
248c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna            Log.d(TAG, "Dropping startUi() in handleServiceConnected() because no longer bound");
249c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna            return;
250c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        }
251c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna
252257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        try {
253257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mService.registerCallback(mFaceUnlockCallback);
254257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        } catch (RemoteException e) {
255257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            Log.e(TAG, "Caught exception connecting to Face Unlock: " + e.toString());
256257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mService = null;
257257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mBoundToService = false;
258257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mIsRunning = false;
259257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            return;
260257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        }
261257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
262257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (mFaceUnlockView != null) {
263257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            IBinder windowToken = mFaceUnlockView.getWindowToken();
264257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            if (windowToken != null) {
265dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez                // When switching between portrait and landscape view while Face Unlock is running,
266dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez                // the screen will eventually go dark unless we poke the wakelock when Face Unlock
267dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez                // is restarted.
268dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller                mKeyguardScreenCallback.userActivity(0);
269dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez
270257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                int[] position;
271257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                position = new int[2];
272257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                mFaceUnlockView.getLocationInWindow(position);
273257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                startUi(windowToken, position[0], position[1], mFaceUnlockView.getWidth(),
274257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                        mFaceUnlockView.getHeight());
275257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            } else {
276257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                Log.e(TAG, "windowToken is null in handleServiceConnected()");
277257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            }
278257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        }
279257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
280257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
281257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
282257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Called when the onServiceDisconnected() callback is received.  This should not happen during
283257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * normal operation.  It indicates an error has occurred.
284257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
285257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    void handleServiceDisconnected() {
286257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        Log.e(TAG, "handleServiceDisconnected()");
287257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        // TODO: this lock may no longer be needed now that everything is being called from a
288257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        // handler
289257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        synchronized (mServiceRunningLock) {
290257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mService = null;
291257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mServiceRunning = false;
292257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        }
293257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        mBoundToService = false;
294257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        mIsRunning = false;
295257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
296257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
297257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
29861413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett     * Stops the Face Unlock service and tells the device to grant access to the user.
299257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
300257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    void handleUnlock() {
301257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "handleUnlock()");
302257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        stop();
303257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        mKeyguardScreenCallback.reportSuccessfulUnlockAttempt();
304dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller        mKeyguardScreenCallback.dismiss(true);
305257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
306257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
307257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
30861413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett     * Stops the Face Unlock service and goes to the backup lock.
309257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
310257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    void handleCancel() {
311257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "handleCancel()");
312667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        // We are going to the backup method, so we don't want to see Face Unlock again until the
313667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        // next time the user visits keyguard.
314667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(false);
315667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna
31661413b5ed215accd7b4f3eaf80edeab2f330aa49Danielle Millett        mKeyguardScreenCallback.showBackupSecurity();
317257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        stop();
318dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller        mKeyguardScreenCallback.userActivity(BACKUP_LOCK_TIMEOUT);
319257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
320257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
321257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
3227019325e183ba1abf1869ccffc4b1ecd8c771a44Brian Colonna     * Increments the number of failed Face Unlock attempts.
323257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
324257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    void handleReportFailedAttempt() {
325257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "handleReportFailedAttempt()");
326667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        // We are going to the backup method, so we don't want to see Face Unlock again until the
327667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        // next time the user visits keyguard.
328667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(false);
329257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
330667b5d58b9e8b77221c87811c5c9aab1bfe44ffaBrian Colonna        mKeyguardScreenCallback.reportFailedUnlockAttempt();
331257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
332257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
333257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
334acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Ross     * If the screen is on, pokes the wakelock to keep the screen alive and active for a specific
335acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Ross     * amount of time.
336257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
337dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez    void handlePokeWakelock(int millis) {
338acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Ross      PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
339acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Ross      if (powerManager.isScreenOn()) {
340dcb3d84b82cc2448d04e73359a716581bfb657dbJim Miller        mKeyguardScreenCallback.userActivity(millis);
341acbe41fc1316cf16f03de80c84ea311cc4f55ffbSteven Ross      }
342257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    }
343257f2ecc97d294e95b069547466d2054926d960fBrian Colonna
344257f2ecc97d294e95b069547466d2054926d960fBrian Colonna    /**
345257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Implements service connection methods.
346257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     */
3479431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    private ServiceConnection mConnection = new ServiceConnection() {
348ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
349257f2ecc97d294e95b069547466d2054926d960fBrian Colonna         * Called when the Face Unlock service connects after calling bind().
350ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
3519431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        public void onServiceConnected(ComponentName className, IBinder iservice) {
352257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            Log.d(TAG, "Connected to Face Unlock service");
3539431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna            mService = IFaceLockInterface.Stub.asInterface(iservice);
354257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mHandler.sendEmptyMessage(MSG_SERVICE_CONNECTED);
3559431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
3569431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
357ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
358257f2ecc97d294e95b069547466d2054926d960fBrian Colonna         * Called if the Face Unlock service unexpectedly disconnects.  This indicates an error.
359ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
3609431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        public void onServiceDisconnected(ComponentName className) {
361257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            Log.e(TAG, "Unexpected disconnect from Face Unlock service");
362257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mHandler.sendEmptyMessage(MSG_SERVICE_DISCONNECTED);
3639431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
3649431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    };
3659431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
366ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
367257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Tells the Face Unlock service to start displaying its UI and start processing.
368ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
3693223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    private void startUi(IBinder windowToken, int x, int y, int w, int h) {
370c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna        if (DEBUG) Log.d(TAG, "startUi()");
371c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        synchronized (mServiceRunningLock) {
372c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            if (!mServiceRunning) {
373c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna                Log.d(TAG, "Starting Face Unlock");
374c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                try {
3754fa995a932d876b98c393c909c4eb2e303783e59Uriel Rodriguez                    mService.startUi(windowToken, x, y, w, h,
3764fa995a932d876b98c393c909c4eb2e303783e59Uriel Rodriguez                            mLockPatternUtils.isBiometricWeakLivelinessEnabled());
377c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                } catch (RemoteException e) {
378ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    Log.e(TAG, "Caught exception starting Face Unlock: " + e.toString());
379c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                    return;
3809431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna                }
381c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                mServiceRunning = true;
382c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            } else {
383257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                Log.w(TAG, "startUi() attempted while running");
3849431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna            }
3859431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
3869431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
3879431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
388ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
389257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Tells the Face Unlock service to stop displaying its UI and stop processing.
390ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
3913223e2537d5f4e2eceeb321405dbd6da50df66b6Brian Colonna    private void stopUi() {
392257f2ecc97d294e95b069547466d2054926d960fBrian Colonna        if (DEBUG) Log.d(TAG, "stopUi()");
393ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        // Note that attempting to stop Face Unlock when it's not running is not an issue.
394ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        // Face Unlock can return, which stops it and then we try to stop it when the
395c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        // screen is turned off.  That's why we check.
396c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna        synchronized (mServiceRunningLock) {
397c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna            if (mServiceRunning) {
398c266070aec3d99c9a4d422325fbceae44c37a4d3Brian Colonna                Log.d(TAG, "Stopping Face Unlock");
399c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                try {
400c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                    mService.stopUi();
401c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                } catch (RemoteException e) {
402ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna                    Log.e(TAG, "Caught exception stopping Face Unlock: " + e.toString());
4039431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna                }
404c169366f2cc44fc395dba76c763505ac2bd61640Brian Colonna                mServiceRunning = false;
405257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            } else {
406257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                // This is usually not an error when this happens.  Sometimes we will tell it to
407257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                // stop multiple times because it's called from both onWindowFocusChanged and
408257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                // onDetachedFromWindow.
409257f2ecc97d294e95b069547466d2054926d960fBrian Colonna                if (DEBUG) Log.d(TAG, "stopUi() attempted while not running");
4109431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna            }
4119431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
4129431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    }
4139431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
414ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    /**
415257f2ecc97d294e95b069547466d2054926d960fBrian Colonna     * Implements the AIDL biometric unlock service callback interface.
416ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna     */
417ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna    private final IFaceLockCallback mFaceUnlockCallback = new IFaceLockCallback.Stub() {
418ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
419257f2ecc97d294e95b069547466d2054926d960fBrian Colonna         * Called when Face Unlock wants to grant access to the user.
420ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
4219431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        public void unlock() {
422ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            if (DEBUG) Log.d(TAG, "unlock()");
423257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mHandler.sendEmptyMessage(MSG_UNLOCK);
4249431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
4259431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
426ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
4277019325e183ba1abf1869ccffc4b1ecd8c771a44Brian Colonna         * Called when Face Unlock wants to go to the backup.
428ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
4299431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        public void cancel() {
430ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            if (DEBUG) Log.d(TAG, "cancel()");
431257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mHandler.sendEmptyMessage(MSG_CANCEL);
4329431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
4339431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
434ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
4357019325e183ba1abf1869ccffc4b1ecd8c771a44Brian Colonna         * Called when Face Unlock wants to increment the number of failed attempts.
436ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
4379431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        public void reportFailedAttempt() {
438ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna            if (DEBUG) Log.d(TAG, "reportFailedAttempt()");
439257f2ecc97d294e95b069547466d2054926d960fBrian Colonna            mHandler.sendEmptyMessage(MSG_REPORT_FAILED_ATTEMPT);
4409431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
4419431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna
442ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna        /**
443dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez         * Called when Face Unlock wants to keep the screen alive and active for a specific amount
444dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez         * of time.
445ea8441e22a4316cb6e78dd8bf461d3e658545b64Brian Colonna         */
446dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez        public void pokeWakelock(int millis) {
447dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez            if (DEBUG) Log.d(TAG, "pokeWakelock() for " + millis + "ms");
448dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez            Message message = mHandler.obtainMessage(MSG_POKE_WAKELOCK, millis, -1);
449dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez            mHandler.sendMessage(message);
4509431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna        }
451dff307697d7a7482efe4c10cb3b07b9249524a42Uriel Rodriguez
4529431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna    };
4539431366ecb4b6e4a87c0047c36548aa0bc23f2b1Brian Colonna}
454