diff options
author | Bernardo Rufino <brufino@google.com> | 2019-08-14 18:22:09 +0100 |
---|---|---|
committer | Bernardo Rufino <brufino@google.com> | 2019-08-14 18:24:18 +0100 |
commit | 0c8b84e4a337769d9251f4276147bb7b05c369f6 (patch) | |
tree | 8ea8b0b7c22d449075ab8643bef6ab1cedf12fd2 /services/backup/java | |
parent | 470f8be8b4e3efae9ddf5a624852657a4cd6df0d (diff) |
Move {get,set}AncestralSerialNumber() to Trampoline
From BMS.
Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I48fd336dce36f39a7b0e7af5f0f9740ee2b4e246
Diffstat (limited to 'services/backup/java')
-rw-r--r-- | services/backup/java/com/android/server/backup/BackupManagerService.java | 53 | ||||
-rw-r--r-- | services/backup/java/com/android/server/backup/Trampoline.java | 52 |
2 files changed, 48 insertions, 57 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 56d612642c56..695fccc84c0a 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -30,11 +30,9 @@ import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.Context; import android.content.pm.PackageManager; -import android.os.Binder; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.UserHandle; -import android.os.UserManager; import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; @@ -100,57 +98,6 @@ public class BackupManagerService { */ // TODO (b/118520567): Stop hardcoding system user when we pass in user id as a parameter - /** - * 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 or null if there is no {@link - * UserBackupManagerService} associated with that user. - * - * <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) { - int callingUserId = Binder.getCallingUserHandle().getIdentifier(); - long oldId = Binder.clearCallingIdentity(); - final int[] userIds; - try { - userIds = - mContext - .getSystemService(UserManager.class) - .getProfileIds(callingUserId, false); - } finally { - Binder.restoreCallingIdentity(oldId); - } - - for (int userId : userIds) { - UserBackupManagerService userBackupManagerService = mServiceUsers.get(userId); - if (userBackupManagerService != null) { - if (userBackupManagerService.getAncestralSerialNumber() == ancestralSerialNumber) { - return UserHandle.of(userId); - } - } - } - - return null; - } - // --------------------------------------------- // SETTINGS OPERATIONS // --------------------------------------------- diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java index d7fa04a1538f..b522c87d6cbe 100644 --- a/services/backup/java/com/android/server/backup/Trampoline.java +++ b/services/backup/java/com/android/server/backup/Trampoline.java @@ -1155,18 +1155,62 @@ public class Trampoline extends IBackupManager.Stub { cancelBackupsForUser(binderGetCallingUserId()); } + /** + * Returns a {@link UserHandle} for the user that has {@code ancestralSerialNumber} as the + * serial number of the its ancestral work profile or null if there is no {@link + * UserBackupManagerService} associated with that user. + * + * <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. + */ @Override - @Nullable public UserHandle getUserForAncestralSerialNumber(long ancestralSerialNumber) { + @Nullable + public UserHandle getUserForAncestralSerialNumber(long ancestralSerialNumber) { if (mGlobalDisable) { return null; } - return mService.getUserForAncestralSerialNumber(ancestralSerialNumber); + int callingUserId = Binder.getCallingUserHandle().getIdentifier(); + long oldId = Binder.clearCallingIdentity(); + final int[] userIds; + try { + userIds = + mContext + .getSystemService(UserManager.class) + .getProfileIds(callingUserId, false); + } finally { + Binder.restoreCallingIdentity(oldId); + } + + for (int userId : userIds) { + UserBackupManagerService userBackupManagerService = mUserServices.get(userId); + if (userBackupManagerService != null) { + if (userBackupManagerService.getAncestralSerialNumber() == ancestralSerialNumber) { + return UserHandle.of(userId); + } + } + } + + 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. + */ @Override public void setAncestralSerialNumber(long ancestralSerialNumber) { - if (!mGlobalDisable) { - mService.setAncestralSerialNumber(ancestralSerialNumber); + if (mGlobalDisable) { + return; + } + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission( + Binder.getCallingUserHandle().getIdentifier(), + "setAncestralSerialNumber()"); + + if (userBackupManagerService != null) { + userBackupManagerService.setAncestralSerialNumber(ancestralSerialNumber); } } |