Tests for new revisionCode attribute.
Verifies that split APKs can be updated with higher revision codes,
but never downgraded.
Bug: 19118834
Change-Id: I3ce174952d368a3ec70e6738852c71037ade19ed
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 16f9ec1..e8e7485 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -34,6 +34,7 @@
CtsSplitApp_arm64-v8a \
CtsSplitApp_mips64 \
CtsSplitApp_mips \
+ CtsSplitAppDiffRevision \
CtsSplitAppDiffVersion \
CtsSplitAppDiffCert \
CtsSplitAppFeature \
diff --git a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/SplitTests.java b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/SplitTests.java
index caa3e46..90cbed9 100644
--- a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/SplitTests.java
+++ b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/SplitTests.java
@@ -57,6 +57,9 @@
private static final String APK_mips64 = "CtsSplitApp_mips64.apk";
private static final String APK_mips = "CtsSplitApp_mips.apk";
+ private static final String APK_DIFF_REVISION = "CtsSplitAppDiffRevision.apk";
+ private static final String APK_DIFF_REVISION_v7 = "CtsSplitAppDiffRevision_v7.apk";
+
private static final String APK_DIFF_VERSION = "CtsSplitAppDiffVersion.apk";
private static final String APK_DIFF_VERSION_v7 = "CtsSplitAppDiffVersion_v7.apk";
@@ -233,6 +236,30 @@
new InstallMultiple().inheritFrom(PKG).addApk(APK_DIFF_VERSION_v7).runExpectingFailure();
}
+ public void testDiffRevision() throws Exception {
+ new InstallMultiple().addApk(APK).addApk(APK_DIFF_REVISION_v7).run();
+ runDeviceTests(PKG, ".SplitAppTest", "testRevision0_12");
+ }
+
+ public void testDiffRevisionInheritBase() throws Exception {
+ new InstallMultiple().addApk(APK).addApk(APK_v7).run();
+ runDeviceTests(PKG, ".SplitAppTest", "testRevision0_0");
+ new InstallMultiple().inheritFrom(PKG).addApk(APK_DIFF_REVISION_v7).run();
+ runDeviceTests(PKG, ".SplitAppTest", "testRevision0_12");
+ }
+
+ public void testDiffRevisionInheritSplit() throws Exception {
+ new InstallMultiple().addApk(APK).addApk(APK_v7).run();
+ runDeviceTests(PKG, ".SplitAppTest", "testRevision0_0");
+ new InstallMultiple().inheritFrom(PKG).addApk(APK_DIFF_REVISION).run();
+ runDeviceTests(PKG, ".SplitAppTest", "testRevision12_0");
+ }
+
+ public void testDiffRevisionDowngrade() throws Exception {
+ new InstallMultiple().addApk(APK).addApk(APK_DIFF_REVISION_v7).run();
+ new InstallMultiple().inheritFrom(PKG).addApk(APK_v7).runExpectingFailure();
+ }
+
public void testFeatureBase() throws Exception {
new InstallMultiple().addApk(APK).addApk(APK_FEATURE).run();
runDeviceTests(PKG, ".SplitAppTest", "testFeatureBase");
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
index 8b25f4b..bf89576 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
@@ -30,7 +30,31 @@
LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version -c mdpi -c hdpi -c xhdpi -c xxhdpi
+LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version
+
+LOCAL_PROGUARD_ENABLED := disabled
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_PACKAGE)
+
+
+#################################################
+# Define a variant with a different revision code
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsSplitAppDiffRevision
+LOCAL_PACKAGE_SPLITS := v7
+
+LOCAL_MANIFEST_FILE := revision/AndroidManifest.xml
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
+LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundredRevisionTwelve --replace-version
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
@@ -53,7 +77,7 @@
LOCAL_PACKAGE_SPLITS := v7
LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 101 --version-name OneHundredOne --replace-version -c mdpi -c hdpi -c xhdpi -c xxhdpi
+LOCAL_AAPT_FLAGS := --version-code 101 --version-name OneHundredOne --replace-version
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
@@ -76,7 +100,7 @@
LOCAL_PACKAGE_SPLITS := v7
LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
-LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version -c mdpi -c hdpi -c xhdpi -c xxhdpi
+LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
index e93f6c3..809a6b8 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
@@ -24,7 +24,7 @@
LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version -c mdpi -c hdpi -c xhdpi -c xxhdpi
+LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version
LOCAL_MODULE_TAGS := tests
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/revision/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/SplitApp/revision/AndroidManifest.xml
new file mode 100644
index 0000000..8e053ba
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/revision/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.splitapp"
+ android:revisionCode="12">
+
+ <uses-permission android:name="android.permission.CAMERA" />
+
+ <application android:label="SplitApp">
+ <activity android:name=".MyActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/my_activity_meta" />
+ </activity>
+ <receiver android:name=".MyReceiver"
+ android:enabled="@bool/my_receiver_enabled">
+ <intent-filter>
+ <action android:name="android.intent.action.DATE_CHANGED" />
+ </intent-filter>
+ </receiver>
+
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.cts.splitapp" />
+
+</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/src/com/android/cts/splitapp/SplitAppTest.java b/hostsidetests/appsecurity/test-apps/SplitApp/src/com/android/cts/splitapp/SplitAppTest.java
index 5046458..3d6cee7 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/src/com/android/cts/splitapp/SplitAppTest.java
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/src/com/android/cts/splitapp/SplitAppTest.java
@@ -21,6 +21,7 @@
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
@@ -30,6 +31,7 @@
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -319,6 +321,30 @@
assertFalse(new File(getContext().getCodeCacheDir(), "cache.raw").exists());
}
+ public void testRevision0_0() throws Exception {
+ final PackageInfo info = getContext().getPackageManager()
+ .getPackageInfo(getContext().getPackageName(), 0);
+ assertEquals(0, info.baseRevisionCode);
+ assertEquals(1, info.splitRevisionCodes.length);
+ assertEquals(0, info.splitRevisionCodes[0]);
+ }
+
+ public void testRevision12_0() throws Exception {
+ final PackageInfo info = getContext().getPackageManager()
+ .getPackageInfo(getContext().getPackageName(), 0);
+ assertEquals(12, info.baseRevisionCode);
+ assertEquals(1, info.splitRevisionCodes.length);
+ assertEquals(0, info.splitRevisionCodes[0]);
+ }
+
+ public void testRevision0_12() throws Exception {
+ final PackageInfo info = getContext().getPackageManager()
+ .getPackageInfo(getContext().getPackageName(), 0);
+ assertEquals(0, info.baseRevisionCode);
+ assertEquals(1, info.splitRevisionCodes.length);
+ assertEquals(12, info.splitRevisionCodes[0]);
+ }
+
private static void updateDpi(Resources r, int densityDpi) {
final Configuration c = new Configuration(r.getConfiguration());
c.densityDpi = densityDpi;