|
|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|