summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.bp3
-rw-r--r--AndroidManifest-common.xml8
-rw-r--r--src/com/android/launcher3/TestInformationProvider.java66
-rw-r--r--src/com/android/launcher3/TestProtocol.java3
-rw-r--r--tests/tapl/AndroidManifest.xml26
-rw-r--r--tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java38
6 files changed, 137 insertions, 7 deletions
diff --git a/Android.bp b/Android.bp
index c5832441c..1121a7962 100644
--- a/Android.bp
+++ b/Android.bp
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-java_library_static {
+android_library {
name: "launcher-aosp-tapl",
static_libs: [
"androidx.annotation_annotation",
@@ -27,5 +27,6 @@ java_library_static {
"src/com/android/launcher3/util/SecureSettingsObserver.java",
"src/com/android/launcher3/TestProtocol.java",
],
+ manifest: "tests/tapl/AndroidManifest.xml",
platform_apis: true,
}
diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml
index 819e6bcc9..5a2d0fe83 100644
--- a/AndroidManifest-common.xml
+++ b/AndroidManifest-common.xml
@@ -152,6 +152,14 @@
android:writePermission="${packageName}.permission.WRITE_SETTINGS"
android:readPermission="${packageName}.permission.READ_SETTINGS" />
+ <provider
+ android:name="com.android.launcher3.TestInformationProvider"
+ android:authorities="${packageName}.TestInfo"
+ android:readPermission="android.permission.WRITE_SECURE_SETTINGS"
+ android:writePermission="android.permission.WRITE_SECURE_SETTINGS"
+ android:exported="true">
+ </provider>
+
<!--
The content provider for exposing various launcher grid options.
TODO: Enable when all apps columns are correct
diff --git a/src/com/android/launcher3/TestInformationProvider.java b/src/com/android/launcher3/TestInformationProvider.java
new file mode 100644
index 000000000..acdb19441
--- /dev/null
+++ b/src/com/android/launcher3/TestInformationProvider.java
@@ -0,0 +1,66 @@
+/*
+ * 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.launcher3;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+
+public class TestInformationProvider extends ContentProvider {
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues contentValues, String s, String[] strings) {
+ return 0;
+ }
+
+ @Override
+ public int delete(Uri uri, String s, String[] strings) {
+ return 0;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues contentValues) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) {
+ return null;
+ }
+
+ @Override
+ public Bundle call(String method, String arg, Bundle extras) {
+ if (TestProtocol.IS_TEST_INFO_ENABLED.equals(method)) {
+ final Bundle response = new Bundle();
+ response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
+ Utilities.IS_RUNNING_IN_TEST_HARNESS);
+ return response;
+ }
+ return null;
+ }
+}
diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/TestProtocol.java
index 23df79e3b..2870d3b55 100644
--- a/src/com/android/launcher3/TestProtocol.java
+++ b/src/com/android/launcher3/TestProtocol.java
@@ -30,4 +30,7 @@ public final class TestProtocol {
public static final int OVERVIEW_STATE_ORDINAL = 2;
public static final int ALL_APPS_STATE_ORDINAL = 3;
public static final int BACKGROUND_APP_STATE_ORDINAL = 4;
+
+ public static final String IS_TEST_INFO_ENABLED = "is-test-info-enabled";
+ public static final String TEST_INFO_RESPONSE_FIELD = "response";
}
diff --git a/tests/tapl/AndroidManifest.xml b/tests/tapl/AndroidManifest.xml
new file mode 100644
index 000000000..0207e2be6
--- /dev/null
+++ b/tests/tapl/AndroidManifest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.launcher3.tapl"
+>
+
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
+</manifest>
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 93b4cc605..7a27fa465 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -18,10 +18,11 @@ package com.android.launcher3.tapl;
import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
-import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.UiAutomation;
+import android.content.ContentResolver;
import android.graphics.Point;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemClock;
@@ -43,6 +44,7 @@ import com.android.quickstep.SwipeUpSetting;
import org.junit.Assert;
+import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.TimeoutException;
@@ -95,6 +97,7 @@ public final class LauncherInstrumentation {
private final UiDevice mDevice;
private final Instrumentation mInstrumentation;
private int mExpectedRotation = Surface.ROTATION_0;
+ private final Uri mTestProviderUri;
/**
* Constructs the root of TAPL hierarchy. You get all other objects from it.
@@ -103,11 +106,34 @@ public final class LauncherInstrumentation {
mInstrumentation = instrumentation;
mDevice = UiDevice.getInstance(instrumentation);
- // Launcher should run in test harness so that custom accessibility protocol between
- // Launcher and TAPL is enabled. In-process tests enable this protocol with a direct call
- // into Launcher.
- assertTrue("Device must run in a test harness",
- TestHelpers.isInLauncherProcess() || ActivityManager.isRunningInTestHarness());
+ final String testPackage = mInstrumentation.getContext().getPackageName();
+ final String targetPackage = mInstrumentation.getTargetContext().getPackageName();
+
+ // Launcher package. As during inproc tests the tested launcher may not be selected as the
+ // current launcher, choosing target package for inproc. For out-of-proc, use the installed
+ // launcher package.
+ final String authorityPackage = testPackage.equals(targetPackage) ?
+ getLauncherPackageName() :
+ targetPackage;
+
+ mTestProviderUri = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(authorityPackage + ".TestInfo")
+ .build();
+
+ try {
+ mDevice.executeShellCommand("pm grant " + testPackage +
+ " android.permission.WRITE_SECURE_SETTINGS");
+ } catch (IOException e) {
+ fail(e.toString());
+ }
+
+ // Launcher should run in test harness so that custom test protocols between Launcher and
+ // TAPL are enabled. In-process tests enable this protocol with a direct call into Launcher.
+ final Bundle response = mInstrumentation.getContext().getContentResolver().call(
+ mTestProviderUri, TestProtocol.IS_TEST_INFO_ENABLED, null, null);
+ assertTrue("Launcher is not running in test harness",
+ response.getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, false));
}
void setActiveContainer(VisibleContainer container) {