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

Commit de93f49a authored by wilsonshih's avatar wilsonshih
Browse files

Support wallpaper on secondary displays.(1/N)

Extends WallpaperConnection:mEngine, mapping an engine to a display.
Handling display change events for add or remove wallpaper on secondary
display.
Only attach wallpaper on accessible display, usually WallpaperService is
third party app and cannot access private display.

Bug: 115486823
Test: atest ActivityManagerMultiDisplayTests
Test: atest WallpaperManagerTest

Change-Id: Idb6063c3cf4c8c5b854676666615e3df4e6d65f4
parent a18cb5a1
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ import android.app.WallpaperColors;
 * @hide
 * @hide
 */
 */
interface IWallpaperConnection {
interface IWallpaperConnection {
	void attachEngine(IWallpaperEngine engine);
    void attachEngine(IWallpaperEngine engine, int displayId);
    void engineShown(IWallpaperEngine engine);
    void engineShown(IWallpaperEngine engine);
    ParcelFileDescriptor setWallpaper(String name);
    ParcelFileDescriptor setWallpaper(String name);
    void onWallpaperColorsChanged(in WallpaperColors colors);
    void onWallpaperColorsChanged(in WallpaperColors colors);
+2 −2
Original line number Original line Diff line number Diff line
@@ -25,5 +25,5 @@ import android.service.wallpaper.IWallpaperConnection;
oneway interface IWallpaperService {
oneway interface IWallpaperService {
    void attach(IWallpaperConnection connection,
    void attach(IWallpaperConnection connection,
            IBinder windowToken, int windowType, boolean isPreview,
            IBinder windowToken, int windowType, boolean isPreview,
    		int reqWidth, int reqHeight, in Rect padding);
            int reqWidth, int reqHeight, in Rect padding, int displayId);
}
}
+18 −10
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.Service;
import android.app.WallpaperColors;
import android.app.WallpaperColors;
import android.app.WallpaperInfo;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
@@ -806,7 +805,7 @@ public abstract class WallpaperService extends Service {
                                com.android.internal.R.style.Animation_Wallpaper;
                                com.android.internal.R.style.Animation_Wallpaper;
                        mInputChannel = new InputChannel();
                        mInputChannel = new InputChannel();
                        if (mSession.addToDisplay(mWindow, mWindow.mSeq, mLayout, View.VISIBLE,
                        if (mSession.addToDisplay(mWindow, mWindow.mSeq, mLayout, View.VISIBLE,
                                Display.DEFAULT_DISPLAY, mWinFrame, mContentInsets, mStableInsets,
                                mDisplay.getDisplayId(), mWinFrame, mContentInsets, mStableInsets,
                                mOutsets, mDisplayCutout, mInputChannel) < 0) {
                                mOutsets, mDisplayCutout, mInputChannel) < 0) {
                            Log.w(TAG, "Failed to add window while updating wallpaper surface.");
                            Log.w(TAG, "Failed to add window while updating wallpaper surface.");
                            return;
                            return;
@@ -1016,6 +1015,14 @@ public abstract class WallpaperService extends Service {
                return;
                return;
            }
            }


            mDisplayManager = getSystemService(DisplayManager.class);
            mDisplay = mDisplayManager.getDisplay(wrapper.mDisplayId);
            if (mDisplay == null) {
                // TODO(b/115486823) Ignore this engine.
                Log.e(TAG, "Attaching to a non-existent display: " + wrapper.mDisplayId);
                return;
            }

            mIWallpaperEngine = wrapper;
            mIWallpaperEngine = wrapper;
            mCaller = wrapper.mCaller;
            mCaller = wrapper.mCaller;
            mConnection = wrapper.mConnection;
            mConnection = wrapper.mConnection;
@@ -1027,10 +1034,7 @@ public abstract class WallpaperService extends Service {
            mWindow.setSession(mSession);
            mWindow.setSession(mSession);


            mLayout.packageName = getPackageName();
            mLayout.packageName = getPackageName();

            mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);
            mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler());
            mDisplayManager.registerDisplayListener(mDisplayListener, mCaller.getHandler());
            mDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
            mDisplayState = mDisplay.getState();
            mDisplayState = mDisplay.getState();


            if (DEBUG) Log.v(TAG, "onCreate(): " + this);
            if (DEBUG) Log.v(TAG, "onCreate(): " + this);
@@ -1268,12 +1272,14 @@ public abstract class WallpaperService extends Service {
        int mReqWidth;
        int mReqWidth;
        int mReqHeight;
        int mReqHeight;
        final Rect mDisplayPadding = new Rect();
        final Rect mDisplayPadding = new Rect();
        int mDisplayId;


        Engine mEngine;
        Engine mEngine;


        IWallpaperEngineWrapper(WallpaperService context,
        IWallpaperEngineWrapper(WallpaperService context,
                IWallpaperConnection conn, IBinder windowToken,
                IWallpaperConnection conn, IBinder windowToken,
                int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding) {
                int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
                int displayId) {
            mCaller = new HandlerCaller(context, context.getMainLooper(), this, true);
            mCaller = new HandlerCaller(context, context.getMainLooper(), this, true);
            mConnection = conn;
            mConnection = conn;
            mWindowToken = windowToken;
            mWindowToken = windowToken;
@@ -1282,6 +1288,7 @@ public abstract class WallpaperService extends Service {
            mReqWidth = reqWidth;
            mReqWidth = reqWidth;
            mReqHeight = reqHeight;
            mReqHeight = reqHeight;
            mDisplayPadding.set(padding);
            mDisplayPadding.set(padding);
            mDisplayId = displayId;
            
            
            Message msg = mCaller.obtainMessage(DO_ATTACH);
            Message msg = mCaller.obtainMessage(DO_ATTACH);
            mCaller.sendMessage(msg);
            mCaller.sendMessage(msg);
@@ -1353,7 +1360,7 @@ public abstract class WallpaperService extends Service {
            switch (message.what) {
            switch (message.what) {
                case DO_ATTACH: {
                case DO_ATTACH: {
                    try {
                    try {
                        mConnection.attachEngine(this);
                        mConnection.attachEngine(this, mDisplayId);
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                        Log.w(TAG, "Wallpaper host disappeared", e);
                        Log.w(TAG, "Wallpaper host disappeared", e);
                        return;
                        return;
@@ -1453,9 +1460,10 @@ public abstract class WallpaperService extends Service {


        @Override
        @Override
        public void attach(IWallpaperConnection conn, IBinder windowToken,
        public void attach(IWallpaperConnection conn, IBinder windowToken,
                int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding) {
                int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
                int displayId) {
            new IWallpaperEngineWrapper(mTarget, conn, windowToken,
            new IWallpaperEngineWrapper(mTarget, conn, windowToken,
                    windowType, isPreview, reqWidth, reqHeight, padding);
                    windowType, isPreview, reqWidth, reqHeight, padding, displayId);
        }
        }
    }
    }


+230 −72

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Original line Diff line number Diff line
@@ -2286,7 +2286,7 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }


        synchronized (mGlobalLock) {
        synchronized (mGlobalLock) {
            final DisplayContent dc = mRoot.getDisplayContent(displayId);
            final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */);
            if (dc == null) {
            if (dc == null) {
                Slog.w(TAG_WM, "addWindowToken: Attempted to add token: " + binder
                Slog.w(TAG_WM, "addWindowToken: Attempted to add token: " + binder
                        + " for non-exiting displayId=" + displayId);
                        + " for non-exiting displayId=" + displayId);