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

Commit 7517b5dc authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Support wallpapers in AoD

Such wallpaper has to define supportsAmbientMode,
and set it to true on its android.service.wallpaper
meta data.

Also introduces WallpaperService.Engine#onAmbientModeChanged
to notify a live wallpaper that the display state has changed.

Change-Id: I49e846069a698b3cc3bb6e7cda98172920eaae4c
Bug: 64155983
Test: runtest -x frameworks/base/packages/SystemUI/tests/src/com/android/systemui/doze/DozeWallpaperStateTest.java
Test: runtest -x frameworks/base/tests/Internal/src/android/app/WallpaperInfoTest.java
Test: runtest -x frameworks/base/tests/Internal/src/android/service/wallpaper/WallpaperServiceTest.java
Test: set AoD wallpaper, go to aod, lock screen, launcher
Test: set regular wallpaper, go to aod, lock screen, launcher
parent 53b2d749
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -155,4 +155,9 @@ interface IWallpaperManager {
     * Unregister a callback that was receiving color updates
     */
    void unregisterWallpaperColorsCallback(IWallpaperManagerCallback cb, int userId);

    /**
     * Called from SystemUI when it shows the AoD UI.
     */
    void setInAmbientMode(boolean inAmbienMode);
}
+30 −30
Original line number Diff line number Diff line
@@ -16,18 +16,15 @@

package android.app;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
@@ -39,6 +36,9 @@ import android.util.AttributeSet;
import android.util.Printer;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

/**
@@ -76,6 +76,7 @@ public final class WallpaperInfo implements Parcelable {
    final int mContextUriResource;
    final int mContextDescriptionResource;
    final boolean mShowMetadataInPreview;
    final boolean mSupportsAmbientMode;

    /**
     * Constructor.
@@ -89,15 +90,7 @@ public final class WallpaperInfo implements Parcelable {
        mService = service;
        ServiceInfo si = service.serviceInfo;
        
        PackageManager pm = context.getPackageManager();
        String settingsActivityComponent = null;
        int thumbnailRes = -1;
        int authorRes = -1;
        int descriptionRes = -1;
        int contextUriRes = -1;
        int contextDescriptionRes = -1;
        boolean showMetadataInPreview = false;

        final PackageManager pm = context.getPackageManager();
        XmlResourceParser parser = null;
        try {
            parser = si.loadXmlMetaData(pm, WallpaperService.SERVICE_META_DATA);
@@ -123,27 +116,30 @@ public final class WallpaperInfo implements Parcelable {
            
            TypedArray sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.Wallpaper);
            settingsActivityComponent = sa.getString(
            mSettingsActivityName = sa.getString(
                    com.android.internal.R.styleable.Wallpaper_settingsActivity);

            thumbnailRes = sa.getResourceId(
            mThumbnailResource = sa.getResourceId(
                    com.android.internal.R.styleable.Wallpaper_thumbnail,
                    -1);
            authorRes = sa.getResourceId(
            mAuthorResource = sa.getResourceId(
                    com.android.internal.R.styleable.Wallpaper_author,
                    -1);
            descriptionRes = sa.getResourceId(
            mDescriptionResource = sa.getResourceId(
                    com.android.internal.R.styleable.Wallpaper_description,
                    -1);
            contextUriRes = sa.getResourceId(
            mContextUriResource = sa.getResourceId(
                    com.android.internal.R.styleable.Wallpaper_contextUri,
                    -1);
            contextDescriptionRes = sa.getResourceId(
            mContextDescriptionResource = sa.getResourceId(
                    com.android.internal.R.styleable.Wallpaper_contextDescription,
                    -1);
            showMetadataInPreview = sa.getBoolean(
            mShowMetadataInPreview = sa.getBoolean(
                    com.android.internal.R.styleable.Wallpaper_showMetadataInPreview,
                    false);
            mSupportsAmbientMode = sa.getBoolean(
                    com.android.internal.R.styleable.Wallpaper_supportsAmbientMode,
                    false);

            sa.recycle();
        } catch (NameNotFoundException e) {
@@ -152,14 +148,6 @@ public final class WallpaperInfo implements Parcelable {
        } finally {
            if (parser != null) parser.close();
        }
        
        mSettingsActivityName = settingsActivityComponent;
        mThumbnailResource = thumbnailRes;
        mAuthorResource = authorRes;
        mDescriptionResource = descriptionRes;
        mContextUriResource = contextUriRes;
        mContextDescriptionResource = contextDescriptionRes;
        mShowMetadataInPreview = showMetadataInPreview;
    }

    WallpaperInfo(Parcel source) {
@@ -170,6 +158,7 @@ public final class WallpaperInfo implements Parcelable {
        mContextUriResource = source.readInt();
        mContextDescriptionResource = source.readInt();
        mShowMetadataInPreview = source.readInt() != 0;
        mSupportsAmbientMode = source.readInt() != 0;
        mService = ResolveInfo.CREATOR.createFromParcel(source);
    }
    
@@ -325,6 +314,16 @@ public final class WallpaperInfo implements Parcelable {
        return mShowMetadataInPreview;
    }

    /**
     * Returns whether a wallpaper was optimized or not for ambient mode.
     *
     * @return {@code true} if wallpaper can draw in ambient mode.
     * @hide
     */
    public boolean getSupportsAmbientMode() {
        return mSupportsAmbientMode;
    }

    /**
     * Return the class name of an activity that provides a settings UI for
     * the wallpaper.  You can launch this activity be starting it with
@@ -366,6 +365,7 @@ public final class WallpaperInfo implements Parcelable {
        dest.writeInt(mContextUriResource);
        dest.writeInt(mContextDescriptionResource);
        dest.writeInt(mShowMetadataInPreview ? 1 : 0);
        dest.writeInt(mSupportsAmbientMode ? 1 : 0);
        mService.writeToParcel(dest, flags);
    }

+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ oneway interface IWallpaperEngine {
    void setDesiredSize(int width, int height);
    void setDisplayPadding(in Rect padding);
    void setVisibility(boolean visible);
    void setInAmbientMode(boolean inAmbientDisplay);
    void dispatchPointer(in MotionEvent event);
    void dispatchWallpaperCommand(String action, int x, int y,
            int z, in Bundle extras);
+64 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public abstract class WallpaperService extends Service {
    private static final int DO_DETACH = 20;
    private static final int DO_SET_DESIRED_SIZE = 30;
    private static final int DO_SET_DISPLAY_PADDING = 40;
    private static final int DO_IN_AMBIENT_MODE = 50;

    private static final int MSG_UPDATE_SURFACE = 10000;
    private static final int MSG_VISIBILITY_CHANGED = 10010;
@@ -195,6 +196,7 @@ public abstract class WallpaperService extends Service {
        float mPendingYOffsetStep;
        boolean mPendingSync;
        MotionEvent mPendingMove;
        boolean mIsInAmbientMode;

        // Needed for throttling onComputeColors.
        private long mLastColorInvalidation;
@@ -432,6 +434,15 @@ public abstract class WallpaperService extends Service {
            return mIWallpaperEngine.mIsPreview;
        }

        /**
         * Returns true if this engine is running in ambient mode -- that is,
         * it is being shown in low power mode, in always on display.
         * @hide
         */
        public boolean isInAmbientMode() {
            return mIsInAmbientMode;
        }
        
        /**
         * Control whether this wallpaper will receive raw touch events
         * from the window manager as the user interacts with the window
@@ -548,6 +559,15 @@ public abstract class WallpaperService extends Service {
            return null;
        }

        /**
         * Called when the device enters or exits ambient mode.
         *
         * @param inAmbientMode {@code true} if in ambient mode.
         * @hide
         */
        public void onAmbientModeChanged(boolean inAmbientMode) {
        }

        /**
         * Called when an application has changed the desired virtual size of
         * the wallpaper.
@@ -631,6 +651,16 @@ public abstract class WallpaperService extends Service {
            return null;
        }

        /**
         * Sets internal engine state. Only for testing.
         * @param created {@code true} or {@code false}.
         * @hide
         */
        @VisibleForTesting
        public void setCreated(boolean created) {
            mCreated = created;
        }

        protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
            out.print(prefix); out.print("mInitializing="); out.print(mInitializing);
                    out.print(" mDestroyed="); out.println(mDestroyed);
