Merge "Configure the number of tasks to scan to determine Home visibility." into tm-qpr-dev am: 59565c560a am: e715974ded
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19094859 Change-Id: I9e509d6d25d4bb9c84af073a99f6bf01b1a2c970 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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(() ->
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
return task.getActivityType() == ACTIVITY_TYPE_HOME;
|
||||
}
|
||||
|
||||
// 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 false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5850,4 +5850,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>
|
||||
|
||||
@@ -3977,6 +3977,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" />
|
||||
|
||||
Reference in New Issue
Block a user