Merge "Always report the real wallpaper visibility when wallpaper supports ambient mode."

This commit is contained in:
Josh Yang
2023-06-27 22:29:36 +00:00
committed by Android (Google) Code Review
4 changed files with 26 additions and 12 deletions

View File

@@ -142,9 +142,13 @@ public final class WallpaperInfo implements Parcelable {
mShowMetadataInPreview = sa.getBoolean(
com.android.internal.R.styleable.Wallpaper_showMetadataInPreview,
false);
// Watch wallpapers support ambient mode by default.
final boolean defSupportsAmbientMode =
pm.hasSystemFeature(PackageManager.FEATURE_WATCH);
mSupportsAmbientMode = sa.getBoolean(
com.android.internal.R.styleable.Wallpaper_supportsAmbientMode,
false);
defSupportsAmbientMode);
mShouldUseDefaultUnfoldTransition = sa.getBoolean(
com.android.internal.R.styleable
.Wallpaper_shouldUseDefaultUnfoldTransition, true);

View File

@@ -16,6 +16,7 @@
package android.service.wallpaper;
import android.app.WallpaperInfo;
import android.graphics.Rect;
import android.service.wallpaper.IWallpaperConnection;
@@ -25,6 +26,7 @@ import android.service.wallpaper.IWallpaperConnection;
oneway interface IWallpaperService {
void attach(IWallpaperConnection connection,
IBinder windowToken, int windowType, boolean isPreview,
int reqWidth, int reqHeight, in Rect padding, int displayId, int which);
int reqWidth, int reqHeight, in Rect padding, int displayId, int which,
in WallpaperInfo info);
void detach(IBinder windowToken);
}

View File

@@ -1606,8 +1606,13 @@ public abstract class WallpaperService extends Service {
if (!mDestroyed) {
mDisplayState =
mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getCommittedState();
boolean displayVisible = Display.isOnState(mDisplayState) && !mIsScreenTurningOn;
boolean visible = mVisible && displayVisible;
boolean displayFullyOn = Display.isOnState(mDisplayState) && !mIsScreenTurningOn;
boolean supportsAmbientMode =
mIWallpaperEngine.mInfo == null
? false
: mIWallpaperEngine.mInfo.supportsAmbientMode();
// Report visibility only if display is fully on or wallpaper supports ambient mode.
boolean visible = mVisible && (displayFullyOn || supportsAmbientMode);
if (DEBUG) {
Log.v(
TAG,
@@ -2060,7 +2065,7 @@ public abstract class WallpaperService extends Service {
}
private void updateFrozenState(boolean frozenRequested) {
if (mIWallpaperEngine.mWallpaperManager.getWallpaperInfo() == null
if (mIWallpaperEngine.mInfo == null
// Procees the unfreeze command in case the wallaper became static while
// being paused.
&& frozenRequested) {
@@ -2355,6 +2360,7 @@ public abstract class WallpaperService extends Service {
final DisplayManager mDisplayManager;
final Display mDisplay;
final WallpaperManager mWallpaperManager;
@Nullable final WallpaperInfo mInfo;
Engine mEngine;
@SetWallpaperFlags int mWhich;
@@ -2362,7 +2368,7 @@ public abstract class WallpaperService extends Service {
IWallpaperEngineWrapper(WallpaperService service,
IWallpaperConnection conn, IBinder windowToken,
int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
int displayId, @SetWallpaperFlags int which) {
int displayId, @SetWallpaperFlags int which, @Nullable WallpaperInfo info) {
mWallpaperManager = getSystemService(WallpaperManager.class);
mCaller = new HandlerCaller(service, service.onProvideEngineLooper(), this, true);
mConnection = conn;
@@ -2374,6 +2380,7 @@ public abstract class WallpaperService extends Service {
mDisplayPadding.set(padding);
mDisplayId = displayId;
mWhich = which;
mInfo = info;
// Create a display context before onCreateEngine.
mDisplayManager = getSystemService(DisplayManager.class);
@@ -2447,8 +2454,7 @@ public abstract class WallpaperService extends Service {
Trace.beginSection("WPMS.mConnection.engineShown");
try {
mConnection.engineShown(this);
Log.d(TAG, "Wallpaper has updated the surface:"
+ mWallpaperManager.getWallpaperInfo());
Log.d(TAG, "Wallpaper has updated the surface:" + mInfo);
} catch (RemoteException e) {
Log.w(TAG, "Wallpaper host disappeared", e);
}
@@ -2702,11 +2708,11 @@ public abstract class WallpaperService extends Service {
@Override
public void attach(IWallpaperConnection conn, IBinder windowToken,
int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
int displayId, @SetWallpaperFlags int which) {
int displayId, @SetWallpaperFlags int which, @Nullable WallpaperInfo info) {
Trace.beginSection("WPMS.ServiceWrapper.attach");
IWallpaperEngineWrapper engineWrapper =
new IWallpaperEngineWrapper(mTarget, conn, windowToken, windowType,
isPreview, reqWidth, reqHeight, padding, displayId, which);
isPreview, reqWidth, reqHeight, padding, displayId, which, info);
synchronized (mActiveEngines) {
mActiveEngines.put(windowToken, engineWrapper);
}

View File

@@ -955,7 +955,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
try {
connection.mService.attach(connection, mToken, TYPE_WALLPAPER, false,
wpdData.mWidth, wpdData.mHeight,
wpdData.mPadding, mDisplayId, wallpaper.mWhich);
wpdData.mPadding, mDisplayId, wallpaper.mWhich, connection.mInfo);
} catch (RemoteException e) {
Slog.w(TAG, "Failed attaching wallpaper on display", e);
if (wallpaper != null && !wallpaper.wallpaperUpdating
@@ -3588,7 +3588,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
final int hasPrivilege = mIPackageManager.checkPermission(
android.Manifest.permission.AMBIENT_WALLPAPER, wi.getPackageName(),
serviceUserId);
if (hasPrivilege != PERMISSION_GRANTED) {
// All watch wallpapers support ambient mode by default.
if (hasPrivilege != PERMISSION_GRANTED
&& !mIPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH, 0)) {
String msg = "Selected service does not have "
+ android.Manifest.permission.AMBIENT_WALLPAPER
+ ": " + componentName;