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

Commit c6696e59 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Remove dependencies to LockscreenWallpaper

Stop calling anything from LockscreenWallpaper (in particular,
notificationMediaManager#updateMediaMetaData) if the config flag for
the lockscreen live wallpaper project is enabled.

This CL does not remove code, since it does not change any behaviour if
the config flag is disabled.

Test: atest CtsWallpaperTestCases
Test: atest CentralSurfacesImplTest
Test: atest SystemUITests:com.android.systemui.statusbar.NotificationMediaManagerTest
Bug: 253507223
Change-Id: I2d0940bf4afc3c3fa283ed0773197360862ee480
parent 251b591a
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
@@ -43,6 +44,7 @@ import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dumpable;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.colorextraction.SysuiColorExtractor;
@@ -117,6 +119,8 @@ public class NotificationMediaManager implements Dumpable {
    private ScrimController mScrimController;
    @Nullable
    private LockscreenWallpaper mLockscreenWallpaper;
    @VisibleForTesting
    boolean mIsLockscreenLiveWallpaperEnabled;

    private final DelayableExecutor mMainExecutor;

@@ -179,7 +183,8 @@ public class NotificationMediaManager implements Dumpable {
            StatusBarStateController statusBarStateController,
            SysuiColorExtractor colorExtractor,
            KeyguardStateController keyguardStateController,
            DumpManager dumpManager) {
            DumpManager dumpManager,
            WallpaperManager wallpaperManager) {
        mContext = context;
        mMediaArtworkProcessor = mediaArtworkProcessor;
        mKeyguardBypassController = keyguardBypassController;
@@ -195,6 +200,7 @@ public class NotificationMediaManager implements Dumpable {
        mStatusBarStateController = statusBarStateController;
        mColorExtractor = colorExtractor;
        mKeyguardStateController = keyguardStateController;
        mIsLockscreenLiveWallpaperEnabled = wallpaperManager.isLockscreenLiveWallpaperEnabled();

        setupNotifPipeline();

@@ -474,13 +480,16 @@ public class NotificationMediaManager implements Dumpable {
     * Refresh or remove lockscreen artwork from media metadata or the lockscreen wallpaper.
     */
    public void updateMediaMetaData(boolean metaDataChanged, boolean allowEnterAnimation) {

        if (mIsLockscreenLiveWallpaperEnabled) return;

        Trace.beginSection("CentralSurfaces#updateMediaMetaData");
        if (!SHOW_LOCKSCREEN_MEDIA_ARTWORK) {
            Trace.endSection();
            return;
        }

        if (mBackdrop == null) {
        if (getBackDropView() == null) {
            Trace.endSection();
            return; // called too early
        }
@@ -709,6 +718,12 @@ public class NotificationMediaManager implements Dumpable {
                && (mBackdropFront.isVisibleToUser() || mBackdropBack.isVisibleToUser());
    }

    // TODO(b/273443374) temporary test helper; remove
    @VisibleForTesting
    BackDropView getBackDropView() {
        return mBackdrop;
    }

    /**
     * {@link AsyncTask} to prepare album art for use as backdrop on lock screen.
     */
+5 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.dagger;

import android.app.IActivityManager;
import android.app.WallpaperManager;
import android.content.Context;
import android.os.RemoteException;
import android.service.dreams.IDreamManager;
@@ -142,7 +143,8 @@ public interface CentralSurfacesDependenciesModule {
            StatusBarStateController statusBarStateController,
            SysuiColorExtractor colorExtractor,
            KeyguardStateController keyguardStateController,
            DumpManager dumpManager) {
            DumpManager dumpManager,
            WallpaperManager wallpaperManager) {
        return new NotificationMediaManager(
                context,
                centralSurfacesOptionalLazy,
@@ -157,7 +159,8 @@ public interface CentralSurfacesDependenciesModule {
                statusBarStateController,
                colorExtractor,
                keyguardStateController,
                dumpManager);
                dumpManager,
                wallpaperManager);
    }

    /** */
+8 −3
Original line number Diff line number Diff line
@@ -1359,8 +1359,13 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
                mHeadsUpManager);

        BackDropView backdrop = mNotificationShadeWindowView.findViewById(R.id.backdrop);
        if (mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
            mMediaManager.setup(null, null, null, mScrimController, null);
        } else {
            mMediaManager.setup(backdrop, backdrop.findViewById(R.id.backdrop_front),
                backdrop.findViewById(R.id.backdrop_back), mScrimController, mLockscreenWallpaper);
                    backdrop.findViewById(R.id.backdrop_back), mScrimController,
                    mLockscreenWallpaper);
        }
        float maxWallpaperZoom = mContext.getResources().getFloat(
                com.android.internal.R.dimen.config_wallpaperMaxScale);
        mNotificationShadeDepthControllerLazy.get().addListener(depth -> {
@@ -2725,7 +2730,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
     */
    @Override
    public void setLockscreenUser(int newUserId) {
        if (mLockscreenWallpaper != null) {
        if (mLockscreenWallpaper != null && !mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
            mLockscreenWallpaper.setCurrentUser(newUserId);
        }
        mScrimController.setCurrentUser(newUserId);
+31 −6
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen

    private static final String TAG = "LockscreenWallpaper";

    // TODO(b/253507223): temporary; remove this
    private static final String DISABLED_ERROR_MESSAGE = "Methods from LockscreenWallpaper.java "
            + "should not be called in this version. The lock screen wallpaper should be "
            + "managed by the WallpaperManagerService and not by this class.";

    private final NotificationMediaManager mMediaManager;
    private final WallpaperManager mWallpaperManager;
    private final KeyguardUpdateMonitor mUpdateMonitor;
@@ -91,7 +96,7 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
        mMediaManager = mediaManager;
        mH = mainHandler;

        if (iWallpaperManager != null) {
        if (iWallpaperManager != null && !mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
            // Service is disabled on some devices like Automotive
            try {
                iWallpaperManager.setLockWallpaperCallback(this);
@@ -102,6 +107,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
    }

    public Bitmap getBitmap() {
        assertLockscreenLiveWallpaperNotEnabled();

        if (mCached) {
            return mCache;
        }
@@ -122,9 +129,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
    public LoaderResult loadBitmap(int currentUserId, UserHandle selectedUser) {
        // May be called on any thread - only use thread safe operations.

        if (mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
            return LoaderResult.success(null);
        }
        assertLockscreenLiveWallpaperNotEnabled();


        if (!mWallpaperManager.isWallpaperSupported()) {
            // When wallpaper is not supported, show the system wallpaper
@@ -164,6 +170,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
    }

    public void setCurrentUser(int user) {
        assertLockscreenLiveWallpaperNotEnabled();

        if (user != mCurrentUserId) {
            if (mSelectedUser == null || user != mSelectedUser.getIdentifier()) {
                mCached = false;
@@ -173,6 +181,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
    }

    public void setSelectedUser(UserHandle selectedUser) {
        assertLockscreenLiveWallpaperNotEnabled();

        if (Objects.equals(selectedUser, mSelectedUser)) {
            return;
        }
@@ -182,16 +192,18 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen

    @Override
    public void onWallpaperChanged() {
        assertLockscreenLiveWallpaperNotEnabled();
        // Called on Binder thread.
        postUpdateWallpaper();
    }

    @Override
    public void onWallpaperColorsChanged(WallpaperColors colors, int which, int userId) {

        assertLockscreenLiveWallpaperNotEnabled();
    }

    private void postUpdateWallpaper() {
        assertLockscreenLiveWallpaperNotEnabled();
        if (mH == null) {
            Log.wtfStack(TAG, "Trying to use LockscreenWallpaper before initialization.");
            return;
@@ -199,11 +211,12 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
        mH.removeCallbacks(this);
        mH.post(this);
    }

    @Override
    public void run() {
        // Called in response to onWallpaperChanged on the main thread.

        assertLockscreenLiveWallpaperNotEnabled();

        if (mLoader != null) {
            mLoader.cancel(false /* interrupt */);
        }
@@ -358,4 +371,16 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
            }
        }
    }

    /**
     * Feature b/253507223 will adapt the logic to always use the
     * WallpaperManagerService to render the lock screen wallpaper.
     * Methods of this class should not be called at all if the project flag is enabled.
     * TODO(b/253507223) temporary assertion; remove this
     */
    private void assertLockscreenLiveWallpaperNotEnabled() {
        if (mWallpaperManager.isLockscreenLiveWallpaperEnabled()) {
            throw new IllegalStateException(DISABLED_ERROR_MESSAGE);
        }
    }
}
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.statusbar

import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.mockito.whenever
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.anyBoolean
import org.mockito.Mockito.doCallRealMethod
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

/**
 * Temporary test for the lock screen live wallpaper project.
 *
 * TODO(b/273443374): remove this test
 */
@RunWith(AndroidTestingRunner::class)
@SmallTest
class NotificationMediaManagerTest : SysuiTestCase() {

    @Mock private lateinit var notificationMediaManager: NotificationMediaManager

    @Mock private lateinit var mockBackDropView: BackDropView

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        doCallRealMethod()
            .whenever(notificationMediaManager)
            .updateMediaMetaData(anyBoolean(), anyBoolean())
        doReturn(mockBackDropView).whenever(notificationMediaManager).backDropView
    }

    @After fun tearDown() {}

    /** Check that updateMediaMetaData is a no-op with mIsLockscreenLiveWallpaperEnabled = true */
    @Test
    fun testUpdateMediaMetaDataDisabled() {
        notificationMediaManager.mIsLockscreenLiveWallpaperEnabled = true
        for (metaDataChanged in listOf(true, false)) {
            for (allowEnterAnimation in listOf(true, false)) {
                notificationMediaManager.updateMediaMetaData(metaDataChanged, allowEnterAnimation)
                verify(notificationMediaManager, never()).mediaMetadata
            }
        }
    }
}