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

Commit d4c13186 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix null pointer exception when getting app label for headless app" into udc-d1-dev

parents 2eaffb6c 6249cd22
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line 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.
        // 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.
        // Otherwise, just use the top-level application name.
        Intent launchIntent = pm.getLaunchIntentForPackage(mContext.getPackageName());
        Intent launchIntent = pm.getLaunchIntentForPackage(mContext.getPackageName());
        if (launchIntent == null) {
            return getDefaultCallingApplicationLabel();
        }
        List<ResolveInfo> infos =
        List<ResolveInfo> infos =
                pm.queryIntentActivities(
                pm.queryIntentActivities(
                        launchIntent, PackageManager.ResolveInfoFlags.of(MATCH_DEFAULT_ONLY));
                        launchIntent, PackageManager.ResolveInfoFlags.of(MATCH_DEFAULT_ONLY));
        if (infos.size() > 0) {
        if (infos.size() > 0) {
            return infos.get(0).loadLabel(pm);
            return infos.get(0).loadLabel(pm);
        }
        }
        return getDefaultCallingApplicationLabel();
    }

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