Add BackupTransport#getBackupManagerMonitor
This allows the framework to ask for a monitor to use for backups that are initiated by the framework (i.e. scheduled backups). Previously the only way to pass a monitor in was through the BackupManager#requestBackup API. I also moved BackupManagerMonitorWrapper to a separate class now that it's shared by three different classes. Bug: 252763821 Test: atest CtsBackupHostTestCases Also manually by implementing a simple monitor inside LocalTransport and calling the new getBackupManagerMonitor. Change-Id: I84d56a3e80d6c94f9a327f7d71876d1bc27fe5ac
This commit is contained in:
@@ -29,7 +29,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
@@ -1123,18 +1122,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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;
|
||||
import android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Wrapper around {@link BackupManagerMonitor} that helps with IPC between the caller of backup
|
||||
* APIs and the backup service.
|
||||
*
|
||||
* The caller implements {@link BackupManagerMonitor} and passes it into framework APIs that run on
|
||||
* the caller's process. Those framework APIs will then wrap it around this class when doing the
|
||||
* actual IPC.
|
||||
*/
|
||||
class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub {
|
||||
private final BackupManagerMonitor mMonitor;
|
||||
|
||||
BackupManagerMonitorWrapper(BackupManagerMonitor monitor) {
|
||||
mMonitor = monitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(final Bundle event) throws RemoteException {
|
||||
mMonitor.onEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -655,6 +655,20 @@ public class BackupTransport {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the transport for a {@link IBackupManagerMonitor} instance which will be used by the
|
||||
* framework to report logging events back to the transport.
|
||||
*
|
||||
* <p>Backups requested from outside the framework may pass in a monitor with the request,
|
||||
* however backups initiated by the framework will call this method to retrieve one.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Nullable
|
||||
public BackupManagerMonitor getBackupManagerMonitor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridge between the actual IBackupTransport implementation and the stable API. If the
|
||||
* binder interface needs to change, we use this layer to translate so that we can
|
||||
@@ -952,5 +966,15 @@ public class BackupTransport {
|
||||
callback.onOperationCompleteWithStatus(BackupTransport.TRANSPORT_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBackupManagerMonitor(AndroidFuture<IBackupManagerMonitor> resultFuture) {
|
||||
try {
|
||||
BackupManagerMonitor result = BackupTransport.this.getBackupManagerMonitor();
|
||||
resultFuture.complete(new BackupManagerMonitorWrapper(result));
|
||||
} catch (RuntimeException e) {
|
||||
resultFuture.cancel(/* mayInterruptIfRunning */ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
@@ -393,17 +392,4 @@ public class RestoreSession {
|
||||
mHandler.obtainMessage(MSG_RESTORE_FINISHED, error, 0));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.internal.backup;
|
||||
|
||||
import android.app.backup.IBackupManagerMonitor;
|
||||
import android.app.backup.RestoreDescription;
|
||||
import android.app.backup.RestoreSet;
|
||||
import android.content.Intent;
|
||||
@@ -400,4 +401,13 @@ oneway interface IBackupTransport {
|
||||
* <p>For supported flags see {@link android.app.backup.BackupAgent}.
|
||||
*/
|
||||
void getTransportFlags(in AndroidFuture<int> resultFuture);
|
||||
|
||||
/**
|
||||
* Ask the transport for a {@link IBackupManagerMonitor} instance which will be used by the
|
||||
* framework to report logging events back to the transport.
|
||||
*
|
||||
* Backups requested from outside the framework may pass in a monitor with the request,
|
||||
* however backups initiated by the framework will call this method to retrieve one.
|
||||
*/
|
||||
void getBackupManagerMonitor(in AndroidFuture<IBackupManagerMonitor> resultFuture);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.app.backup.BackupTransport;
|
||||
import android.app.backup.IBackupManagerMonitor;
|
||||
import android.app.backup.RestoreDescription;
|
||||
import android.app.backup.RestoreSet;
|
||||
import android.content.Intent;
|
||||
@@ -254,6 +255,9 @@ public class BackupTransportClientTest {
|
||||
ITransportStatusCallback c) throws RemoteException {}
|
||||
@Override public void abortFullRestore(ITransportStatusCallback c) throws RemoteException {}
|
||||
@Override public void getTransportFlags(AndroidFuture<Integer> f) throws RemoteException {}
|
||||
@Override
|
||||
public void getBackupManagerMonitor(AndroidFuture<IBackupManagerMonitor> resultFuture)
|
||||
throws RemoteException {}
|
||||
@Override public IBinder asBinder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user