Merge "Create a common lib for app enumeration tests" into rvc-dev
diff --git a/tests/tests/appenumeration/Android.bp b/tests/tests/appenumeration/Android.bp
index 2304cef..3bb83dc 100644
--- a/tests/tests/appenumeration/Android.bp
+++ b/tests/tests/appenumeration/Android.bp
@@ -26,6 +26,7 @@
"compatibility-device-util-axt",
"androidx.test.ext.junit",
"hamcrest-library",
+ "CtsAppEnumerationTestLib",
],
srcs: ["src/**/*.java"],
diff --git a/tests/tests/appenumeration/app/source/Android.bp b/tests/tests/appenumeration/app/source/Android.bp
index 1250634..01d26fa 100644
--- a/tests/tests/appenumeration/app/source/Android.bp
+++ b/tests/tests/appenumeration/app/source/Android.bp
@@ -12,156 +12,141 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+java_defaults {
+ name: "CtsAppEnumerationQueriesDefaults",
+ srcs: ["src/**/*.java"],
+ static_libs: ["CtsAppEnumerationTestLib"],
+ sdk_version: "test_current",
+}
+
android_test_helper_app {
name: "CtsAppEnumerationQueriesNothing",
manifest: "AndroidManifest-queriesNothing.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesActivityViaAction",
manifest: "AndroidManifest-queriesActivityAction.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesServiceViaAction",
manifest: "AndroidManifest-queriesServiceAction.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesProviderViaAuthority",
manifest: "AndroidManifest-queriesProviderAuthority.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesUnexportedActivityViaAction",
manifest: "AndroidManifest-queriesUnexportedActivityAction.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesUnexportedServiceViaAction",
manifest: "AndroidManifest-queriesUnexportedServiceAction.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesUnexportedProviderViaAuthority",
manifest: "AndroidManifest-queriesUnexportedProviderAuthority.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesPackage",
manifest: "AndroidManifest-queriesPackage.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesNothingTargetsQ",
manifest: "AndroidManifest-queriesNothing-targetsQ.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationQueriesNothingHasPermission",
manifest: "AndroidManifest-queriesNothing-hasPermission.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
android_test_helper_app {
name: "CtsAppEnumerationSharedUidSource",
manifest: "AndroidManifest-queriesNothing-sharedUser.xml",
- defaults: ["cts_support_defaults"],
- srcs: ["src/**/*.java"],
+ defaults: ["CtsAppEnumerationQueriesDefaults"],
// Tag this module as a cts test artifact
test_suites: [
"cts",
"vts",
"general-tests",
],
- sdk_version: "test_current",
}
\ No newline at end of file
diff --git a/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java b/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
index 0b38712..01aef3c 100644
--- a/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
+++ b/tests/tests/appenumeration/app/source/src/android/appenumeration/cts/query/TestActivity.java
@@ -16,6 +16,17 @@
package android.appenumeration.cts.query;
+import static android.appenumeration.cts.Constants.ACTION_GET_INSTALLED_PACKAGES;
+import static android.appenumeration.cts.Constants.ACTION_GET_PACKAGE_INFO;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_ACTIVITIES;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_PROVIDERS;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_SERVICES;
+import static android.appenumeration.cts.Constants.ACTION_SEND_RESULT;
+import static android.appenumeration.cts.Constants.ACTION_START_DIRECTLY;
+import static android.appenumeration.cts.Constants.ACTION_START_FOR_RESULT;
+import static android.appenumeration.cts.Constants.EXTRA_ERROR;
+import static android.appenumeration.cts.Constants.EXTRA_FLAGS;
+import static android.appenumeration.cts.Constants.EXTRA_REMOTE_CALLBACK;
import static android.content.Intent.EXTRA_RETURN_RESULT;
import android.app.Activity;
@@ -39,23 +50,23 @@
}
private void handleIntent(Intent intent) {
- RemoteCallback remoteCallback = intent.getParcelableExtra("remoteCallback");
+ RemoteCallback remoteCallback = intent.getParcelableExtra(EXTRA_REMOTE_CALLBACK);
try {
final String action = intent.getAction();
final Intent queryIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT);
- if ("android.appenumeration.cts.action.GET_PACKAGE_INFO".equals(action)) {
+ if (ACTION_GET_PACKAGE_INFO.equals(action)) {
final String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
sendPackageInfo(remoteCallback, packageName);
- } else if ("android.appenumeration.cts.action.START_FOR_RESULT".equals(action)) {
+ } else if (ACTION_START_FOR_RESULT.equals(action)) {
final String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
int requestCode = RESULT_FIRST_USER + callbacks.size();
callbacks.put(requestCode, remoteCallback);
startActivityForResult(
- new Intent("android.appenumeration.cts.action.SEND_RESULT").setComponent(
+ new Intent(ACTION_SEND_RESULT).setComponent(
new ComponentName(packageName, getClass().getCanonicalName())),
requestCode);
// don't send anything... await result callback
- } else if ("android.appenumeration.cts.action.SEND_RESULT".equals(action)) {
+ } else if (ACTION_SEND_RESULT.equals(action)) {
try {
setResult(RESULT_OK,
getIntent().putExtra(
@@ -65,13 +76,13 @@
setResult(RESULT_FIRST_USER, new Intent().putExtra("error", e));
}
finish();
- } else if ("android.appenumeration.cts.action.QUERY_INTENT_ACTIVITIES".equals(action)) {
+ } else if (ACTION_QUERY_ACTIVITIES.equals(action)) {
sendQueryIntentActivities(remoteCallback, queryIntent);
- } else if ("android.appenumeration.cts.action.QUERY_INTENT_SERVICES".equals(action)) {
+ } else if (ACTION_QUERY_SERVICES.equals(action)) {
sendQueryIntentServices(remoteCallback, queryIntent);
- } else if ("android.appenumeration.cts.action.QUERY_INTENT_PROVIDERS".equals(action)) {
+ } else if (ACTION_QUERY_PROVIDERS.equals(action)) {
sendQueryIntentProviders(remoteCallback, queryIntent);
- } else if ("android.appenumeration.cts.action.START_DIRECTLY".equals(action)) {
+ } else if (ACTION_START_DIRECTLY.equals(action)) {
try {
startActivity(queryIntent);
remoteCallback.sendResult(new Bundle());
@@ -79,8 +90,8 @@
sendError(remoteCallback, e);
}
finish();
- } else if ("android.appenumeration.cts.action.GET_INSTALLED_PACKAGES".equals(action)) {
- sendGetInstalledPackages(remoteCallback, queryIntent.getIntExtra("flags", 0));
+ } else if (ACTION_GET_INSTALLED_PACKAGES.equals(action)) {
+ sendGetInstalledPackages(remoteCallback, queryIntent.getIntExtra(EXTRA_FLAGS, 0));
} else {
sendError(remoteCallback, new Exception("unknown action " + action));
}
@@ -137,7 +148,7 @@
private void sendError(RemoteCallback remoteCallback, Exception failure) {
Bundle result = new Bundle();
- result.putSerializable("error", failure);
+ result.putSerializable(EXTRA_ERROR, failure);
remoteCallback.sendResult(result);
finish();
}
@@ -161,7 +172,7 @@
super.onActivityResult(requestCode, resultCode, data);
final RemoteCallback remoteCallback = callbacks.get(requestCode);
if (resultCode != RESULT_OK) {
- Exception e = (Exception) data.getSerializableExtra("error");
+ Exception e = (Exception) data.getSerializableExtra(EXTRA_ERROR);
sendError(remoteCallback, e == null ? new Exception("Result was " + resultCode) : e);
return;
}
diff --git a/tests/tests/appenumeration/lib/Android.bp b/tests/tests/appenumeration/lib/Android.bp
new file mode 100644
index 0000000..1b53acc
--- /dev/null
+++ b/tests/tests/appenumeration/lib/Android.bp
@@ -0,0 +1,18 @@
+// 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.
+
+java_library {
+ name: "CtsAppEnumerationTestLib",
+ srcs: ["src/**/*.java"],
+}
diff --git a/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java b/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java
new file mode 100644
index 0000000..3c80da6
--- /dev/null
+++ b/tests/tests/appenumeration/lib/src/android/appenumeration/cts/Constants.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2020 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.appenumeration.cts;
+
+public class Constants {
+ public static final String PKG_BASE = "android.appenumeration.";
+
+ /** A package that queries for {@link #TARGET_NO_API} package */
+ public static final String QUERIES_PACKAGE = PKG_BASE + "queries.pkg";
+ /** Queries for the unexported authority in {@link #TARGET_FILTERS} provider */
+ public static final String QUERIES_UNEXPORTED_PROVIDER_AUTH =
+ PKG_BASE + "queries.provider.authority.unexported";
+ /** Queries for the unexported action in {@link #TARGET_FILTERS} service filter */
+ public static final String QUERIES_UNEXPORTED_SERVICE_ACTION =
+ PKG_BASE + "queries.service.action.unexported";
+ /** Queries for the unexported action in {@link #TARGET_FILTERS} activity filter */
+ public static final String QUERIES_UNEXPORTED_ACTIVITY_ACTION =
+ PKG_BASE + "queries.activity.action.unexported";
+ /** A package that queries for the authority in {@link #TARGET_FILTERS} provider */
+ public static final String QUERIES_PROVIDER_AUTH = PKG_BASE + "queries.provider.authority";
+ /** A package that queries for the action in {@link #TARGET_FILTERS} service filter */
+ public static final String QUERIES_SERVICE_ACTION = PKG_BASE + "queries.service.action";
+ /** A package that queries for the action in {@link #TARGET_FILTERS} activity filter */
+ public static final String QUERIES_ACTIVITY_ACTION = PKG_BASE + "queries.activity.action";
+ /** A package that has no queries but gets the QUERY_ALL_PACKAGES permission */
+ public static final String QUERIES_NOTHING_PERM = PKG_BASE + "queries.nothing.haspermission";
+ /** A package that has no queries tag or permissions but targets Q */
+ public static final String QUERIES_NOTHING_Q = PKG_BASE + "queries.nothing.q";
+ /** A package that has no queries tag or permission to query any specific packages */
+ public static final String QUERIES_NOTHING = PKG_BASE + "queries.nothing";
+ /** A package that queries nothing, but is part of a shared user */
+ public static final String QUERIES_NOTHING_SHARED_USER = PKG_BASE + "queries.nothing.shareduid";
+ /** A package that exposes nothing, but is part of a shared user */
+ public static final String TARGET_SHARED_USER = PKG_BASE + "noapi.shareduid";
+ /** A package that exposes itself via various intent filters (activities, services, etc.) */
+ public static final String TARGET_FILTERS = PKG_BASE + "filters";
+ /** A package that declares itself force queryable, making it visible to all other packages */
+ public static final String TARGET_FORCEQUERYABLE = PKG_BASE + "forcequeryable";
+ /** A package with no published API and so isn't queryable by anything but package name */
+ public static final String TARGET_NO_API = PKG_BASE + "noapi";
+
+ public static final String[] ALL_QUERIES_TARGETING_Q_PACKAGES = {
+ QUERIES_NOTHING,
+ QUERIES_NOTHING_PERM,
+ QUERIES_ACTIVITY_ACTION,
+ QUERIES_SERVICE_ACTION,
+ QUERIES_PROVIDER_AUTH,
+ QUERIES_UNEXPORTED_ACTIVITY_ACTION,
+ QUERIES_UNEXPORTED_SERVICE_ACTION,
+ QUERIES_UNEXPORTED_PROVIDER_AUTH,
+ QUERIES_PACKAGE,
+ QUERIES_NOTHING_SHARED_USER
+ };
+
+ public static final String ACTIVITY_CLASS_TEST = PKG_BASE + "cts.query.TestActivity";
+ public static final String ACTIVITY_CLASS_DUMMY_ACTIVITY = PKG_BASE + "testapp.DummyActivity";
+
+ public static final String ACTION_MANIFEST_ACTIVITY = PKG_BASE + "action.ACTIVITY";
+ public static final String ACTION_MANIFEST_SERVICE = PKG_BASE + "action.SERVICE";
+ public static final String ACTION_MANIFEST_PROVIDER = PKG_BASE + "action.PROVIDER";
+ public static final String ACTION_SEND_RESULT = PKG_BASE + "cts.action.SEND_RESULT";
+ public static final String ACTION_GET_PACKAGE_INFO = PKG_BASE + "cts.action.GET_PACKAGE_INFO";
+ public static final String ACTION_START_FOR_RESULT = PKG_BASE + "cts.action.START_FOR_RESULT";
+ public static final String ACTION_START_DIRECTLY = PKG_BASE + "cts.action.START_DIRECTLY";
+ public static final String ACTION_QUERY_ACTIVITIES =
+ PKG_BASE + "cts.action.QUERY_INTENT_ACTIVITIES";
+ public static final String ACTION_QUERY_SERVICES =
+ PKG_BASE + "cts.action.QUERY_INTENT_SERVICES";
+ public static final String ACTION_QUERY_PROVIDERS =
+ PKG_BASE + "cts.action.QUERY_INTENT_PROVIDERS";
+ public static final String ACTION_GET_INSTALLED_PACKAGES =
+ PKG_BASE + "cts.action.GET_INSTALLED_PACKAGES";
+
+ public static final String EXTRA_REMOTE_CALLBACK = "remoteCallback";
+ public static final String EXTRA_ERROR = "error";
+ public static final String EXTRA_FLAGS = "flags";
+}
diff --git a/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java b/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
index 2edb724..9beffff 100644
--- a/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
+++ b/tests/tests/appenumeration/src/android/appenumeration/cts/AppEnumerationTests.java
@@ -16,6 +16,37 @@
package android.appenumeration.cts;
+import static android.appenumeration.cts.Constants.ACTION_GET_INSTALLED_PACKAGES;
+import static android.appenumeration.cts.Constants.ACTION_GET_PACKAGE_INFO;
+import static android.appenumeration.cts.Constants.ACTION_MANIFEST_ACTIVITY;
+import static android.appenumeration.cts.Constants.ACTION_MANIFEST_PROVIDER;
+import static android.appenumeration.cts.Constants.ACTION_MANIFEST_SERVICE;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_ACTIVITIES;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_PROVIDERS;
+import static android.appenumeration.cts.Constants.ACTION_QUERY_SERVICES;
+import static android.appenumeration.cts.Constants.ACTION_START_DIRECTLY;
+import static android.appenumeration.cts.Constants.ACTION_START_FOR_RESULT;
+import static android.appenumeration.cts.Constants.ACTIVITY_CLASS_DUMMY_ACTIVITY;
+import static android.appenumeration.cts.Constants.ACTIVITY_CLASS_TEST;
+import static android.appenumeration.cts.Constants.ALL_QUERIES_TARGETING_Q_PACKAGES;
+import static android.appenumeration.cts.Constants.EXTRA_ERROR;
+import static android.appenumeration.cts.Constants.EXTRA_FLAGS;
+import static android.appenumeration.cts.Constants.EXTRA_REMOTE_CALLBACK;
+import static android.appenumeration.cts.Constants.QUERIES_ACTIVITY_ACTION;
+import static android.appenumeration.cts.Constants.QUERIES_NOTHING;
+import static android.appenumeration.cts.Constants.QUERIES_NOTHING_PERM;
+import static android.appenumeration.cts.Constants.QUERIES_NOTHING_Q;
+import static android.appenumeration.cts.Constants.QUERIES_NOTHING_SHARED_USER;
+import static android.appenumeration.cts.Constants.QUERIES_PACKAGE;
+import static android.appenumeration.cts.Constants.QUERIES_PROVIDER_AUTH;
+import static android.appenumeration.cts.Constants.QUERIES_SERVICE_ACTION;
+import static android.appenumeration.cts.Constants.QUERIES_UNEXPORTED_ACTIVITY_ACTION;
+import static android.appenumeration.cts.Constants.QUERIES_UNEXPORTED_PROVIDER_AUTH;
+import static android.appenumeration.cts.Constants.QUERIES_UNEXPORTED_SERVICE_ACTION;
+import static android.appenumeration.cts.Constants.TARGET_FILTERS;
+import static android.appenumeration.cts.Constants.TARGET_FORCEQUERYABLE;
+import static android.appenumeration.cts.Constants.TARGET_NO_API;
+import static android.appenumeration.cts.Constants.TARGET_SHARED_USER;
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import static org.hamcrest.Matchers.greaterThan;
@@ -43,7 +74,6 @@
import com.android.compatibility.common.util.SystemUtil;
-import org.hamcrest.Matchers;
import org.hamcrest.core.IsNull;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -63,57 +93,6 @@
@RunWith(AndroidJUnit4.class)
public class AppEnumerationTests {
- private static final String PKG_BASE = "android.appenumeration.";
-
- /** A package with no published API and so isn't queryable by anything but package name */
- private static final String TARGET_NO_API = PKG_BASE + "noapi";
- /** A package that declares itself force queryable, making it visible to all other packages */
- private static final String TARGET_FORCEQUERYABLE = PKG_BASE + "forcequeryable";
- /** A package that exposes itself via various intent filters (activities, services, etc.) */
- private static final String TARGET_FILTERS = PKG_BASE + "filters";
- /** A package that exposes nothing, but is part of a shared user */
- private static final String TARGET_SHARED_USER = PKG_BASE + "noapi.shareduid";
-
- /** A package that queries nothing, but is part of a shared user */
- private static final String QUERIES_NOTHING_SHARED_USER =
- PKG_BASE + "queries.nothing.shareduid";
- /** A package that has no queries tag or permission to query any specific packages */
- private static final String QUERIES_NOTHING = PKG_BASE + "queries.nothing";
- /** A package that has no queries tag or permissions but targets Q */
- private static final String QUERIES_NOTHING_Q = PKG_BASE + "queries.nothing.q";
- /** A package that has no queries but gets the QUERY_ALL_PACKAGES permission */
- private static final String QUERIES_NOTHING_PERM = PKG_BASE + "queries.nothing.haspermission";
- /** A package that queries for the action in {@link #TARGET_FILTERS} activity filter */
- private static final String QUERIES_ACTIVITY_ACTION = PKG_BASE + "queries.activity.action";
- /** A package that queries for the action in {@link #TARGET_FILTERS} service filter */
- private static final String QUERIES_SERVICE_ACTION = PKG_BASE + "queries.service.action";
- /** A package that queries for the authority in {@link #TARGET_FILTERS} provider */
- private static final String QUERIES_PROVIDER_AUTH = PKG_BASE + "queries.provider.authority";
- /** Queries for the unexported action in {@link #TARGET_FILTERS} activity filter */
- private static final String QUERIES_UNEXPORTED_ACTIVITY_ACTION =
- PKG_BASE + "queries.activity.action.unexported";
- /** Queries for the unexported action in {@link #TARGET_FILTERS} service filter */
- private static final String QUERIES_UNEXPORTED_SERVICE_ACTION =
- PKG_BASE + "queries.service.action.unexported";
- /** Queries for the unexported authority in {@link #TARGET_FILTERS} provider */
- private static final String QUERIES_UNEXPORTED_PROVIDER_AUTH =
- PKG_BASE + "queries.provider.authority.unexported";
- /** A package that queries for {@link #TARGET_NO_API} package */
- private static final String QUERIES_PACKAGE = PKG_BASE + "queries.pkg";
-
- private static final String[] ALL_QUERIES_TARGETING_Q_PACKAGES = {
- QUERIES_NOTHING,
- QUERIES_NOTHING_PERM,
- QUERIES_ACTIVITY_ACTION,
- QUERIES_SERVICE_ACTION,
- QUERIES_PROVIDER_AUTH,
- QUERIES_UNEXPORTED_ACTIVITY_ACTION,
- QUERIES_UNEXPORTED_SERVICE_ACTION,
- QUERIES_UNEXPORTED_PROVIDER_AUTH,
- QUERIES_PACKAGE,
- QUERIES_NOTHING_SHARED_USER
- };
-
private static Handler sResponseHandler;
private static HandlerThread sResponseThread;
@@ -230,31 +209,31 @@
@Test
public void queriesNothing_cannotSeeFilters() throws Exception {
assertNotQueryable(QUERIES_NOTHING, TARGET_FILTERS,
- "android.appenumeration.action.ACTIVITY", this::queryIntentActivities);
+ ACTION_MANIFEST_ACTIVITY, this::queryIntentActivities);
assertNotQueryable(QUERIES_NOTHING, TARGET_FILTERS,
- "android.appenumeration.action.SERVICE", this::queryIntentServices);
+ ACTION_MANIFEST_SERVICE, this::queryIntentServices);
assertNotQueryable(QUERIES_NOTHING, TARGET_FILTERS,
- "android.appenumeration.action.PROVIDER", this::queryIntentProviders);
+ ACTION_MANIFEST_PROVIDER, this::queryIntentProviders);
}
@Test
public void queriesActivityAction_canSeeFilters() throws Exception {
assertQueryable(QUERIES_ACTIVITY_ACTION, TARGET_FILTERS,
- "android.appenumeration.action.ACTIVITY", this::queryIntentActivities);
+ ACTION_MANIFEST_ACTIVITY, this::queryIntentActivities);
assertQueryable(QUERIES_SERVICE_ACTION, TARGET_FILTERS,
- "android.appenumeration.action.SERVICE", this::queryIntentServices);
+ ACTION_MANIFEST_SERVICE, this::queryIntentServices);
assertQueryable(QUERIES_PROVIDER_AUTH, TARGET_FILTERS,
- "android.appenumeration.action.PROVIDER", this::queryIntentProviders);
+ ACTION_MANIFEST_PROVIDER, this::queryIntentProviders);
}
@Test
public void queriesNothingHasPermission_canSeeFilters() throws Exception {
assertQueryable(QUERIES_NOTHING_PERM, TARGET_FILTERS,
- "android.appenumeration.action.ACTIVITY", this::queryIntentActivities);
+ ACTION_MANIFEST_ACTIVITY, this::queryIntentActivities);
assertQueryable(QUERIES_NOTHING_PERM, TARGET_FILTERS,
- "android.appenumeration.action.SERVICE", this::queryIntentServices);
+ ACTION_MANIFEST_SERVICE, this::queryIntentServices);
assertQueryable(QUERIES_NOTHING_PERM, TARGET_FILTERS,
- "android.appenumeration.action.PROVIDER", this::queryIntentProviders);
+ ACTION_MANIFEST_PROVIDER, this::queryIntentProviders);
}
@Test
@@ -391,63 +370,58 @@
private PackageInfo getPackageInfo(String sourcePackageName, String targetPackageName)
throws Exception {
Bundle response = sendCommand(sourcePackageName, targetPackageName,
- null /*queryIntent*/, PKG_BASE + "cts.action.GET_PACKAGE_INFO");
+ null /*queryIntent*/, ACTION_GET_PACKAGE_INFO);
return response.getParcelable(Intent.EXTRA_RETURN_RESULT);
}
private PackageInfo startForResult(String sourcePackageName, String targetPackageName)
throws Exception {
Bundle response = sendCommand(sourcePackageName, targetPackageName,
- null /*queryIntent*/, PKG_BASE + "cts.action.START_FOR_RESULT");
+ null /*queryIntent*/, ACTION_START_FOR_RESULT);
return response.getParcelable(Intent.EXTRA_RETURN_RESULT);
}
private String[] queryIntentActivities(String sourcePackageName, Intent queryIntent)
throws Exception {
- Bundle response = sendCommand(sourcePackageName, null, queryIntent, PKG_BASE +
- "cts.action.QUERY_INTENT_ACTIVITIES");
+ Bundle response = sendCommand(sourcePackageName, null, queryIntent, ACTION_QUERY_ACTIVITIES);
return response.getStringArray(Intent.EXTRA_RETURN_RESULT);
}
private String[] queryIntentServices(String sourcePackageName, Intent queryIntent)
throws Exception {
- Bundle response = sendCommand(sourcePackageName, null, queryIntent, PKG_BASE +
- "cts.action.QUERY_INTENT_SERVICES");
+ Bundle response = sendCommand(sourcePackageName, null, queryIntent, ACTION_QUERY_SERVICES);
return response.getStringArray(Intent.EXTRA_RETURN_RESULT);
}
private String[] queryIntentProviders(String sourcePackageName, Intent queryIntent)
throws Exception {
- Bundle response = sendCommand(sourcePackageName, null, queryIntent, PKG_BASE +
- "cts.action.QUERY_INTENT_PROVIDERS");
+ Bundle response = sendCommand(sourcePackageName, null, queryIntent, ACTION_QUERY_PROVIDERS);
return response.getStringArray(Intent.EXTRA_RETURN_RESULT);
}
private String[] getInstalledPackages(String sourcePackageNames, int flags) throws Exception {
- Bundle response = sendCommand(sourcePackageNames, null, new Intent().putExtra("flags", flags),
- "android.appenumeration.cts.action.GET_INSTALLED_PACKAGES");
+ Bundle response = sendCommand(sourcePackageNames, null, new Intent().putExtra(EXTRA_FLAGS,
+ flags), ACTION_GET_INSTALLED_PACKAGES);
return response.getStringArray(Intent.EXTRA_RETURN_RESULT);
}
private void startExplicitIntent(String sourcePackage, String targetPackage) throws Exception {
sendCommand(sourcePackage, targetPackage,
new Intent().setComponent(new ComponentName(targetPackage,
- "android.appenumeration.testapp.DummyActivity")),
- "android.appenumeration.cts.action.START_DIRECTLY");
+ ACTIVITY_CLASS_DUMMY_ACTIVITY)),
+ ACTION_START_DIRECTLY);
}
private void startImplicitIntent(String sourcePackage) throws Exception {
- sendCommand(sourcePackage, TARGET_FILTERS,
- new Intent("android.appenumeration.action.ACTIVITY"),
- "android.appenumeration.cts.action.START_DIRECTLY");
+ sendCommand(sourcePackage, TARGET_FILTERS, new Intent(ACTION_MANIFEST_ACTIVITY),
+ ACTION_START_DIRECTLY);
}
private Bundle sendCommand(String sourcePackageName, @Nullable String targetPackageName,
@Nullable Intent queryIntent, String action)
throws Exception {
final Intent intent = new Intent(action)
- .setComponent(new ComponentName(
- sourcePackageName, PKG_BASE + "cts.query.TestActivity"))
+ .setComponent(new ComponentName(sourcePackageName, ACTIVITY_CLASS_TEST))
// data uri unique to each activity start to ensure actual launch and not just
// redisplay
.setData(Uri.parse("test://" + name.getMethodName()
@@ -469,15 +443,15 @@
latch.open();
},
sResponseHandler);
- intent.putExtra("remoteCallback", callback);
+ intent.putExtra(EXTRA_REMOTE_CALLBACK, callback);
InstrumentationRegistry.getInstrumentation().getContext().startActivity(intent);
if (!latch.block(TimeUnit.SECONDS.toMillis(10))) {
throw new TimeoutException(
"Latch timed out while awiating a response from " + sourcePackageName);
}
final Bundle bundle = resultReference.get();
- if (bundle != null && bundle.containsKey("error")) {
- throw (Exception) Objects.requireNonNull(bundle.getSerializable("error"));
+ if (bundle != null && bundle.containsKey(EXTRA_ERROR)) {
+ throw (Exception) Objects.requireNonNull(bundle.getSerializable(EXTRA_ERROR));
}
return bundle;
}