Merge "Route backup data through IntermediateEncryptingTransport"

This commit is contained in:
Chandan Nath
2019-09-25 18:18:28 +00:00
committed by Android (Google) Code Review
4 changed files with 43 additions and 12 deletions

View File

@@ -16,7 +16,10 @@
package com.android.server.backup.encryption.transport;
import static com.android.server.backup.encryption.BackupEncryptionService.TAG;
import android.os.RemoteException;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.backup.IBackupTransport;
@@ -47,6 +50,7 @@ public class IntermediateEncryptingTransport extends DelegatingTransport {
}
private void connect() throws RemoteException {
Log.i(TAG, "connecting " + mTransportClient);
synchronized (mConnectLock) {
if (mRealTransport == null) {
mRealTransport = mTransportClient.connect("IntermediateEncryptingTransport");

View File

@@ -72,6 +72,7 @@ public class IntermediateEncryptingTransportManager {
* Create an instance of {@link IntermediateEncryptingTransport}.
*/
private IntermediateEncryptingTransport create(Intent realTransportIntent) {
Log.d(TAG, "create: intent:" + realTransportIntent);
return new IntermediateEncryptingTransport(mTransportClientManager.getTransportClient(
realTransportIntent.getComponent(), realTransportIntent.getExtras(), CALLER));
}

View File

@@ -93,7 +93,8 @@ public class TransportManager {
mTransportWhitelist = Preconditions.checkNotNull(whitelist);
mCurrentTransportName = selectedTransport;
mTransportStats = new TransportStats();
mTransportClientManager = new TransportClientManager(mUserId, context, mTransportStats);
mTransportClientManager = TransportClientManager.createEncryptingClientManager(mUserId,
context, mTransportStats);
}
@VisibleForTesting

View File

@@ -19,6 +19,7 @@ package com.android.server.backup.transport;
import static com.android.server.backup.TransportManager.SERVICE_ACTION_TRANSPORT_HOST;
import static com.android.server.backup.transport.TransportUtils.formatMessage;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.content.Context;
@@ -32,6 +33,7 @@ import com.android.server.backup.transport.TransportUtils.Priority;
import java.io.PrintWriter;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Function;
/**
* Manages the creation and disposal of {@link TransportClient}s. The only class that should use
@@ -52,6 +54,7 @@ public class TransportClientManager {
private final Object mTransportClientsLock = new Object();
private int mTransportClientsCreated = 0;
private Map<TransportClient, String> mTransportClientsCallerMap = new WeakHashMap<>();
private final Function<ComponentName, Intent> mIntentFunction;
/**
* Return an {@link Intent} which resolves to an intermediate {@link IBackupTransport} that
@@ -64,6 +67,14 @@ public class TransportClientManager {
.putExtra(ENCRYPTING_TRANSPORT_REAL_TRANSPORT_KEY, tranportComponent);
}
/**
* Return an {@link Intent} which resolves to the {@link IBackupTransport} for the {@link
* ComponentName}.
*/
private static Intent getRealTransportIntent(ComponentName transportComponent) {
return new Intent(SERVICE_ACTION_TRANSPORT_HOST).setComponent(transportComponent);
}
/**
* Given a {@link Intent} originally created by {@link
* #getEncryptingTransportIntent(ComponentName)}, returns the {@link Intent} which resolves to
@@ -72,18 +83,35 @@ public class TransportClientManager {
public static Intent getRealTransportIntent(Intent encryptingTransportIntent) {
ComponentName transportComponent = encryptingTransportIntent.getParcelableExtra(
ENCRYPTING_TRANSPORT_REAL_TRANSPORT_KEY);
Intent intent = new Intent(SERVICE_ACTION_TRANSPORT_HOST)
.setComponent(transportComponent)
Intent intent = getRealTransportIntent(transportComponent)
.putExtras(encryptingTransportIntent.getExtras());
intent.removeExtra(ENCRYPTING_TRANSPORT_REAL_TRANSPORT_KEY);
return intent;
}
/**
* Create a {@link TransportClientManager} such that {@link #getTransportClient(ComponentName,
* Bundle, String)} returns a {@link TransportClient} which connects to an intermediate {@link
* IBackupTransport} that encrypts (or decrypts) the data when sending it (or receiving it) from
* the {@link IBackupTransport} for the given {@link ComponentName}.
*/
public static TransportClientManager createEncryptingClientManager(@UserIdInt int userId,
Context context, TransportStats transportStats) {
return new TransportClientManager(userId, context, transportStats,
TransportClientManager::getEncryptingTransportIntent);
}
public TransportClientManager(@UserIdInt int userId, Context context,
TransportStats transportStats) {
this(userId, context, transportStats, TransportClientManager::getRealTransportIntent);
}
private TransportClientManager(@UserIdInt int userId, Context context,
TransportStats transportStats, Function<ComponentName, Intent> intentFunction) {
mUserId = userId;
mContext = context;
mTransportStats = transportStats;
mIntentFunction = intentFunction;
}
/**
@@ -97,10 +125,7 @@ public class TransportClientManager {
* @return A {@link TransportClient}.
*/
public TransportClient getTransportClient(ComponentName transportComponent, String caller) {
Intent bindIntent =
new Intent(SERVICE_ACTION_TRANSPORT_HOST).setComponent(transportComponent);
return getTransportClient(transportComponent, caller, bindIntent);
return getTransportClient(transportComponent, null, caller);
}
/**
@@ -115,11 +140,11 @@ public class TransportClientManager {
* @return A {@link TransportClient}.
*/
public TransportClient getTransportClient(
ComponentName transportComponent, Bundle extras, String caller) {
Intent bindIntent =
new Intent(SERVICE_ACTION_TRANSPORT_HOST).setComponent(transportComponent);
bindIntent.putExtras(extras);
ComponentName transportComponent, @Nullable Bundle extras, String caller) {
Intent bindIntent = mIntentFunction.apply(transportComponent);
if (extras != null) {
bindIntent.putExtras(extras);
}
return getTransportClient(transportComponent, caller, bindIntent);
}