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

Commit 8ea210c4 authored by kwaky's avatar kwaky
Browse files

Add null check for resolveInfo and Automotive feature.

AAOS uses multi-user model, and apps become queriable after user is
unlocked. Thus we need to make sure that the querying happens at the
right time with the right user with resolveActivityAsUser.

In order not to affect the stability, we can use the null check +
Automotive check for R.

This null check + Automotive check can be removed when resolving
Activity as User is implemented in S+.

Bug: 158508455
Test: Manual
Change-Id: I58e37f795136508ef7bb53c40214ed3c76f588bf
parent e4c1cb51
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

    private final Context mContext;
    private final boolean mIsPrimaryUser;
    private final boolean mIsAutomotive;
    private final StatusBarStateController mStatusBarStateController;
    HashMap<Integer, SimData> mSimDatas = new HashMap<>();
    HashMap<Integer, ServiceState> mServiceStates = new HashMap<Integer, ServiceState>();
@@ -1749,6 +1750,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            mFaceManager.addLockoutResetCallback(mFaceLockoutResetCallback);
        }

        mIsAutomotive = isAutomotive();

        ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
        mUserManager = context.getSystemService(UserManager.class);
        mIsPrimaryUser = mUserManager.isPrimaryUser();
@@ -2469,6 +2472,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                .addCategory(Intent.CATEGORY_HOME);
        ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent,
                0 /* flags */);

        // TODO(b/160971249): Replace in the future by resolving activity as user.
        if (resolveInfo == null && mIsAutomotive) {
            Log.w(TAG, "resolveNeedsSlowUnlockTransition: returning false since activity "
                    + "could not be resolved.");
            return false;
        }

        return FALLBACK_HOME_COMPONENT.equals(resolveInfo.getComponentInfo().getComponentName());
    }

@@ -2539,6 +2550,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        return false;
    }

    private boolean isAutomotive() {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
    }

    /**
     * Remove the given observer's callback.
     *
@@ -2966,5 +2981,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                pw.println("    " + time + " " + model.toString());
            }
        }
        if (mIsAutomotive) {
            pw.println("  Running on Automotive build");
        }
    }
}