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

Commit 12a30e88 authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Add support for showing wallpaper for the user selected in UI.

This change will go nyc-dev.

There will be another change in the UI, which will go to our
branch.

Bug: 25185253
Change-Id: I6feac9fa4190b28a8599a18367bea8c6a5a83b9a
parent f9935c51
Loading
Loading
Loading
Loading
+39 −8
Original line number Diff line number Diff line
@@ -28,10 +28,13 @@ import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;

import libcore.io.IoUtils;

import java.util.Objects;

/**
 * Manages the lockscreen wallpaper.
 */
@@ -42,11 +45,15 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
    private final Context mContext;
    private final PhoneStatusBar mBar;
    private final IWallpaperManager mService;
    private final WallpaperManager mWallpaperManager;
    private final Handler mH;

    private boolean mCached;
    private Bitmap mCache;
    private int mUserId;
    private int mCurrentUserId;
    // The user selected in the UI, or null if no user is selected or UI doesn't support selecting
    // users.
    private UserHandle mSelectedUser;

    public LockscreenWallpaper(Context ctx, PhoneStatusBar bar, Handler h) {
        mContext = ctx;
@@ -54,7 +61,8 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
        mH = h;
        mService = IWallpaperManager.Stub.asInterface(
                ServiceManager.getService(Context.WALLPAPER_SERVICE));
        mUserId = ActivityManager.getCurrentUser();
        mWallpaperManager = (WallpaperManager) ctx.getSystemService(Context.WALLPAPER_SERVICE);
        mCurrentUserId = ActivityManager.getCurrentUser();

        try {
            mService.setLockWallpaperCallback(this);
@@ -73,8 +81,12 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
                mCache = null;
                return null;
            }
            // Prefer the selected user (when specified) over the current user for the FLAG_SET_LOCK
            // wallpaper.
            final int lockWallpaperUserId =
                    mSelectedUser != null ? mSelectedUser.getIdentifier() : mCurrentUserId;
            ParcelFileDescriptor fd = mService.getWallpaper(null, WallpaperManager.FLAG_SET_LOCK,
                    new Bundle(), mUserId);
                    new Bundle(), lockWallpaperUserId);
            if (fd != null) {
                try {
                    BitmapFactory.Options options = new BitmapFactory.Options();
@@ -90,8 +102,17 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
                }
            } else {
                mCached = true;
                if (mSelectedUser != null && mSelectedUser.getIdentifier() != mCurrentUserId) {
                    // When selected user is different from the current user, show the selected
                    // user's static wallpaper.
                    mWallpaperManager.forgetLoadedWallpaper();
                    mCache = mWallpaperManager.getBitmapAsUser(mSelectedUser.getIdentifier());
                } else {
                    // When there is no selected user, or it's same as the current user, show the
                    // system (possibly dynamic) wallpaper for the selected user.
                    mCache = null;
                return null;
                }
                return mCache;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "System dead?" + e);
@@ -99,11 +120,21 @@ public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implemen
        }
    }

    public void setUser(int user) {
        if (user != mUserId) {
    public void setCurrentUser(int user) {
        if (user != mCurrentUserId) {
            mCached = false;
            mUserId = user;
            mCurrentUserId = user;
        }
    }

    public void setSelectedUser(UserHandle selectedUser) {
        if (Objects.equals(selectedUser, mSelectedUser)) {
            return;
        }
        mSelectedUser = selectedUser;

        mH.removeCallbacks(this);
        mH.post(this);
    }

    @Override
+2 −4
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.app.IWallpaperManagerCallback;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.app.WallpaperManager;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
@@ -69,7 +68,6 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.Vibrator;
@@ -296,7 +294,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    AccessibilityController mAccessibilityController;
    FingerprintUnlockController mFingerprintUnlockController;
    LightStatusBarController mLightStatusBarController;
    private LockscreenWallpaper mLockscreenWallpaper;
    protected LockscreenWallpaper mLockscreenWallpaper;

    int mNaturalBarHeight = -1;

@@ -3171,7 +3169,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        resetUserSetupObserver();
        setControllerUsers();
        clearCurrentMediaNotification();
        mLockscreenWallpaper.setUser(newUserId);
        mLockscreenWallpaper.setCurrentUser(newUserId);
        updateMediaMetaData(true, false);
    }