Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17047306 authored by Josh Yang's avatar Josh Yang
Browse files

Always report the real wallpaper visibility when wallpaper supports

ambient mode.

On wear os, wallpaper needs to be visible during STATE_DOZE and
STATE_DOZE_SUSPEND. This changes the wallpaper visibility reporting
logic so that wallpaper can be visible as long as it supports ambient
mode.

Since all wear os wallpapers (watch faces) are supposed to be visible
during ambient mode, this change also makes all wear os wallpapers
support ambient mode by default, and exclude watches from the ambient
wallpaper permission check.

Bug: 287174294
Test: wallpaper is now visible during ambient mode
Change-Id: Ic4fa68d8040782e659aac100b10a8126a232baa1
parent 9e9cef8d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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);
+3 −1
Original line number Diff line number Diff line
@@ -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);
}
+14 −8
Original line number Diff line number Diff line
@@ -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);
            }
+4 −2
Original line number Diff line number Diff line
@@ -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;