Revert Session.transfer tests
This reverts:
8745fd152602f640bd4152cc42e6e4041097042f
3b5d2ed11e0d135275c15c96edcc04e8a65ec522
Bug: 64467704
Test: none, 100% revert
Change-Id: Iadda74926db5fa6d4f38ab6bff4d5f8c07426a9f
diff --git a/tests/tests/content/AndroidTest.xml b/tests/tests/content/AndroidTest.xml
index 5cab0ac..92d8963 100644
--- a/tests/tests/content/AndroidTest.xml
+++ b/tests/tests/content/AndroidTest.xml
@@ -16,23 +16,10 @@
<configuration description="Config for CTS Content test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="framework" />
-
- <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
- <option name="run-command" value="mkdir -p /data/local/tmp/cts/content" />
- <option name="teardown-command" value="rm -rf /data/local/tmp/cts"/>
- </target_preparer>
-
- <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
- <option name="cleanup" value="true" />
- <option name="push" value="CtsContentTestCases.apk->/data/local/tmp/cts/content/CtsContentTestCases.apk" />
- <option name="push" value="CtsContentEmptyTestApp.apk->/data/local/tmp/cts/content/CtsContentEmptyTestApp.apk" />
- </target_preparer>
-
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="CtsContentTestCases.apk" />
</target_preparer>
-
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="android.content.cts" />
<option name="runtime-hint" value="21m30s" />
diff --git a/tests/tests/content/emptytestapp/Android.mk b/tests/tests/content/emptytestapp/Android.mk
deleted file mode 100644
index ea4d35a..0000000
--- a/tests/tests/content/emptytestapp/Android.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright (C) 2017 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.
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsContentEmptyTestApp
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-
-LOCAL_SDK_VERSION := current
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
-
-include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/content/emptytestapp/AndroidManifest.xml b/tests/tests/content/emptytestapp/AndroidManifest.xml
deleted file mode 100644
index 88bc06c..0000000
--- a/tests/tests/content/emptytestapp/AndroidManifest.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 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="android.content.cts.emptytestapp" >
- <application android:hasCode="false" android:label="Empty Test App" />
-</manifest>
diff --git a/tests/tests/content/src/android/content/pm/cts/InstallSessionParamsUnitTest.java b/tests/tests/content/src/android/content/pm/cts/InstallSessionParamsUnitTest.java
deleted file mode 100644
index d978b70..0000000
--- a/tests/tests/content/src/android/content/pm/cts/InstallSessionParamsUnitTest.java
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * Copyright (C) 2017 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 android.content.pm.cts;
-
-import static android.content.pm.PackageInfo.INSTALL_LOCATION_AUTO;
-import static android.content.pm.PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
-import static android.content.pm.PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL;
-import static android.content.pm.PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
-import static android.content.pm.PackageInstaller.SessionParams.MODE_FULL_INSTALL;
-import static android.content.pm.PackageInstaller.SessionParams.MODE_INHERIT_EXISTING;
-import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_RESTORE;
-import static android.content.pm.PackageManager.INSTALL_REASON_DEVICE_SETUP;
-import static android.content.pm.PackageManager.INSTALL_REASON_POLICY;
-import static android.content.pm.PackageManager.INSTALL_REASON_UNKNOWN;
-import static android.content.pm.PackageManager.INSTALL_REASON_USER;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.junit.Assert.fail;
-
-import android.content.Context;
-import android.content.pm.PackageInstaller;
-import android.content.pm.PackageInstaller.SessionInfo;
-import android.content.pm.PackageInstaller.SessionParams;
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.support.test.InstrumentationRegistry;
-import android.util.Log;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.function.Consumer;
-
-@RunWith(Parameterized.class)
-public class InstallSessionParamsUnitTest {
- private static final String LOG_TAG = InstallSessionParamsUnitTest.class.getSimpleName();
- private static Optional UNSET = new Optional(false, null);
-
- @Parameterized.Parameter(0)
- public Optional<Integer> mode;
- @Parameterized.Parameter(1)
- public Optional<Integer> installLocation;
- @Parameterized.Parameter(2)
- public Optional<Integer> size;
- @Parameterized.Parameter(3)
- public Optional<String> appPackageName;
- @Parameterized.Parameter(4)
- public Optional<Bitmap> appIcon;
- @Parameterized.Parameter(5)
- public Optional<String> appLabel;
- @Parameterized.Parameter(6)
- public Optional<Uri> originatingUri;
- @Parameterized.Parameter(7)
- public Optional<Integer> originatingUid;
- @Parameterized.Parameter(8)
- public Optional<Uri> referredUri;
- @Parameterized.Parameter(9)
- public Optional<Integer> installReason;
- @Parameterized.Parameter(10)
- public boolean expectFailure;
-
- /**
- * Generate test-parameters where all params are the same, but one param cycles through all
- * values.
- */
- private static ArrayList<Object[]> getSingleParameterChangingTests(
- Object[][][] allParameterValues, int changingParameterIndex,
- Object[] changingParameterValues, boolean expectFailure) {
- ArrayList<Object[]> params = new ArrayList<>();
-
- for (Object changingParameterValue : changingParameterValues) {
- ArrayList<Object> singleTestParams = new ArrayList<>();
-
- // parameterIndex is the index of the parameter (0 = mode, ...)
- for (int parameterIndex = 0; parameterIndex < allParameterValues.length;
- parameterIndex++) {
- Object[][] parameterValues = allParameterValues[parameterIndex];
-
- if (parameterIndex == changingParameterIndex) {
- if (changingParameterValue == UNSET) {
- // No need to wrap UNSET again
- singleTestParams.add(UNSET);
- } else {
- singleTestParams.add(Optional.of(changingParameterValue));
- }
- } else {
- singleTestParams.add(Optional.of(parameterValues[0][0]));
- }
- }
- singleTestParams.add(expectFailure);
- params.add(singleTestParams.toArray());
- }
-
- return params;
- }
-
- /**
- * Generate test-parameters for all tests.
- */
- @Parameterized.Parameters
- public static Collection<Object[]> getParameters() {
- // {{{valid parameters}, {invalid parameters}}}
- Object[][][] allParameterValues = {
- /*mode*/
- {{MODE_FULL_INSTALL, MODE_INHERIT_EXISTING}, {0xfff}},
- /*installLocation*/
- {{INSTALL_LOCATION_UNSPECIFIED, INSTALL_LOCATION_AUTO,
- INSTALL_LOCATION_INTERNAL_ONLY, INSTALL_LOCATION_PREFER_EXTERNAL,
- /* parame is not verified */ 0xfff}, {}},
- /*size*/
- {{1, 8092, Integer.MAX_VALUE, /* parame is not verified */ -1, 0}, {}},
- /*appPackageName*/
- {{"a.package.name", null, /* param is not verified */ "android"}, {}},
- /*appIcon*/
- {{null, Bitmap.createBitmap(42, 42, Bitmap.Config.ARGB_8888)}, {}},
- /*appLabel*/
- {{"A label", null}, {}},
- /*originatingUri*/
- {{Uri.parse("android.com"), null}, {}},
- /*originatingUid*/
- {{-1, 0, 1}, {}},
- /*referredUri*/
- {{Uri.parse("android.com"), null}, {}},
- /*installReason*/
- {{INSTALL_REASON_UNKNOWN, INSTALL_REASON_POLICY, INSTALL_REASON_DEVICE_RESTORE,
- INSTALL_REASON_DEVICE_SETUP, INSTALL_REASON_USER,
- /* parame is not verified */ 0xfff}, {}}};
-
- ArrayList<Object[]> allTestParams = new ArrayList<>();
-
- // changingParameterIndex is the index the parameter that changes (0 = mode ...)
- for (int changingParameterIndex = 0; changingParameterIndex < allParameterValues.length;
- changingParameterIndex++) {
- // Allowed values
- allTestParams.addAll(getSingleParameterChangingTests(allParameterValues,
- changingParameterIndex, allParameterValues[changingParameterIndex][0], false));
-
- // Value unset (mode param cannot be unset)
- if (changingParameterIndex != 0) {
- Object[] unset = {UNSET};
- allTestParams.addAll(getSingleParameterChangingTests(allParameterValues,
- changingParameterIndex, unset, false));
- }
-
- // Illegal values
- allTestParams.addAll(getSingleParameterChangingTests(allParameterValues,
- changingParameterIndex, allParameterValues[changingParameterIndex][1], true));
- }
-
- return allTestParams;
- }
-
- /**
- * Get the sessionInfo if this package owns the session.
- *
- * @param sessionId The id of the session
- *
- * @return The {@link PackageInstaller.SessionInfo} object, or {@code null} if session is not
- * owned by the this package.
- */
- private SessionInfo getSessionInfo(int sessionId) {
- Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
- PackageInstaller installer = context.getPackageManager().getPackageInstaller();
- List<SessionInfo> mySessionInfos = installer.getMySessions();
-
- for (SessionInfo sessionInfo : mySessionInfos) {
- if (sessionInfo.sessionId == sessionId) {
- return sessionInfo;
- }
- }
-
- return null;
- }
-
- /**
- * Create a new installer session.
- *
- * @return The new session
- */
- private int createSession(SessionParams params) throws Exception {
- Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
- PackageInstaller installer = context.getPackageManager().getPackageInstaller();
-
- return installer.createSession(params);
- }
-
- @Test
- public void checkSessionParams() throws Exception {
- Log.i(LOG_TAG, "mode=" + mode + " installLocation=" + installLocation + " size=" + size
- + " appPackageName=" + appPackageName + " appIcon=" + appIcon + " appLabel="
- + appLabel + " originatingUri=" + originatingUri + " originatingUid="
- + originatingUid + " referredUri=" + referredUri + " installReason=" + installReason
- + " expectFailure=" + expectFailure);
-
- SessionParams params = new SessionParams(mode.get());
- installLocation.ifPresent(params::setInstallLocation);
- size.ifPresent(params::setSize);
- appPackageName.ifPresent(params::setAppPackageName);
- appIcon.ifPresent(params::setAppIcon);
- appLabel.ifPresent(params::setAppLabel);
- originatingUri.ifPresent(params::setOriginatingUri);
- originatingUid.ifPresent(params::setOriginatingUid);
- referredUri.ifPresent(params::setReferrerUri);
- installReason.ifPresent(params::setInstallReason);
-
- int sessionId;
- try {
- sessionId = createSession(params);
-
- if (expectFailure) {
- fail("Creating session did not fail");
- }
- } catch (Exception e) {
- if (expectFailure) {
- return;
- }
-
- throw e;
- }
-
- SessionInfo info = getSessionInfo(sessionId);
-
- assertThat(info.getMode()).isEqualTo(mode.get());
- installLocation.ifPresent(i -> assertThat(info.getInstallLocation()).isEqualTo(i));
- size.ifPresent(i -> assertThat(info.getSize()).isEqualTo(i));
- appPackageName.ifPresent(s -> assertThat(info.getAppPackageName()).isEqualTo(s));
-
- if (appIcon.isPresent()) {
- if (appIcon.get() == null) {
- assertThat(info.getAppIcon()).isNull();
- } else {
- assertThat(appIcon.get().sameAs(info.getAppIcon())).isTrue();
- }
- }
-
- appLabel.ifPresent(s -> assertThat(info.getAppLabel()).isEqualTo(s));
- originatingUri.ifPresent(uri -> assertThat(info.getOriginatingUri()).isEqualTo(uri));
- originatingUid.ifPresent(i -> assertThat(info.getOriginatingUid()).isEqualTo(i));
- referredUri.ifPresent(uri -> assertThat(info.getReferrerUri()).isEqualTo(uri));
- installReason.ifPresent(i -> assertThat(info.getInstallReason()).isEqualTo(i));
- }
-
- /** Similar to java.util.Optional but distinguishing between null and unset */
- private static class Optional<T> {
- private final boolean mIsSet;
- private final T mValue;
-
- Optional(boolean isSet, T value) {
- mIsSet = isSet;
- mValue = value;
- }
-
- static <T> Optional of(T value) {
- return new Optional(true, value);
- }
-
- T get() {
- if (!mIsSet) {
- throw new IllegalStateException(this + " is not set");
- }
- return mValue;
- }
-
- public String toString() {
- if (!mIsSet) {
- return "unset";
- } else if (mValue == null) {
- return "null";
- } else {
- return mValue.toString();
- }
- }
-
- boolean isPresent() {
- return mIsSet;
- }
-
- void ifPresent(Consumer<T> consumer) {
- if (mIsSet) {
- consumer.accept(mValue);
- }
- }
- }
-}
diff --git a/tests/tests/content/src/android/content/pm/cts/InstallSessionTransferTest.java b/tests/tests/content/src/android/content/pm/cts/InstallSessionTransferTest.java
deleted file mode 100644
index dd45668..0000000
--- a/tests/tests/content/src/android/content/pm/cts/InstallSessionTransferTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright (C) 2017 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 android.content.pm.cts;
-
-import static android.content.pm.PackageInstaller.SessionParams.MODE_FULL_INSTALL;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeNotNull;
-
-import android.annotation.NonNull;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageInstaller;
-import android.content.pm.PackageInstaller.Session;
-import android.content.pm.PackageInstaller.SessionInfo;
-import android.content.pm.PackageInstaller.SessionParams;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import libcore.io.Streams;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-@RunWith(AndroidJUnit4.class)
-public class InstallSessionTransferTest {
- /**
- * Get the sessionInfo if this package owns the session.
- *
- * @param sessionId The id of the session
- *
- * @return The {@link PackageInstaller.SessionInfo} object, or {@code null} if session is not
- * owned by the this package.
- */
- private SessionInfo getSessionInfo(@NonNull PackageInstaller installer,
- int sessionId) {
- List<SessionInfo> mySessionInfos = installer.getMySessions();
-
- for (SessionInfo sessionInfo : mySessionInfos) {
- if (sessionInfo.sessionId == sessionId) {
- return sessionInfo;
- }
- }
-
- return null;
- }
-
- /**
- * Get name of the package installer.
- *
- * @return The package name of the package installer
- */
- private static String getPackageInstallerPackageName() throws Exception {
- Intent installerIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
- installerIntent.setDataAndType(Uri.fromFile(new File("foo.apk")),
- "application/vnd.android.package-archive");
-
- ResolveInfo installer = InstrumentationRegistry.getInstrumentation().getTargetContext()
- .getPackageManager().resolveActivity(installerIntent,
- PackageManager.MATCH_DEFAULT_ONLY);
-
- if (installer != null) {
- return installer.activityInfo.packageName;
- }
-
- return null;
- }
-
- /**
- * Write an APK to the session.
- *
- * @param session The session to write to
- * @param name The name of the apk to write
- */
- private void writeApk(@NonNull Session session, @NonNull String name) throws IOException {
- try (InputStream in = new FileInputStream("/data/local/tmp/cts/content/" + name + ".apk")) {
- try (OutputStream out = session.openWrite(name, 0, -1)) {
- Streams.copy(in, out);
- }
- }
- }
-
- /**
- * Create a new installer session.
- *
- * @return The new session
- */
- private Session createSession() throws Exception {
- Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
-
- PackageInstaller installer = context.getPackageManager().getPackageInstaller();
-
- SessionParams params = new SessionParams(MODE_FULL_INSTALL);
- int sessionId = installer.createSession(params);
- return installer.openSession(sessionId);
- }
-
- @Test
- public void transferSession() throws Exception {
- Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
-
- String packageInstallerPackage = getPackageInstallerPackageName();
- assumeNotNull(packageInstallerPackage);
-
- PackageInstaller installer = context.getPackageManager().getPackageInstaller();
-
- SessionParams params = new SessionParams(MODE_FULL_INSTALL);
- int sessionId = installer.createSession(params);
- Session session = installer.openSession(sessionId);
-
- writeApk(session, "CtsContentTestCases");
-
- InputStream danglingReadStream = session.openRead("CtsContentTestCases");
-
- SessionInfo info = getSessionInfo(installer, sessionId);
- assertThat(info.getInstallerPackageName()).isEqualTo(context.getPackageName());
- assertThat(info.isSealed()).isFalse();
-
- // This transfers the session to the new owner
- session.transfer(packageInstallerPackage);
- assertThat(getSessionInfo(installer, sessionId)).isNull();
-
- try {
- // Session is transferred, all operations on the session are invalid
- session.getNames();
- fail();
- } catch (SecurityException e) {
- // expected
- }
-
- // Even when the session is transferred read streams still work and contain the same content
- // that we initially wrote into it.
- try (InputStream originalContent = new FileInputStream(
- "/data/local/tmp/cts/content/CtsContentTestCases.apk")) {
- try (InputStream sessionContent = danglingReadStream) {
- byte[] buffer = new byte[4096];
- while (true) {
- int numReadOriginal = originalContent.read(buffer);
- int numReadSession = sessionContent.read(buffer);
-
- assertThat(numReadOriginal).isEqualTo(numReadSession);
- if (numReadOriginal == -1) {
- break;
- }
- }
- }
- }
-
- danglingReadStream.close();
- }
-
- @Test
- public void transferToInvalidNewOwner() throws Exception {
- Session session = createSession();
- writeApk(session, "CtsContentTestCases");
-
- try {
- // This will fail as the name of the new owner is invalid
- session.transfer("android.content.cts.invalid.package");
- fail();
- } catch (PackageManager.NameNotFoundException e) {
- // Expected
- }
-
- session.abandon();
- }
-
- @Test
- public void transferToOwnerWithoutInstallPermission() throws Exception {
- Session session = createSession();
- writeApk(session, "CtsContentTestCases");
-
- try {
- // This will fail as the current package does not own the install-packages permission
- session.transfer(InstrumentationRegistry.getInstrumentation().getTargetContext()
- .getPackageName());
- fail();
- } catch (SecurityException e) {
- // Expected
- }
-
- session.abandon();
- }
-
- @Test
- public void transferWithOpenWrite() throws Exception {
- Session session = createSession();
- String packageInstallerPackage = getPackageInstallerPackageName();
- assumeNotNull(packageInstallerPackage);
-
- session.openWrite("danglingWriteStream", 0, 1);
- try {
- // This will fail as the danglingWriteStream is still open
- session.transfer(packageInstallerPackage);
- fail();
- } catch (SecurityException e) {
- // Expected
- }
-
- session.abandon();
- }
-
- @Test
- public void transferSessionWithInvalidApk() throws Exception {
- Session session = createSession();
- String packageInstallerPackage = getPackageInstallerPackageName();
- assumeNotNull(packageInstallerPackage);
-
- try (OutputStream out = session.openWrite("invalid", 0, 2)) {
- out.write(new byte[]{23, 42});
- out.flush();
- }
-
- try {
- // This will fail as the content of 'invalid' is not a valid APK
- session.transfer(packageInstallerPackage);
- fail();
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- session.abandon();
- }
-
- @Test
- public void transferWithApkFromWrongPackage() throws Exception {
- Session session = createSession();
- String packageInstallerPackage = getPackageInstallerPackageName();
- assumeNotNull(packageInstallerPackage);
-
- writeApk(session, "CtsContentEmptyTestApp");
-
- try {
- // This will fail as the session contains the a apk from the wrong package
- session.transfer(packageInstallerPackage);
- fail();
- } catch (SecurityException e) {
- // expected
- }
-
- session.abandon();
- }
-}