@@ -683,7 +713,8 @@ public abstract class WallpaperService extends Service {
                }
                Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT, event);
                mCaller.sendMessage(msg);
            } else {event.recycle();
            } else {
                event.recycle();
            }
        }

@@ -986,6 +1017,26 @@ public abstract class WallpaperService extends Service {
            updateSurface(false, false, false);
        }

        /**
         * Executes life cycle event and updates internal ambient mode state based on
         * message sent from handler.
         *
         * @param inAmbientMode True if in ambient mode.
         * @hide
         */
        @VisibleForTesting
        public void doAmbientModeChanged(boolean inAmbientMode) {
            if (!mDestroyed) {
                if (DEBUG) {
                    Log.v(TAG, "onAmbientModeChanged(" + inAmbientMode + "): " + this);
                }
                mIsInAmbientMode = inAmbientMode;
                if (mCreated) {
                    onAmbientModeChanged(inAmbientMode);
                }
            }
        }

        void doDesiredSizeChanged(int desiredWidth, int desiredHeight) {
            if (!mDestroyed) {
                if (DEBUG) Log.v(TAG, "onDesiredSizeChanged("
@@ -1226,6 +1277,12 @@ public abstract class WallpaperService extends Service {
            mCaller.sendMessage(msg);
        }

        @Override
        public void setInAmbientMode(boolean inAmbientDisplay) throws RemoteException {
            Message msg = mCaller.obtainMessageI(DO_IN_AMBIENT_MODE, inAmbientDisplay ? 1 : 0);
            mCaller.sendMessage(msg);
        }

        public void dispatchPointer(MotionEvent event) {
            if (mEngine != null) {
                mEngine.dispatchPointer(event);
@@ -1263,6 +1320,7 @@ public abstract class WallpaperService extends Service {
            mCaller.sendMessage(msg);
        }

        @Override
        public void executeMessage(Message message) {
            switch (message.what) {
                case DO_ATTACH: {
@@ -1289,6 +1347,11 @@ public abstract class WallpaperService extends Service {
                }
                case DO_SET_DISPLAY_PADDING: {
                    mEngine.doDisplayPaddingChanged((Rect) message.obj);
                    return;
                }
                case DO_IN_AMBIENT_MODE: {
                    mEngine.doAmbientModeChanged(message.arg1 != 0);
                    return;
                }
                case MSG_UPDATE_SURFACE:
                    mEngine.updateSurface(true, false, false);
+4 −0
Original line number Diff line number Diff line
@@ -7729,6 +7729,10 @@
             wallpaper. -->
        <attr name="showMetadataInPreview" format="boolean" />

        <!-- Wallpapers optimized and capable of drawing in ambient mode will return true.
            @hide -->
        <attr name="supportsAmbientMode" format="boolean" />

    </declare-styleable>

    <!-- Use <code>dream</code> as the root tag of the XML resource that
Loading