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

Commit 643bf13f authored by wilsonshih's avatar wilsonshih Committed by Andrii Kulian
Browse files

Notify the WMS when the display content is ready.

We only add wallpaper to the display that can support the display
system decoration attribute. However, when receiving a display
add callback does not mean that the display content has already
been created, we could not add wallpaper to the display in this
case.
To prevent above condition, we can notify the wallpaper that the
content is ready to add wallpaper instead of listening a display
was added.

Bug: 125007644
Bug: 124073468
Test: atest ActivityManagerMultiDisplayTests#testWallpaperShowOnSecondaryDisplays

Change-Id: I67062ce62cdf185884ab77a5741e5374e5987ef6
parent dd98961b
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wallpaper;

/**
 * Wallpaper manager local system service interface.
 *
 * @hide Only for use within the system server.
 */
public abstract class WallpaperManagerInternal {

    /**
     * Notifies the display is ready for adding wallpaper on it.
     */
    public abstract void onDisplayReady(int displayId);
}
+34 −21
Original line number Diff line number Diff line
@@ -756,27 +756,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub

        @Override
        public void onDisplayAdded(int displayId) {
            synchronized (mLock) {
                if (mLastWallpaper != null) {
                    if (supportsMultiDisplay(mLastWallpaper.connection)) {
                        final WallpaperConnection.DisplayConnector connector =
                                mLastWallpaper.connection.getDisplayConnectorOrCreate(displayId);
                        if (connector == null) return;
                        connector.connectLocked(mLastWallpaper.connection, mLastWallpaper);
                        return;
                    }
                    // System wallpaper does not support multiple displays, attach this display to
                    // the fallback wallpaper.
                    if (mFallbackWallpaper != null) {
                        final WallpaperConnection.DisplayConnector connector = mFallbackWallpaper
                                .connection.getDisplayConnectorOrCreate(displayId);
                        if (connector == null) return;
                        connector.connectLocked(mFallbackWallpaper.connection, mFallbackWallpaper);
                    } else {
                        Slog.w(TAG, "No wallpaper can be added to the new display");
                    }
                }
            }
        }

        @Override
@@ -1590,6 +1569,15 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        mDisplayManager.registerDisplayListener(mDisplayListener, null /* handler */);
        mMonitor = new MyPackageMonitor();
        mColorsChangedListeners = new SparseArray<>();

        LocalServices.addService(WallpaperManagerInternal.class, new LocalService());
    }

    private final class LocalService extends WallpaperManagerInternal {
        @Override
        public void onDisplayReady(int displayId) {
            onDisplayReadyInternal(displayId);
        }
    }

    void initialize() {
@@ -2775,6 +2763,31 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        return (wallpaper != null) ? wallpaper.allowBackup : false;
    }

    private void onDisplayReadyInternal(int displayId) {
        synchronized (mLock) {
            if (mLastWallpaper == null) {
                return;
            }
            if (supportsMultiDisplay(mLastWallpaper.connection)) {
                final WallpaperConnection.DisplayConnector connector =
                        mLastWallpaper.connection.getDisplayConnectorOrCreate(displayId);
                if (connector == null) return;
                connector.connectLocked(mLastWallpaper.connection, mLastWallpaper);
                return;
            }
            // System wallpaper does not support multiple displays, attach this display to
            // the fallback wallpaper.
            if (mFallbackWallpaper != null) {
                final WallpaperConnection.DisplayConnector connector = mFallbackWallpaper
                        .connection.getDisplayConnectorOrCreate(displayId);
                if (connector == null) return;
                connector.connectLocked(mFallbackWallpaper.connection, mFallbackWallpaper);
            } else {
                Slog.w(TAG, "No wallpaper can be added to the new display");
            }
        }
    }

    private static JournaledFile makeJournaledFile(int userId) {
        final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath();
        return new JournaledFile(new File(base), new File(base + ".tmp"));
+6 −1
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ import com.android.server.policy.WindowManagerPolicy.ScreenOnListener;
import com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs;
import com.android.server.policy.WindowOrientationListener;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.wallpaper.WallpaperManagerInternal;
import com.android.server.wm.utils.InsetUtils;

import java.io.PrintWriter;
@@ -2605,7 +2606,11 @@ public class DisplayPolicy {
    }

    void notifyDisplayReady() {
        mHandler.post(() -> getStatusBarManagerInternal().onDisplayReady(getDisplayId()));
        mHandler.post(() -> {
            final int displayId = getDisplayId();
            getStatusBarManagerInternal().onDisplayReady(displayId);
            LocalServices.getService(WallpaperManagerInternal.class).onDisplayReady(displayId);
        });
    }

    /**