Loading packages/BackupEncryption/src/com/android/server/backup/encryption/transport/IntermediateEncryptingTransport.java +4 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); Loading packages/BackupEncryption/src/com/android/server/backup/encryption/transport/IntermediateEncryptingTransportManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -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)); } Loading services/backup/backuplib/java/com/android/server/backup/TransportManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading services/backup/backuplib/java/com/android/server/backup/transport/TransportClientManager.java +36 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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; } /** Loading @@ -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); } /** Loading @@ -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); ComponentName transportComponent, @Nullable Bundle extras, String caller) { Intent bindIntent = mIntentFunction.apply(transportComponent); if (extras != null) { bindIntent.putExtras(extras); } return getTransportClient(transportComponent, caller, bindIntent); } Loading Loading
packages/BackupEncryption/src/com/android/server/backup/encryption/transport/IntermediateEncryptingTransport.java +4 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); Loading
packages/BackupEncryption/src/com/android/server/backup/encryption/transport/IntermediateEncryptingTransportManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -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)); } Loading
services/backup/backuplib/java/com/android/server/backup/TransportManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
services/backup/backuplib/java/com/android/server/backup/transport/TransportClientManager.java +36 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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; } /** Loading @@ -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); } /** Loading @@ -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); ComponentName transportComponent, @Nullable Bundle extras, String caller) { Intent bindIntent = mIntentFunction.apply(transportComponent); if (extras != null) { bindIntent.putExtras(extras); } return getTransportClient(transportComponent, caller, bindIntent); } Loading