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

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

Merge "Configure the number of tasks to scan to determine Home visibility." into tm-qpr-dev

parents 8ccd22f4 cfefeb72
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5124,7 +5124,7 @@ public class ActivityManager {
        Preconditions.checkNotNull(listener);
        Preconditions.checkNotNull(executor);
        try {
            listener.init(mContext, executor, this);
            listener.init(mContext, executor);
            getService().registerProcessObserver(listener.mObserver);
            // Notify upon first registration.
            executor.execute(() ->
+23 −22
Original line number Diff line number Diff line
@@ -16,16 +16,17 @@

package android.app;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.view.Display.DEFAULT_DISPLAY;

import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.ComponentName;
import android.content.Context;
import android.os.Binder;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/**
@@ -39,20 +40,21 @@ import java.util.concurrent.Executor;
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@TestApi
public abstract class HomeVisibilityListener {
    private Context mContext;
    private ActivityManager mActivityManager;
    private ActivityTaskManager mActivityTaskManager;
    private Executor mExecutor;
    private int mMaxScanTasksForHomeVisibility;
    /** @hide */
    android.app.IProcessObserver.Stub mObserver;
    /** @hide */
    boolean mIsHomeActivityVisible;

    /** @hide */
    void init(Context context, Executor executor, ActivityManager activityManager) {
        mContext = context;
        mActivityManager = activityManager;
        mIsHomeActivityVisible = isHomeActivityVisible();
    void init(Context context, Executor executor) {
        mActivityTaskManager = ActivityTaskManager.getInstance();
        mExecutor = executor;
        mMaxScanTasksForHomeVisibility = context.getResources().getInteger(
                com.android.internal.R.integer.config_maxScanTasksForHomeVisibility);
        mIsHomeActivityVisible = isHomeActivityVisible();
    }

    /**
@@ -91,22 +93,21 @@ public abstract class HomeVisibilityListener {
    }

    private boolean isHomeActivityVisible() {
        List<ActivityManager.RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1);
        if (tasks == null || tasks.isEmpty()) {
        List<ActivityManager.RunningTaskInfo> tasksTopToBottom = mActivityTaskManager.getTasks(
                mMaxScanTasksForHomeVisibility, /* filterOnlyVisibleRecents= */ true,
                /* keepIntentExtra= */ false, DEFAULT_DISPLAY);
        if (tasksTopToBottom == null || tasksTopToBottom.isEmpty()) {
            return false;
        }

        String top = tasks.get(0).topActivity.getPackageName();
        if (top == null) {
            return false;
        for (int i = 0, taskSize = tasksTopToBottom.size(); i < taskSize; ++i) {
            ActivityManager.RunningTaskInfo task = tasksTopToBottom.get(i);
            if (!task.isVisible()
                    || (task.baseIntent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0) {
                continue;
            }

        // We can assume that the screen is idle if the home application is in the foreground.
        ComponentName defaultHomeComponent = mContext.getPackageManager()
                .getHomeActivities(new ArrayList<>());
        if (defaultHomeComponent == null) return false;

        String defaultHomePackage = defaultHomeComponent.getPackageName();
        return Objects.equals(top, defaultHomePackage);
            return task.getActivityType() == ACTIVITY_TYPE_HOME;
        }
        return false;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -5881,4 +5881,7 @@

    <!-- Whether the wake screen on notifications feature is available. -->
    <bool name="config_pulseOnNotificationsAvailable">true</bool>

    <!-- The number of tasks to scan to get the visibility of Home -->
    <integer name="config_maxScanTasksForHomeVisibility">10</integer>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -3978,6 +3978,8 @@

  <java-symbol type="string" name="config_customCountryDetector" />

  <java-symbol type="integer" name="config_maxScanTasksForHomeVisibility" />

  <!-- For Foldables -->
  <java-symbol type="array" name="config_foldedDeviceStates" />
  <java-symbol type="array" name="config_deviceStatesOnWhichToWakeUp" />