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;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeUnit;
/**
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
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;
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
@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) {
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;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ResolveInfo;
import androidx.annotation.Nullable;
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 {
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;
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
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;