Add monitoring to backup in BackupManager.
This is the first CL of many that will add instumentation to backup/restore operation in the BackupManager. For more details please point to: https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit# This first Cl introduces 3 events that we sent to the monitor. Test: ag/1858962 (same topic) BUG: 34873525 Change-Id: I6c338b6fd9f4d7c8670dac201897250b6b170677
This commit is contained in:
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
80
core/java/android/app/backup/BackupManagerMonitor.java
Normal file
80
core/java/android/app/backup/BackupManagerMonitor.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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) {
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.app.backup;
|
||||
|
||||
import android.app.backup.IBackupObserver;
|
||||
import android.app.backup.IBackupManagerMonitor;
|
||||
import android.app.backup.IFullBackupRestoreObserver;
|
||||
import android.app.backup.IRestoreSession;
|
||||
import android.app.backup.ISelectBackupTransportCallback;
|
||||
@@ -376,9 +377,13 @@ interface IBackupManager {
|
||||
* @param observer The {@link BackupObserver} to receive callbacks during the backup
|
||||
* operation.
|
||||
*
|
||||
* @param monitor the {@link BackupManagerMonitor} to receive callbacks about important events
|
||||
* during the backup operation.
|
||||
*
|
||||
* @param flags {@link BackupManager#FLAG_NON_INCREMENTAL_BACKUP}.
|
||||
*
|
||||
* @return Zero on success; nonzero on error.
|
||||
*/
|
||||
int requestBackup(in String[] packages, IBackupObserver observer, int flags);
|
||||
int requestBackup(in String[] packages, IBackupObserver observer, IBackupManagerMonitor monitor,
|
||||
int flags);
|
||||
}
|
||||
|
||||
36
core/java/android/app/backup/IBackupManagerMonitor.aidl
Normal file
36
core/java/android/app/backup/IBackupManagerMonitor.aidl
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.os.Bundle;
|
||||
|
||||
/**
|
||||
* Callback class for receiving important events during backup/restore operations.
|
||||
* These callbacks will run on the binder thread.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
oneway interface IBackupManagerMonitor {
|
||||
|
||||
/**
|
||||
* This method will be called each time something important happens on BackupManager.
|
||||
*
|
||||
* @param event bundle will contain data about event, like package name, package version etc.
|
||||
*/
|
||||
void onEvent(in Bundle event);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user