Skip to content

Commit c266070

Browse files
author
Brian Colonna
committed
Not calling startUi() if no longer bound
After the bind to the FUL service is complete, an onServiceConnected() callback is received. This callback is asynchronous - bindService() does not block while we are waiting for the service to finish binding. Therefore, when rapidly turning the screen on and off, it is possible to call bindService() and then call unbindService() before the onServiceConnected() callback is received. When onServiceConnected() is received, startUi() is called. If the service is no longer bound, a runtime restart occurs when calling startUi(). Note that onServiceConnected() actually has its work done via a handler. The delay of calling the handler increases the possibility of unbindService() being called before trying to call startUi(). But since this problem still happens without using the handler, eliminating using the handler would not solve the problem and would just create the problems that come with performing operations on different threads since onServiceConnected() is not called on the main thread. Also note that a new instance of FaceUnlock is created in LockPatternKeyguardView with each iteration. So, if we bind/stop/bind before getting onServiceConnected(), the second bind happens in a new instance of FaceUnlock and therefore does not lead to a problem when onServiceConnected() returns as a result of the first bind. This fixes some occurrences of bug 6409767. However, this fixes the problem when turned the device on and off rapidly. It seems there are some reports of bug 6409767 where this is not the case, so I can't be sure this has any affect on those cases. This change also cleans up some debugging and modifies other debugging to try to get just the information that is useful for tracking down the bug. Change-Id: Ifa59107b9974acaa8a18b74b5d47e4cf3a794b8e
1 parent ffc731d commit c266070

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

policy/src/com/android/internal/policy/impl/FaceUnlock.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,18 @@ void handleHideFaceUnlockView() {
300300
* onServiceConnected() callback is received.
301301
*/
302302
void handleServiceConnected() {
303-
if (DEBUG) Log.d(TAG, "handleServiceConnected()");
303+
Log.d(TAG, "handleServiceConnected()");
304+
305+
// It is possible that an unbind has occurred in the time between the bind and when this
306+
// function is reached. If an unbind has already occurred, proceeding on to call startUi()
307+
// can result in a fatal error. Note that the onServiceConnected() callback is
308+
// asynchronous, so this possibility would still exist if we executed this directly in
309+
// onServiceConnected() rather than using a handler.
310+
if (!mBoundToService) {
311+
Log.d(TAG, "Dropping startUi() in handleServiceConnected() because no longer bound");
312+
return;
313+
}
314+
304315
try {
305316
mService.registerCallback(mFaceUnlockCallback);
306317
} catch (RemoteException e) {
@@ -452,25 +463,12 @@ public void onServiceDisconnected(ComponentName className) {
452463
* Tells the Face Unlock service to start displaying its UI and start processing.
453464
*/
454465
private void startUi(IBinder windowToken, int x, int y, int w, int h) {
455-
Log.d(TAG, "startUi()");
466+
if (DEBUG) Log.d(TAG, "startUi()");
456467
synchronized (mServiceRunningLock) {
457468
if (!mServiceRunning) {
458-
if (DEBUG) Log.d(TAG, "Starting Face Unlock");
469+
Log.d(TAG, "Starting Face Unlock");
459470
try {
460-
// TODO: these checks and logs are for tracking down bug 6409767 and can be
461-
// removed when that bug is fixed.
462-
if (mService == null) {
463-
Log.d(TAG, "mService is null");
464-
}
465-
if (windowToken == null) {
466-
Log.d(TAG, "windowToken is null");
467-
}
468-
if (mLockPatternUtils == null) {
469-
Log.d(TAG, "mLockPatternUtils is null");
470-
}
471-
Log.d(TAG, "x,y,w,h,live: " + x + "," + y + "," + w + "," + h + ", no");
472471
mService.startUi(windowToken, x, y, w, h, false);
473-
Log.d(TAG, "mService.startUi() called");
474472
} catch (RemoteException e) {
475473
Log.e(TAG, "Caught exception starting Face Unlock: " + e.toString());
476474
return;
@@ -492,7 +490,7 @@ private void stopUi() {
492490
// screen is turned off. That's why we check.
493491
synchronized (mServiceRunningLock) {
494492
if (mServiceRunning) {
495-
if (DEBUG) Log.d(TAG, "Stopping Face Unlock");
493+
Log.d(TAG, "Stopping Face Unlock");
496494
try {
497495
mService.stopUi();
498496
} catch (RemoteException e) {

0 commit comments

Comments
 (0)