Added CTS Verifier test for Instant Apps notification.
Design doc: go/instant-cts-verifier.
Two other tests will be added in similar fashion using different instruction text.
What's included:
1. A sample Instant App under //cts/apps/CtsVerifierInstantApp
2. make cts-verifier will install the sample Instant App via adb install --instant
3. Added Instant Apps test category with one test.
Bug: 128338329
Test: make cts-verifier
Test: manual test
Change-Id: I55264a59dea86faa5d6c34be01ff1802a8e49213
(cherry picked from commit c7f7aa0721b7bbcc64b2b08deb124f5ced269aa0)
diff --git a/apps/CtsVerifier/Android.mk b/apps/CtsVerifier/Android.mk
index 798ee91..50f9d5a 100644
--- a/apps/CtsVerifier/Android.mk
+++ b/apps/CtsVerifier/Android.mk
@@ -111,6 +111,9 @@
CtsPermissionApp \
NotificationBot
+# Apps to be installed as Instant App using adb install --instant
+pre-installed-instant-app := CtsVerifierInstantApp
+
other-required-apps := \
CtsVerifierUSBCompanion \
CtsVpnFirewallAppApi23 \
@@ -119,6 +122,7 @@
apps-to-include := \
$(pre-installed-apps) \
+ $(pre-installed-instant-app) \
$(other-required-apps)
define apk-location-for
@@ -127,10 +131,11 @@
# Builds and launches CTS Verifier on a device.
.PHONY: cts-verifier
-cts-verifier: CtsVerifier adb $(pre-installed-apps)
+cts-verifier: CtsVerifier adb $(pre-installed-apps) $(pre-installed-instant-app)
adb install -r $(PRODUCT_OUT)/data/app/CtsVerifier/CtsVerifier.apk \
$(foreach app,$(pre-installed-apps), \
&& adb install -r -t $(call apk-location-for,$(app))) \
+ && adb install -r --instant $(call apk-location-for,$(pre-installed-instant-app)) \
&& adb shell "am start -n com.android.cts.verifier/.CtsVerifierActivity"
#
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index cc6638a..c2af735 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -3855,6 +3855,15 @@
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
+
+ <activity android:name=".instantapps.NotificationTestActivity"
+ android:label="@string/ia_notification">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.cts.intent.category.MANUAL_TEST" />
+ </intent-filter>
+ <meta-data android:name="test_category" android:value="@string/test_category_instant_apps" />
+ </activity>
</application>
</manifest>
diff --git a/apps/CtsVerifier/res/layout/instant_apps.xml b/apps/CtsVerifier/res/layout/instant_apps.xml
new file mode 100644
index 0000000..f41250c
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/instant_apps.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+<ScrollView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fillViewport="true"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:orientation="vertical">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="bottom"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/instruction_header"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ia_instruction_heading_label" />
+
+ <TextView
+ android:id="@+id/instruction_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ia_instruction_text_photo_label" />
+
+ <TextView
+ android:id="@+id/instruction_extra_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ia_notification_instruction_label" />
+
+ <Button
+ android:id="@+id/start_test_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:enabled="false"
+ android:text="@string/ia_start_test_button_caption" />
+
+ </LinearLayout>
+ </LinearLayout>
+ <include layout="@layout/pass_fail_buttons" />
+ </LinearLayout>
+</ScrollView>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index c56a60d..dac1778 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -41,6 +41,7 @@
<string name="test_category_telecom">Telecom</string>
<string name="test_category_telephony">Telephony</string>
<string name="test_category_tv">TV</string>
+ <string name="test_category_instant_apps">Instant Apps</string>
<string name="test_category_other">Other</string>
<string name="clear">Clear</string>
<string name="test_results_clear_title">Remove all test results?</string>
@@ -4982,4 +4983,30 @@
<string name="bubbles_test_summary_title">Test Complete</string>
<string name="bubbles_test_summary">%1$d out of %2$d tests passed</string>
<string name="bubble_activity_title">Bubble Activity</string>
+
+ <!-- Strings for Instant Apps -->
+ <string name="ia_instruction_heading_label">Instructions:</string>
+ <string name="ia_instruction_text_photo_label">READ BEFORE STARTING TEST</string>
+ <string name="ia_start_test_button_caption">Start Test</string>
+ <string name="ia_install_dialog_title">Install Instant App</string>
+ <string name="ia_install_dialog_text">
+ For this test you need to install CtsVerifierInstantApp.apk by running \n
+ adb install -r --instant /path/to/CtsVerifierInstantApp.apk \n\n
+ CtsVerifierInstantApp.apk can be found in android-cts-verifier.zip that you have downloaded.
+ </string>
+ <string name="ia_notification">Instant Apps Notification Test</string>
+ <string name="ia_notification_info">
+ This test verifies that Instant Apps notification is shown when an Instant App is at foreground.\n\n
+ - Read the message above the \"Start Test\" button for
+ step-by-step instructions.
+ </string>
+ <string name="ia_notification_instruction_label">\n
+ 1. Click Start Test. \n\n
+ 2. An alert dialog with install instruction will be shown if the sample Instant App has not been installed, otherwise, the sample Instant App will be opened automatically. \n\n
+ 3. Drag down the notification bar when the sample Instant App is at foreground. \n\n
+ 4. Check if Instant App is shown in notification area with the following (Please expand the notification if it is collapsed): \n
+ \u0020\u0020\u0020a. It provides information about Instant Apps not requiring installation and an action that provides more information about the Instant App. \n
+ \u0020\u0020\u0020b. It provides an action allowing the user to launch the associated link with web browser. \n\n
+ 5. Click Pass button if all checks in step 4 passed, otherwise click Fail button.
+ </string>
</resources>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/instantapps/NotificationTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/instantapps/NotificationTestActivity.java
new file mode 100644
index 0000000..7c77f67
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/instantapps/NotificationTestActivity.java
@@ -0,0 +1,127 @@
+/*
+ * 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.cts.verifier.instantapps;
+
+import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.ImageFormat;
+import android.graphics.Matrix;
+import android.hardware.Camera;
+import android.os.Bundle;
+import android.os.Handler;
+import android.net.Uri;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.TextView;
+
+import com.android.cts.verifier.PassFailButtons;
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.TestResult;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TreeSet;
+
+/**
+ *
+ * Test for manual verification of Instant Apps notification.
+ *
+ * The test verifies that an Instant App notification will be shown when
+ * an Instant App is at foreground.
+ */
+public class NotificationTestActivity extends PassFailButtons.Activity
+ implements OnClickListener {
+
+ private static final String TAG = "InstantApps";
+ private static final String APP_URL = "https://instantapp.cts.android.com";
+ private static final String APP_PACKAGE = "com.android.cts.instantapp";
+
+ private ImageButton mPassButton;
+ private ImageButton mFailButton;
+ private Button mStartTestButton;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.instant_apps);
+ setPassFailButtonClickListeners();
+ setInfoResources(R.string.ia_notification, R.string.ia_notification_info, -1);
+
+ mPassButton = (ImageButton) findViewById(R.id.pass_button);
+ mFailButton = (ImageButton) findViewById(R.id.fail_button);
+ mStartTestButton = (Button) findViewById(R.id.start_test_button);
+ mStartTestButton.setOnClickListener(this);
+
+ resetButtons();
+
+ mStartTestButton.setEnabled(true);
+ }
+
+ @Override
+ public void onClick(View view) {
+ if (view != mStartTestButton) return;
+
+ Log.v(TAG, "Start Test button clicked");
+ try {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ intent.setPackage(APP_PACKAGE);
+ startActivity(intent);
+
+ mStartTestButton.setEnabled(false);
+ enablePassFailButtons(true);
+ } catch (ActivityNotFoundException e) {
+ // Use ActivityNotFoundException as an indicator that Instant App is
+ // not installed.
+ Log.v(TAG, "Instant App not installed.");
+
+ // Display alert dialog with instruction for installing the Instant App.
+ new AlertDialog.Builder(
+ NotificationTestActivity.this)
+ .setIcon(android.R.drawable.ic_dialog_info)
+ .setTitle(R.string.ia_install_dialog_title)
+ .setMessage(R.string.ia_install_dialog_text)
+ .setPositiveButton(android.R.string.ok, null)
+ .show();
+ }
+ }
+
+ private void resetButtons() {
+ enablePassFailButtons(false);
+ }
+
+ private void enablePassFailButtons(boolean enable) {
+ mPassButton.setEnabled(enable);
+ mFailButton.setEnabled(enable);
+ }
+}
diff --git a/apps/CtsVerifierInstantApp/Android.mk b/apps/CtsVerifierInstantApp/Android.mk
new file mode 100644
index 0000000..13697e7
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/Android.mk
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2018 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_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsVerifierInstantApp
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_COMPATIBILITY_SUITE := cts sts
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/apps/CtsVerifierInstantApp/AndroidManifest.xml b/apps/CtsVerifierInstantApp/AndroidManifest.xml
new file mode 100644
index 0000000..bb59c13
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.instantapp"
+ android:versionCode="1"
+ android:versionName="1.0"
+ android:targetSandboxVersion="2">
+ <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="28"/>
+
+ <application android:label="Sample Instant App for Testing">
+ <activity android:name=".HelloActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <intent-filter android:autoVerify="true">
+ <action android:name="android.intent.action.VIEW"/>
+ <category android:name="android.intent.category.BROWSABLE"/>
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:host="instantapp.cts.android.com" android:scheme="http"/>
+ <data android:host="instantapp.cts.android.com" android:scheme="https"/>
+ </intent-filter>
+ <meta-data android:name="default-url"
+ android:value="http://instantapp.cts.android.com" />
+ </activity>
+ </application>
+</manifest>
diff --git a/apps/CtsVerifierInstantApp/OWNERS b/apps/CtsVerifierInstantApp/OWNERS
new file mode 100644
index 0000000..42ab685
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/OWNERS
@@ -0,0 +1,4 @@
+# Bug component: 137915
+alanma@google.com
+jboekeno@google.com
+jieplum@google.com
diff --git a/apps/CtsVerifierInstantApp/res/layout/hello_activity.xml b/apps/CtsVerifierInstantApp/res/layout/hello_activity.xml
new file mode 100644
index 0000000..534130e
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/res/layout/hello_activity.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:textSize="20sp"
+ android:gravity="center"
+ android:text="@string/hello_activity_text_text" />
diff --git a/apps/CtsVerifierInstantApp/res/values/strings.xml b/apps/CtsVerifierInstantApp/res/values/strings.xml
new file mode 100644
index 0000000..03c268d
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="hello_activity_text_text">Hello, World!</string>
+
+</resources>
diff --git a/apps/CtsVerifierInstantApp/src/com/android/cts/instantapp/HelloActivity.java b/apps/CtsVerifierInstantApp/src/com/android/cts/instantapp/HelloActivity.java
new file mode 100644
index 0000000..f57f215
--- /dev/null
+++ b/apps/CtsVerifierInstantApp/src/com/android/cts/instantapp/HelloActivity.java
@@ -0,0 +1,39 @@
+/*
+ * 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.cts.instantapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.WindowManager;
+
+/**
+ * A minimal "Hello, World!" application.
+ */
+public class HelloActivity extends Activity {
+ /**
+ * Called with the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Set the layout for this activity. You can find it
+ // in res/layout/hello_activity.xml
+ setContentView(R.layout.hello_activity);
+ }
+}