summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/AppJankTest/AndroidManifest.xml2
-rw-r--r--tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java15
-rw-r--r--tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt4
-rw-r--r--tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt24
-rw-r--r--tests/UsbManagerTests/lib/src/com/android/server/usblib/UsbManagerTestLib.java108
-rw-r--r--tests/UsbManagerTests/src/com/android/server/usbtest/UsbManagerApiTest.java32
-rw-r--r--tests/testables/src/android/testing/TestableLooper.java18
-rw-r--r--tests/utils/testutils/java/android/os/test/TestLooper.java12
8 files changed, 176 insertions, 39 deletions
diff --git a/tests/AppJankTest/AndroidManifest.xml b/tests/AppJankTest/AndroidManifest.xml
index ae973393b90e..abed1798c47c 100644
--- a/tests/AppJankTest/AndroidManifest.xml
+++ b/tests/AppJankTest/AndroidManifest.xml
@@ -18,7 +18,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.app.jank.tests">
- <application>
+ <application android:appCategory="news">
<uses-library android:name="android.test.runner" />
<activity android:name=".EmptyActivity"
android:label="EmptyActivity"
diff --git a/tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java b/tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java
index a3e5533599bc..1bdf019d6c42 100644
--- a/tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java
+++ b/tests/AppJankTest/src/android/app/jank/tests/JankTrackerTest.java
@@ -17,6 +17,7 @@
package android.app.jank.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import android.app.jank.Flags;
import android.app.jank.JankTracker;
@@ -31,6 +32,8 @@ import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ActivityScenario;
import androidx.test.runner.AndroidJUnit4;
+import com.android.internal.policy.DecorView;
+
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -153,4 +156,16 @@ public class JankTrackerTest {
assertEquals(1, stateData.size());
}
+
+ /**
+ * Test confirms a JankTracker object is retrieved from the activity.
+ */
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_DETAILED_APP_JANK_METRICS_LOGGING_ENABLED)
+ public void jankTracker_NotNull_WhenRetrievedFromDecorView() {
+ DecorView decorView = (DecorView) sActivityDecorView;
+ JankTracker jankTracker = decorView.getJankTracker();
+
+ assertNotNull(jankTracker);
+ }
}
diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
index 9a9a331a3753..ea61ad9d4481 100644
--- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
+++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
@@ -28,6 +28,7 @@ import android.tools.traces.parsers.WindowManagerStateHelper
import android.tools.traces.wm.WindowingMode
import android.view.WindowInsets
import android.view.WindowManager
+import android.window.DesktopModeFlags
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
@@ -35,7 +36,6 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.helpers.MotionEventHelper.InputMethod.TOUCH
-import com.android.window.flags.Flags
import java.time.Duration
/**
@@ -107,7 +107,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) :
// drag the window to move to desktop
if (motionEventHelper.inputMethod == TOUCH
- && Flags.enableHoldToDragAppHandle()) {
+ && DesktopModeFlags.ENABLE_HOLD_TO_DRAG_APP_HANDLE.isTrue) {
// Touch requires hold-to-drag.
motionEventHelper.holdToDrag(startX, startY, startX, endY, steps = 100)
} else {
diff --git a/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt b/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
index 61400edba165..09a686ca2c3f 100644
--- a/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
+++ b/tests/Input/src/com/android/server/input/KeyGestureControllerTests.kt
@@ -782,6 +782,30 @@ class KeyGestureControllerTests {
KeyEvent.META_META_ON or KeyEvent.META_ALT_ON,
intArrayOf(KeyGestureEvent.ACTION_GESTURE_COMPLETE)
),
+ TestData(
+ "META + ALT + M -> Toggle Magnification",
+ intArrayOf(
+ KeyEvent.KEYCODE_META_LEFT,
+ KeyEvent.KEYCODE_ALT_LEFT,
+ KeyEvent.KEYCODE_M
+ ),
+ KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
+ intArrayOf(KeyEvent.KEYCODE_M),
+ KeyEvent.META_META_ON or KeyEvent.META_ALT_ON,
+ intArrayOf(KeyGestureEvent.ACTION_GESTURE_COMPLETE)
+ ),
+ TestData(
+ "META + ALT + S -> Activate Select to Speak",
+ intArrayOf(
+ KeyEvent.KEYCODE_META_LEFT,
+ KeyEvent.KEYCODE_ALT_LEFT,
+ KeyEvent.KEYCODE_S
+ ),
+ KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK,
+ intArrayOf(KeyEvent.KEYCODE_S),
+ KeyEvent.META_META_ON or KeyEvent.META_ALT_ON,
+ intArrayOf(KeyGestureEvent.ACTION_GESTURE_COMPLETE)
+ ),
)
}
diff --git a/tests/UsbManagerTests/lib/src/com/android/server/usblib/UsbManagerTestLib.java b/tests/UsbManagerTests/lib/src/com/android/server/usblib/UsbManagerTestLib.java
index e2099e652c49..635e5de935c7 100644
--- a/tests/UsbManagerTests/lib/src/com/android/server/usblib/UsbManagerTestLib.java
+++ b/tests/UsbManagerTests/lib/src/com/android/server/usblib/UsbManagerTestLib.java
@@ -18,19 +18,27 @@ package com.android.server.usblib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
+import android.hardware.usb.flags.Flags;
import android.os.Binder;
+import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -43,13 +51,36 @@ public class UsbManagerTestLib {
private UsbManager mUsbManagerSys;
private UsbManager mUsbManagerMock;
- @Mock private android.hardware.usb.IUsbManager mMockUsbService;
+ @Mock
+ private android.hardware.usb.IUsbManager mMockUsbService;
+ private TestParcelFileDescriptor mTestParcelFileDescriptor = new TestParcelFileDescriptor(
+ new ParcelFileDescriptor(new FileDescriptor()));
+ @Mock
+ private UsbAccessory mMockUsbAccessory;
/**
* Counter for tracking UsbOperation operations.
*/
private static final AtomicInteger sUsbOperationCount = new AtomicInteger();
+ private class TestParcelFileDescriptor extends ParcelFileDescriptor {
+
+ private final AtomicInteger mCloseCount = new AtomicInteger();
+
+ TestParcelFileDescriptor(ParcelFileDescriptor wrapped) {
+ super(wrapped);
+ }
+
+ @Override
+ public void close() {
+ int unused = mCloseCount.incrementAndGet();
+ }
+
+ public void clearCloseCount() {
+ mCloseCount.set(0);
+ }
+ }
+
public UsbManagerTestLib(Context context) {
MockitoAnnotations.initMocks(this);
mContext = context;
@@ -74,6 +105,34 @@ public class UsbManagerTestLib {
mUsbManagerSys.setCurrentFunctions(functions);
}
+ private InputStream openAccessoryInputStream(UsbAccessory accessory) {
+ try {
+ when(mMockUsbService.openAccessory(accessory)).thenReturn(mTestParcelFileDescriptor);
+ } catch (RemoteException remEx) {
+ Log.w(TAG, "RemoteException");
+ }
+
+ if (Flags.enableAccessoryStreamApi()) {
+ return mUsbManagerMock.openAccessoryInputStream(accessory);
+ }
+
+ throw new UnsupportedOperationException("Stream APIs not available");
+ }
+
+ private OutputStream openAccessoryOutputStream(UsbAccessory accessory) {
+ try {
+ when(mMockUsbService.openAccessory(accessory)).thenReturn(mTestParcelFileDescriptor);
+ } catch (RemoteException remEx) {
+ Log.w(TAG, "RemoteException");
+ }
+
+ if (Flags.enableAccessoryStreamApi()) {
+ return mUsbManagerMock.openAccessoryOutputStream(accessory);
+ }
+
+ throw new UnsupportedOperationException("Stream APIs not available");
+ }
+
private void testSetGetCurrentFunctions_Matched(long functions) {
setCurrentFunctions(functions);
assertEquals("CurrentFunctions mismatched: ", functions, getCurrentFunctions());
@@ -94,7 +153,7 @@ public class UsbManagerTestLib {
try {
setCurrentFunctions(functions);
- verify(mMockUsbService).setCurrentFunctions(eq(functions), operationId);
+ verify(mMockUsbService).setCurrentFunctions(eq(functions), eq(operationId));
} catch (RemoteException remEx) {
Log.w(TAG, "RemoteException");
}
@@ -118,7 +177,7 @@ public class UsbManagerTestLib {
int operationId = sUsbOperationCount.incrementAndGet() + Binder.getCallingUid();
setCurrentFunctions(functions);
- verify(mMockUsbService).setCurrentFunctions(eq(functions), operationId);
+ verify(mMockUsbService).setCurrentFunctions(eq(functions), eq(operationId));
}
public void testGetCurrentFunctions_shouldMatched() {
@@ -138,4 +197,47 @@ public class UsbManagerTestLib {
testSetCurrentFunctionsMock_Matched(UsbManager.FUNCTION_RNDIS);
testSetCurrentFunctionsMock_Matched(UsbManager.FUNCTION_NCM);
}
+
+ public void testParcelFileDescriptorClosedWhenAllOpenStreamsAreClosed() {
+ mTestParcelFileDescriptor.clearCloseCount();
+ try {
+ try (InputStream ignored = openAccessoryInputStream(mMockUsbAccessory)) {
+ //noinspection EmptyTryBlock
+ try (OutputStream ignored2 = openAccessoryOutputStream(mMockUsbAccessory)) {
+ // do nothing
+ }
+ }
+
+ // ParcelFileDescriptor is closed only once.
+ assertEquals(mTestParcelFileDescriptor.mCloseCount.get(), 1);
+ mTestParcelFileDescriptor.clearCloseCount();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+
+ public void testOnlyOneOpenInputStreamAllowed() {
+ try {
+ //noinspection EmptyTryBlock
+ try (InputStream ignored = openAccessoryInputStream(mMockUsbAccessory)) {
+ assertThrows(IllegalStateException.class,
+ () -> openAccessoryInputStream(mMockUsbAccessory));
+ }
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+
+ public void testOnlyOneOpenOutputStreamAllowed() {
+ try {
+ //noinspection EmptyTryBlock
+ try (OutputStream ignored = openAccessoryOutputStream(mMockUsbAccessory)) {
+ assertThrows(IllegalStateException.class,
+ () -> openAccessoryOutputStream(mMockUsbAccessory));
+ }
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+
}
diff --git a/tests/UsbManagerTests/src/com/android/server/usbtest/UsbManagerApiTest.java b/tests/UsbManagerTests/src/com/android/server/usbtest/UsbManagerApiTest.java
index 8b21763b4a24..40fd0b431451 100644
--- a/tests/UsbManagerTests/src/com/android/server/usbtest/UsbManagerApiTest.java
+++ b/tests/UsbManagerTests/src/com/android/server/usbtest/UsbManagerApiTest.java
@@ -18,17 +18,21 @@ package com.android.server.usbtest;
import android.content.Context;
import android.hardware.usb.UsbManager;
+import android.hardware.usb.flags.Flags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import org.junit.Ignore;
+import com.android.server.usblib.UsbManagerTestLib;
+
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import com.android.server.usblib.UsbManagerTestLib;
-
/**
* Unit tests for {@link android.hardware.usb.UsbManager}.
* Note: MUST claimed MANAGE_USB permission in Manifest
@@ -41,6 +45,9 @@ public class UsbManagerApiTest {
private final UsbManagerTestLib mUsbManagerTestLib =
new UsbManagerTestLib(mContext = InstrumentationRegistry.getContext());
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule =
+ DeviceFlagsValueProvider.createCheckFlagsRule();
/**
* Verify NO SecurityException
* Go through System Server
@@ -92,4 +99,23 @@ public class UsbManagerApiTest {
public void testUsbApi_SetCurrentFunctions_shouldMatched() {
mUsbManagerTestLib.testSetCurrentFunctions_shouldMatched();
}
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_ACCESSORY_STREAM_API)
+ public void testUsbApi_closesParcelFileDescriptorAfterAllStreamsClosed() {
+ mUsbManagerTestLib.testParcelFileDescriptorClosedWhenAllOpenStreamsAreClosed();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_ACCESSORY_STREAM_API)
+ public void testUsbApi_callingOpenAccessoryInputStreamTwiceThrowsException() {
+ mUsbManagerTestLib.testOnlyOneOpenInputStreamAllowed();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_ACCESSORY_STREAM_API)
+ public void testUsbApi_callingOpenAccessoryOutputStreamTwiceThrowsException() {
+ mUsbManagerTestLib.testOnlyOneOpenOutputStreamAllowed();
+ }
+
}
diff --git a/tests/testables/src/android/testing/TestableLooper.java b/tests/testables/src/android/testing/TestableLooper.java
index ac96ef28f501..be5c84c0353c 100644
--- a/tests/testables/src/android/testing/TestableLooper.java
+++ b/tests/testables/src/android/testing/TestableLooper.java
@@ -53,7 +53,6 @@ public class TestableLooper {
private static final Field MESSAGE_QUEUE_MESSAGES_FIELD;
private static final Field MESSAGE_NEXT_FIELD;
private static final Field MESSAGE_WHEN_FIELD;
- private static Field MESSAGE_QUEUE_USE_CONCURRENT_FIELD = null;
private Looper mLooper;
private MessageQueue mQueue;
@@ -64,14 +63,6 @@ public class TestableLooper {
static {
try {
- MESSAGE_QUEUE_USE_CONCURRENT_FIELD =
- MessageQueue.class.getDeclaredField("mUseConcurrent");
- MESSAGE_QUEUE_USE_CONCURRENT_FIELD.setAccessible(true);
- } catch (NoSuchFieldException ignored) {
- // Ignore - maybe this is not CombinedMessageQueue?
- }
-
- try {
MESSAGE_QUEUE_MESSAGES_FIELD = MessageQueue.class.getDeclaredField("mMessages");
MESSAGE_QUEUE_MESSAGES_FIELD.setAccessible(true);
MESSAGE_NEXT_FIELD = Message.class.getDeclaredField("next");
@@ -155,15 +146,6 @@ public class TestableLooper {
mLooper = l;
mQueue = mLooper.getQueue();
mHandler = new Handler(mLooper);
-
- // If we are using CombinedMessageQueue, we need to disable concurrent mode for testing.
- if (MESSAGE_QUEUE_USE_CONCURRENT_FIELD != null) {
- try {
- MESSAGE_QUEUE_USE_CONCURRENT_FIELD.set(mQueue, false);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
}
/**
diff --git a/tests/utils/testutils/java/android/os/test/TestLooper.java b/tests/utils/testutils/java/android/os/test/TestLooper.java
index 1bcfaf60857d..56b0a25ed2dd 100644
--- a/tests/utils/testutils/java/android/os/test/TestLooper.java
+++ b/tests/utils/testutils/java/android/os/test/TestLooper.java
@@ -100,18 +100,6 @@ public class TestLooper {
throw new RuntimeException("Reflection error constructing or accessing looper", e);
}
- // If we are using CombinedMessageQueue, we need to disable concurrent mode for testing.
- try {
- Field messageQueueUseConcurrentField =
- MessageQueue.class.getDeclaredField("mUseConcurrent");
- messageQueueUseConcurrentField.setAccessible(true);
- messageQueueUseConcurrentField.set(mLooper.getQueue(), false);
- } catch (NoSuchFieldException e) {
- // Ignore - maybe this is not CombinedMessageQueue?
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Reflection error constructing or accessing looper", e);
- }
-
mClock = clock;
}