Merge "Test to verify legacy a11y service request a11y button API"
diff --git a/tests/accessibilityservice/testsdk29/Android.bp b/tests/accessibilityservice/testsdk29/Android.bp
new file mode 100644
index 0000000..87d3c5a
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/Android.bp
@@ -0,0 +1,34 @@
+// 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.
+
+android_test {
+    name: "CtsAccessibilityServiceSdk29TestCases",
+    defaults: ["cts_defaults"],
+
+    srcs: ["src/**/*.java"],
+
+    sdk_version: "test_current",
+
+    static_libs: [
+        "ctstestrunner-axt",
+        "CtsAccessibilityCommon",
+    ],
+
+    // Tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "vts",
+        "general-tests",
+    ],
+}
diff --git a/tests/accessibilityservice/testsdk29/AndroidManifest.xml b/tests/accessibilityservice/testsdk29/AndroidManifest.xml
new file mode 100644
index 0000000..90b2f5f
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/AndroidManifest.xml
@@ -0,0 +1,52 @@
+<?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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="android.accessibilityservice.cts.testsdk29">
+
+    <uses-sdk android:targetSdkVersion="29" />
+
+    <application android:theme="@android:style/Theme.Holo.NoActionBar"
+                 android:requestLegacyExternalStorage="true">
+
+        <uses-library android:name="android.test.runner" />
+
+        <service
+            android:name="android.accessibilityservice.cts.StubAccessibilityButtonSdk29Service"
+            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
+            <intent-filter>
+                <action android:name="android.accessibilityservice.AccessibilityService" />
+                <category android:name="android.accessibilityservice.category.FEEDBACK_GENERIC" />
+            </intent-filter>
+
+            <meta-data
+                android:name="android.accessibilityservice"
+                android:resource="@xml/stub_accessibility_button_service" />
+        </service>
+
+    </application>
+
+    <instrumentation
+        android:name="androidx.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.accessibilityservice.cts.testsdk29"
+        android:label="Tests for the accessibility Sdk 29 APIs.">
+        <meta-data
+            android:name="listener"
+            android:value="com.android.cts.runner.CtsTestRunListener" />
+    </instrumentation>
+
+</manifest>
diff --git a/tests/accessibilityservice/testsdk29/AndroidTest.xml b/tests/accessibilityservice/testsdk29/AndroidTest.xml
new file mode 100644
index 0000000..7125585
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/AndroidTest.xml
@@ -0,0 +1,37 @@
+<?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.
+-->
+<configuration description="Config for CTS accessibility service Sdk 29 test cases">
+    <option name="test-suite-tag" value="cts" />
+    <option name="config-descriptor:metadata" key="component" value="framework" />
+    <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+        <option name="run-command" value="cmd accessibility set-bind-instant-service-allowed true" />
+        <option name="teardown-command" value="cmd accessibility set-bind-instant-service-allowed false" />
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="CtsAccessibilityServiceSdk29TestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.accessibilityservice.cts.testsdk29" />
+        <option name="runtime-hint" value="1m" />
+    </test>
+    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+        <option name="directory-keys" value="/sdcard/android.accessibilityservice.cts.testsdk29" />
+        <option name="collect-on-run-ended-only" value="true" />
+    </metrics_collector>
+</configuration>
diff --git a/tests/accessibilityservice/testsdk29/res/values/strings.xml b/tests/accessibilityservice/testsdk29/res/values/strings.xml
new file mode 100644
index 0000000..3ed4fee
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?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 description for the accessibility button service -->
+    <string name="stub_accessibility_button_service_description">StubAccessibilityButtonSdk29Service</string>
+
+</resources>
diff --git a/tests/accessibilityservice/testsdk29/res/xml/stub_accessibility_button_service.xml b/tests/accessibilityservice/testsdk29/res/xml/stub_accessibility_button_service.xml
new file mode 100644
index 0000000..6e7e483
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/res/xml/stub_accessibility_button_service.xml
@@ -0,0 +1,22 @@
+<?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.
+-->
+
+<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
+                       android:description="@string/stub_accessibility_button_service_description"
+                       android:accessibilityEventTypes="typeAllMask"
+                       android:accessibilityFeedbackType="feedbackGeneric"
+                       android:accessibilityFlags="flagRequestAccessibilityButton"
+                       android:notificationTimeout="0" />
diff --git a/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/AccessibilityButtonSdk29Test.java b/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/AccessibilityButtonSdk29Test.java
new file mode 100644
index 0000000..6ea4e2a
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/AccessibilityButtonSdk29Test.java
@@ -0,0 +1,74 @@
+/**
+ * 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 android.accessibilityservice.cts;
+
+import static android.accessibilityservice.AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON;
+
+import static org.junit.Assert.assertTrue;
+
+import android.accessibility.cts.common.AccessibilityDumpOnFailureRule;
+import android.accessibility.cts.common.InstrumentedAccessibilityServiceTestRule;
+import android.accessibilityservice.AccessibilityServiceInfo;
+import android.os.Build;
+import android.platform.test.annotations.AppModeFull;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.runner.RunWith;
+
+/**
+ * Test to verify accessibility button targeting sdk 29 APIs.
+ */
+@AppModeFull
+@RunWith(AndroidJUnit4.class)
+public class AccessibilityButtonSdk29Test {
+
+    private InstrumentedAccessibilityServiceTestRule<StubAccessibilityButtonSdk29Service>
+            mServiceRule = new InstrumentedAccessibilityServiceTestRule<>(
+                    StubAccessibilityButtonSdk29Service.class);
+
+    private AccessibilityDumpOnFailureRule mDumpOnFailureRule =
+            new AccessibilityDumpOnFailureRule();
+
+    @Rule
+    public final RuleChain mRuleChain = RuleChain
+            .outerRule(mServiceRule)
+            .around(mDumpOnFailureRule);
+
+    private StubAccessibilityButtonSdk29Service mService;
+    private AccessibilityServiceInfo mServiceInfo;
+
+    @Before
+    public void setUp() {
+        mService = mServiceRule.getService();
+        mServiceInfo = mService.getServiceInfo();
+
+        assertTrue(mService.getApplicationInfo().targetSdkVersion == Build.VERSION_CODES.Q);
+        assertTrue((mServiceInfo.flags & FLAG_REQUEST_ACCESSIBILITY_BUTTON)
+                == FLAG_REQUEST_ACCESSIBILITY_BUTTON);
+    }
+
+    @Test
+    public void testUpdateRequestAccessibilityButtonFlag_succeeds() {
+        mServiceInfo.flags &= ~FLAG_REQUEST_ACCESSIBILITY_BUTTON;
+        mService.setServiceInfo(mServiceInfo);
+        assertTrue("Update flagRequestAccessibilityButton should succeed",
+                mService.getServiceInfo().flags == mServiceInfo.flags);
+    }
+}
diff --git a/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/StubAccessibilityButtonSdk29Service.java b/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/StubAccessibilityButtonSdk29Service.java
new file mode 100644
index 0000000..59a1feb
--- /dev/null
+++ b/tests/accessibilityservice/testsdk29/src/android/accessibilityservice/cts/StubAccessibilityButtonSdk29Service.java
@@ -0,0 +1,23 @@
+/**
+ * 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 android.accessibilityservice.cts;
+
+import android.accessibility.cts.common.InstrumentedAccessibilityService;
+
+/**
+ * A stub accessibility service targeting sdk 29 for accessibility button test cases.
+ */
+public class StubAccessibilityButtonSdk29Service extends InstrumentedAccessibilityService {
+}