diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-03 00:01:16 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-03 00:01:16 +0000 |
commit | 9db09ca87b5b27bdb3c52c73b5f4ab78b37c00ed (patch) | |
tree | 7ecb9adbbed7e0f3ef307332d1a4bc063a3a6c0f | |
parent | 6006aa112267350671cf9a3bd38e4345b389d1d4 (diff) | |
parent | 73f8eb5aea838ad32d990b601ecdb93762119a68 (diff) | |
download | cts-android13-d3-s1-release.tar.gz |
Snap for 9556973 from 73f8eb5aea838ad32d990b601ecdb93762119a68 to tm-d3-releaseandroid-13.0.0_r57android13-d3-s1-release
Change-Id: I6eaa98d0cd4d8d49aeaedbee790e736d265e7e25
10 files changed, 368 insertions, 16 deletions
diff --git a/tests/app/AndroidManifest.xml b/tests/app/AndroidManifest.xml index 96e92ab7cb0..1ae84b82948 100644 --- a/tests/app/AndroidManifest.xml +++ b/tests/app/AndroidManifest.xml @@ -34,6 +34,10 @@ <application android:usesCleartextTraffic="true"> <uses-library android:name="android.test.runner" /> <uses-library android:name="org.apache.http.legacy" android:required="false" /> + + <service android:name=".InstrumentationHelperService" + android:exported="true" + android:process=":helper" /> </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" @@ -62,4 +66,11 @@ android:targetProcesses="com.android.cts.launcherapps.simpleapp:other,com.android.cts.launcherapps.simpleapp"> </instrumentation> + <instrumentation android:name=".ChainedInstrumentationFirst" + android:targetPackage="com.android.test.cantsavestate1" > + </instrumentation> + + <instrumentation android:name=".ChainedInstrumentationSecond" + android:targetPackage="com.android.test.cantsavestate2" > + </instrumentation> </manifest> diff --git a/tests/app/CantSaveState1/AndroidManifest.xml b/tests/app/CantSaveState1/AndroidManifest.xml index 41aad1f37d6..85faa5335b8 100644 --- a/tests/app/CantSaveState1/AndroidManifest.xml +++ b/tests/app/CantSaveState1/AndroidManifest.xml @@ -16,6 +16,9 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.test.cantsavestate1"> + <queries> + <package android:name="com.android.test.cantsavestate2" /> + </queries> <application android:label="Can't Save 1" android:cantSaveState="true"> <activity android:name="CantSave1Activity" diff --git a/tests/app/src/android/app/cts/BaseChainedInstrumentation.java b/tests/app/src/android/app/cts/BaseChainedInstrumentation.java new file mode 100644 index 00000000000..d265263dc4d --- /dev/null +++ b/tests/app/src/android/app/cts/BaseChainedInstrumentation.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2022 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.app.cts; + +import android.app.Activity; +import android.app.Application; +import android.app.Instrumentation; +import android.content.ComponentName; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; + +/** + * Base class supporting "chained" instrumentation: start another instrumentation while + * running the current instrumentation. + */ +public class BaseChainedInstrumentation extends Instrumentation { + static final String EXTRA_MESSENGER = "messenger"; + + final ComponentName mNestedInstrComp; + + /** Constructor */ + public BaseChainedInstrumentation(ComponentName nestedInstrComp) { + mNestedInstrComp = nestedInstrComp; + } + + @Override + public void onCreate(Bundle arguments) { + super.onCreate(arguments); + final String proc = getProcessName(); + final String appProc = Application.getProcessName(); + if (!proc.equals(appProc)) { + throw new RuntimeException(String.format( + "getProcessName()s mismatch. Instr=%s App=%s", proc, appProc)); + } + final Bundle result = new Bundle(); + result.putBoolean(proc, true); + if (mNestedInstrComp != null) { + // We're in the main process. + // Because the Context#startInstrumentation doesn't support result watcher, + // we'd have to craft a private way to relay the result back. + final Handler handler = new Handler(Looper.myLooper(), msg -> { + final Bundle nestedResult = (Bundle) msg.obj; + result.putAll(nestedResult); + finish(Activity.RESULT_OK, result); + return true; + }); + final Messenger messenger = new Messenger(handler); + final Bundle extras = new Bundle(); + extras.putParcelable(EXTRA_MESSENGER, messenger); + getContext().startInstrumentation(mNestedInstrComp, null, extras); + scheduleTimeoutCleanup(); + } else { + final Messenger messenger = arguments.getParcelable(EXTRA_MESSENGER); + final Message msg = Message.obtain(); + try { + msg.obj = result; + messenger.send(msg); + } catch (RemoteException e) { + } finally { + msg.recycle(); + } + finish(Activity.RESULT_OK, result); + } + } + + private void scheduleTimeoutCleanup() { + new Handler(Looper.myLooper()).postDelayed(() -> { + Bundle result = new Bundle(); + result.putString("FAILURE", + "Timed out waiting for sub-instrumentation to complete"); + finish(Activity.RESULT_CANCELED, result); + }, 20 * 1000); + } +} diff --git a/tests/app/src/android/app/cts/ChainedInstrumentationFirst.java b/tests/app/src/android/app/cts/ChainedInstrumentationFirst.java new file mode 100644 index 00000000000..0fd22b06cbf --- /dev/null +++ b/tests/app/src/android/app/cts/ChainedInstrumentationFirst.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 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.app.cts; + +import android.content.ComponentName; + +/** + * Chained instrumentation test class. + */ +public final class ChainedInstrumentationFirst extends BaseChainedInstrumentation { + static final String PACKAGE_NAME = "android.app.cts"; + /** Constructor */ + public ChainedInstrumentationFirst() { + super(new ComponentName(PACKAGE_NAME, PACKAGE_NAME + ".ChainedInstrumentationSecond")); + } +} diff --git a/tests/app/src/android/app/cts/ChainedInstrumentationSecond.java b/tests/app/src/android/app/cts/ChainedInstrumentationSecond.java new file mode 100644 index 00000000000..ebed475c0c0 --- /dev/null +++ b/tests/app/src/android/app/cts/ChainedInstrumentationSecond.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 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.app.cts; + +/** + * Chained instrumentation test class. + */ +public final class ChainedInstrumentationSecond extends BaseChainedInstrumentation { + /** Constructor */ + public ChainedInstrumentationSecond() { + super(null); + } +} diff --git a/tests/app/src/android/app/cts/InstrumentationHelperService.java b/tests/app/src/android/app/cts/InstrumentationHelperService.java new file mode 100644 index 00000000000..0c4f48d626a --- /dev/null +++ b/tests/app/src/android/app/cts/InstrumentationHelperService.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2022 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.app.cts; + +import android.app.Service; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.IBinder; +import android.os.ResultReceiver; + +import java.util.concurrent.CountDownLatch; + +/** + * The helper class to start an instrumentation from a different process. + */ +public class InstrumentationHelperService extends Service { + private static final String ACTION_START_INSTRUMENTATION = + "android.app.cts.ACTION_START_INSTRUMENTATION"; + private static final String EXTRA_INSTRUMENTATIION_NAME = "instrumentation_name"; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + final String action = intent.getAction(); + if (ACTION_START_INSTRUMENTATION.equals(action)) { + final String instrumentationName = intent.getStringExtra(EXTRA_INSTRUMENTATIION_NAME); + final ResultReceiver r = intent.getParcelableExtra(Intent.EXTRA_RESULT_RECEIVER); + + boolean result = false; + try { + startInstrumentation( + ComponentName.unflattenFromString(instrumentationName), null, null); + result = true; + } catch (SecurityException e) { + } + r.send(result ? 1 : 0, null); + } + return START_NOT_STICKY; + } + + /** + * Start the given instrumentation from this service and return result. + */ + static boolean startInstrumentation(Context context, String instrumentationName) + throws InterruptedException { + final Intent intent = new Intent(ACTION_START_INSTRUMENTATION); + final boolean[] resultHolder = new boolean[1]; + final CountDownLatch latch = new CountDownLatch(1); + final ResultReceiver r = new ResultReceiver(null) { + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + resultHolder[0] = resultCode == 1; + latch.countDown(); + } + }; + intent.putExtra(EXTRA_INSTRUMENTATIION_NAME, instrumentationName); + intent.putExtra(Intent.EXTRA_RESULT_RECEIVER, r); + intent.setClassName("android.app.cts", "android.app.cts.InstrumentationHelperService"); + context.startService(intent); + latch.await(); + return resultHolder[0]; + } +} diff --git a/tests/app/src/android/app/cts/InstrumentationTest.java b/tests/app/src/android/app/cts/InstrumentationTest.java index 70499b8265f..7830fe966a5 100644 --- a/tests/app/src/android/app/cts/InstrumentationTest.java +++ b/tests/app/src/android/app/cts/InstrumentationTest.java @@ -16,6 +16,15 @@ package android.app.cts; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; + import android.app.Activity; import android.app.Application; import android.app.Instrumentation; @@ -33,10 +42,10 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.SystemClock; -import android.test.InstrumentationTestCase; import android.test.UiThreadTest; import android.view.InputQueue; import android.view.KeyCharacterMap; @@ -48,12 +57,21 @@ import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.Window; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + import com.android.compatibility.common.util.SystemUtil; import com.android.compatibility.common.util.WindowUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.util.List; -public class InstrumentationTest extends InstrumentationTestCase { +@RunWith(AndroidJUnit4.class) +public class InstrumentationTest { private static final int WAIT_TIME = 1000; @@ -67,10 +85,9 @@ public class InstrumentationTest extends InstrumentationTestCase { private Context mContext; private MockActivity mMockActivity; - @Override - protected void setUp() throws Exception { - super.setUp(); - mInstrumentation = getInstrumentation(); + @Before + public void setUp() throws Exception { + mInstrumentation = InstrumentationRegistry.getInstrumentation(); mContext = mInstrumentation.getTargetContext(); mIntent = new Intent(mContext, InstrumentationTestActivity.class); mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -78,46 +95,86 @@ public class InstrumentationTest extends InstrumentationTestCase { WindowUtil.waitForFocus(mActivity); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { mInstrumentation = null; mIntent = null; if (mActivity != null) { mActivity.finish(); mActivity = null; } - super.tearDown(); } + @Test public void testDefaultProcessInstrumentation() throws Exception { String cmd = "am instrument -w android.app.cts/.DefaultProcessInstrumentation"; - String result = SystemUtil.runShellCommand(getInstrumentation(), cmd); + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); assertEquals("INSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + "=true" + "\nINSTRUMENTATION_CODE: -1\n", result); } + @Test public void testAltProcessInstrumentation() throws Exception { String cmd = "am instrument -w android.app.cts/.AltProcessInstrumentation"; - String result = SystemUtil.runShellCommand(getInstrumentation(), cmd); + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); assertEquals("INSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + ":other=true" + "\nINSTRUMENTATION_CODE: -1\n", result); } + @Test public void testWildcardProcessInstrumentation() throws Exception { String cmd = "am instrument -w android.app.cts/.WildcardProcessInstrumentation"; - String result = SystemUtil.runShellCommand(getInstrumentation(), cmd); + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); assertEquals("INSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + "=true" + "\nINSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + ":receiver=true" + "\nINSTRUMENTATION_CODE: -1\n", result); } + @Test public void testMultiProcessInstrumentation() throws Exception { String cmd = "am instrument -w android.app.cts/.MultiProcessInstrumentation"; - String result = SystemUtil.runShellCommand(getInstrumentation(), cmd); + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); assertEquals("INSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + "=true" + "\nINSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + ":other=true" + "\nINSTRUMENTATION_CODE: -1\n", result); } + @Test + public void testEnforceStartFromShell() throws Exception { + assumeFalse(Build.isDebuggable()); + // Start the instrumentation from shell, it should succeed. + final String defaultInstrumentationName = "android.app.cts/.DefaultProcessInstrumentation"; + String cmd = "am instrument -w " + defaultInstrumentationName; + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); + assertEquals("INSTRUMENTATION_RESULT: " + SIMPLE_PACKAGE_NAME + "=true" + + "\nINSTRUMENTATION_CODE: -1\n", result); + // Start the instrumentation by ourselves, it should succeed (chained instrumentation). + mContext.startInstrumentation( + ComponentName.unflattenFromString(defaultInstrumentationName), null, null); + // Start the instrumentation from another process, this time it should fail. + SystemUtil.runShellCommand(mInstrumentation, + "cmd deviceidle tempwhitelist android.app.cts"); + try { + assertFalse(InstrumentationHelperService.startInstrumentation( + mContext, defaultInstrumentationName)); + } finally { + SystemUtil.runShellCommand(mInstrumentation, + "cmd deviceidle tempwhitelist -r android.app.cts"); + } + } + + @Test + public void testChainedInstrumentation() throws Exception { + final String testPkg1 = "com.android.test.cantsavestate1"; + final String testPkg2 = "com.android.test.cantsavestate2"; + String cmd = "am instrument -w android.app.cts/.ChainedInstrumentationFirst"; + String result = SystemUtil.runShellCommand(mInstrumentation, cmd); + assertEquals("INSTRUMENTATION_RESULT: " + testPkg1 + "=true" + + "\nINSTRUMENTATION_RESULT: " + testPkg2 + "=true" + + "\nINSTRUMENTATION_CODE: -1\n", result); + } + + @Test public void testMonitor() throws Exception { if (mActivity != null) mActivity.finish(); @@ -158,6 +215,7 @@ public class InstrumentationTest extends InstrumentationTestCase { mInstrumentation.removeMonitor(am); } + @Test public void testCallActivityOnCreate() throws Throwable { mActivity.setOnCreateCalled(false); runTestOnUiThread(new Runnable() { @@ -169,6 +227,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnCreateCalled()); } + @Test public void testAllocCounting() throws Exception { mInstrumentation.startAllocCounting(); @@ -203,6 +262,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(threadAllocCount, Debug.getThreadAllocCount()); } + @Test public void testSendTrackballEventSync() throws Exception { long now = SystemClock.uptimeMillis(); MotionEvent orig = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, @@ -216,18 +276,21 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(orig.getDownTime(), motionEvent.getDownTime()); } + @Test public void testCallApplicationOnCreate() throws Exception { InstrumentationTestStub ca = new InstrumentationTestStub(); mInstrumentation.callApplicationOnCreate(ca); assertTrue(ca.mIsOnCreateCalled); } + @Test public void testContext() throws Exception { Context c1 = mInstrumentation.getContext(); Context c2 = mInstrumentation.getTargetContext(); assertNotSame(c1.getPackageName(), c2.getPackageName()); } + @Test public void testInvokeMenuActionSync() throws Exception { final int resId = R.id.goto_menu_id; if (mActivity.getWindow().hasFeature(Window.FEATURE_OPTIONS_PANEL)) { @@ -238,6 +301,7 @@ public class InstrumentationTest extends InstrumentationTestCase { } } + @Test public void testCallActivityOnPostCreate() throws Throwable { mActivity.setOnPostCreate(false); runTestOnUiThread(new Runnable() { @@ -249,6 +313,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnPostCreate()); } + @Test public void testCallActivityOnNewIntent() throws Throwable { mActivity.setOnNewIntentCalled(false); runTestOnUiThread(new Runnable() { @@ -261,6 +326,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnNewIntentCalled()); } + @Test public void testCallActivityOnResume() throws Throwable { mActivity.setOnResume(false); runTestOnUiThread(new Runnable() { @@ -272,15 +338,18 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnResume()); } + @Test public void testMisc() throws Exception { } + @Test public void testPerformanceSnapshot() throws Exception { mInstrumentation.setAutomaticPerformanceSnapshots(); mInstrumentation.startPerformanceSnapshot(); mInstrumentation.endPerformanceSnapshot(); } + @Test public void testProfiling() throws Exception { // by default, profiling was disabled. but after set the handleProfiling attribute in the // manifest file for this Instrumentation to true, the profiling was also disabled. @@ -290,6 +359,7 @@ public class InstrumentationTest extends InstrumentationTestCase { mInstrumentation.stopProfiling(); } + @Test public void testInvokeContextMenuAction() throws Exception { mActivity.runOnUiThread(new Runnable() { public void run() { @@ -306,6 +376,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(flag, mMockActivity.mWindow.mFlags); } + @Test public void testSendStringSync() { final String text = "abcd"; mInstrumentation.sendStringSync(text); @@ -326,6 +397,7 @@ public class InstrumentationTest extends InstrumentationTestCase { } } + @Test public void testCallActivityOnSaveInstanceState() throws Throwable { final Bundle bundle = new Bundle(); mActivity.setOnSaveInstanceState(false); @@ -340,6 +412,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertSame(bundle, mActivity.getBundle()); } + @Test public void testSendPointerSync() throws Exception { mInstrumentation.waitForIdleSync(); mInstrumentation.setInTouchMode(true); @@ -361,13 +434,15 @@ public class InstrumentationTest extends InstrumentationTestCase { mActivity.setOnTouchEventCalled(false); } + @Test public void testGetComponentName() throws Exception { - ComponentName com = getInstrumentation().getComponentName(); + ComponentName com = mInstrumentation.getComponentName(); assertNotNull(com.getPackageName()); assertNotNull(com.getClassName()); assertNotNull(com.getShortClassName()); } + @Test public void testNewApplication() throws Exception { final String className = "android.app.stubs.MockApplication"; ClassLoader cl = getClass().getClassLoader(); @@ -379,6 +454,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(className, app.getClass().getName()); } + @Test public void testRunOnMainSync() throws Exception { mRunOnMainSyncResult = false; mInstrumentation.runOnMainSync(new Runnable() { @@ -390,6 +466,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mRunOnMainSyncResult); } + @Test public void testCallActivityOnPause() throws Throwable { mActivity.setOnPauseCalled(false); runTestOnUiThread(() -> { @@ -399,6 +476,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnPauseCalled()); } + @Test public void testSendKeyDownUpSync() throws Exception { mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_0); mInstrumentation.waitForIdleSync(); @@ -408,6 +486,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(KeyEvent.KEYCODE_0, mActivity.getKeyDownList().get(0).getKeyCode()); } + @Test @UiThreadTest public void testNewActivity() throws Exception { Intent intent = new Intent(); @@ -435,6 +514,7 @@ public class InstrumentationTest extends InstrumentationTestCase { activity.finish(); } + @Test public void testCallActivityOnStart() throws Exception { mActivity.setOnStart(false); mInstrumentation.callActivityOnStart(mActivity); @@ -442,6 +522,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnStart()); } + @Test public void testWaitForIdle() throws Exception { MockRunnable mr = new MockRunnable(); assertFalse(mr.isRunCalled()); @@ -450,6 +531,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mr.isRunCalled()); } + @Test public void testSendCharacterSync() throws Exception { mInstrumentation.sendCharacterSync(KeyEvent.KEYCODE_0); mInstrumentation.waitForIdleSync(); @@ -457,6 +539,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertEquals(KeyEvent.KEYCODE_0, mActivity.getKeyUpCode()); } + @Test public void testCallActivityOnRestart() throws Exception { mActivity.setOnRestart(false); mInstrumentation.callActivityOnRestart(mActivity); @@ -464,6 +547,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnRestart()); } + @Test public void testCallActivityOnStop() throws Exception { mActivity.setOnStop(false); mInstrumentation.callActivityOnStop(mActivity); @@ -471,6 +555,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnStop()); } + @Test public void testCallActivityOnUserLeaving() throws Exception { assertFalse(mActivity.isOnLeave()); mInstrumentation.callActivityOnUserLeaving(mActivity); @@ -478,6 +563,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnLeave()); } + @Test public void testCallActivityOnRestoreInstanceState() throws Exception { mActivity.setOnRestoreInstanceState(false); mInstrumentation.callActivityOnRestoreInstanceState(mActivity, new Bundle()); @@ -485,6 +571,7 @@ public class InstrumentationTest extends InstrumentationTestCase { assertTrue(mActivity.isOnRestoreInstanceState()); } + @Test public void testSendKeySync() throws Exception { KeyEvent key = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0); mInstrumentation.sendKeySync(key); @@ -748,4 +835,20 @@ public class InstrumentationTest extends InstrumentationTestCase { mIsOnCreateCalled = true; } } + + private void runTestOnUiThread(final Runnable r) throws Throwable { + final Throwable[] exceptions = new Throwable[1]; + mInstrumentation.runOnMainSync(new Runnable() { + public void run() { + try { + r.run(); + } catch (Throwable throwable) { + exceptions[0] = throwable; + } + } + }); + if (exceptions[0] != null) { + throw exceptions[0]; + } + } } diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ExtensionRearDisplayTest.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ExtensionRearDisplayTest.java index d479e6ec073..8a6df771fb6 100644 --- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ExtensionRearDisplayTest.java +++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ExtensionRearDisplayTest.java @@ -44,6 +44,7 @@ import androidx.test.filters.LargeTest; import androidx.window.extensions.area.WindowAreaComponent; import androidx.window.extensions.area.WindowAreaComponent.WindowAreaSessionState; import androidx.window.extensions.area.WindowAreaComponent.WindowAreaStatus; +import androidx.window.extensions.core.util.function.Consumer; import com.android.compatibility.common.util.ApiTest; import com.android.compatibility.common.util.PollingCheck; @@ -57,7 +58,6 @@ import org.junit.runner.RunWith; import java.util.HashSet; import java.util.Objects; import java.util.Set; -import java.util.function.Consumer; /** * Tests for the {@link androidx.window.extensions.area.WindowAreaComponent} implementation @@ -208,8 +208,8 @@ public class ExtensionRearDisplayTest extends WindowManagerJetpackTestBase imple mActivity.mConfigurationChanged = false; mWindowAreaComponent.endRearDisplaySession(); + waitAndAssert(() -> WindowAreaComponent.SESSION_STATE_INACTIVE == mWindowAreaSessionState); waitAndAssert(() -> mActivity.mConfigurationChanged); - assertEquals(WindowAreaComponent.SESSION_STATE_INACTIVE, (int) mWindowAreaSessionState); assertTrue(isActivityVisible(mActivity)); // Cancelling rear display mode should cancel the override, so verifying that the // device state is the same as the physical state of the device. diff --git a/tests/framework/base/windowmanager/jetpack/window-extensions-release.aar b/tests/framework/base/windowmanager/jetpack/window-extensions-release.aar Binary files differindex 367e3b9d967..7eee6daae0f 100644 --- a/tests/framework/base/windowmanager/jetpack/window-extensions-release.aar +++ b/tests/framework/base/windowmanager/jetpack/window-extensions-release.aar diff --git a/tests/tests/content/src/android/content/cts/ContextTest.java b/tests/tests/content/src/android/content/cts/ContextTest.java index b742cc9e75b..cd6f3d60a35 100644 --- a/tests/tests/content/src/android/content/cts/ContextTest.java +++ b/tests/tests/content/src/android/content/cts/ContextTest.java @@ -16,6 +16,7 @@ package android.content.cts; +import static android.Manifest.permission.READ_WALLPAPER_INTERNAL; import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; @@ -151,7 +152,9 @@ public class ContextTest extends AndroidTestCase { mRegisteredReceiverList = new ArrayList<BroadcastReceiver>(); - mOriginalWallpaper = (BitmapDrawable) mContext.getWallpaper(); + SystemUtil.runWithShellPermissionIdentity( + () -> mOriginalWallpaper = (BitmapDrawable) mContext.getWallpaper(), + READ_WALLPAPER_INTERNAL); } @Override |