summaryrefslogtreecommitdiff
path: root/services/robotests/src
diff options
context:
space:
mode:
authorRuslan Tkhakokhov <rthakohov@google.com>2019-01-19 21:35:32 +0000
committerRuslan Tkhakokhov <rthakohov@google.com>2019-01-23 15:57:11 +0000
commit6712b72a485e87e7b5a3fb8795892c539ebaa5ba (patch)
tree0dfe80ed154a56537ca50f1477e613ef4074417b /services/robotests/src
parenta47310fde06c41a7b41ddb59db767993e195180d (diff)
[Multi-user] Verfiy full backup/restore flow
Bug: 121198030 Test: 1) atest RunBackupFrameworksServicesRoboTests 2) atest $(find \ frameworks/base/services/tests/servicestests/src/com/android/server/backup \ -name '*Test.java') 3) atest CtsBackupTestCases 4) atest CtsBackupHostTestCases 5) atest GtsBackupTestCases 6) atest GtsBackupHostTestCases Manual testing: 1. Start secondary user -> verify fb-schedule file is created, full backup queue initialised 2. Verify fullbackup of 1 package for system/secondary users, [package] only exists for current user: * bmgr --user [user-id] fullbackup [package] * Verify in logs that backup is successful * Uninstall/install [package] * Verify data is restored 3. Verify fullbackup of 1 package for secondary user, [package] eixtst for user 0: * bmgr fullbackup [package] * bmgr --user [user-id] fullbackup [package] * Verify in logs that backup is successful * Uninstall/install [package] for secondary user * bmgr --user [user-id] restore [token] [package] * Verify the data restored is different from system user data and belongs to [user-id] 3. Verify backup of all packages for system/secondary users: * bmgr --user [user-id] backupnow --all * Verify system packages (android, settings, wallpaper) are skipped for secondary user * Verify in logs that backup is successful * Uninstall/install [package] * Verify data is restored Base -> Patchset 2: Update method calls to use asUser versions Patchset 2 -> Patchset 3: Update opComplete callback to accept userId Patchset 3 -> Patchset 4: Gate system packages from backup/restore for non-system users Change-Id: Ic3986709ba4d46c0af9da45bb4dd682ee2aef3ce
Diffstat (limited to 'services/robotests/src')
-rw-r--r--services/robotests/src/com/android/server/testing/shadows/ShadowAppBackupUtils.java2
-rw-r--r--services/robotests/src/com/android/server/testing/shadows/ShadowBackupActivityThread.java79
2 files changed, 80 insertions, 1 deletions
diff --git a/services/robotests/src/com/android/server/testing/shadows/ShadowAppBackupUtils.java b/services/robotests/src/com/android/server/testing/shadows/ShadowAppBackupUtils.java
index aefc871d2639..33b8aa73d293 100644
--- a/services/robotests/src/com/android/server/testing/shadows/ShadowAppBackupUtils.java
+++ b/services/robotests/src/com/android/server/testing/shadows/ShadowAppBackupUtils.java
@@ -62,7 +62,7 @@ public class ShadowAppBackupUtils {
}
@Implementation
- protected static boolean appIsEligibleForBackup(ApplicationInfo app, PackageManager pm) {
+ protected static boolean appIsEligibleForBackup(ApplicationInfo app, int userId) {
return sAppsEligibleForBackup.contains(app.packageName);
}
diff --git a/services/robotests/src/com/android/server/testing/shadows/ShadowBackupActivityThread.java b/services/robotests/src/com/android/server/testing/shadows/ShadowBackupActivityThread.java
new file mode 100644
index 000000000000..ca2e3b6dafef
--- /dev/null
+++ b/services/robotests/src/com/android/server/testing/shadows/ShadowBackupActivityThread.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2019 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 com.android.server.testing.shadows;
+
+import android.app.ActivityThread;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
+import android.os.RemoteException;
+
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.shadows.ShadowActivityThread;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Extends the existing {@link ShadowActivityThread} to add support for
+ * {@link PackageManager#getApplicationEnabledSetting(String)} in the shadow {@link PackageManager}
+ * returned by {@link ShadowBackupActivityThread#getPackageManager()}.
+ */
+@Implements(value = ActivityThread.class, isInAndroidSdk = false, looseSignatures = true)
+public class ShadowBackupActivityThread extends ShadowActivityThread {
+ @Implementation
+ public static Object getPackageManager() {
+ ClassLoader classLoader = ShadowActivityThread.class.getClassLoader();
+ Class<?> iPackageManagerClass;
+ try {
+ iPackageManagerClass = classLoader.loadClass("android.content.pm.IPackageManager");
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ return Proxy.newProxyInstance(
+ classLoader,
+ new Class[] {iPackageManagerClass},
+ new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, @Nonnull Method method, Object[] args)
+ throws Exception {
+ if (method.getName().equals("getApplicationInfo")) {
+ String packageName = (String) args[0];
+ int flags = (Integer) args[1];
+
+ try {
+ return RuntimeEnvironment.application
+ .getPackageManager()
+ .getApplicationInfo(packageName, flags);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new RemoteException(e.getMessage());
+ }
+ } else if (method.getName().equals("getApplicationEnabledSetting")) {
+ return 0;
+ } else {
+ return null;
+ }
+ }
+ });
+ }
+}