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

Commit 37ce3a8a authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Multi-user - wallpaper service

- Allow each user to have their own wallpaper (live or static).
- Migrate old wallpaper on upgrade.
- Update SystemBackupAgent to backup/restore from primary user's
  new wallpaper directory.

Reduce dependency on Binder.getOrigCallingUser() by passing the
userId for bindService.

Change-Id: I19c8c3296d3d2efa7f28f951d4b84407489e2166
parent 11ca3172
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -670,8 +670,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            String resolvedType = data.readString();
            b = data.readStrongBinder();
            int fl = data.readInt();
            int userId = data.readInt();
            IServiceConnection conn = IServiceConnection.Stub.asInterface(b);
            int res = bindService(app, token, service, resolvedType, conn, fl);
            int res = bindService(app, token, service, resolvedType, conn, fl, userId);
            reply.writeNoException();
            reply.writeInt(res);
            return true;
@@ -2288,7 +2289,7 @@ class ActivityManagerProxy implements IActivityManager
    }
    public int bindService(IApplicationThread caller, IBinder token,
            Intent service, String resolvedType, IServiceConnection connection,
            int flags) throws RemoteException {
            int flags, int userId) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
@@ -2298,6 +2299,7 @@ class ActivityManagerProxy implements IActivityManager
        data.writeString(resolvedType);
        data.writeStrongBinder(connection.asBinder());
        data.writeInt(flags);
        data.writeInt(userId);
        mRemote.transact(BIND_SERVICE_TRANSACTION, data, reply, 0);
        reply.readException();
        int res = reply.readInt();
+7 −1
Original line number Diff line number Diff line
@@ -1125,6 +1125,12 @@ class ContextImpl extends Context {
    @Override
    public boolean bindService(Intent service, ServiceConnection conn,
            int flags) {
        return bindService(service, conn, flags, UserId.getUserId(Process.myUid()));
    }

    /** @hide */
    @Override
    public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
        IServiceConnection sd;
        if (mPackageInfo != null) {
            sd = mPackageInfo.getServiceDispatcher(conn, getOuterContext(),
@@ -1143,7 +1149,7 @@ class ContextImpl extends Context {
            int res = ActivityManagerNative.getDefault().bindService(
                mMainThread.getApplicationThread(), getActivityToken(),
                service, service.resolveTypeIfNeeded(getContentResolver()),
                sd, flags);
                sd, flags, userId);
            if (res < 0) {
                throw new SecurityException(
                        "Not allowed to bind to service " + service);
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public interface IActivityManager extends IInterface {
            int id, Notification notification, boolean keepNotification) throws RemoteException;
    public int bindService(IApplicationThread caller, IBinder token,
            Intent service, String resolvedType,
            IServiceConnection connection, int flags) throws RemoteException;
            IServiceConnection connection, int flags, int userId) throws RemoteException;
    public boolean unbindService(IServiceConnection connection) throws RemoteException;
    public void publishService(IBinder token,
            Intent intent, IBinder service) throws RemoteException;
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+18 −9
Original line number Diff line number Diff line
@@ -38,15 +38,23 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
    private static final boolean DEBUG = false;

    // This path must match what the WallpaperManagerService uses
    private static final String WALLPAPER_IMAGE = "/data/data/com.android.settings/files/wallpaper";
    // TODO: Will need to change if backing up non-primary user's wallpaper
    public static final String WALLPAPER_IMAGE = "/data/system/users/0/wallpaper";
    public static final String WALLPAPER_INFO = "/data/system/users/0/wallpaper_info.xml";
    // Use old keys to keep legacy data compatibility and avoid writing two wallpapers
    public static final String WALLPAPER_IMAGE_KEY =
            "/data/data/com.android.settings/files/wallpaper";
    public static final String WALLPAPER_INFO_KEY = "/data/system/wallpaper_info.xml";

    // Stage file - should be adjacent to the WALLPAPER_IMAGE location.  The wallpapers
    // will be saved to this file from the restore stream, then renamed to the proper
    // location if it's deemed suitable.
    private static final String STAGE_FILE = "/data/data/com.android.settings/files/wallpaper-tmp";
    // TODO: Will need to change if backing up non-primary user's wallpaper
    private static final String STAGE_FILE = "/data/system/users/0/wallpaper-tmp";

    Context mContext;
    String[] mFiles;
    String[] mKeys;
    double mDesiredMinWidth;
    double mDesiredMinHeight;

@@ -57,11 +65,12 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
     * @param context
     * @param files
     */
    public WallpaperBackupHelper(Context context, String... files) {
    public WallpaperBackupHelper(Context context, String[] files, String[] keys) {
        super(context);

        mContext = context;
        mFiles = files;
        mKeys = keys;

        WallpaperManager wpm;
        wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
@@ -89,7 +98,7 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
     */
    public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) {
        performBackup_checked(oldState, data, newState, mFiles, mFiles);
        performBackup_checked(oldState, data, newState, mFiles, mKeys);
    }

    /**
@@ -99,8 +108,8 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
     */
    public void restoreEntity(BackupDataInputStream data) {
        final String key = data.getKey();
        if (isKeyInList(key, mFiles)) {
            if (key.equals(WALLPAPER_IMAGE)) {
        if (isKeyInList(key, mKeys)) {
            if (key.equals(WALLPAPER_IMAGE_KEY)) {
                // restore the file to the stage for inspection
                File f = new File(STAGE_FILE);
                if (writeFile(f, data)) {
@@ -135,9 +144,9 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
                        f.delete();
                    }
                }
            } else {
                // Some other normal file; just decode it to its destination
                File f = new File(key);
            } else if (key.equals(WALLPAPER_INFO_KEY)) {
                // XML file containing wallpaper info
                File f = new File(WALLPAPER_INFO);
                writeFile(f, data);
            }
        }
Loading