Merge "Camera ITS: Setting the tablet orientation." into sc-dev
diff --git a/apps/CameraITS/tests/scene2_b/test_num_faces.py b/apps/CameraITS/tests/scene2_b/test_num_faces.py
new file mode 120000
index 0000000..8d67dcf
--- /dev/null
+++ b/apps/CameraITS/tests/scene2_b/test_num_faces.py
@@ -0,0 +1 @@
+../scene2_a/test_num_faces.py
\ No newline at end of file
diff --git a/apps/CameraITS/tests/scene2_c/test_num_faces.py b/apps/CameraITS/tests/scene2_c/test_num_faces.py
new file mode 120000
index 0000000..8d67dcf
--- /dev/null
+++ b/apps/CameraITS/tests/scene2_c/test_num_faces.py
@@ -0,0 +1 @@
+../scene2_a/test_num_faces.py
\ No newline at end of file
diff --git a/apps/CameraITS/tests/scene2_d/test_num_faces.py b/apps/CameraITS/tests/scene2_d/test_num_faces.py
new file mode 120000
index 0000000..8d67dcf
--- /dev/null
+++ b/apps/CameraITS/tests/scene2_d/test_num_faces.py
@@ -0,0 +1 @@
+../scene2_a/test_num_faces.py
\ No newline at end of file
diff --git a/apps/CameraITS/tests/scene2_e/test_num_faces.py b/apps/CameraITS/tests/scene2_e/test_num_faces.py
new file mode 120000
index 0000000..8d67dcf
--- /dev/null
+++ b/apps/CameraITS/tests/scene2_e/test_num_faces.py
@@ -0,0 +1 @@
+../scene2_a/test_num_faces.py
\ No newline at end of file
diff --git a/apps/CameraITS/tools/run_all_tests.py b/apps/CameraITS/tools/run_all_tests.py
index 2095f0f..8543b01 100644
--- a/apps/CameraITS/tools/run_all_tests.py
+++ b/apps/CameraITS/tools/run_all_tests.py
@@ -79,26 +79,6 @@
# Scenes that have to be run manually regardless of configuration
_MANUAL_SCENES = ['scene5']
-# Tests run in more than 1 scene.
-# List is created of type ['scene_source', 'test_to_be_repeated']
-# for the test run in current scene.
-_REPEATED_TESTS = {
- 'scene0': [],
- 'scene1_1': [],
- 'scene1_2': [],
- 'scene2_a': [],
- 'scene2_b': [['scene2_a', 'test_num_faces']],
- 'scene2_c': [['scene2_a', 'test_num_faces']],
- 'scene2_d': [['scene2_a', 'test_num_faces']],
- 'scene2_e': [['scene2_a', 'test_num_faces']],
- 'scene3': [],
- 'scene4': [],
- 'scene5': [],
- 'scene6': [],
- 'sensor_fusion': [],
- 'scene_change': []
-}
-
# Scene requirements for manual testing.
_SCENE_REQ = {
'scene0': None,
@@ -506,9 +486,6 @@
for file_name in scene_dir:
if file_name.endswith('.py') and 'test' in file_name:
scene_test_list.append(file_name)
- if _REPEATED_TESTS[s]:
- for t in _REPEATED_TESTS[s]:
- scene_test_list.append((os.path.join('tests', t[0], t[1] + '.py')))
else: # sub-camera
if SUB_CAMERA_TESTS.get(s):
scene_test_list = [f'{test}.py' for test in SUB_CAMERA_TESTS[s]]
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/Android.bp b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/Android.bp
index 8fab49a..b91fec2 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/Android.bp
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/Android.bp
@@ -52,6 +52,7 @@
name: "CtsDeviceAndProfileOwnerApp25",
defaults: ["cts_defaults"],
platform_apis: true,
+ min_sdk_version: "30",
target_sdk_version: "25",
srcs: ["src/**/*.java"],
libs: [
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/SensorToggleRestrictionTest.java b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/SensorToggleRestrictionTest.java
index 76b3f0a..49a0721 100755
--- a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/SensorToggleRestrictionTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/SensorToggleRestrictionTest.java
@@ -16,6 +16,8 @@
package com.android.cts.deviceowner;
+import static android.hardware.SensorPrivacyManager.Sources.OTHER;
+
import android.hardware.SensorPrivacyManager;
import android.os.UserManager;
@@ -56,7 +58,7 @@
mDevicePolicyManager.addUserRestriction(getWho(), UserManager.DISALLOW_CAMERA_TOGGLE);
ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mSensorPrivacyManager,
- m -> m.setSensorPrivacy(SensorPrivacyManager.Sensors.CAMERA, true));
+ m -> m.setSensorPrivacy(OTHER, SensorPrivacyManager.Sensors.CAMERA, true));
assertFalse("Camera sensor privacy should not be enabled given admin restriction",
ShellIdentityUtils.invokeMethodWithShellPermissions(mSensorPrivacyManager,
@@ -73,7 +75,7 @@
mDevicePolicyManager.addUserRestriction(getWho(), UserManager.DISALLOW_MICROPHONE_TOGGLE);
ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mSensorPrivacyManager,
- m -> m.setSensorPrivacy(SensorPrivacyManager.Sensors.MICROPHONE, true));
+ m -> m.setSensorPrivacy(OTHER, SensorPrivacyManager.Sensors.MICROPHONE, true));
assertFalse("Microphone sensor privacy should not be enabled given admin restriction",
ShellIdentityUtils.invokeMethodWithShellPermissions(mSensorPrivacyManager,
@@ -85,7 +87,7 @@
return;
}
ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mSensorPrivacyManager,
- m -> m.setSensorPrivacy(SensorPrivacyManager.Sensors.CAMERA, true));
+ m -> m.setSensorPrivacy(OTHER, SensorPrivacyManager.Sensors.CAMERA, true));
mDevicePolicyManager.addUserRestriction(getWho(), UserManager.DISALLOW_CAMERA_TOGGLE);
@@ -104,7 +106,7 @@
return;
}
ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn(mSensorPrivacyManager,
- m -> m.setSensorPrivacy(SensorPrivacyManager.Sensors.MICROPHONE, true));
+ m -> m.setSensorPrivacy(OTHER, SensorPrivacyManager.Sensors.MICROPHONE, true));
mDevicePolicyManager.addUserRestriction(getWho(), UserManager.DISALLOW_MICROPHONE_TOGGLE);
diff --git a/hostsidetests/edi/Android.bp b/hostsidetests/edi/Android.bp
index 3f4bac8..1b32a4b 100644
--- a/hostsidetests/edi/Android.bp
+++ b/hostsidetests/edi/Android.bp
@@ -33,6 +33,7 @@
],
static_libs: [
"compat-classpaths-testing",
+ "modules-utils-build-testing",
"hamcrest-library",
],
}
diff --git a/hostsidetests/edi/app/Android.bp b/hostsidetests/edi/app/Android.bp
index 6ef3059..96f2870 100644
--- a/hostsidetests/edi/app/Android.bp
+++ b/hostsidetests/edi/app/Android.bp
@@ -20,9 +20,12 @@
name: "CtsDeviceInfoTestApp",
srcs: ["src/**/*.java"],
defaults: ["cts_defaults"],
+ min_sdk_version: "26",
+ target_sdk_version: "31",
static_libs: [
"androidx.test.rules",
"androidx.test.core",
+ "modules-utils-build",
"guava",
],
sdk_version: "test_current",
diff --git a/hostsidetests/edi/app/AndroidManifest.xml b/hostsidetests/edi/app/AndroidManifest.xml
index 00206b7..2f589dc 100644
--- a/hostsidetests/edi/app/AndroidManifest.xml
+++ b/hostsidetests/edi/app/AndroidManifest.xml
@@ -19,6 +19,8 @@
package="android.edi.cts.app"
android:targetSandboxVersion="2">
+ <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="31"/>
+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_SHARED_LIBRARIES" />
diff --git a/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java b/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
index a68d626..5c22e43 100644
--- a/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
+++ b/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
@@ -16,6 +16,8 @@
package android.edi.cts.app;
+import static org.junit.Assume.assumeTrue;
+
import android.app.Instrumentation;
import android.content.Context;
import android.content.pm.SharedLibraryInfo;
@@ -24,6 +26,8 @@
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
+import com.android.modules.utils.build.SdkLevel;
+
import com.google.common.collect.ImmutableList;
import org.junit.After;
@@ -53,6 +57,7 @@
@Before
public void before() {
+ assumeTrue(SdkLevel.isAtLeastS());
instrumentation.getUiAutomation().adoptShellPermissionIdentity();
}
diff --git a/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java b/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
index 2785ab2..8fc1059 100644
--- a/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
+++ b/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
@@ -26,6 +26,7 @@
import com.android.compatibility.common.util.DeviceInfo;
import com.android.compatibility.common.util.HostInfoStore;
+import com.android.modules.utils.build.testing.DeviceSdkLevel;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil.CLog;
@@ -44,10 +45,12 @@
private static final String HELPER_APP_CLASS = HELPER_APP_PACKAGE + ".ClasspathDeviceTest";
private ITestDevice mDevice;
+ private DeviceSdkLevel deviceSdkLevel;
@Override
protected void collectDeviceInfo(HostInfoStore store) throws Exception {
mDevice = getDevice();
+ deviceSdkLevel = new DeviceSdkLevel(mDevice);
store.startArray("jars");
collectClasspathsJars(store);
@@ -75,6 +78,10 @@
}
private void collectSharedLibraryJars(HostInfoStore store) throws Exception {
+ if (!deviceSdkLevel.isDeviceAtLeastS()) {
+ return;
+ }
+
// Trigger helper app to collect and write info about shared libraries on the device.
assertThat(runDeviceTests(HELPER_APP_PACKAGE, HELPER_APP_CLASS)).isTrue();
diff --git a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java
index 77a0729..281df8f 100644
--- a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java
+++ b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/AppCloningHostTest.java
@@ -42,7 +42,6 @@
public class AppCloningHostTest extends BaseHostTestCase {
private static final String APP_A = "CtsScopedStorageTestAppA.apk";
private static final String APP_A_PACKAGE = "android.scopedstorage.cts.testapp.A.withres";
- private static final String APP_FOR_PVT_PACKAGE = "com.google.android.gms";
private static final String CONTENT_PROVIDER_URL = "content://android.tradefed.contentprovider";
private static final int CLONE_PROFILE_DIRECTORY_CREATION_TIMEOUT_MS = 20000;
private String mCloneUserId;
@@ -67,7 +66,7 @@
@After
public void tearDown() throws Exception {
- if (isHeadlessSystemUserMode()) return;
+ if (isHeadlessSystemUserMode() || !isAtLeastS()) return;
mContentProviderHandler.tearDown();
executeShellCommand("pm remove-user %s", mCloneUserId);
}
@@ -111,8 +110,10 @@
@Test
public void testPrivateAppDataDirectoryForCloneUser() throws Exception {
+ installAppAsUser(APP_A, Integer.valueOf(mCloneUserId));
eventually(() -> {
- assertThat(isPackageInstalled(APP_FOR_PVT_PACKAGE, mCloneUserId)).isTrue();
+ // Wait for finish.
+ assertThat(isPackageInstalled(APP_A_PACKAGE, mCloneUserId)).isTrue();
}, CLONE_PROFILE_DIRECTORY_CREATION_TIMEOUT_MS);
}
diff --git a/tests/app/src/android/app/cts/StatusBarManagerTest.java b/tests/app/src/android/app/cts/StatusBarManagerTest.java
index 65c933d..9995099 100644
--- a/tests/app/src/android/app/cts/StatusBarManagerTest.java
+++ b/tests/app/src/android/app/cts/StatusBarManagerTest.java
@@ -26,6 +26,7 @@
import android.app.UiAutomation;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.view.KeyEvent;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -144,4 +145,38 @@
// Nothing thrown, passed
}
+
+ @Test(expected = SecurityException.class)
+ public void testTogglePanel_withoutStatusBarPermission_throws() throws Exception {
+ // We've adopted shell identity for STATUS_BAR in setUp(), so drop it now
+ mUiAutomation.dropShellPermissionIdentity();
+
+ mStatusBarManager.togglePanel();
+ }
+
+ @Test
+ public void testTogglePanel_withStatusBarPermission_doesNotThrow() throws Exception {
+ // We've adopted shell identity for STATUS_BAR in setUp()
+
+ mStatusBarManager.togglePanel();
+
+ // Nothing thrown, passed
+ }
+
+ @Test(expected = SecurityException.class)
+ public void testHandleSystemKey_withoutStatusBarPermission_throws() throws Exception {
+ // We've adopted shell identity for STATUS_BAR in setUp(), so drop it now
+ mUiAutomation.dropShellPermissionIdentity();
+
+ mStatusBarManager.handleSystemKey(KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP);
+ }
+
+ @Test
+ public void testHandleSystemKey_withStatusBarPermission_doesNotThrow() throws Exception {
+ // We've adopted shell identity for STATUS_BAR in setUp()
+
+ mStatusBarManager.handleSystemKey(KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP);
+
+ // Nothing thrown, passed
+ }
}
diff --git a/tests/framework/base/windowmanager/AndroidManifest.xml b/tests/framework/base/windowmanager/AndroidManifest.xml
index 86b50fa..f0f40a6 100644
--- a/tests/framework/base/windowmanager/AndroidManifest.xml
+++ b/tests/framework/base/windowmanager/AndroidManifest.xml
@@ -490,6 +490,12 @@
android:screenOrientation="portrait"
android:exported="true"/>
+ <activity android:name="android.server.wm.CompatChangeTests$ResizeableLargeAspectRatioActivity"
+ android:resizeableActivity="true"
+ android:screenOrientation="portrait"
+ android:minAspectRatio="3"
+ android:exported="true"/>
+
<activity android:name="android.server.wm.CompatChangeTests$NonResizeablePortraitActivity"
android:resizeableActivity="false"
android:screenOrientation="portrait"
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/CompatChangeTests.java b/tests/framework/base/windowmanager/src/android/server/wm/CompatChangeTests.java
index a15bdb9..66dcfa8 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/CompatChangeTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/CompatChangeTests.java
@@ -73,6 +73,8 @@
public final class CompatChangeTests extends MultiDisplayTestBase {
private static final ComponentName RESIZEABLE_PORTRAIT_ACTIVITY =
component(ResizeablePortraitActivity.class);
+ private static final ComponentName RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY =
+ component(ResizeableLargeAspectRatioActivity.class);
private static final ComponentName NON_RESIZEABLE_PORTRAIT_ACTIVITY =
component(NonResizeablePortraitActivity.class);
private static final ComponentName NON_RESIZEABLE_ASPECT_RATIO_ACTIVITY =
@@ -180,7 +182,7 @@
*/
@Test
public void testSandboxForNonResizableAspectRatioActivity() {
- runSandboxTest(/* isSandboxed= */ true);
+ runSandboxTest(NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */ true);
}
/**
@@ -191,7 +193,7 @@
@Test
@EnableCompatChanges({ActivityInfo.NEVER_SANDBOX_DISPLAY_APIS})
public void testSandboxForNonResizableAspectRatioActivityNeverSandboxDisplayApisEnabled() {
- runSandboxTest(/* isSandboxed= */ false);
+ runSandboxTest(NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */ false);
}
/**
@@ -204,7 +206,7 @@
setNeverConstrainDisplayApisAllPackagesFlag("true");
// Setting 'never_constrain_display_apis' as well to make sure it is ignored.
setNeverConstrainDisplayApisFlag("com.android.other::");
- runSandboxTest(/* isSandboxed= */ false);
+ runSandboxTest(NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */ false);
}
/**
@@ -214,10 +216,10 @@
*/
@Test
public void testSandboxForNonResizableActivityPackageUnboundedInNeverSandboxDeviceConfigFlag() {
- ComponentName activity = NON_RESIZEABLE_ASPECT_RATIO_ACTIVITY;
+ ComponentName activity = NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
setNeverConstrainDisplayApisFlag(
"com.android.other::," + activity.getPackageName() + "::");
- runSandboxTest(/* isSandboxed= */ false);
+ runSandboxTest(activity, /* isSandboxed= */ false);
}
/**
@@ -227,12 +229,12 @@
*/
@Test
public void testSandboxForNonResizableActivityPackageWithinRangeInNeverSandboxDeviceConfig() {
- ComponentName activity = NON_RESIZEABLE_ASPECT_RATIO_ACTIVITY;
+ ComponentName activity = NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
long version = getPackageVersion(activity);
setNeverConstrainDisplayApisFlag(
"com.android.other::," + activity.getPackageName() + ":" + String.valueOf(
version - 1) + ":" + String.valueOf(version + 1));
- runSandboxTest(/* isSandboxed= */ false);
+ runSandboxTest(activity, /* isSandboxed= */ false);
}
/**
@@ -242,12 +244,12 @@
*/
@Test
public void testSandboxForNonResizableActivityPackageOutsideRangeInNeverSandboxDeviceConfig() {
- ComponentName activity = NON_RESIZEABLE_ASPECT_RATIO_ACTIVITY;
+ ComponentName activity = NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
long version = getPackageVersion(activity);
setNeverConstrainDisplayApisFlag(
"com.android.other::," + activity.getPackageName() + ":" + String.valueOf(
version + 1) + ":");
- runSandboxTest(/* isSandboxed= */ true);
+ runSandboxTest(activity, /* isSandboxed= */ true);
}
/**
@@ -258,7 +260,7 @@
@Test
public void testSandboxForNonResizableActivityPackageNotInNeverSandboxDeviceConfigFlag() {
setNeverConstrainDisplayApisFlag("com.android.other::,com.android.other2::");
- runSandboxTest(/* isSandboxed= */ true);
+ runSandboxTest(NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */ true);
}
/**
@@ -268,7 +270,7 @@
@Test
public void testSandboxForNonResizableActivityNeverSandboxDeviceConfigFlagEmpty() {
setNeverConstrainDisplayApisFlag("");
- runSandboxTest(/* isSandboxed= */ true);
+ runSandboxTest(NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */ true);
}
/**
@@ -278,21 +280,46 @@
*/
@Test
public void testSandboxForNonResizableActivityInvalidEntryInNeverSandboxDeviceConfigFlag() {
- ComponentName activity = NON_RESIZEABLE_ASPECT_RATIO_ACTIVITY;
+ ComponentName activity = NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
setNeverConstrainDisplayApisFlag(
"com.android.other::," + activity.getPackageName() + ":::");
- runSandboxTest(/* isSandboxed= */ true);
+ runSandboxTest(activity, /* isSandboxed= */ true);
+ }
+
+ /**
+ * Test that a min aspect ratio activity not eligible for size compat mode does have the
+ * Display APIs sandboxed when the {@link ActivityInfo#ALWAYS_SANDBOX_DISPLAY_APIS} compat
+ * change is enabled.
+ */
+ @Test
+ @EnableCompatChanges({ActivityInfo.ALWAYS_SANDBOX_DISPLAY_APIS})
+ public void testSandboxForResizableAspectRatioActivityAlwaysSandboxDisplayApisEnabled() {
+ runSandboxTest(RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */
+ true, /* inSizeCompatModeAfterResize= */ false);
+ }
+
+ /**
+ * Test that a min aspect ratio activity non eligible for size compat mode does not have the
+ * Display APIs sandboxed when the 'always_constrain_display_apis' Device Config flag is empty.
+ */
+ @Test
+ public void testSandboxResizableActivityAlwaysSandboxDeviceConfigFlagEmpty() {
+ setAlwaysConstrainDisplayApisFlag("");
+ runSandboxTest(RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY, /* isSandboxed= */
+ false, /* inSizeCompatModeAfterResize= */ false);
}
/**
* Test that a min aspect ratio activity eligible for size compat mode does have the Display
- * APIs sandboxed when the {@link ActivityInfo#ALWAYS_SANDBOX_DISPLAY_APIS} compat change is
- * enabled.
+ * APIs sandboxed when the 'always_constrain_display_apis' Device Config flag contains the test
+ * package.
*/
@Test
- @EnableCompatChanges({ActivityInfo.ALWAYS_SANDBOX_DISPLAY_APIS})
- public void testSandboxForNonResizableAspectRatioActivityAlwaysSandboxDisplayApisEnabled() {
- runSandboxTest(/* isSandboxed= */ true);
+ public void testSandboxResizableActivityPackageInAlwaysSandboxDeviceConfigFlag() {
+ ComponentName activity = RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
+ setNeverConstrainDisplayApisFlag(
+ "com.android.other::," + activity.getPackageName() + "::");
+ runSandboxTest(activity, /* isSandboxed= */ true, /* inSizeCompatModeAfterResize= */ false);
}
/**
@@ -432,21 +459,28 @@
}
}
+ private void runSandboxTest(ComponentName activity, boolean isSandboxed) {
+ runSandboxTest(activity, isSandboxed, /* inSizeCompatModeAfterResize= */ true);
+ }
+
/**
* Similar to {@link #runSizeCompatTest(ComponentName, boolean)}, but the activity is expected
* to be in size compat mode after resizing the display.
*
- * @param isSandboxed when {@code true}, {@link android.app.WindowConfiguration#getMaxBounds()}
- * are sandboxed to the activity bounds. Otherwise, they inherit the
- * DisplayArea bounds
+ * @param activity the activity under test
+ * @param isSandboxed when {@code true}, {@link android.app.WindowConfiguration#getMaxBounds()}
+ * are sandboxed to the activity bounds. Otherwise, they inherit the
+ * DisplayArea bounds
+ * @param inSizeCompatModeAfterResize if the activity should be in size compat mode after
+ * resizing the display
*/
- private void runSandboxTest(boolean isSandboxed) {
+ private void runSandboxTest(ComponentName activity, boolean isSandboxed,
+ boolean inSizeCompatModeAfterResize) {
assertThat(getInitialDisplayAspectRatio()).isLessThan(ACTIVITY_LARGE_MIN_ASPECT_RATIO);
- ComponentName activity = NON_RESIZEABLE_LARGE_ASPECT_RATIO_ACTIVITY;
- runSizeCompatTest(activity, /* resizeRatio= */ 0.5, /* inSizeCompatModeAfterResize=*/ true);
+ runSizeCompatTest(activity, /* resizeRatio= */ 0.5, inSizeCompatModeAfterResize);
assertSandboxed(activity, isSandboxed);
restoreDisplay(activity);
- runSizeCompatTest(activity, /* resizeRatio= */ 2, /* inSizeCompatModeAfterResize=*/ true);
+ runSizeCompatTest(activity, /* resizeRatio= */ 2, inSizeCompatModeAfterResize);
assertSandboxed(activity, isSandboxed);
}
@@ -477,10 +511,12 @@
() -> {
mInitialProperties = DeviceConfig.getProperties(
NAMESPACE_CONSTRAIN_DISPLAY_APIS);
+ try {
+ DeviceConfig.setProperties(new Properties.Builder(
+ NAMESPACE_CONSTRAIN_DISPLAY_APIS).build());
+ } catch (Exception e) {
+ }
});
- // Clear all flags
- setNeverConstrainDisplayApisFlag(null);
- setNeverConstrainDisplayApisAllPackagesFlag(null);
}
@Override
@@ -501,19 +537,21 @@
}
private void setNeverConstrainDisplayApisFlag(@Nullable String value) {
- runWithShellPermission(
- () -> {
- DeviceConfig.setProperty(NAMESPACE_CONSTRAIN_DISPLAY_APIS,
- "never_constrain_display_apis",
- value, /* makeDefault= */ false);
- });
+ setConstrainDisplayApisFlag("never_constrain_display_apis", value);
}
private void setNeverConstrainDisplayApisAllPackagesFlag(@Nullable String value) {
+ setConstrainDisplayApisFlag("never_constrain_display_apis_all_packages", value);
+ }
+
+ private void setAlwaysConstrainDisplayApisFlag(@Nullable String value) {
+ setConstrainDisplayApisFlag("always_constrain_display_apis", value);
+ }
+
+ private void setConstrainDisplayApisFlag(String flagName, @Nullable String value) {
runWithShellPermission(
() -> {
- DeviceConfig.setProperty(NAMESPACE_CONSTRAIN_DISPLAY_APIS,
- "never_constrain_display_apis_all_packages",
+ DeviceConfig.setProperty(NAMESPACE_CONSTRAIN_DISPLAY_APIS, flagName,
value, /* makeDefault= */ false);
});
}
@@ -633,6 +671,9 @@
public static class ResizeablePortraitActivity extends FocusableActivity {
}
+ public static class ResizeableLargeAspectRatioActivity extends FocusableActivity {
+ }
+
public static class NonResizeablePortraitActivity extends FocusableActivity {
}
diff --git a/tests/location/location_fine/src/android/location/cts/fine/LocationManagerFineTest.java b/tests/location/location_fine/src/android/location/cts/fine/LocationManagerFineTest.java
index 102d301..dcaee4f 100644
--- a/tests/location/location_fine/src/android/location/cts/fine/LocationManagerFineTest.java
+++ b/tests/location/location_fine/src/android/location/cts/fine/LocationManagerFineTest.java
@@ -17,6 +17,7 @@
package android.location.cts.fine;
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
+import static android.content.pm.PackageManager.FEATURE_AUTOMOTIVE;
import static android.location.LocationManager.EXTRA_PROVIDER_ENABLED;
import static android.location.LocationManager.EXTRA_PROVIDER_NAME;
import static android.location.LocationManager.FUSED_PROVIDER;
@@ -40,6 +41,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import android.Manifest;
@@ -49,6 +51,7 @@
import android.app.UiAutomation;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.GnssMeasurementsEvent;
import android.location.GnssNavigationMessage;
@@ -662,6 +665,9 @@
@Test
public void testRequestLocationUpdates_BatterySaver_GpsDisabledScreenOff() throws Exception {
+ // battery saver is unsupported on auto
+ assumeFalse(mContext.getPackageManager().hasSystemFeature(FEATURE_AUTOMOTIVE));
+
PowerManager powerManager = Objects.requireNonNull(
mContext.getSystemService(PowerManager.class));
@@ -719,6 +725,9 @@
@Test
public void testRequestLocationUpdates_BatterySaver_AllDisabledScreenOff() throws Exception {
+ // battery saver is unsupported on auto
+ assumeFalse(mContext.getPackageManager().hasSystemFeature(FEATURE_AUTOMOTIVE));
+
PowerManager powerManager = Objects.requireNonNull(
mContext.getSystemService(PowerManager.class));
@@ -757,6 +766,9 @@
@Test
public void testRequestLocationUpdates_BatterySaver_ThrottleScreenOff() throws Exception {
+ // battery saver is unsupported on auto
+ assumeFalse(mContext.getPackageManager().hasSystemFeature(FEATURE_AUTOMOTIVE));
+
PowerManager powerManager = Objects.requireNonNull(
mContext.getSystemService(PowerManager.class));
@@ -796,11 +808,8 @@
@Test
public void testRequestLocationUpdates_LocationSettingsIgnored() throws Exception {
try (LocationListenerCapture capture = new LocationListenerCapture(mContext);
- ScreenResetter ignored1 = new ScreenResetter();
DeviceConfigStateHelper locationDeviceConfigStateHelper =
- new DeviceConfigStateHelper(DeviceConfig.NAMESPACE_LOCATION);
- DeviceConfigStateHelper batterySaverDeviceConfigStateHelper =
- new DeviceConfigStateHelper(DeviceConfig.NAMESPACE_BATTERY_SAVER)) {
+ new DeviceConfigStateHelper(DeviceConfig.NAMESPACE_LOCATION)) {
locationDeviceConfigStateHelper.set(IGNORE_SETTINGS_ALLOWLIST,
mContext.getPackageName());
@@ -822,12 +831,6 @@
// turn off provider
mManager.setTestProviderEnabled(TEST_PROVIDER, false);
- // enable battery saver throttling
- batterySaverDeviceConfigStateHelper.set("location_mode", "4");
- BatteryUtils.runDumpsysBatteryUnplug();
- BatteryUtils.enableBatterySaver(true);
- ScreenUtils.setScreenOn(false);
-
// test that all restrictions are bypassed
Location loc = createLocation(TEST_PROVIDER, mRandom);
mManager.setTestProviderLocation(TEST_PROVIDER, loc);
@@ -835,9 +838,6 @@
loc = createLocation(TEST_PROVIDER, mRandom);
mManager.setTestProviderLocation(TEST_PROVIDER, loc);
assertThat(capture.getNextLocation(FAILURE_TIMEOUT_MS)).isEqualTo(loc);
- } finally {
- BatteryUtils.enableBatterySaver(false);
- BatteryUtils.runDumpsysBatteryReset();
}
}
diff --git a/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/StatusBarManagerApi30Test.java b/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/StatusBarManagerApi30Test.java
index baf9aac..5f275ed 100644
--- a/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/StatusBarManagerApi30Test.java
+++ b/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/StatusBarManagerApi30Test.java
@@ -21,6 +21,7 @@
import android.app.StatusBarManager;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.view.KeyEvent;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -53,4 +54,18 @@
// Nothing thrown, passed
}
+
+ @Test
+ public void testTogglePanel_withoutStatusBarPermission_doesNotThrow() throws Exception {
+ mStatusBarManager.togglePanel();
+
+ // Nothing thrown, passed
+ }
+
+ @Test
+ public void testHandleSystemKey_withoutStatusBarPermission_doesNotThrow() throws Exception {
+ mStatusBarManager.handleSystemKey(KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP);
+
+ // Nothing thrown, passed
+ }
}
diff --git a/tests/tests/os/AutoRevokeSApp/Android.bp b/tests/tests/os/AutoRevokeSApp/Android.bp
index 638b452..77fba78 100644
--- a/tests/tests/os/AutoRevokeSApp/Android.bp
+++ b/tests/tests/os/AutoRevokeSApp/Android.bp
@@ -22,6 +22,8 @@
name: "CtsAutoRevokeSApp",
defaults: ["cts_defaults"],
sdk_version: "test_current",
+ min_sdk_version: "31",
+ target_sdk_version: "31",
// Tag this module as a cts test artifact
test_suites: [
"cts",
diff --git a/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml b/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml
index e541a79..08478e8 100644
--- a/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml
+++ b/tests/tests/os/AutoRevokeSApp/AndroidManifest.xml
@@ -21,8 +21,6 @@
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.BLUETOOTH" />
- <uses-sdk android:minSdkVersion="31" android:targetSdkVersion="31" />
-
<application>
<activity android:name="android.os.cts.autorevokesapp.MainActivity"
android:exported="true"
diff --git a/tests/tests/permission2/src/android/permission2/cts/IntelligenceRolesPolicyTest.java b/tests/tests/permission2/src/android/permission2/cts/IntelligenceRolesPolicyTest.java
index 8a3dd87..bcfd8b6 100644
--- a/tests/tests/permission2/src/android/permission2/cts/IntelligenceRolesPolicyTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/IntelligenceRolesPolicyTest.java
@@ -72,11 +72,19 @@
String packageName = sContext.getResources().getString(mConfigKey);
assumeTrue(!Strings.isNullOrEmpty(packageName));
- List<String> requestedPermissions = getRequestedPermissions(sContext, packageName);
+ List<String> requestedPermissions;
+
+ try {
+ requestedPermissions = getRequestedPermissions(sContext, packageName);
+ } catch (PackageManager.NameNotFoundException e) {
+ // A package is not found, despite overlay config pointing to it. Strictly speaking that
+ // means that the policy for being an intelligence role is fulfilled.
+ return;
+ }
assertWithMessage("Package " + packageName + "MUST NOT request INTERNET permission. "
- + "Instead it’s required to model internet connection through well-defined APIs in "
- + "an open source project.")
+ + "Instead packages MUST access the internet through well-defined APIs in an open "
+ + "source project.")
.that(requestedPermissions)
.doesNotContain(android.Manifest.permission.INTERNET);
}
diff --git a/tests/tests/sensorprivacy/src/android/sensorprivacy/cts/SensorPrivacyBaseTest.kt b/tests/tests/sensorprivacy/src/android/sensorprivacy/cts/SensorPrivacyBaseTest.kt
index 7ed633e..a133e19 100644
--- a/tests/tests/sensorprivacy/src/android/sensorprivacy/cts/SensorPrivacyBaseTest.kt
+++ b/tests/tests/sensorprivacy/src/android/sensorprivacy/cts/SensorPrivacyBaseTest.kt
@@ -26,6 +26,7 @@
import android.platform.test.annotations.AppModeFull
import android.hardware.SensorPrivacyManager.Sensors.CAMERA
import android.hardware.SensorPrivacyManager.Sensors.MICROPHONE
+import android.hardware.SensorPrivacyManager.Sources.OTHER
import android.support.test.uiautomator.By
import android.view.KeyEvent
import androidx.test.platform.app.InstrumentationRegistry
@@ -335,7 +336,7 @@
protected fun setSensor(enable: Boolean) {
runWithShellPermissionIdentity {
- spm.setSensorPrivacy(sensor, enable)
+ spm.setSensorPrivacy(OTHER, sensor, enable)
}
}
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
index e83fa29..83c4a7e 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/TelephonyManagerTest.java
@@ -4601,6 +4601,7 @@
@Test
public void testCheckCarrierPrivilegesForPackageThrowsExceptionWithoutReadPrivilege() {
+ if (!hasCellular()) return;
try {
mTelephonyManager.checkCarrierPrivilegesForPackage(mSelfPackageName);
fail("TelephonyManager#checkCarrierPrivilegesForPackage must be protected "
@@ -4639,6 +4640,7 @@
@Test
public void testGetCarrierPackageNamesForIntentAndPhoneThrowsExceptionWithoutReadPrivilege() {
+ if (!hasCellular()) return;
try {
Intent intent = new Intent();
int phoneId = 1;
@@ -4670,6 +4672,7 @@
@Test
public void testGetPackagesWithCarrierPrivilegesThrowsExceptionWithoutReadPrivilege() {
+ if (!hasCellular()) return;
try {
mTelephonyManager.getPackagesWithCarrierPrivileges();
fail("TelephonyManager#getPackagesWithCarrierPrivileges must be protected "
diff --git a/tests/tests/view/src/android/view/cts/PixelCopyTest.java b/tests/tests/view/src/android/view/cts/PixelCopyTest.java
index e0ddddb..502170d 100644
--- a/tests/tests/view/src/android/view/cts/PixelCopyTest.java
+++ b/tests/tests/view/src/android/view/cts/PixelCopyTest.java
@@ -35,6 +35,7 @@
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
+import android.hardware.HardwareBuffer;
import android.media.Image;
import android.media.ImageReader;
import android.media.ImageWriter;
@@ -817,7 +818,9 @@
@Test
public void testBufferQueueCrop() throws InterruptedException {
- ImageReader reader = ImageReader.newInstance(100, 100, PixelFormat.RGBA_8888, 1);
+ ImageReader reader = ImageReader.newInstance(100, 100, PixelFormat.RGBA_8888, 1,
+ HardwareBuffer.USAGE_CPU_WRITE_OFTEN | HardwareBuffer.USAGE_CPU_READ_OFTEN
+ | HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
ImageWriter writer = ImageWriter.newInstance(reader.getSurface(), 1);
Image image = writer.dequeueInputImage();
Image.Plane plane = image.getPlanes()[0];
diff --git a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/AbstractRecognitionServiceTest.java b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/AbstractRecognitionServiceTest.java
index ee6ec03..6debb44 100644
--- a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/AbstractRecognitionServiceTest.java
+++ b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/AbstractRecognitionServiceTest.java
@@ -44,7 +44,6 @@
import com.android.compatibility.common.util.PollingCheck;
import com.google.common.collect.ImmutableList;
-import com.google.common.truth.TruthJUnit;
import org.junit.Before;
import org.junit.Rule;
@@ -88,12 +87,6 @@
prepareDevice();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mActivity = mActivityTestRule.getActivity();
- if (isOnDeviceTest()) {
- // Has to happen before mActivity#init or createOnDeviceSpeechRecognizer() will fail.
- TruthJUnit.assume()
- .that(SpeechRecognizer.isOnDeviceRecognitionAvailable(mActivity))
- .isTrue();
- }
mActivity.init(isOnDeviceTest(), customRecognizer());
}
diff --git a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
index c0a850d..6a9aecc 100644
--- a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
+++ b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/RecognitionServiceMicIndicatorTest.java
@@ -45,7 +45,6 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -161,7 +160,6 @@
return componentName != null ? componentName.getPackageName() : "";
}
- @Ignore("b/184963112")
@Test
public void testNonTrustedRecognitionServiceCanBlameCallingApp() throws Throwable {
// This is a workaound solution for R QPR. We treat trusted if the current voice recognizer
@@ -172,7 +170,6 @@
testVoiceRecognitionServiceBlameCallingApp(/* trustVoiceService */ true);
}
- @Ignore("b/184963112")
@Test
public void testTrustedRecognitionServiceCanBlameCallingApp() throws Throwable {
// This is a workaround solution for R QPR. We treat trusted if the current voice recognizer
diff --git a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognitionActivity.java b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognitionActivity.java
index 055bf9b..a9d506a 100644
--- a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognitionActivity.java
+++ b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognitionActivity.java
@@ -90,7 +90,7 @@
mHandler = new Handler(getMainLooper());
mHandler.post(() -> {
if (onDevice) {
- mRecognizer = SpeechRecognizer.createOnDeviceSpeechRecognizer(this);
+ mRecognizer = SpeechRecognizer.createOnDeviceTestingSpeechRecognizer(this);
} else if (customRecognizerComponent != null) {
mRecognizer = SpeechRecognizer.createSpeechRecognizer(this,
ComponentName.unflattenFromString(customRecognizerComponent));
diff --git a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognizerAvailabilityTest.java b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognizerAvailabilityTest.java
index 640c6b6..0c23cf2 100644
--- a/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognizerAvailabilityTest.java
+++ b/tests/tests/voiceRecognition/src/android/voicerecognition/cts/SpeechRecognizerAvailabilityTest.java
@@ -19,7 +19,6 @@
import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
import static com.google.common.truth.Truth.assertThat;
-
import static org.junit.Assert.assertThrows;
import android.content.Context;
diff --git a/tests/tests/voiceinteraction/service/src/android/voiceinteraction/service/MainHotwordDetectionService.java b/tests/tests/voiceinteraction/service/src/android/voiceinteraction/service/MainHotwordDetectionService.java
index 493a183..d63dc3d 100644
--- a/tests/tests/voiceinteraction/service/src/android/voiceinteraction/service/MainHotwordDetectionService.java
+++ b/tests/tests/voiceinteraction/service/src/android/voiceinteraction/service/MainHotwordDetectionService.java
@@ -16,7 +16,12 @@
package android.voiceinteraction.service;
+import static android.media.AudioFormat.CHANNEL_IN_FRONT;
+
+import android.media.AudioAttributes;
import android.media.AudioFormat;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
@@ -44,15 +49,25 @@
public class MainHotwordDetectionService extends HotwordDetectionService {
static final String TAG = "MainHotwordDetectionService";
- // TODO: Fill in the remaining fields.
public static final HotwordDetectedResult DETECTED_RESULT =
new HotwordDetectedResult.Builder()
+ .setAudioChannel(CHANNEL_IN_FRONT)
.setConfidenceLevel(HotwordDetectedResult.CONFIDENCE_LEVEL_HIGH)
+ .setHotwordDetectionPersonalized(true)
+ .setHotwordDurationMillis(1000)
+ .setHotwordOffsetMillis(500)
+ .setHotwordPhraseId(5)
+ .setPersonalizedScore(10)
+ .setScore(15)
.build();
public static final HotwordDetectedResult DETECTED_RESULT_AFTER_STOP_DETECTION =
new HotwordDetectedResult.Builder()
.setScore(57)
.build();
+ public static final HotwordDetectedResult DETECTED_RESULT_FOR_MIC_FAILURE =
+ new HotwordDetectedResult.Builder()
+ .setScore(58)
+ .build();
public static final HotwordRejectedResult REJECTED_RESULT =
new HotwordRejectedResult.Builder()
.setConfidenceLevel(HotwordRejectedResult.CONFIDENCE_LEVEL_MEDIUM)
@@ -80,6 +95,11 @@
long timeoutMillis, @NonNull Callback callback) {
Log.d(TAG, "onDetect for DSP source");
+ if (!canReadAudio()) {
+ callback.onDetected(DETECTED_RESULT_FOR_MIC_FAILURE);
+ return;
+ }
+
// TODO: Check the capture session (needs to be reflectively accessed).
byte[] data = eventPayload.getTriggerAudio();
if (data != null && data.length > 0) {
@@ -169,7 +189,12 @@
// also more realistic to schedule it onto another thread.
mDetectionJob = () -> {
Log.d(TAG, "Sending detected result");
- callback.onDetected(DETECTED_RESULT);
+
+ if (canReadAudio()) {
+ callback.onDetected(DETECTED_RESULT);
+ } else {
+ callback.onDetected(DETECTED_RESULT_FOR_MIC_FAILURE);
+ }
};
mHandler.postDelayed(mDetectionJob, 1500);
} else {
@@ -247,4 +272,53 @@
}
return true;
}
+
+ private boolean canReadAudio() {
+ int bytesPerSample = 2; // for ENCODING_PCM_16BIT
+ int sampleRate = 16000;
+ int bytesPerSecond = bytesPerSample * sampleRate; // for single channel
+ AudioRecord record =
+ new AudioRecord.Builder()
+ .setAudioAttributes(
+ new AudioAttributes.Builder()
+ .setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD)
+ .build())
+ .setAudioFormat(
+ new AudioFormat.Builder()
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setSampleRate(sampleRate)
+ .build())
+ .setBufferSizeInBytes(bytesPerSecond)
+ .build();
+ if (record.getState() != AudioRecord.STATE_INITIALIZED) {
+ Log.e(TAG, "Failed to initialize AudioRecord");
+ record.release();
+ return false;
+ }
+
+ record.startRecording();
+ try {
+ byte[] buffer = new byte[bytesPerSecond]; // read 1 second of audio
+ int numBytes = 0;
+ while (numBytes < buffer.length) {
+ int bytesRead =
+ record.read(buffer, numBytes, Math.min(1024, buffer.length - numBytes));
+ if (bytesRead < 0) {
+ Log.e(TAG, "Error reading from mic: " + bytesRead);
+ return false;
+ }
+ numBytes += bytesRead;
+ }
+ for (byte b : buffer) {
+ // TODO: Maybe check that some portion of the bytes are non-zero.
+ if (b != 0) {
+ return true;
+ }
+ }
+ return false;
+ } finally {
+ record.release();
+ }
+ }
}
diff --git a/tests/tests/voiceinteraction/src/android/voiceinteraction/cts/HotwordDetectionServiceBasicTest.java b/tests/tests/voiceinteraction/src/android/voiceinteraction/cts/HotwordDetectionServiceBasicTest.java
index 6121088..2a8309a 100644
--- a/tests/tests/voiceinteraction/src/android/voiceinteraction/cts/HotwordDetectionServiceBasicTest.java
+++ b/tests/tests/voiceinteraction/src/android/voiceinteraction/cts/HotwordDetectionServiceBasicTest.java
@@ -16,6 +16,8 @@
package android.voiceinteraction.cts;
+import static android.content.pm.PackageManager.FEATURE_MICROPHONE;
+
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
@@ -40,13 +42,16 @@
import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.RequiresDevice;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.compatibility.common.util.BlockingBroadcastReceiver;
+import com.android.compatibility.common.util.RequiredFeatureRule;
import com.android.compatibility.common.util.SystemUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +63,10 @@
public final class HotwordDetectionServiceBasicTest
extends AbstractVoiceInteractionBasicTestCase {
static final String TAG = "HotwordDetectionServiceBasicTest";
+
+ @Rule
+ public RequiredFeatureRule REQUIRES_MIC_RULE = new RequiredFeatureRule(FEATURE_MICROPHONE);
+
private static final String INDICATORS_FLAG = "camera_mic_icons_enabled";
private static final String PRIVACY_CHIP_PKG = "com.android.systemui";
private static final String PRIVACY_CHIP_ID = "privacy_chip";
@@ -126,6 +135,7 @@
}
@Test
+ @RequiresDevice
public void testHotwordDetectionService_onDetectFromDsp_success()
throws Throwable {
// Create AlwaysOnHotwordDetector and wait the HotwordDetectionService ready
@@ -139,6 +149,7 @@
}
@Test
+ @RequiresDevice
public void testHotwordDetectionService_onDetectFromDsp_rejection()
throws Throwable {
Thread.sleep(CLEAR_CHIP_MS);
@@ -173,6 +184,7 @@
}
@Test
+ @RequiresDevice
public void testHotwordDetectionService_onDetectFromMic_success()
throws Throwable {
// Create SoftwareHotwordDetector and wait the HotwordDetectionService ready
@@ -186,6 +198,7 @@
}
@Test
+ @RequiresDevice
public void testHotwordDetectionService_onStopDetection()
throws Throwable {
// Create SoftwareHotwordDetector and wait the HotwordDetectionService ready
@@ -260,8 +273,20 @@
((EventPayloadParcelable) result).mHotwordDetectedResult;
ParcelFileDescriptor audioStream = ((EventPayloadParcelable) result).mAudioStream;
assertThat(hotwordDetectedResult).isNotNull();
+ assertThat(hotwordDetectedResult.getAudioChannel()).isEqualTo(
+ expected.getAudioChannel());
assertThat(hotwordDetectedResult.getConfidenceLevel()).isEqualTo(
expected.getConfidenceLevel());
+ assertThat(hotwordDetectedResult.isHotwordDetectionPersonalized()).isEqualTo(
+ expected.isHotwordDetectionPersonalized());
+ assertThat(hotwordDetectedResult.getHotwordDurationMillis()).isEqualTo(
+ expected.getHotwordDurationMillis());
+ assertThat(hotwordDetectedResult.getHotwordOffsetMillis()).isEqualTo(
+ expected.getHotwordOffsetMillis());
+ assertThat(hotwordDetectedResult.getHotwordPhraseId()).isEqualTo(
+ expected.getHotwordPhraseId());
+ assertThat(hotwordDetectedResult.getPersonalizedScore()).isEqualTo(
+ expected.getPersonalizedScore());
assertThat(hotwordDetectedResult.getScore()).isEqualTo(expected.getScore());
assertThat(audioStream).isNull();
}
diff --git a/tests/tests/wifi/src/android/net/wifi/aware/cts/SingleDeviceTest.java b/tests/tests/wifi/src/android/net/wifi/aware/cts/SingleDeviceTest.java
index 67ea6ec..903f3a5 100644
--- a/tests/tests/wifi/src/android/net/wifi/aware/cts/SingleDeviceTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/aware/cts/SingleDeviceTest.java
@@ -54,6 +54,7 @@
import android.platform.test.annotations.AppModeFull;
import com.android.compatibility.common.util.ApiLevelUtil;
+import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.compatibility.common.util.SystemUtil;
import java.util.ArrayDeque;
@@ -87,6 +88,8 @@
private final Object mLock = new Object();
private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest");
private final Handler mHandler;
+ private Boolean mWasVerboseLoggingEnabled;
+
{
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
@@ -391,6 +394,14 @@
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
assertNotNull("Wi-Fi Manager", mWifiManager);
+
+ // turn on verbose logging for tests
+ mWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.isVerboseLoggingEnabled());
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.setVerboseLoggingEnabled(true));
+
+ // Turn on Wi-Fi
mWifiLock = mWifiManager.createWifiLock(TAG);
mWifiLock.acquire();
if (!mWifiManager.isWifiEnabled()) {
@@ -427,6 +438,9 @@
mSessions.clear();
}
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
+
super.tearDown();
Thread.sleep(INTERVAL_BETWEEN_TESTS_SECS * 1000);
}
diff --git a/tests/tests/wifi/src/android/net/wifi/rtt/cts/TestBase.java b/tests/tests/wifi/src/android/net/wifi/rtt/cts/TestBase.java
index 5a3730a..c69fd7c 100644
--- a/tests/tests/wifi/src/android/net/wifi/rtt/cts/TestBase.java
+++ b/tests/tests/wifi/src/android/net/wifi/rtt/cts/TestBase.java
@@ -32,6 +32,7 @@
import android.os.HandlerExecutor;
import android.os.HandlerThread;
+import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.compatibility.common.util.SystemUtil;
import java.util.List;
@@ -68,6 +69,8 @@
private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest");
protected final Executor mExecutor;
+ private Boolean mWasVerboseLoggingEnabled;
+
{
mHandlerThread.start();
mExecutor = new HandlerExecutor(new Handler(mHandlerThread.getLooper()));
@@ -110,6 +113,13 @@
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
assertNotNull("Wi-Fi Manager", mWifiManager);
+
+ // turn on verbose logging for tests
+ mWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.isVerboseLoggingEnabled());
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.setVerboseLoggingEnabled(true));
+
mWifiLock = mWifiManager.createWifiLock(TAG);
mWifiLock.acquire();
if (!mWifiManager.isWifiEnabled()) {
@@ -136,6 +146,9 @@
return;
}
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
+
super.tearDown();
}