Merge changes from topic "presubmit-am-7ba48eb6ba70402ba7633198b5ee3795" into tm-qpr-dev-plus-aosp

* changes:
  [automerge] Report visibility only when display is fully on in WallpaperService 2p: 66266df517
  Report visibility only when display is fully on in WallpaperService
This commit is contained in:
Nicolò Mazzucato
2023-04-12 10:46:26 +00:00
committed by Android (Google) Code Review
6 changed files with 152 additions and 3 deletions

View File

@@ -205,6 +205,20 @@ interface IWallpaperManager {
*/
void notifyGoingToSleep(int x, int y, in Bundle extras);
/**
* Called when the screen has been fully turned on and is visible.
*
* @hide
*/
void notifyScreenTurnedOn(int displayId);
/**
* Called when the screen starts turning on.
*
* @hide
*/
void notifyScreenTurningOn(int displayId);
/**
* Sets the wallpaper dim amount between [0f, 1f] which would be blended with the system default
* dimming. 0f doesn't add any additional dimming and 1f makes the wallpaper fully black.

View File

@@ -32,6 +32,8 @@ interface IWallpaperEngine {
oneway void setDisplayPadding(in Rect padding);
@UnsupportedAppUsage
oneway void setVisibility(boolean visible);
oneway void onScreenTurningOn();
oneway void onScreenTurnedOn();
oneway void setInAmbientMode(boolean inAmbientDisplay, long animationDuration);
@UnsupportedAppUsage
oneway void dispatchPointer(in MotionEvent event);

View File

@@ -168,6 +168,7 @@ public abstract class WallpaperService extends Service {
private static final int MSG_ZOOM = 10100;
private static final int MSG_RESIZE_PREVIEW = 10110;
private static final int MSG_REPORT_SHOWN = 10150;
private static final int MSG_UPDATE_SCREEN_TURNING_ON = 10170;
private static final int MSG_UPDATE_DIMMING = 10200;
/** limit calls to {@link Engine#onComputeColors} to at most once per second */
@@ -213,6 +214,16 @@ public abstract class WallpaperService extends Service {
boolean mInitializing = true;
boolean mVisible;
/**
* Whether the screen is turning on.
* After the display is powered on, brightness is initially off. It is turned on only after
* all windows have been drawn, and sysui notifies that it's ready (See
* {@link com.android.internal.policy.IKeyguardDrawnCallback}).
* As some wallpapers use visibility as a signal to start animations, this makes sure
* {@link Engine#onVisibilityChanged} is invoked only when the display is both on and
* visible (with brightness on).
*/
private boolean mIsScreenTurningOn;
boolean mReportedVisible;
boolean mDestroyed;
// Set to true after receiving WallpaperManager#COMMAND_FREEZE. It's reset back to false
@@ -988,6 +999,7 @@ public abstract class WallpaperService extends Service {
out.print(" mDestroyed="); out.println(mDestroyed);
out.print(prefix); out.print("mVisible="); out.print(mVisible);
out.print(" mReportedVisible="); out.println(mReportedVisible);
out.print(" mIsScreenTurningOn="); out.println(mIsScreenTurningOn);
out.print(prefix); out.print("mDisplay="); out.println(mDisplay);
out.print(prefix); out.print("mCreated="); out.print(mCreated);
out.print(" mSurfaceCreated="); out.print(mSurfaceCreated);
@@ -1522,6 +1534,13 @@ public abstract class WallpaperService extends Service {
}
}
void onScreenTurningOnChanged(boolean isScreenTurningOn) {
if (!mDestroyed) {
mIsScreenTurningOn = isScreenTurningOn;
reportVisibility();
}
}
void doVisibilityChanged(boolean visible) {
if (!mDestroyed) {
mVisible = visible;
@@ -1538,9 +1557,10 @@ public abstract class WallpaperService extends Service {
return;
}
if (!mDestroyed) {
mDisplayState = mDisplay == null ? Display.STATE_UNKNOWN :
mDisplay.getCommittedState();
boolean visible = mVisible && mDisplayState != Display.STATE_OFF;
mDisplayState =
mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getCommittedState();
boolean displayVisible = Display.isOnState(mDisplayState) && !mIsScreenTurningOn;
boolean visible = mVisible && displayVisible;
if (mReportedVisible != visible) {
mReportedVisible = visible;
if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible
@@ -2414,6 +2434,20 @@ public abstract class WallpaperService extends Service {
}
}
public void updateScreenTurningOn(boolean isScreenTurningOn) {
Message msg = mCaller.obtainMessageBO(MSG_UPDATE_SCREEN_TURNING_ON, isScreenTurningOn,
null);
mCaller.sendMessage(msg);
}
public void onScreenTurningOn() throws RemoteException {
updateScreenTurningOn(true);
}
public void onScreenTurnedOn() throws RemoteException {
updateScreenTurningOn(false);
}
@Override
public void executeMessage(Message message) {
if (mDetached.get()) {
@@ -2464,6 +2498,13 @@ public abstract class WallpaperService extends Service {
+ ": " + message.arg1);
mEngine.doVisibilityChanged(message.arg1 != 0);
break;
case MSG_UPDATE_SCREEN_TURNING_ON:
if (DEBUG) {
Log.v(TAG,
message.arg1 != 0 ? "Screen turning on" : "Screen turned on");
}
mEngine.onScreenTurningOnChanged(/* isScreenTurningOn= */ message.arg1 != 0);
break;
case MSG_WALLPAPER_OFFSETS: {
mEngine.doOffsetsChanged(true);
} break;

View File

@@ -213,6 +213,7 @@ import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.vr.VrManagerInternal;
import com.android.server.wallpaper.WallpaperManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.DisplayPolicy;
import com.android.server.wm.DisplayRotation;
@@ -404,6 +405,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
SensorPrivacyManager mSensorPrivacyManager;
DisplayManager mDisplayManager;
DisplayManagerInternal mDisplayManagerInternal;
private WallpaperManagerInternal mWallpaperManagerInternal;
boolean mPreloadedRecentApps;
final Object mServiceAcquireLock = new Object();
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
@@ -4823,11 +4827,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return bootCompleted ? mKeyguardDrawnTimeout : 5000;
}
@Nullable
private WallpaperManagerInternal getWallpaperManagerInternal() {
if (mWallpaperManagerInternal == null) {
mWallpaperManagerInternal = LocalServices.getService(WallpaperManagerInternal.class);
}
return mWallpaperManagerInternal;
}
private void reportScreenTurningOnToWallpaper(int displayId) {
WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
if (wallpaperManagerInternal != null) {
wallpaperManagerInternal.onScreenTurningOn(displayId);
}
}
private void reportScreenTurnedOnToWallpaper(int displayId) {
WallpaperManagerInternal wallpaperManagerInternal = getWallpaperManagerInternal();
if (wallpaperManagerInternal != null) {
wallpaperManagerInternal.onScreenTurnedOn(displayId);
}
}
// Called on the DisplayManager's DisplayPowerController thread.
@Override
public void screenTurningOn(int displayId, final ScreenOnListener screenOnListener) {
if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turning on...");
reportScreenTurningOnToWallpaper(displayId);
if (displayId == DEFAULT_DISPLAY) {
Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn",
0 /* cookie */);
@@ -4868,6 +4895,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
public void screenTurnedOn(int displayId) {
if (DEBUG_WAKEUP) Slog.i(TAG, "Display " + displayId + " turned on...");
reportScreenTurnedOnToWallpaper(displayId);
if (displayId != DEFAULT_DISPLAY) {
return;
}

View File

@@ -27,4 +27,10 @@ public abstract class WallpaperManagerInternal {
* Notifies the display is ready for adding wallpaper on it.
*/
public abstract void onDisplayReady(int displayId);
/** Notifies when the screen finished turning on and is visible to the user. */
public abstract void onScreenTurnedOn(int displayId);
/** Notifies when the screen starts turning on and is not yet visible to the user. */
public abstract void onScreenTurningOn(int displayId);
}

View File

@@ -1763,6 +1763,15 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
public void onDisplayReady(int displayId) {
onDisplayReadyInternal(displayId);
}
@Override
public void onScreenTurnedOn(int displayId) {
notifyScreenTurnedOn(displayId);
}
@Override
public void onScreenTurningOn(int displayId) {
notifyScreenTurningOn(displayId);
}
}
void initialize() {
@@ -2573,6 +2582,54 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
}
/**
* Propagates screen turned on event to wallpaper engine.
*/
@Override
public void notifyScreenTurnedOn(int displayId) {
synchronized (mLock) {
final WallpaperData data = mWallpaperMap.get(mCurrentUserId);
if (data != null
&& data.connection != null
&& data.connection.containsDisplay(displayId)) {
final IWallpaperEngine engine = data.connection
.getDisplayConnectorOrCreate(displayId).mEngine;
if (engine != null) {
try {
engine.onScreenTurnedOn();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
}
/**
* Propagate screen turning on event to wallpaper engine.
*/
@Override
public void notifyScreenTurningOn(int displayId) {
synchronized (mLock) {
final WallpaperData data = mWallpaperMap.get(mCurrentUserId);
if (data != null
&& data.connection != null
&& data.connection.containsDisplay(displayId)) {
final IWallpaperEngine engine = data.connection
.getDisplayConnectorOrCreate(displayId).mEngine;
if (engine != null) {
try {
engine.onScreenTurningOn();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
}
@Override
public boolean setLockWallpaperCallback(IWallpaperManagerCallback cb) {
checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW);