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

Commit 2f101954 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add fallback holder for home role behavior."

parents f1514a0c 8b1b37d5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -323,6 +323,7 @@
        behavior="HomeRoleBehavior"
        exclusive="true"
        label="@string/role_label_home">
        <!-- Also used by HomeRoleBehavior.getFallbackHolder(). -->
        <required-components>
            <activity>
                <intent-filter>
+36 −0
Original line number Diff line number Diff line
@@ -26,11 +26,13 @@ import android.os.UserHandle;
import android.provider.Settings;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;

import com.android.packageinstaller.role.utils.UserUtils;
import com.android.permissioncontroller.R;

import java.util.List;
import java.util.Objects;

/**
@@ -48,6 +50,40 @@ public class HomeRoleBehavior implements RoleBehavior {
        return !UserUtils.isWorkProfile(user, context);
    }

    /**
     * @see com.android.server.pm.PackageManagerService#getDefaultHomeActivity(int)
     */
    @Nullable
    @Override
    public String getFallbackHolder(@NonNull Role role, @NonNull Context context) {
        PackageManager packageManager = context.getPackageManager();
        Intent intent = role.getRequiredComponents().get(0).getIntentFilterData().createIntent();
        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE
                | PackageManager.MATCH_DIRECT_BOOT_UNAWARE);

        String packageName = null;
        int priority = Integer.MIN_VALUE;
        int resolveInfosSize = resolveInfos.size();
        for (int i = 0; i < resolveInfosSize; i++) {
            ResolveInfo resolveInfo = resolveInfos.get(i);

            // Leave the fallback to PackageManagerService if there is only the fallback home in
            // Settings, because if we fallback to it here, we cannot fallback to a normal home
            // later, and user cannot see the fallback home in the UI anyway.
            if (isSettingsApplication(resolveInfo.activityInfo.applicationInfo, context)) {
                continue;
            }
            if (resolveInfo.priority > priority) {
                packageName = resolveInfo.activityInfo.packageName;
                priority = resolveInfo.priority;
            } else if (resolveInfo.priority == priority) {
                packageName = null;
            }
        }
        return packageName;
    }

    @Override
    public void prepareApplicationPreferenceAsUser(@NonNull Role role,
            @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo,