aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathew Inwood <mathewi@google.com>2019-07-01 13:31:53 +0100
committerMathew Inwood <mathewi@google.com>2019-07-25 15:31:53 +0100
commit61865657a782c55130a70724bf6c8a1d11c6038b (patch)
treed2a8daebf22f27a954b3864897fb194896d66b28
parent5837a28eb01e4850268f8d2330d2066f6e90af2e (diff)
downloadexperimental-61865657a782c55130a70724bf6c8a1d11c6038b.tar.gz
Add app compat test app.
Note: patch in http://aosp/1008615 in order to use this app. Test: m CompatTestApp Test: adb install -r out/soong/.intermediates/packages/experimental/\ CompatTest/CompatTestApp/android_common/CompatTestApp.apk Change-Id: Id75c4c34ec96336060554331daec0d755c386b3c
-rw-r--r--CompatTest/Android.bp25
-rw-r--r--CompatTest/AndroidManifest.xml32
-rw-r--r--CompatTest/res/layout/main.xml34
-rw-r--r--CompatTest/src/com/android/compat/testapp/CompatActivity.java67
4 files changed, 158 insertions, 0 deletions
diff --git a/CompatTest/Android.bp b/CompatTest/Android.bp
new file mode 100644
index 0000000..856fee5
--- /dev/null
+++ b/CompatTest/Android.bp
@@ -0,0 +1,25 @@
+// 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_helper_app {
+ name: "CompatTestApp",
+ resource_dirs: ["res"],
+ sdk_version: "current",
+ srcs: [
+ "src/**/*.java",
+ ],
+ static_libs: [
+ ],
+
+}
diff --git a/CompatTest/AndroidManifest.xml b/CompatTest/AndroidManifest.xml
new file mode 100644
index 0000000..2b3a892
--- /dev/null
+++ b/CompatTest/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?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="com.android.compat.testapp">
+ <application>
+ <activity
+ android:name=".CompatActivity"
+ android:label="App Compat test"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest> \ No newline at end of file
diff --git a/CompatTest/res/layout/main.xml b/CompatTest/res/layout/main.xml
new file mode 100644
index 0000000..23c2033
--- /dev/null
+++ b/CompatTest/res/layout/main.xml
@@ -0,0 +1,34 @@
+<?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
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <Button
+ android:id="@+id/button1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Click Me" />
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:singleLine="false"
+ />
+
+</LinearLayout> \ No newline at end of file
diff --git a/CompatTest/src/com/android/compat/testapp/CompatActivity.java b/CompatTest/src/com/android/compat/testapp/CompatActivity.java
new file mode 100644
index 0000000..2b7af88
--- /dev/null
+++ b/CompatTest/src/com/android/compat/testapp/CompatActivity.java
@@ -0,0 +1,67 @@
+/*
+ * 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.compat.testapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.TextView;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+
+public class CompatActivity extends Activity {
+
+ private static final String TAG = "CompatTest";
+
+ private TextView mText;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ mText = findViewById(R.id.text);
+ findViewById(R.id.button1).setOnClickListener(view -> {
+ try {
+ message("Returned: " + accessHiddenApi());
+ } catch (ReflectiveOperationException roe) {
+ message(roe);
+ }
+ });
+ }
+
+ private Object accessHiddenApi() throws ReflectiveOperationException {
+ // Note: this class does not exist. Patch in http://aosp/1008615 in order
+ // for this to work as intended.
+ Class<?> c = Class.forName("android.compattest.CompatTest");
+ Method m = c.getDeclaredMethod("testApi");
+ return m.invoke(null);
+ }
+
+ private void message(Throwable t) {
+ StringWriter s = new StringWriter();
+ t.printStackTrace(new PrintWriter(s));
+ message(s.toString());
+ }
+
+ private void message(String m) {
+ Log.d(TAG, m);
+ mText.setText(m);
+ }
+} \ No newline at end of file