Loading Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ LOCAL_SRC_FILES += \ core/java/android/app/trust/ITrustListener.aidl \ core/java/android/app/backup/IBackupManager.aidl \ core/java/android/app/backup/IBackupObserver.aidl \ core/java/android/app/backup/IBackupManagerMonitor.aidl \ core/java/android/app/backup/IFullBackupRestoreObserver.aidl \ core/java/android/app/backup/IRestoreObserver.aidl \ core/java/android/app/backup/IRestoreSession.aidl \ Loading api/system-current.txt +16 −1 Original line number Diff line number Diff line Loading @@ -6896,7 +6896,7 @@ package android.app.backup { method public boolean isBackupEnabled(); method public java.lang.String[] listAllTransports(); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver, int); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver, android.app.backup.BackupManagerMonitor, int); method public int requestRestore(android.app.backup.RestoreObserver); method public deprecated java.lang.String selectBackupTransport(java.lang.String); method public void selectBackupTransport(android.content.ComponentName, android.app.backup.SelectBackupTransportCallback); Loading @@ -6915,6 +6915,21 @@ package android.app.backup { field public static final int SUCCESS = 0; // 0x0 } public class BackupManagerMonitor { ctor public BackupManagerMonitor(); method public void onEvent(android.os.Bundle); field public static final java.lang.String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; field public static final java.lang.String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_NAME = "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_VERSION = "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; field public static final int LOG_EVENT_CATEGORY_AGENT = 2; // 0x2 field public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; // 0x3 field public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; // 0x1 field public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; // 0x4 field public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; // 0x15 field public static final int LOG_EVENT_ID_NO_PACKAGES = 49; // 0x31 } public abstract class BackupObserver { ctor public BackupObserver(); method public void backupFinished(int); cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java +3 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.commands.bmgr; import android.app.backup.BackupManager; import android.app.backup.BackupManagerMonitor; import android.app.backup.BackupProgress; import android.app.backup.IBackupManager; import android.app.backup.IBackupObserver; Loading Loading @@ -312,8 +313,9 @@ public final class Bmgr { } try { BackupObserver observer = new BackupObserver(); // TODO: implement monitor here? int err = mBmgr.requestBackup(packages.toArray(new String[packages.size()]), observer, flags); null, flags); if (err == 0) { // Off and running -- wait for the backup to complete observer.waitForCompletion(); Loading core/java/android/app/backup/BackupManager.java +24 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.app.backup; import android.annotation.SystemApi; import android.content.ComponentName; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -556,7 +557,7 @@ public class BackupManager { */ @SystemApi public int requestBackup(String[] packages, BackupObserver observer) { return requestBackup(packages, observer, 0); return requestBackup(packages, observer, null, 0); } /** Loading @@ -570,20 +571,26 @@ public class BackupManager { * @param packages List of package names to backup. * @param observer The {@link BackupObserver} to receive callbacks during the backup * operation. Could be {@code null}. * @param monitor The {@link BackupManagerMonitorWrapper} to receive callbacks of important * events during the backup operation. Could be {@code null}. * @param flags {@link #FLAG_NON_INCREMENTAL_BACKUP}. * @return {@link BackupManager#SUCCESS} on success; nonzero on error. * @throws IllegalArgumentException on null or empty {@code packages} param. * @hide */ @SystemApi public int requestBackup(String[] packages, BackupObserver observer, int flags) { public int requestBackup(String[] packages, BackupObserver observer, BackupManagerMonitor monitor, int flags) { checkServiceBinder(); if (sService != null) { try { BackupObserverWrapper observerWrapper = observer == null ? null : new BackupObserverWrapper(mContext, observer); return sService.requestBackup(packages, observerWrapper, flags); BackupManagerMonitorWrapper monitorWrapper = monitor == null ? null : new BackupManagerMonitorWrapper(monitor); return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags); } catch (RemoteException e) { Log.e(TAG, "requestBackup() couldn't connect"); } Loading Loading @@ -680,4 +687,18 @@ public class BackupManager { }); } } private class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub { final BackupManagerMonitor mMonitor; BackupManagerMonitorWrapper(BackupManagerMonitor monitor) { mMonitor = monitor; } @Override public void onEvent(final Bundle event) throws RemoteException { mMonitor.onEvent(event); } } } core/java/android/app/backup/BackupManagerMonitor.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.app.backup; import android.annotation.SystemApi; import android.os.Bundle; /** * Callback class for receiving important events during backup/restore operations. * Events consist mostly of errors and exceptions, giving detailed reason on why a restore/backup * failed or any time BackupManager makes an important decision. * On the other hand {@link BackupObserver} will give a failure/success view without * getting into details why. This callback runs on the thread it was called on because it can get * a bit spammy. * These callbacks will run on the binder thread. * * @hide */ @SystemApi public class BackupManagerMonitor { // Logging constants for BackupManagerMonitor public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; public static final int LOG_EVENT_CATEGORY_AGENT = 2; public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; /** string : the package name */ public static final String EXTRA_LOG_EVENT_PACKAGE_NAME = "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; /** int : the versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME */ public static final String EXTRA_LOG_EVENT_PACKAGE_VERSION = "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; /** int : the id of the log message, will be a unique identifier */ public static final String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; /** * int : category will be one of * { LOG_EVENT_CATEGORY_TRANSPORT, * LOG_EVENT_CATEGORY_AGENT, * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY}. */ public static final String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; // TODO complete this list with all log messages. And document properly. public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; public static final int LOG_EVENT_ID_NO_PACKAGES = 49; /** * This method will be called each time something important happens on BackupManager. * * @param event bundle will contain data about event: * - event id, not optional, a unique identifier for each event. * - package name, optional, the current package we're backing up/restoring if applicable. * - package version, optional, the current package version we're backing up/restoring * if applicable. * - category of event, not optional, one of * { LOG_EVENT_CATEGORY_TRANSPORT, * LOG_EVENT_CATEGORY_AGENT, * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY} * */ public void onEvent(Bundle event) { } } Loading
Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ LOCAL_SRC_FILES += \ core/java/android/app/trust/ITrustListener.aidl \ core/java/android/app/backup/IBackupManager.aidl \ core/java/android/app/backup/IBackupObserver.aidl \ core/java/android/app/backup/IBackupManagerMonitor.aidl \ core/java/android/app/backup/IFullBackupRestoreObserver.aidl \ core/java/android/app/backup/IRestoreObserver.aidl \ core/java/android/app/backup/IRestoreSession.aidl \ Loading
api/system-current.txt +16 −1 Original line number Diff line number Diff line Loading @@ -6896,7 +6896,7 @@ package android.app.backup { method public boolean isBackupEnabled(); method public java.lang.String[] listAllTransports(); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver, int); method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver, android.app.backup.BackupManagerMonitor, int); method public int requestRestore(android.app.backup.RestoreObserver); method public deprecated java.lang.String selectBackupTransport(java.lang.String); method public void selectBackupTransport(android.content.ComponentName, android.app.backup.SelectBackupTransportCallback); Loading @@ -6915,6 +6915,21 @@ package android.app.backup { field public static final int SUCCESS = 0; // 0x0 } public class BackupManagerMonitor { ctor public BackupManagerMonitor(); method public void onEvent(android.os.Bundle); field public static final java.lang.String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; field public static final java.lang.String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_NAME = "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; field public static final java.lang.String EXTRA_LOG_EVENT_PACKAGE_VERSION = "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; field public static final int LOG_EVENT_CATEGORY_AGENT = 2; // 0x2 field public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; // 0x3 field public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; // 0x1 field public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; // 0x4 field public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; // 0x15 field public static final int LOG_EVENT_ID_NO_PACKAGES = 49; // 0x31 } public abstract class BackupObserver { ctor public BackupObserver(); method public void backupFinished(int);
cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java +3 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.commands.bmgr; import android.app.backup.BackupManager; import android.app.backup.BackupManagerMonitor; import android.app.backup.BackupProgress; import android.app.backup.IBackupManager; import android.app.backup.IBackupObserver; Loading Loading @@ -312,8 +313,9 @@ public final class Bmgr { } try { BackupObserver observer = new BackupObserver(); // TODO: implement monitor here? int err = mBmgr.requestBackup(packages.toArray(new String[packages.size()]), observer, flags); null, flags); if (err == 0) { // Off and running -- wait for the backup to complete observer.waitForCompletion(); Loading
core/java/android/app/backup/BackupManager.java +24 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.app.backup; import android.annotation.SystemApi; import android.content.ComponentName; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -556,7 +557,7 @@ public class BackupManager { */ @SystemApi public int requestBackup(String[] packages, BackupObserver observer) { return requestBackup(packages, observer, 0); return requestBackup(packages, observer, null, 0); } /** Loading @@ -570,20 +571,26 @@ public class BackupManager { * @param packages List of package names to backup. * @param observer The {@link BackupObserver} to receive callbacks during the backup * operation. Could be {@code null}. * @param monitor The {@link BackupManagerMonitorWrapper} to receive callbacks of important * events during the backup operation. Could be {@code null}. * @param flags {@link #FLAG_NON_INCREMENTAL_BACKUP}. * @return {@link BackupManager#SUCCESS} on success; nonzero on error. * @throws IllegalArgumentException on null or empty {@code packages} param. * @hide */ @SystemApi public int requestBackup(String[] packages, BackupObserver observer, int flags) { public int requestBackup(String[] packages, BackupObserver observer, BackupManagerMonitor monitor, int flags) { checkServiceBinder(); if (sService != null) { try { BackupObserverWrapper observerWrapper = observer == null ? null : new BackupObserverWrapper(mContext, observer); return sService.requestBackup(packages, observerWrapper, flags); BackupManagerMonitorWrapper monitorWrapper = monitor == null ? null : new BackupManagerMonitorWrapper(monitor); return sService.requestBackup(packages, observerWrapper, monitorWrapper, flags); } catch (RemoteException e) { Log.e(TAG, "requestBackup() couldn't connect"); } Loading Loading @@ -680,4 +687,18 @@ public class BackupManager { }); } } private class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub { final BackupManagerMonitor mMonitor; BackupManagerMonitorWrapper(BackupManagerMonitor monitor) { mMonitor = monitor; } @Override public void onEvent(final Bundle event) throws RemoteException { mMonitor.onEvent(event); } } }
core/java/android/app/backup/BackupManagerMonitor.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package android.app.backup; import android.annotation.SystemApi; import android.os.Bundle; /** * Callback class for receiving important events during backup/restore operations. * Events consist mostly of errors and exceptions, giving detailed reason on why a restore/backup * failed or any time BackupManager makes an important decision. * On the other hand {@link BackupObserver} will give a failure/success view without * getting into details why. This callback runs on the thread it was called on because it can get * a bit spammy. * These callbacks will run on the binder thread. * * @hide */ @SystemApi public class BackupManagerMonitor { // Logging constants for BackupManagerMonitor public static final int LOG_EVENT_CATEGORY_TRANSPORT = 1; public static final int LOG_EVENT_CATEGORY_AGENT = 2; public static final int LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY = 3; /** string : the package name */ public static final String EXTRA_LOG_EVENT_PACKAGE_NAME = "android.app.backup.extra.LOG_EVENT_PACKAGE_NAME"; /** int : the versionCode of the package named by EXTRA_LOG_EVENT_PACKAGE_NAME */ public static final String EXTRA_LOG_EVENT_PACKAGE_VERSION = "android.app.backup.extra.LOG_EVENT_PACKAGE_VERSION"; /** int : the id of the log message, will be a unique identifier */ public static final String EXTRA_LOG_EVENT_ID = "android.app.backup.extra.LOG_EVENT_ID"; /** * int : category will be one of * { LOG_EVENT_CATEGORY_TRANSPORT, * LOG_EVENT_CATEGORY_AGENT, * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY}. */ public static final String EXTRA_LOG_EVENT_CATEGORY = "android.app.backup.extra.LOG_EVENT_CATEGORY"; // TODO complete this list with all log messages. And document properly. public static final int LOG_EVENT_ID_FULL_BACKUP_TIMEOUT = 4; public static final int LOG_EVENT_ID_KEY_VALUE_BACKUP_TIMEOUT = 21; public static final int LOG_EVENT_ID_NO_PACKAGES = 49; /** * This method will be called each time something important happens on BackupManager. * * @param event bundle will contain data about event: * - event id, not optional, a unique identifier for each event. * - package name, optional, the current package we're backing up/restoring if applicable. * - package version, optional, the current package version we're backing up/restoring * if applicable. * - category of event, not optional, one of * { LOG_EVENT_CATEGORY_TRANSPORT, * LOG_EVENT_CATEGORY_AGENT, * LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY} * */ public void onEvent(Bundle event) { } }