Merge "Don't handle the system UI visibility at server side"

This commit is contained in:
Tiger Huang
2020-11-18 13:30:06 +00:00
committed by Android (Google) Code Review
12 changed files with 62 additions and 55 deletions

View File

@@ -78,6 +78,7 @@ import android.util.DisplayMetrics;
import android.util.Singleton;
import android.util.Size;
import android.view.Surface;
import android.view.WindowInsetsController.Appearance;
import com.android.internal.app.LocalePicker;
import com.android.internal.app.procstats.ProcessStats;
@@ -2116,7 +2117,7 @@ public class ActivityManager {
// the task having a secure window or having previews disabled
private final boolean mIsRealSnapshot;
private final int mWindowingMode;
private final int mSystemUiVisibility;
private final @Appearance int mAppearance;
private final boolean mIsTranslucent;
// Must be one of the named color spaces, otherwise, always use SRGB color space.
private final ColorSpace mColorSpace;
@@ -2125,7 +2126,7 @@ public class ActivityManager {
@NonNull ComponentName topActivityComponent, HardwareBuffer snapshot,
@NonNull ColorSpace colorSpace, int orientation, int rotation, Point taskSize,
Rect contentInsets, boolean isLowResolution, boolean isRealSnapshot,
int windowingMode, int systemUiVisibility, boolean isTranslucent) {
int windowingMode, @Appearance int appearance, boolean isTranslucent) {
mId = id;
mTopActivityComponent = topActivityComponent;
mSnapshot = snapshot;
@@ -2138,7 +2139,7 @@ public class ActivityManager {
mIsLowResolution = isLowResolution;
mIsRealSnapshot = isRealSnapshot;
mWindowingMode = windowingMode;
mSystemUiVisibility = systemUiVisibility;
mAppearance = appearance;
mIsTranslucent = isTranslucent;
}
@@ -2157,7 +2158,7 @@ public class ActivityManager {
mIsLowResolution = source.readBoolean();
mIsRealSnapshot = source.readBoolean();
mWindowingMode = source.readInt();
mSystemUiVisibility = source.readInt();
mAppearance = source.readInt();
mIsTranslucent = source.readBoolean();
}
@@ -2265,11 +2266,11 @@ public class ActivityManager {
}
/**
* @return The system ui visibility flags for the top most visible fullscreen window at the
* @return The {@link Appearance} flags for the top most visible fullscreen window at the
* time that the snapshot was taken.
*/
public int getSystemUiVisibility() {
return mSystemUiVisibility;
public @Appearance int getAppearance() {
return mAppearance;
}
@Override
@@ -2291,7 +2292,7 @@ public class ActivityManager {
dest.writeBoolean(mIsLowResolution);
dest.writeBoolean(mIsRealSnapshot);
dest.writeInt(mWindowingMode);
dest.writeInt(mSystemUiVisibility);
dest.writeInt(mAppearance);
dest.writeBoolean(mIsTranslucent);
}
@@ -2311,7 +2312,7 @@ public class ActivityManager {
+ " mIsLowResolution=" + mIsLowResolution
+ " mIsRealSnapshot=" + mIsRealSnapshot
+ " mWindowingMode=" + mWindowingMode
+ " mSystemUiVisibility=" + mSystemUiVisibility
+ " mAppearance=" + mAppearance
+ " mIsTranslucent=" + mIsTranslucent;
}
@@ -2336,7 +2337,7 @@ public class ActivityManager {
private Rect mContentInsets;
private boolean mIsRealSnapshot;
private int mWindowingMode;
private int mSystemUiVisibility;
private @Appearance int mAppearance;
private boolean mIsTranslucent;
private int mPixelFormat;
@@ -2393,8 +2394,8 @@ public class ActivityManager {
return this;
}
public Builder setSystemUiVisibility(int systemUiVisibility) {
mSystemUiVisibility = systemUiVisibility;
public Builder setAppearance(@Appearance int appearance) {
mAppearance = appearance;
return this;
}
@@ -2428,7 +2429,7 @@ public class ActivityManager {
false /* isLowResolution */,
mIsRealSnapshot,
mWindowingMode,
mSystemUiVisibility,
mAppearance,
mIsTranslucent);
}

View File

@@ -381,7 +381,7 @@ message WindowStateProto {
optional int32 requested_width = 18;
optional int32 requested_height = 19;
optional int32 view_visibility = 20 [(.android.typedef) = "android.view.View.Visibility"];
optional int32 system_ui_visibility = 21;
optional int32 system_ui_visibility = 21 [deprecated=true];
optional bool has_surface = 22;
optional bool is_ready_for_display = 23;
optional .android.graphics.RectProto display_frame = 24 [deprecated=true];

View File

@@ -29,6 +29,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.util.Log;
import android.view.WindowInsetsController.Appearance;
/**
* Data for a single thumbnail.
@@ -43,7 +44,7 @@ public class ThumbnailData {
public boolean isRealSnapshot;
public boolean isTranslucent;
public int windowingMode;
public int systemUiVisibility;
public @Appearance int appearance;
public float scale;
public long snapshotId;
@@ -57,7 +58,6 @@ public class ThumbnailData {
isRealSnapshot = true;
isTranslucent = false;
windowingMode = WINDOWING_MODE_UNDEFINED;
systemUiVisibility = 0;
snapshotId = 0;
}
@@ -93,7 +93,7 @@ public class ThumbnailData {
isRealSnapshot = snapshot.isRealSnapshot();
isTranslucent = snapshot.isTranslucent();
windowingMode = snapshot.getWindowingMode();
systemUiVisibility = snapshot.getSystemUiVisibility();
appearance = snapshot.getAppearance();
snapshotId = snapshot.getId();
}
}

View File

@@ -29,7 +29,7 @@
int32 inset_bottom = 5;
bool is_real_snapshot = 6;
int32 windowing_mode = 7;
int32 system_ui_visibility = 8;
int32 system_ui_visibility = 8 [deprecated=true];
bool is_translucent = 9;
string top_activity_component = 10;
// deprecated because original width and height are stored now instead of the scale.
@@ -40,4 +40,5 @@
int32 task_width = 14;
// The task height when the snapshot was taken
int32 task_height = 15;
int32 appearance = 16;
}

View File

@@ -118,7 +118,6 @@ import android.app.ActivityManager;
import android.app.ActivityThread;
import android.app.LoadedApk;
import android.app.ResourcesManager;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -2746,7 +2745,7 @@ public class DisplayPolicy {
final int dockedAppearance = updateLightStatusBarLw(0 /* appearance */,
mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState,
mDockedStackBounds);
final int disableFlags = win.getSystemUiVisibility() & StatusBarManager.DISABLE_MASK;
final int disableFlags = win.getDisableFlags();
final int opaqueAppearance = updateSystemBarsLw(win, disableFlags);
final WindowState navColorWin = chooseNavigationColorWindowLw(
mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState,

View File

@@ -41,6 +41,7 @@ import android.view.InsetsState;
import android.view.SurfaceControl;
import android.view.ThreadedRenderer;
import android.view.WindowInsets.Type;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowManager.LayoutParams;
import com.android.internal.annotations.VisibleForTesting;
@@ -333,7 +334,7 @@ class TaskSnapshotController {
builder.setOrientation(activity.getTask().getConfiguration().orientation);
builder.setRotation(activity.getTask().getDisplayContent().getRotation());
builder.setWindowingMode(task.getWindowingMode());
builder.setSystemUiVisibility(getSystemUiVisibility(task));
builder.setAppearance(getAppearance(task));
return true;
}
@@ -507,7 +508,7 @@ class TaskSnapshotController {
hwBitmap.getColorSpace(), mainWindow.getConfiguration().orientation,
mainWindow.getWindowConfiguration().getRotation(), new Point(taskWidth, taskHeight),
contentInsets, false /* isLowResolution */, false /* isRealSnapshot */,
task.getWindowingMode(), getSystemUiVisibility(task), false);
task.getWindowingMode(), getAppearance(task), false);
}
/**
@@ -584,16 +585,16 @@ class TaskSnapshotController {
}
/**
* @return The SystemUI visibility flags for the top fullscreen opaque window in the given
* @return The {@link Appearance} flags for the top fullscreen opaque window in the given
* {@param task}.
*/
private int getSystemUiVisibility(Task task) {
private @Appearance int getAppearance(Task task) {
final ActivityRecord topFullscreenActivity = task.getTopFullscreenActivity();
final WindowState topFullscreenOpaqueWindow = topFullscreenActivity != null
? topFullscreenActivity.getTopFullscreenOpaqueWindow()
: null;
if (topFullscreenOpaqueWindow != null) {
return topFullscreenOpaqueWindow.getSystemUiVisibility();
return topFullscreenOpaqueWindow.mAttrs.insetsFlags.appearance;
}
return 0;
}

View File

@@ -197,7 +197,7 @@ class TaskSnapshotLoader {
hwBitmap.getColorSpace(), proto.orientation, proto.rotation, taskSize,
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
loadLowResolutionBitmap, proto.isRealSnapshot, proto.windowingMode,
proto.systemUiVisibility, proto.isTranslucent);
proto.appearance, proto.isTranslucent);
} catch (IOException e) {
Slog.w(TAG, "Unable to load task snapshot data for taskId=" + taskId);
return null;

View File

@@ -382,7 +382,7 @@ class TaskSnapshotPersister {
proto.insetBottom = mSnapshot.getContentInsets().bottom;
proto.isRealSnapshot = mSnapshot.isRealSnapshot();
proto.windowingMode = mSnapshot.getWindowingMode();
proto.systemUiVisibility = mSnapshot.getSystemUiVisibility();
proto.appearance = mSnapshot.getAppearance();
proto.isTranslucent = mSnapshot.isTranslucent();
proto.topActivityComponent = mSnapshot.getTopActivityComponent().flattenToString();
proto.id = mSnapshot.getId();

View File

@@ -2212,15 +2212,12 @@ public class WindowManagerService extends IWindowManager.Stub
if (attrs != null) {
displayPolicy.adjustWindowParamsLw(win, attrs, pid, uid);
win.mToken.adjustWindowParams(win, attrs);
int systemUiVisibility = attrs.systemUiVisibility
| attrs.subtreeSystemUiVisibility;
if ((systemUiVisibility & DISABLE_MASK) != 0) {
// if they don't have the permission, mask out the status bar bits
if (!hasStatusBarPermission(pid, uid)) {
systemUiVisibility &= ~DISABLE_MASK;
}
int disableFlags =
(attrs.systemUiVisibility | attrs.subtreeSystemUiVisibility) & DISABLE_MASK;
if (disableFlags != 0 && !hasStatusBarPermission(pid, uid)) {
disableFlags = 0;
}
win.mSystemUiVisibility = systemUiVisibility;
win.mDisableFlags = disableFlags;
if (win.mAttrs.type != attrs.type) {
throw new IllegalArgumentException(
"Window type can not be changed after the window is added.");

View File

@@ -176,7 +176,6 @@ import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
import static com.android.server.wm.WindowStateProto.STACK_ID;
import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
@@ -231,6 +230,7 @@ import android.view.Surface.Rotation;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewTreeObserver;
import android.view.WindowInfo;
import android.view.WindowInsets.Type.InsetsType;
@@ -307,7 +307,14 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
final boolean mIsWallpaper;
private final boolean mIsFloatingLayer;
int mViewVisibility;
int mSystemUiVisibility;
/**
* Flags to disable system UI functions. This can only be set by the one which has the
* status bar permission.
*
* @see View.SystemUiVisibility
*/
int mDisableFlags;
/**
* The visibility flag of the window based on policy like {@link WindowManagerPolicy}.
@@ -1284,9 +1291,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
return mAttrs;
}
/** Retrieves the current system UI visibility flags associated with this window. */
int getSystemUiVisibility() {
return mSystemUiVisibility;
/** Retrieves the flags used to disable system UI functions. */
int getDisableFlags() {
return mDisableFlags;
}
/** Gets the layer at which this window's surface will be Z-ordered. */
@@ -3889,7 +3896,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
proto.write(REQUESTED_WIDTH, mRequestedWidth);
proto.write(REQUESTED_HEIGHT, mRequestedHeight);
proto.write(VIEW_VISIBILITY, mViewVisibility);
proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
proto.write(HAS_SURFACE, mHasSurface);
proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
@@ -3965,8 +3971,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
+ " mHaveFrame=" + mHaveFrame
+ " mObscured=" + mObscured);
pw.println(prefix
+ " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
if (mDisableFlags != 0) {
pw.println(prefix + "mDisableFlags=" + ViewDebug.flagsToString(
View.class, "mSystemUiVisibility", mDisableFlags));
}
}
if (!isVisibleByPolicy() || !mLegacyPolicyVisibilityAfterAnim || !mAppOpVisibility
|| isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow

View File

@@ -16,6 +16,7 @@
package com.android.server.wm;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
@@ -41,7 +42,6 @@ import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.platform.test.annotations.Presubmit;
import android.util.ArraySet;
import android.view.View;
import androidx.test.filters.SmallTest;
@@ -135,7 +135,7 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
final long id = 1234L;
final ComponentName activityComponent = new ComponentName("package", ".Class");
final int windowingMode = WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
final int systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN;
final int appearance = APPEARANCE_LIGHT_STATUS_BARS;
final int pixelFormat = PixelFormat.RGBA_8888;
final int orientation = Configuration.ORIENTATION_PORTRAIT;
final float scaleFraction = 0.25f;
@@ -147,7 +147,7 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
new ActivityManager.TaskSnapshot.Builder();
builder.setId(id);
builder.setTopActivityComponent(activityComponent);
builder.setSystemUiVisibility(systemUiVisibility);
builder.setAppearance(appearance);
builder.setWindowingMode(windowingMode);
builder.setColorSpace(sRGB);
builder.setOrientation(orientation);
@@ -164,7 +164,7 @@ public class TaskSnapshotControllerTest extends WindowTestsBase {
ActivityManager.TaskSnapshot snapshot = builder.build();
assertEquals(id, snapshot.getId());
assertEquals(activityComponent, snapshot.getTopActivityComponent());
assertEquals(systemUiVisibility, snapshot.getSystemUiVisibility());
assertEquals(appearance, snapshot.getAppearance());
assertEquals(windowingMode, snapshot.getWindowingMode());
assertEquals(sRGB, snapshot.getColorSpace());
// Snapshots created with the Builder class are always high-res. The only way to get a

View File

@@ -18,6 +18,8 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
@@ -36,7 +38,6 @@ import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.ArraySet;
import android.view.Surface;
import android.view.View;
import androidx.test.filters.MediumTest;
@@ -362,17 +363,16 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
}
@Test
public void testSystemUiVisibilityPersistAndLoadSnapshot() {
final int lightBarFlags = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
| View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
public void testAppearancePersistAndLoadSnapshot() {
final int lightBarFlags = APPEARANCE_LIGHT_STATUS_BARS | APPEARANCE_LIGHT_NAVIGATION_BARS;
TaskSnapshot a = new TaskSnapshotBuilder()
.setSystemUiVisibility(0)
.build();
TaskSnapshot b = new TaskSnapshotBuilder()
.setSystemUiVisibility(lightBarFlags)
.build();
assertEquals(0, a.getSystemUiVisibility());
assertEquals(lightBarFlags, b.getSystemUiVisibility());
assertEquals(0, a.getAppearance());
assertEquals(lightBarFlags, b.getAppearance());
mPersister.persistSnapshot(1, mTestUserId, a);
mPersister.persistSnapshot(2, mTestUserId, b);
mPersister.waitForQueueEmpty();
@@ -382,8 +382,8 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
false /* isLowResolution */);
assertNotNull(snapshotA);
assertNotNull(snapshotB);
assertEquals(0, snapshotA.getSystemUiVisibility());
assertEquals(lightBarFlags, snapshotB.getSystemUiVisibility());
assertEquals(0, snapshotA.getAppearance());
assertEquals(lightBarFlags, snapshotB.getAppearance());
}
@Test