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

Commit 8c78deec authored by Govinda Wasserman's avatar Govinda Wasserman
Browse files

Fix default home detection logic

Default home detection did not perform priority analysis if the default
home was null. Furthermore, the default home was retrieved before it was
initialized. By listening for boot complete and package changes, we
ensure that we get the correct default home.

This fixes incorrect handle behavior and metrics logging.

Test: Tested locally
BUG:135150547
Change-Id: I4ca36cbb1fad73905344e2434592a1893c178e23
FIX:135150547
parent 7fc7f9ce
Loading
Loading
Loading
Loading
+33 −5
Original line number Diff line number Diff line
@@ -16,14 +16,13 @@

package com.android.systemui.assist;

import static com.android.systemui.shared.system.PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.os.Handler;
import android.os.SystemClock;
import android.provider.Settings;
@@ -44,6 +43,7 @@ import com.android.systemui.statusbar.StatusBarState;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
@@ -68,6 +68,14 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
    private static final boolean DEFAULT_SUPPRESS_ON_LAUNCHER = false;
    private static final boolean DEFAULT_SUPPRESS_ON_APPS = false;

    private static final String[] DEFAULT_HOME_CHANGE_ACTIONS = new String[] {
            PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED,
            Intent.ACTION_BOOT_COMPLETED,
            Intent.ACTION_PACKAGE_ADDED,
            Intent.ACTION_PACKAGE_CHANGED,
            Intent.ACTION_PACKAGE_REMOVED
    };

    private final StatusBarStateController.StateListener mStatusBarStateListener =
            new StatusBarStateController.StateListener() {
                @Override
@@ -110,8 +118,7 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
            mDefaultHome = getCurrentDefaultHome();
        }
    };
    private final IntentFilter mDefaultHomeIntentFilter =
            new IntentFilter(ACTION_PREFERRED_ACTIVITY_CHANGED);
    private final IntentFilter mDefaultHomeIntentFilter;
    private final Runnable mResetConsecutiveTaskSwitches = this::resetConsecutiveTaskSwitches;

    private final Handler mHandler;
@@ -146,6 +153,10 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {
        mStatusBarStateController = Dependency.get(StatusBarStateController.class);
        mActivityManagerWrapper = ActivityManagerWrapper.getInstance();
        mOverviewProxyService = Dependency.get(OverviewProxyService.class);
        mDefaultHomeIntentFilter = new IntentFilter();
        for (String action : DEFAULT_HOME_CHANGE_ACTIONS) {
            mDefaultHomeIntentFilter.addAction(action);
        }
    }

    @Override
@@ -205,7 +216,24 @@ final class AssistHandleReminderExpBehavior implements BehaviorController {

    @Nullable
    private static ComponentName getCurrentDefaultHome() {
        return PackageManagerWrapper.getInstance().getHomeActivities(new ArrayList<>());
        List<ResolveInfo> homeActivities = new ArrayList<>();
        ComponentName defaultHome =
                PackageManagerWrapper.getInstance().getHomeActivities(homeActivities);
        if (defaultHome != null) {
            return defaultHome;
        }

        int topPriority = Integer.MIN_VALUE;
        ComponentName topComponent = null;
        for (ResolveInfo resolveInfo : homeActivities) {
            if (resolveInfo.priority > topPriority) {
                topComponent = resolveInfo.activityInfo.getComponentName();
                topPriority = resolveInfo.priority;
            } else if (resolveInfo.priority == topPriority) {
                topComponent = null;
            }
        }
        return topComponent;
    }

    private void handleStatusBarStateChanged(int newState) {
+39 −6
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.assist;

import static com.android.systemui.shared.system.PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
@@ -25,6 +23,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;

import androidx.annotation.Nullable;

@@ -38,6 +37,7 @@ import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.StatusBar;

import java.util.ArrayList;
import java.util.List;

/** Class to monitor and report the state of the phone. */
final class PhoneStateMonitor {
@@ -53,6 +53,14 @@ final class PhoneStateMonitor {
    private static final int PHONE_STATE_APP_IMMERSIVE = 9;
    private static final int PHONE_STATE_APP_FULLSCREEN = 10;

    private static final String[] DEFAULT_HOME_CHANGE_ACTIONS = new String[] {
            PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED,
            Intent.ACTION_BOOT_COMPLETED,
            Intent.ACTION_PACKAGE_ADDED,
            Intent.ACTION_PACKAGE_CHANGED,
            Intent.ACTION_PACKAGE_REMOVED
    };

    private final Context mContext;
    private final StatusBarStateController mStatusBarStateController;

@@ -64,14 +72,17 @@ final class PhoneStateMonitor {
        mStatusBarStateController = Dependency.get(StatusBarStateController.class);

        ActivityManagerWrapper activityManagerWrapper = ActivityManagerWrapper.getInstance();
        mDefaultHome = PackageManagerWrapper.getInstance().getHomeActivities(new ArrayList<>());
        mDefaultHome = getCurrentDefaultHome();
        IntentFilter intentFilter = new IntentFilter();
        for (String action : DEFAULT_HOME_CHANGE_ACTIONS) {
            intentFilter.addAction(action);
        }
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                mDefaultHome =
                        PackageManagerWrapper.getInstance().getHomeActivities(new ArrayList<>());
                mDefaultHome = getCurrentDefaultHome();
            }
        }, new IntentFilter(ACTION_PREFERRED_ACTIVITY_CHANGED));
        }, intentFilter);
        mLauncherShowing = isLauncherShowing(activityManagerWrapper.getRunningTask());
        activityManagerWrapper.registerTaskStackListener(new TaskStackChangeListener() {
            @Override
@@ -93,6 +104,28 @@ final class PhoneStateMonitor {
        return phoneState;
    }

    @Nullable
    private static ComponentName getCurrentDefaultHome() {
        List<ResolveInfo> homeActivities = new ArrayList<>();
        ComponentName defaultHome =
                PackageManagerWrapper.getInstance().getHomeActivities(homeActivities);
        if (defaultHome != null) {
            return defaultHome;
        }

        int topPriority = Integer.MIN_VALUE;
        ComponentName topComponent = null;
        for (ResolveInfo resolveInfo : homeActivities) {
            if (resolveInfo.priority > topPriority) {
                topComponent = resolveInfo.activityInfo.getComponentName();
                topPriority = resolveInfo.priority;
            } else if (resolveInfo.priority == topPriority) {
                topComponent = null;
            }
        }
        return topComponent;
    }

    private int getPhoneLockscreenState() {
        if (isDozing()) {
            return PHONE_STATE_AOD1;