Merge "Configure the number of tasks to scan to determine Home visibility." into tm-qpr-dev am: 59565c560a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19094859 Change-Id: I11fc4da1b1b89265d6ac386cca8f3603451b86bb 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(listener);
|
||||||
Preconditions.checkNotNull(executor);
|
Preconditions.checkNotNull(executor);
|
||||||
try {
|
try {
|
||||||
listener.init(mContext, executor, this);
|
listener.init(mContext, executor);
|
||||||
getService().registerProcessObserver(listener.mObserver);
|
getService().registerProcessObserver(listener.mObserver);
|
||||||
// Notify upon first registration.
|
// Notify upon first registration.
|
||||||
executor.execute(() ->
|
executor.execute(() ->
|
||||||
|
|||||||
@@ -16,16 +16,17 @@
|
|||||||
|
|
||||||
package android.app;
|
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.SuppressLint;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,20 +40,21 @@ import java.util.concurrent.Executor;
|
|||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
@TestApi
|
@TestApi
|
||||||
public abstract class HomeVisibilityListener {
|
public abstract class HomeVisibilityListener {
|
||||||
private Context mContext;
|
private ActivityTaskManager mActivityTaskManager;
|
||||||
private ActivityManager mActivityManager;
|
|
||||||
private Executor mExecutor;
|
private Executor mExecutor;
|
||||||
|
private int mMaxScanTasksForHomeVisibility;
|
||||||
/** @hide */
|
/** @hide */
|
||||||
android.app.IProcessObserver.Stub mObserver;
|
android.app.IProcessObserver.Stub mObserver;
|
||||||
/** @hide */
|
/** @hide */
|
||||||
boolean mIsHomeActivityVisible;
|
boolean mIsHomeActivityVisible;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
void init(Context context, Executor executor, ActivityManager activityManager) {
|
void init(Context context, Executor executor) {
|
||||||
mContext = context;
|
mActivityTaskManager = ActivityTaskManager.getInstance();
|
||||||
mActivityManager = activityManager;
|
|
||||||
mIsHomeActivityVisible = isHomeActivityVisible();
|
|
||||||
mExecutor = executor;
|
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() {
|
private boolean isHomeActivityVisible() {
|
||||||
List<ActivityManager.RunningTaskInfo> tasks = mActivityManager.getRunningTasks(1);
|
List<ActivityManager.RunningTaskInfo> tasksTopToBottom = mActivityTaskManager.getTasks(
|
||||||
if (tasks == null || tasks.isEmpty()) {
|
mMaxScanTasksForHomeVisibility, /* filterOnlyVisibleRecents= */ true,
|
||||||
|
/* keepIntentExtra= */ false, DEFAULT_DISPLAY);
|
||||||
|
if (tasksTopToBottom == null || tasksTopToBottom.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String top = tasks.get(0).topActivity.getPackageName();
|
for (int i = 0, taskSize = tasksTopToBottom.size(); i < taskSize; ++i) {
|
||||||
if (top == null) {
|
ActivityManager.RunningTaskInfo task = tasksTopToBottom.get(i);
|
||||||
return false;
|
if (!task.isVisible()
|
||||||
|
|| (task.baseIntent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return task.getActivityType() == ACTIVITY_TYPE_HOME;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5838,4 +5838,7 @@
|
|||||||
|
|
||||||
<!-- Whether the wake screen on notifications feature is available. -->
|
<!-- Whether the wake screen on notifications feature is available. -->
|
||||||
<bool name="config_pulseOnNotificationsAvailable">true</bool>
|
<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>
|
</resources>
|
||||||
|
|||||||
@@ -3967,6 +3967,8 @@
|
|||||||
|
|
||||||
<java-symbol type="string" name="config_customCountryDetector" />
|
<java-symbol type="string" name="config_customCountryDetector" />
|
||||||
|
|
||||||
|
<java-symbol type="integer" name="config_maxScanTasksForHomeVisibility" />
|
||||||
|
|
||||||
<!-- For Foldables -->
|
<!-- For Foldables -->
|
||||||
<java-symbol type="array" name="config_foldedDeviceStates" />
|
<java-symbol type="array" name="config_foldedDeviceStates" />
|
||||||
<java-symbol type="array" name="config_deviceStatesOnWhichToWakeUp" />
|
<java-symbol type="array" name="config_deviceStatesOnWhichToWakeUp" />
|
||||||
|
|||||||
Reference in New Issue
Block a user