Loading core/java/android/app/ActivityThread.java +19 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.app.assist.AssistContent; import android.app.assist.AssistStructure; import android.app.backup.BackupAgent; import android.app.backup.BackupAnnotations.BackupDestination; import android.app.backup.BackupAnnotations.OperationType; import android.app.servertransaction.ActivityLifecycleItem; import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; import android.app.servertransaction.ActivityRelaunchItem; Loading Loading @@ -4403,7 +4404,8 @@ public final class ActivityThread extends ClientTransactionHandler context.setOuterContext(agent); agent.attach(context); agent.onCreate(UserHandle.of(data.userId), data.backupDestination); agent.onCreate(UserHandle.of(data.userId), data.backupDestination, getOperationTypeFromBackupMode(data.backupMode)); binder = agent.onBind(); backupAgents.put(packageName, agent); } catch (Exception e) { Loading Loading @@ -4431,6 +4433,22 @@ public final class ActivityThread extends ClientTransactionHandler } } @OperationType private static int getOperationTypeFromBackupMode(int backupMode) { switch (backupMode) { case ApplicationThreadConstants.BACKUP_MODE_RESTORE: case ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL: return OperationType.RESTORE; case ApplicationThreadConstants.BACKUP_MODE_FULL: case ApplicationThreadConstants.BACKUP_MODE_INCREMENTAL: return OperationType.BACKUP; default: Slog.w(TAG, "Invalid backup mode when initialising BackupAgent: " + backupMode); return OperationType.UNKNOWN; } } private String getBackupAgentName(CreateBackupAgentData data) { String agentName = data.appInfo.backupAgentName; // full backup operation but no app-supplied agent? use the default implementation Loading core/java/android/app/backup/BackupAgent.java +22 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.app.IBackupAgent; import android.app.QueuedWork; import android.app.backup.BackupAnnotations.BackupDestination; import android.app.backup.BackupAnnotations.OperationType; import android.app.backup.FullBackup.BackupScheme.PathWithRequiredFlags; import android.content.Context; import android.content.ContextWrapper; Loading Loading @@ -265,27 +266,40 @@ public abstract class BackupAgent extends ContextWrapper { } /** * Provided as a convenience for agent implementations that need an opportunity * to do one-time initialization before the actual backup or restore operation * is begun with information about the calling user. * <p> * * @hide */ public void onCreate(UserHandle user) { onCreate(user, DEFAULT_BACKUP_DESTINATION); onCreate(); } /** * Provided as a convenience for agent implementations that need an opportunity * to do one-time initialization before the actual backup or restore operation * is begun with information about the calling user. * <p> * @deprecated Use {@link BackupAgent#onCreate(UserHandle, int, int)} instead. * * @hide */ @Deprecated public void onCreate(UserHandle user, @BackupDestination int backupDestination) { // TODO: Instantiate with the correct type using a parameter. mLogger = new BackupRestoreEventLogger(BackupRestoreEventLogger.OperationType.BACKUP); onCreate(); mUser = user; mBackupDestination = backupDestination; onCreate(user); } /** * @hide */ public void onCreate(UserHandle user, @BackupDestination int backupDestination, @OperationType int operationType) { mUser = user; mBackupDestination = backupDestination; mLogger = new BackupRestoreEventLogger(operationType); onCreate(user, backupDestination); } /** Loading core/java/android/app/backup/BackupAnnotations.java +2 −0 Original line number Diff line number Diff line Loading @@ -30,10 +30,12 @@ public class BackupAnnotations { /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ OperationType.UNKNOWN, OperationType.BACKUP, OperationType.RESTORE, }) public @interface OperationType { int UNKNOWN = -1; int BACKUP = 0; int RESTORE = 1; } Loading core/java/android/app/backup/BackupRestoreEventLogger.java +1 −16 Original line number Diff line number Diff line Loading @@ -16,13 +16,13 @@ package android.app.backup; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.util.ArrayMap; import android.app.backup.BackupAnnotations.OperationType; import android.util.Slog; import java.lang.annotation.Retention; Loading Loading @@ -55,21 +55,6 @@ public class BackupRestoreEventLogger { */ public static final int DATA_TYPES_ALLOWED = 15; /** * Operation types for which this logger can be used. * * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ OperationType.BACKUP, OperationType.RESTORE }) @interface OperationType { int BACKUP = 1; int RESTORE = 2; } /** * Denotes that the annotated element identifies a data type as required by the logging methods * of {@code BackupRestoreEventLogger} Loading core/tests/coretests/src/android/app/backup/BackupAgentTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -85,24 +85,26 @@ public class BackupAgentTest { @Test public void getBackupRestoreEventLogger_afterOnCreateForBackup_initializedForBackup() { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.BACKUP); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo(1); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo( OperationType.BACKUP); } @Test public void getBackupRestoreEventLogger_afterOnCreateForRestore_initializedForRestore() { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.RESTORE); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo(1); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo( OperationType.RESTORE); } @Test public void getBackupRestoreEventLogger_afterBackup_containsLogsLoggedByAgent() throws Exception { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.BACKUP); // TestFullBackupAgent logs DATA_TYPE_BACKED_UP when onFullBackup is called. agent.onFullBackup(new FullBackupDataOutput(/* quota = */ 0)); Loading Loading
core/java/android/app/ActivityThread.java +19 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.app.assist.AssistContent; import android.app.assist.AssistStructure; import android.app.backup.BackupAgent; import android.app.backup.BackupAnnotations.BackupDestination; import android.app.backup.BackupAnnotations.OperationType; import android.app.servertransaction.ActivityLifecycleItem; import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; import android.app.servertransaction.ActivityRelaunchItem; Loading Loading @@ -4403,7 +4404,8 @@ public final class ActivityThread extends ClientTransactionHandler context.setOuterContext(agent); agent.attach(context); agent.onCreate(UserHandle.of(data.userId), data.backupDestination); agent.onCreate(UserHandle.of(data.userId), data.backupDestination, getOperationTypeFromBackupMode(data.backupMode)); binder = agent.onBind(); backupAgents.put(packageName, agent); } catch (Exception e) { Loading Loading @@ -4431,6 +4433,22 @@ public final class ActivityThread extends ClientTransactionHandler } } @OperationType private static int getOperationTypeFromBackupMode(int backupMode) { switch (backupMode) { case ApplicationThreadConstants.BACKUP_MODE_RESTORE: case ApplicationThreadConstants.BACKUP_MODE_RESTORE_FULL: return OperationType.RESTORE; case ApplicationThreadConstants.BACKUP_MODE_FULL: case ApplicationThreadConstants.BACKUP_MODE_INCREMENTAL: return OperationType.BACKUP; default: Slog.w(TAG, "Invalid backup mode when initialising BackupAgent: " + backupMode); return OperationType.UNKNOWN; } } private String getBackupAgentName(CreateBackupAgentData data) { String agentName = data.appInfo.backupAgentName; // full backup operation but no app-supplied agent? use the default implementation Loading
core/java/android/app/backup/BackupAgent.java +22 −8 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.app.IBackupAgent; import android.app.QueuedWork; import android.app.backup.BackupAnnotations.BackupDestination; import android.app.backup.BackupAnnotations.OperationType; import android.app.backup.FullBackup.BackupScheme.PathWithRequiredFlags; import android.content.Context; import android.content.ContextWrapper; Loading Loading @@ -265,27 +266,40 @@ public abstract class BackupAgent extends ContextWrapper { } /** * Provided as a convenience for agent implementations that need an opportunity * to do one-time initialization before the actual backup or restore operation * is begun with information about the calling user. * <p> * * @hide */ public void onCreate(UserHandle user) { onCreate(user, DEFAULT_BACKUP_DESTINATION); onCreate(); } /** * Provided as a convenience for agent implementations that need an opportunity * to do one-time initialization before the actual backup or restore operation * is begun with information about the calling user. * <p> * @deprecated Use {@link BackupAgent#onCreate(UserHandle, int, int)} instead. * * @hide */ @Deprecated public void onCreate(UserHandle user, @BackupDestination int backupDestination) { // TODO: Instantiate with the correct type using a parameter. mLogger = new BackupRestoreEventLogger(BackupRestoreEventLogger.OperationType.BACKUP); onCreate(); mUser = user; mBackupDestination = backupDestination; onCreate(user); } /** * @hide */ public void onCreate(UserHandle user, @BackupDestination int backupDestination, @OperationType int operationType) { mUser = user; mBackupDestination = backupDestination; mLogger = new BackupRestoreEventLogger(operationType); onCreate(user, backupDestination); } /** Loading
core/java/android/app/backup/BackupAnnotations.java +2 −0 Original line number Diff line number Diff line Loading @@ -30,10 +30,12 @@ public class BackupAnnotations { /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ OperationType.UNKNOWN, OperationType.BACKUP, OperationType.RESTORE, }) public @interface OperationType { int UNKNOWN = -1; int BACKUP = 0; int RESTORE = 1; } Loading
core/java/android/app/backup/BackupRestoreEventLogger.java +1 −16 Original line number Diff line number Diff line Loading @@ -16,13 +16,13 @@ package android.app.backup; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.util.ArrayMap; import android.app.backup.BackupAnnotations.OperationType; import android.util.Slog; import java.lang.annotation.Retention; Loading Loading @@ -55,21 +55,6 @@ public class BackupRestoreEventLogger { */ public static final int DATA_TYPES_ALLOWED = 15; /** * Operation types for which this logger can be used. * * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ OperationType.BACKUP, OperationType.RESTORE }) @interface OperationType { int BACKUP = 1; int RESTORE = 2; } /** * Denotes that the annotated element identifies a data type as required by the logging methods * of {@code BackupRestoreEventLogger} Loading
core/tests/coretests/src/android/app/backup/BackupAgentTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -85,24 +85,26 @@ public class BackupAgentTest { @Test public void getBackupRestoreEventLogger_afterOnCreateForBackup_initializedForBackup() { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.BACKUP); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo(1); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo( OperationType.BACKUP); } @Test public void getBackupRestoreEventLogger_afterOnCreateForRestore_initializedForRestore() { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.RESTORE); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo(1); assertThat(agent.getBackupRestoreEventLogger().getOperationType()).isEqualTo( OperationType.RESTORE); } @Test public void getBackupRestoreEventLogger_afterBackup_containsLogsLoggedByAgent() throws Exception { BackupAgent agent = new TestFullBackupAgent(); agent.onCreate(USER_HANDLE, OperationType.BACKUP); // TODO: pass in new operation type agent.onCreate(USER_HANDLE, BackupDestination.CLOUD, OperationType.BACKUP); // TestFullBackupAgent logs DATA_TYPE_BACKED_UP when onFullBackup is called. agent.onFullBackup(new FullBackupDataOutput(/* quota = */ 0)); Loading