Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a179062a authored by Han Wang's avatar Han Wang
Browse files

KeyguardStateMonitor: Don't get IUsbRestrict service in constructor

 * If boot up is "too fast" and Trust HAL starts a bit slowly,
   we may end up getting a NULL IUsbRestrict service in
   constructor. This causes a NPE later in onShowingStateChanged().

 * To avoid this, we just try to get IUsbRestrict service in
   onShowingStateChanged(). This adds a little overhead, but prevents
   possible crashes.

Change-Id: Idc09cc1700aad8753244789a1f14ea1d5267f77c
parent e4f75f0e
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
    private final LockPatternUtils mLockPatternUtils;
    private final StateCallback mCallback;

    private IUsbRestrict mUsbRestrictor;
    private IUsbRestrict mUsbRestrictor = null;
    private ContentResolver mContentResolver;

    IKeystoreService mKeystoreService;
@@ -77,12 +77,6 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
        } catch (RemoteException e) {
            Slog.w(TAG, "Remote Exception", e);
        }

        try {
            mUsbRestrictor = IUsbRestrict.getService();
        } catch (NoSuchElementException | RemoteException ignored) {
            // Ignore, the hal is not available
        }
    }

    public boolean isShowing() {
@@ -116,6 +110,20 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
            Slog.e(TAG, "Error informing keystore of screen lock", e);
        }

        if (mUsbRestrictor == null) {
            try {
                mUsbRestrictor = IUsbRestrict.getService();
            } catch (NoSuchElementException | RemoteException ignored) {
                // Ignore, the hal is not available
                return;
            }
        }

        if (mUsbRestrictor == null) {
            // Return for now and retry on next time
            return;
        }

        boolean shouldRestrictUsb = LineageSettings.Secure.getInt(mContentResolver,
                LineageSettings.Secure.TRUST_RESTRICT_USB_KEYGUARD, 0) == 1;
        if (shouldRestrictUsb) {