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

Commit c05c4cd9 authored by Anthony Alridge's avatar Anthony Alridge
Browse files

Fix null pointer exception when getting app label for headless app

Will follow up with regression test in CrossProfileAppsTest cts
test.

Test: Manual - go to settings -> Digital WellBeing -> Confirm switch profile button is shown
Test: atest frameworks/base/core/tests/coretests/src/android/content/pm/CrossProfileAppsTest.java
Bug: 295888390
Change-Id: I2c95a73434fa724f69a945809106e4de3b59a6ba
parent 6e178a6d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -344,15 +344,22 @@ public class CrossProfileApps {
        // If there is a label for the launcher intent, then use that as it is typically shorter.
        // Otherwise, just use the top-level application name.
        Intent launchIntent = pm.getLaunchIntentForPackage(mContext.getPackageName());
        if (launchIntent == null) {
            return getDefaultCallingApplicationLabel();
        }
        List<ResolveInfo> infos =
                pm.queryIntentActivities(
                        launchIntent, PackageManager.ResolveInfoFlags.of(MATCH_DEFAULT_ONLY));
        if (infos.size() > 0) {
            return infos.get(0).loadLabel(pm);
        }
        return getDefaultCallingApplicationLabel();
    }

    private CharSequence getDefaultCallingApplicationLabel() {
        return mContext.getApplicationInfo()
                .loadSafeLabel(
                        pm,
                        mContext.getPackageManager(),
                        /* ellipsizeDip= */ 0,
                        TextUtils.SAFE_STRING_FLAG_SINGLE_LINE
                                | TextUtils.SAFE_STRING_FLAG_TRIM);