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

Commit bd849186 authored by Stefano Tommasini's avatar Stefano Tommasini Committed by Android (Google) Code Review
Browse files

Merge "Create API in BackupManagerService for work profile serial id mapping."

parents 72be7c2a 471a35da
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7248,6 +7248,7 @@ package android.app.backup {
    ctor public BackupManager(android.content.Context);
    method public void dataChanged();
    method public static void dataChanged(String);
    method @Nullable public android.os.UserHandle getUserForAncestralSerialNumber(long);
    method @Deprecated public int requestRestore(android.app.backup.RestoreObserver);
  }
+1 −0
Original line number Diff line number Diff line
@@ -711,6 +711,7 @@ package android.app.backup {
    method @Deprecated public int requestRestore(android.app.backup.RestoreObserver, android.app.backup.BackupManagerMonitor);
    method @Deprecated @RequiresPermission(android.Manifest.permission.BACKUP) public String selectBackupTransport(String);
    method @RequiresPermission(android.Manifest.permission.BACKUP) public void selectBackupTransport(android.content.ComponentName, android.app.backup.SelectBackupTransportCallback);
    method @RequiresPermission(android.Manifest.permission.BACKUP) public void setAncestralSerialNumber(long);
    method @RequiresPermission(android.Manifest.permission.BACKUP) public void setAutoRestore(boolean);
    method @RequiresPermission(android.Manifest.permission.BACKUP) public void setBackupEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.BACKUP) public void updateTransportAttributes(android.content.ComponentName, String, @Nullable android.content.Intent, String, @Nullable android.content.Intent, @Nullable String);
+41 −0
Original line number Diff line number Diff line
@@ -750,6 +750,47 @@ public class BackupManager {
        }
    }

    /**
     * Returns a {@link UserHandle} for the user that has {@code ancestralSerialNumber} as the
     * serial number of the its ancestral work profile or {@code null} if there is none.
     *
     * <p> The ancestral serial number will have a corresponding {@link UserHandle} if the device
     * has a work profile that was restored from another work profile with serial number
     * {@code ancestralSerialNumber}.
     *
     * @see UserManager#getSerialNumberForUser(UserHandle)
     */
    @Nullable
    public UserHandle getUserForAncestralSerialNumber(long ancestralSerialNumber) {
        if (sService != null) {
            try {
                return sService.getUserForAncestralSerialNumber(ancestralSerialNumber);
            } catch (RemoteException e) {
                Log.e(TAG, "getUserForAncestralSerialNumber() couldn't connect");
            }
        }
        return null;
    }

    /**
     * Sets the ancestral work profile for the calling user.
     *
     * <p> The ancestral work profile corresponds to the profile that was used to restore to the
     * callers profile.
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.BACKUP)
    public void setAncestralSerialNumber(long ancestralSerialNumber) {
        if (sService != null) {
            try {
                sService.setAncestralSerialNumber(ancestralSerialNumber);
            } catch (RemoteException e) {
                Log.e(TAG, "setAncestralSerialNumber() couldn't connect");
            }
        }
    }

    /**
     * Returns an {@link Intent} for the specified transport's configuration UI.
     * This value is set by {@link #updateTransportAttributes(ComponentName, String, Intent, String,
+21 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.IRestoreSession;
import android.app.backup.ISelectBackupTransportCallback;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.content.Intent;
import android.content.ComponentName;

@@ -685,4 +686,24 @@ interface IBackupManager {
     * {@link android.app.backup.IBackupManager.cancelBackups} for the calling user id.
     */
    void cancelBackups();

    /**
     * Returns a {@link UserHandle} for the user that has {@code ancestralSerialNumber} as the serial
     * number of the it's ancestral work profile.
     *
     * <p> The ancestral work profile is set by {@link #setAncestralSerialNumber(long)}
     * and it corresponds to the profile that was used to restore to the callers profile.
     */
    UserHandle getUserForAncestralSerialNumber(in long ancestralSerialNumber);

    /**
     * Sets the ancestral work profile for the calling user.
     *
     * <p> The ancestral work profile corresponds to the profile that was used to restore to the
     * callers profile.
     *
     * <p>Callers must hold the android.permission.BACKUP permission to use this method.
     */
    void setAncestralSerialNumber(in long ancestralSerialNumber);

}
+41 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Slog;
import android.util.SparseArray;

@@ -437,6 +438,44 @@ public class BackupManagerService {
            : userBackupManagerService.getConfigurationIntent(transportName);
    }

    /**
     * Sets the ancestral work profile for the calling user.
     *
     * <p> The ancestral work profile corresponds to the profile that was used to restore to the
     * callers profile.
     */
    public void setAncestralSerialNumber(long ancestralSerialNumber) {
        UserBackupManagerService userBackupManagerService =
                getServiceForUserIfCallerHasPermission(
                        Binder.getCallingUserHandle().getIdentifier(),
                        "setAncestralSerialNumber()");

        if (userBackupManagerService != null) {
            userBackupManagerService.setAncestralSerialNumber(ancestralSerialNumber);
        }
    }

    /**
     * Returns a {@link UserHandle} for the user that has {@code ancestralSerialNumber} as the
     * serial number of the its ancestral work profile.
     *
     * <p> The ancestral work profile is set by {@link #setAncestralSerialNumber(long)}
     * and it corresponds to the profile that was used to restore to the callers profile.
     */
    @Nullable
    public UserHandle getUserForAncestralSerialNumber(long ancestralSerialNumber) {
        for (UserHandle handle : mContext.getSystemService(UserManager.class).getUserProfiles()) {
            UserBackupManagerService userBackupManagerService = getServiceUsers().get(
                    handle.getIdentifier());
            if (userBackupManagerService != null) {
                if (userBackupManagerService.getAncestralSerialNumber() == ancestralSerialNumber) {
                    return handle;
                }
            }
        }
        return null;
    }

    /**
     * Supply the current destination string for the given transport. If the name is not one of the
     * registered transports the method will return null.
Loading