Merge "Isolate count of visible window from mirror of uid state" into sc-v2-dev
This commit is contained in:
@@ -19,7 +19,7 @@ package com.android.server.wm;
|
|||||||
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
|
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
|
||||||
|
|
||||||
import android.app.ActivityManager.ProcessState;
|
import android.app.ActivityManager.ProcessState;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -29,15 +29,14 @@ import java.io.PrintWriter;
|
|||||||
* adjustment) or getting state from window manager (background start check).
|
* adjustment) or getting state from window manager (background start check).
|
||||||
*/
|
*/
|
||||||
class MirrorActiveUids {
|
class MirrorActiveUids {
|
||||||
private final SparseArray<UidRecord> mUidStates = new SparseArray<>();
|
/** Uid -> process state. */
|
||||||
|
private final SparseIntArray mUidStates = new SparseIntArray();
|
||||||
|
|
||||||
|
/** Uid -> number of non-app visible windows belong to the uid. */
|
||||||
|
private final SparseIntArray mNumNonAppVisibleWindowMap = new SparseIntArray();
|
||||||
|
|
||||||
synchronized void onUidActive(int uid, int procState) {
|
synchronized void onUidActive(int uid, int procState) {
|
||||||
UidRecord r = mUidStates.get(uid);
|
mUidStates.put(uid, procState);
|
||||||
if (r == null) {
|
|
||||||
r = new UidRecord();
|
|
||||||
mUidStates.put(uid, r);
|
|
||||||
}
|
|
||||||
r.mProcState = procState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onUidInactive(int uid) {
|
synchronized void onUidInactive(int uid) {
|
||||||
@@ -45,22 +44,28 @@ class MirrorActiveUids {
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onUidProcStateChanged(int uid, int procState) {
|
synchronized void onUidProcStateChanged(int uid, int procState) {
|
||||||
final UidRecord r = mUidStates.get(uid);
|
final int index = mUidStates.indexOfKey(uid);
|
||||||
if (r != null) {
|
if (index >= 0) {
|
||||||
r.mProcState = procState;
|
mUidStates.setValueAt(index, procState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized @ProcessState int getUidState(int uid) {
|
synchronized @ProcessState int getUidState(int uid) {
|
||||||
final UidRecord r = mUidStates.get(uid);
|
return mUidStates.get(uid, PROCESS_STATE_NONEXISTENT);
|
||||||
return r != null ? r.mProcState : PROCESS_STATE_NONEXISTENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when the surface of non-application (exclude toast) window is shown or hidden. */
|
/** Called when the surface of non-application (exclude toast) window is shown or hidden. */
|
||||||
synchronized void onNonAppSurfaceVisibilityChanged(int uid, boolean visible) {
|
synchronized void onNonAppSurfaceVisibilityChanged(int uid, boolean visible) {
|
||||||
final UidRecord r = mUidStates.get(uid);
|
final int index = mNumNonAppVisibleWindowMap.indexOfKey(uid);
|
||||||
if (r != null) {
|
if (index >= 0) {
|
||||||
r.mNumNonAppVisibleWindow += visible ? 1 : -1;
|
final int num = mNumNonAppVisibleWindowMap.valueAt(index) + (visible ? 1 : -1);
|
||||||
|
if (num > 0) {
|
||||||
|
mNumNonAppVisibleWindowMap.setValueAt(index, num);
|
||||||
|
} else {
|
||||||
|
mNumNonAppVisibleWindowMap.removeAt(index);
|
||||||
|
}
|
||||||
|
} else if (visible) {
|
||||||
|
mNumNonAppVisibleWindowMap.append(uid, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,23 +75,15 @@ class MirrorActiveUids {
|
|||||||
* {@link VisibleActivityProcessTracker}.
|
* {@link VisibleActivityProcessTracker}.
|
||||||
*/
|
*/
|
||||||
synchronized boolean hasNonAppVisibleWindow(int uid) {
|
synchronized boolean hasNonAppVisibleWindow(int uid) {
|
||||||
final UidRecord r = mUidStates.get(uid);
|
return mNumNonAppVisibleWindowMap.get(uid) > 0;
|
||||||
return r != null && r.mNumNonAppVisibleWindow > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void dump(PrintWriter pw, String prefix) {
|
synchronized void dump(PrintWriter pw, String prefix) {
|
||||||
pw.print(prefix + "NumNonAppVisibleWindowByUid:[");
|
pw.print(prefix + "NumNonAppVisibleWindowUidMap:[");
|
||||||
for (int i = mUidStates.size() - 1; i >= 0; i--) {
|
for (int i = mNumNonAppVisibleWindowMap.size() - 1; i >= 0; i--) {
|
||||||
final UidRecord r = mUidStates.valueAt(i);
|
pw.print(" " + mNumNonAppVisibleWindowMap.keyAt(i) + ":"
|
||||||
if (r.mNumNonAppVisibleWindow > 0) {
|
+ mNumNonAppVisibleWindowMap.valueAt(i));
|
||||||
pw.print(" " + mUidStates.keyAt(i) + ":" + r.mNumNonAppVisibleWindow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pw.println("]");
|
pw.println("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class UidRecord {
|
|
||||||
@ProcessState int mProcState;
|
|
||||||
int mNumNonAppVisibleWindow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -800,7 +800,6 @@ public class WindowStateTests extends WindowTestsBase {
|
|||||||
@Test
|
@Test
|
||||||
public void testHasActiveVisibleWindow() {
|
public void testHasActiveVisibleWindow() {
|
||||||
final int uid = ActivityBuilder.DEFAULT_FAKE_UID;
|
final int uid = ActivityBuilder.DEFAULT_FAKE_UID;
|
||||||
mAtm.mActiveUids.onUidActive(uid, 0 /* any proc state */);
|
|
||||||
|
|
||||||
final WindowState app = createWindow(null, TYPE_APPLICATION, "app", uid);
|
final WindowState app = createWindow(null, TYPE_APPLICATION, "app", uid);
|
||||||
app.mActivityRecord.setVisible(false);
|
app.mActivityRecord.setVisible(false);
|
||||||
@@ -828,6 +827,11 @@ public class WindowStateTests extends WindowTestsBase {
|
|||||||
// Make the application overlay window visible. It should be a valid active visible window.
|
// Make the application overlay window visible. It should be a valid active visible window.
|
||||||
overlay.onSurfaceShownChanged(true);
|
overlay.onSurfaceShownChanged(true);
|
||||||
assertTrue(mAtm.hasActiveVisibleWindow(uid));
|
assertTrue(mAtm.hasActiveVisibleWindow(uid));
|
||||||
|
|
||||||
|
// The number of windows should be independent of the existence of uid state.
|
||||||
|
mAtm.mActiveUids.onUidInactive(uid);
|
||||||
|
mAtm.mActiveUids.onUidActive(uid, 0 /* any proc state */);
|
||||||
|
assertTrue(mAtm.mActiveUids.hasNonAppVisibleWindow(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseTestDisplay(addWindows = W_ACTIVITY)
|
@UseTestDisplay(addWindows = W_ACTIVITY)
|
||||||
|
|||||||
Reference in New Issue
Block a user