Merge "[Multi-user] Transport changes"
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.server.backup;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.annotation.WorkerThread;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.app.backup.BackupTransport;
|
||||
@@ -29,7 +30,6 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Slog;
|
||||
@@ -61,7 +61,7 @@ public class TransportManager {
|
||||
public static final String SERVICE_ACTION_TRANSPORT_HOST = "android.backup.TRANSPORT_HOST";
|
||||
|
||||
private final Intent mTransportServiceIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST);
|
||||
private final Context mContext;
|
||||
private final @UserIdInt int mUserId;
|
||||
private final PackageManager mPackageManager;
|
||||
private final Set<ComponentName> mTransportWhitelist;
|
||||
private final TransportClientManager mTransportClientManager;
|
||||
@@ -86,22 +86,24 @@ public class TransportManager {
|
||||
@Nullable
|
||||
private volatile String mCurrentTransportName;
|
||||
|
||||
TransportManager(Context context, Set<ComponentName> whitelist, String selectedTransport) {
|
||||
mContext = context;
|
||||
TransportManager(@UserIdInt int userId, Context context, Set<ComponentName> whitelist,
|
||||
String selectedTransport) {
|
||||
mUserId = userId;
|
||||
mPackageManager = context.getPackageManager();
|
||||
mTransportWhitelist = Preconditions.checkNotNull(whitelist);
|
||||
mCurrentTransportName = selectedTransport;
|
||||
mTransportStats = new TransportStats();
|
||||
mTransportClientManager = new TransportClientManager(context, mTransportStats);
|
||||
mTransportClientManager = new TransportClientManager(mUserId, context, mTransportStats);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
TransportManager(
|
||||
@UserIdInt int userId,
|
||||
Context context,
|
||||
Set<ComponentName> whitelist,
|
||||
String selectedTransport,
|
||||
TransportClientManager transportClientManager) {
|
||||
mContext = context;
|
||||
mUserId = userId;
|
||||
mPackageManager = context.getPackageManager();
|
||||
mTransportWhitelist = Preconditions.checkNotNull(whitelist);
|
||||
mCurrentTransportName = selectedTransport;
|
||||
@@ -575,7 +577,7 @@ public class TransportManager {
|
||||
private void registerTransportsForIntent(
|
||||
Intent intent, Predicate<ComponentName> transportComponentFilter) {
|
||||
List<ResolveInfo> hosts =
|
||||
mPackageManager.queryIntentServicesAsUser(intent, 0, UserHandle.USER_SYSTEM);
|
||||
mPackageManager.queryIntentServicesAsUser(intent, 0, mUserId);
|
||||
if (hosts == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public class UserBackupManagerService {
|
||||
Slog.v(TAG, "Starting with transport " + currentTransport);
|
||||
}
|
||||
TransportManager transportManager =
|
||||
new TransportManager(context, transportWhitelist, currentTransport);
|
||||
new TransportManager(userId, context, transportWhitelist, currentTransport);
|
||||
|
||||
File baseStateDir = UserBackupManagerFiles.getBaseStateDir(userId);
|
||||
File dataDir = UserBackupManagerFiles.getDataDir(userId);
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.android.server.backup.transport.TransportUtils.formatMessage;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.annotation.WorkerThread;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -34,7 +35,6 @@ import android.os.UserHandle;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.EventLog;
|
||||
import android.util.Slog;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
@@ -79,6 +79,7 @@ public class TransportClient {
|
||||
@VisibleForTesting static final String TAG = "TransportClient";
|
||||
private static final int LOG_BUFFER_SIZE = 5;
|
||||
|
||||
private final @UserIdInt int mUserId;
|
||||
private final Context mContext;
|
||||
private final TransportStats mTransportStats;
|
||||
private final Intent mBindIntent;
|
||||
@@ -106,6 +107,7 @@ public class TransportClient {
|
||||
private volatile IBackupTransport mTransport;
|
||||
|
||||
TransportClient(
|
||||
@UserIdInt int userId,
|
||||
Context context,
|
||||
TransportStats transportStats,
|
||||
Intent bindIntent,
|
||||
@@ -113,6 +115,7 @@ public class TransportClient {
|
||||
String identifier,
|
||||
String caller) {
|
||||
this(
|
||||
userId,
|
||||
context,
|
||||
transportStats,
|
||||
bindIntent,
|
||||
@@ -124,6 +127,7 @@ public class TransportClient {
|
||||
|
||||
@VisibleForTesting
|
||||
TransportClient(
|
||||
@UserIdInt int userId,
|
||||
Context context,
|
||||
TransportStats transportStats,
|
||||
Intent bindIntent,
|
||||
@@ -131,6 +135,7 @@ public class TransportClient {
|
||||
String identifier,
|
||||
String caller,
|
||||
Handler listenerHandler) {
|
||||
mUserId = userId;
|
||||
mContext = context;
|
||||
mTransportStats = transportStats;
|
||||
mTransportComponent = transportComponent;
|
||||
@@ -213,7 +218,7 @@ public class TransportClient {
|
||||
mBindIntent,
|
||||
mConnection,
|
||||
Context.BIND_AUTO_CREATE,
|
||||
UserHandle.SYSTEM);
|
||||
UserHandle.of(mUserId));
|
||||
if (hasBound) {
|
||||
// We don't need to set a time-out because we are guaranteed to get a call
|
||||
// back in ServiceConnection, either an onServiceConnected() or
|
||||
|
||||
@@ -19,12 +19,15 @@ 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.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.server.backup.TransportManager;
|
||||
import com.android.server.backup.transport.TransportUtils.Priority;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
@@ -36,13 +39,16 @@ import java.util.WeakHashMap;
|
||||
public class TransportClientManager {
|
||||
private static final String TAG = "TransportClientManager";
|
||||
|
||||
private final @UserIdInt int mUserId;
|
||||
private final Context mContext;
|
||||
private final TransportStats mTransportStats;
|
||||
private final Object mTransportClientsLock = new Object();
|
||||
private int mTransportClientsCreated = 0;
|
||||
private Map<TransportClient, String> mTransportClientsCallerMap = new WeakHashMap<>();
|
||||
|
||||
public TransportClientManager(Context context, TransportStats transportStats) {
|
||||
public TransportClientManager(@UserIdInt int userId, Context context,
|
||||
TransportStats transportStats) {
|
||||
mUserId = userId;
|
||||
mContext = context;
|
||||
mTransportStats = transportStats;
|
||||
}
|
||||
@@ -89,6 +95,7 @@ public class TransportClientManager {
|
||||
synchronized (mTransportClientsLock) {
|
||||
TransportClient transportClient =
|
||||
new TransportClient(
|
||||
mUserId,
|
||||
mContext,
|
||||
mTransportStats,
|
||||
bindIntent,
|
||||
|
||||
@@ -41,6 +41,7 @@ import static java.util.stream.Collectors.toSet;
|
||||
import static java.util.stream.Stream.concat;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.app.backup.BackupTransport;
|
||||
import android.content.ComponentName;
|
||||
@@ -48,6 +49,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import com.android.server.backup.testing.TransportData;
|
||||
@@ -84,12 +86,14 @@ public class TransportManagerTest {
|
||||
private TransportData mTransportA2;
|
||||
private TransportData mTransportB1;
|
||||
private ShadowPackageManager mShadowPackageManager;
|
||||
private @UserIdInt int mUserId;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mUserId = UserHandle.USER_SYSTEM;
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mShadowPackageManager = shadowOf(mContext.getPackageManager());
|
||||
|
||||
@@ -684,6 +688,7 @@ public class TransportManagerTest {
|
||||
@Nullable TransportData selectedTransport, TransportData... transports) {
|
||||
TransportManager transportManager =
|
||||
new TransportManager(
|
||||
mUserId,
|
||||
mContext,
|
||||
merge(selectedTransport, transports)
|
||||
.stream()
|
||||
|
||||
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -49,6 +50,7 @@ public class TransportClientManagerTest {
|
||||
|
||||
@Mock private Context mContext;
|
||||
@Mock private TransportConnectionListener mTransportConnectionListener;
|
||||
private @UserIdInt int mUserId;
|
||||
private TransportClientManager mTransportClientManager;
|
||||
private ComponentName mTransportComponent;
|
||||
private Intent mBindIntent;
|
||||
@@ -57,7 +59,9 @@ public class TransportClientManagerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mTransportClientManager = new TransportClientManager(mContext, new TransportStats());
|
||||
mUserId = UserHandle.USER_SYSTEM;
|
||||
mTransportClientManager =
|
||||
new TransportClientManager(mUserId, mContext, new TransportStats());
|
||||
mTransportComponent = new ComponentName(PACKAGE_NAME, CLASS_NAME);
|
||||
mBindIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST).setComponent(mTransportComponent);
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import static org.robolectric.shadow.api.Shadow.extract;
|
||||
import static org.testng.Assert.expectThrows;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -83,6 +84,7 @@ public class TransportClientTest {
|
||||
@Mock private TransportConnectionListener mTransportConnectionListener;
|
||||
@Mock private TransportConnectionListener mTransportConnectionListener2;
|
||||
@Mock private IBackupTransport.Stub mTransportBinder;
|
||||
@UserIdInt private int mUserId;
|
||||
private TransportStats mTransportStats;
|
||||
private TransportClient mTransportClient;
|
||||
private ComponentName mTransportComponent;
|
||||
@@ -96,6 +98,7 @@ public class TransportClientTest {
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mUserId = UserHandle.USER_SYSTEM;
|
||||
Looper mainLooper = Looper.getMainLooper();
|
||||
mShadowMainLooper = extract(mainLooper);
|
||||
mTransportComponent =
|
||||
@@ -105,6 +108,7 @@ public class TransportClientTest {
|
||||
mBindIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST).setComponent(mTransportComponent);
|
||||
mTransportClient =
|
||||
new TransportClient(
|
||||
mUserId,
|
||||
mContext,
|
||||
mTransportStats,
|
||||
mBindIntent,
|
||||
|
||||
Reference in New Issue
Block a user