summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-12 04:40:01 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-12 04:40:01 +0000
commit966576ce1b136b83dca154a484f9d377cb5cd74b (patch)
treee104567f3d06c3cee16990ac08ef4f5803b811f7
parent5c40ef385ea4997ff875edc59c099a50d9b1e09f (diff)
parent92563fc0333e1d350f2eaa0942ba30382665c938 (diff)
downloadcts-966576ce1b136b83dca154a484f9d377cb5cd74b.tar.gz
Snap for 10481324 from 92563fc0333e1d350f2eaa0942ba30382665c938 to mainline-os-statsd-releaseaml_sta_340912000aml_sta_340911000
Change-Id: I15bf1059ca181c54ea1ce739d4de1005503b2dbd
-rwxr-xr-xapps/CameraITS/tools/run_all_tests.py6
-rw-r--r--apps/CtsVerifier/AndroidManifest.xml6
-rw-r--r--apps/CtsVerifier/res/values/strings.xml3
-rw-r--r--apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java8
-rw-r--r--hostsidetests/appcompat/compatchanges/src/com/android/cts/appcompat/CompatChangesValidConfigTest.java6
-rw-r--r--hostsidetests/appsearch/src/android/appsearch/cts/AppSearchMultiUserTest.java2
-rw-r--r--hostsidetests/appsearch/src/android/appsearch/cts/AppSearchPackageTest.java2
-rw-r--r--hostsidetests/appsearch/src/android/appsearch/cts/ContactsIndexerMultiUserTest.java8
-rw-r--r--hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/LegacyStorageHostTest.java5
-rw-r--r--hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java29
-rw-r--r--tests/PhotoPicker/src/android/photopicker/cts/PickerProviderMediaGenerator.java19
-rw-r--r--tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderPrimary.java2
-rw-r--r--tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderSecondary.java2
-rw-r--r--tests/app/StorageDelegator/Android.bp1
-rw-r--r--tests/app/app/Android.bp1
-rw-r--r--tests/autofillservice/src/android/autofillservice/cts/dialog/LoginActivityTest.java49
-rw-r--r--tests/autofillservice/src/android/autofillservice/cts/dropdown/LoginActivityTest.java43
-rw-r--r--tests/autofillservice/src/android/autofillservice/cts/testcore/UiBot.java4
-rw-r--r--tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java15
-rw-r--r--tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java6
-rw-r--r--tests/devicepolicy/telephony/src/android/devicepolicy/cts/telephony/WorkProfileTelephonyTest.java6
-rw-r--r--tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java8
-rw-r--r--tests/tests/content/src/android/content/pm/cts/PackageManagerShellCommandIncrementalTest.java2
-rw-r--r--tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt30
-rw-r--r--tests/tests/media/decoder/src/android/media/decoder/cts/DecodeOnlyTest.java149
-rw-r--r--tests/tests/os/Android.bp1
-rw-r--r--tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java12
-rw-r--r--tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveConnectionInfoAndReturnStatusService.java5
-rw-r--r--tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveScanResultsAndReturnStatusService.java5
-rw-r--r--tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveTransportInfoAndReturnStatusService.java8
-rw-r--r--tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/TriggerScanAndReturnStatusService.java5
-rw-r--r--tests/tests/wifi/src/android/net/wifi/aware/cts/SingleDeviceTest.java29
-rw-r--r--tests/tests/wifi/src/android/net/wifi/cts/ConnectedNetworkScorerTest.java173
-rw-r--r--tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java7
-rw-r--r--tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoBackgroundTest.java (renamed from tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoTest.java)243
-rw-r--r--tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoForegroundTest.java270
-rw-r--r--tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java2
-rw-r--r--tools/cts-tradefed/Android.bp2
38 files changed, 793 insertions, 381 deletions
diff --git a/apps/CameraITS/tools/run_all_tests.py b/apps/CameraITS/tools/run_all_tests.py
index 1115a9388ba..b55e61d117d 100755
--- a/apps/CameraITS/tools/run_all_tests.py
+++ b/apps/CameraITS/tools/run_all_tests.py
@@ -163,7 +163,11 @@ SUB_CAMERA_TESTS = {
}
_LIGHTING_CONTROL_TESTS = [
- 'test_auto_flash.py'
+ 'test_auto_flash.py',
+ 'test_preview_min_frame_rate.py',
+ 'test_led_snapshot.py',
+ 'test_night_extension.py',
+ 'test_hdr_extension.py',
]
_DST_SCENE_DIR = '/sdcard/Download/'
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 015f9a6122b..5745d794116 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.cts.verifier"
android:versionCode="5"
- android:versionName="14_r1">
+ android:versionName="14_r2">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="34"/>
@@ -4628,10 +4628,6 @@
<meta-data android:name="test_excluded_features"
android:value="android.hardware.type.television:android.software.leanback:android.hardware.type.automotive" />
<meta-data android:name="display_mode" android:value="single_display_mode" />
- <meta-data
- android:name="test_required_configs"
- android:value="config_battery_supported" />
- <meta-data android:name="CddTest" android:value="7.3/C-1-5" />
</activity>
<service
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index aabf40992f9..6731a7d298f 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -4219,7 +4219,8 @@ You should be prompted to select credentials; choose the ones you just installed
- You cannot share an admin configured WiFi config.\n
- Sharing option is disabled in Settings.\n
\n
- Use the Back button to return to this page.
+ Use the Back button to return to this page.\n
+ NOTE: If the device does not support Wi-Fi sharing please skip this test and mark it as passing.
</string>
<string name="device_owner_wifi_security_level_restriction">Set WiFi security level restriction</string>
<string name="device_owner_wifi_security_level_restriction_info">
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
index e44903d4a14..f285f0fec3f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
@@ -33,7 +33,6 @@ import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.ListView;
-import com.android.compatibility.common.util.BatteryUtils;
import com.android.cts.verifier.TestListActivity.DisplayMode;
import com.android.modules.utils.build.SdkLevel;
@@ -149,8 +148,6 @@ public class ManifestTestListAdapter extends TestListAdapter {
private static final String TEST_PASS_MODE = "test_pass_mode";
- private static final String CONFIG_BATTERY_SUPPORTED = "config_battery_supported";
-
private static final String CONFIG_NO_EMULATOR = "config_no_emulator";
private static final String CONFIG_VOICE_CAPABLE = "config_voice_capable";
@@ -506,11 +503,6 @@ public class ManifestTestListAdapter extends TestListAdapter {
exception);
}
break;
- case CONFIG_BATTERY_SUPPORTED:
- if (!BatteryUtils.hasBattery()) {
- return false;
- }
- break;
case CONFIG_QUICK_SETTINGS_SUPPORTED:
if (!getSystemResourceFlag(context, "config_quickSettingsSupported")) {
return false;
diff --git a/hostsidetests/appcompat/compatchanges/src/com/android/cts/appcompat/CompatChangesValidConfigTest.java b/hostsidetests/appcompat/compatchanges/src/com/android/cts/appcompat/CompatChangesValidConfigTest.java
index e475a41ac2e..51daffd70a3 100644
--- a/hostsidetests/appcompat/compatchanges/src/com/android/cts/appcompat/CompatChangesValidConfigTest.java
+++ b/hostsidetests/appcompat/compatchanges/src/com/android/cts/appcompat/CompatChangesValidConfigTest.java
@@ -39,6 +39,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
public final class CompatChangesValidConfigTest extends CompatChangeGatingTestCase {
private static final long RESTRICT_STORAGE_ACCESS_FRAMEWORK = 141600225L;
+ private static final long SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING = 288845345L;
private static final String FEATURE_WATCH = "android.hardware.type.watch";
private static final Set<String> OVERRIDES_ALLOWLIST = ImmutableSet.of(
@@ -168,6 +169,11 @@ public final class CompatChangesValidConfigTest extends CompatChangeGatingTestCa
}
}
}
+
+ // Exclude SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING
+ // This feature is enabled only from U for apps targeting SDK 34+, see b/288845345
+ changes.removeIf(c -> c.changeId == SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING);
+
return changes;
}
diff --git a/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchMultiUserTest.java b/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchMultiUserTest.java
index b318d55480e..e1223580811 100644
--- a/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchMultiUserTest.java
+++ b/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchMultiUserTest.java
@@ -26,6 +26,7 @@ import com.android.tradefed.testtype.junit4.AfterClassWithInfo;
import com.android.tradefed.testtype.junit4.BeforeClassWithInfo;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -45,6 +46,7 @@ import java.util.Map;
* <p>Unlock your device when test locally.
*/
@RunWith(DeviceJUnit4ClassRunner.class)
+@Ignore("b/290690596 Re-enable tests after fixing flaky behavior.")
public class AppSearchMultiUserTest extends AppSearchHostTestBase {
private static int sInitialUserId;
diff --git a/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchPackageTest.java b/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchPackageTest.java
index e9b29936f82..ecf488a0982 100644
--- a/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchPackageTest.java
+++ b/hostsidetests/appsearch/src/android/appsearch/cts/AppSearchPackageTest.java
@@ -23,6 +23,7 @@ import com.android.tradefed.util.RunUtil;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +40,7 @@ import org.junit.runner.RunWith;
* <p>Unlock your device when test locally.
*/
@RunWith(DeviceJUnit4ClassRunner.class)
+@Ignore("b/290690596 Re-enable tests after fixing flaky behavior.")
public class AppSearchPackageTest extends AppSearchHostTestBase {
private int mPrimaryUserId;
diff --git a/hostsidetests/appsearch/src/android/appsearch/cts/ContactsIndexerMultiUserTest.java b/hostsidetests/appsearch/src/android/appsearch/cts/ContactsIndexerMultiUserTest.java
index 245f0c0ac4a..1e667679a4f 100644
--- a/hostsidetests/appsearch/src/android/appsearch/cts/ContactsIndexerMultiUserTest.java
+++ b/hostsidetests/appsearch/src/android/appsearch/cts/ContactsIndexerMultiUserTest.java
@@ -39,6 +39,8 @@ import java.util.Collections;
* <p>Unlock your device when testing locally.
*/
@RunWith(DeviceJUnit4ClassRunner.class)
+@Ignore("b/285969557 Re-enable tests after figuring out a better way to wait for lifecycle "
+ + "events to complete")
public class ContactsIndexerMultiUserTest extends AppSearchHostTestBase {
private static int sSecondaryUserId;
@@ -90,9 +92,6 @@ public class ContactsIndexerMultiUserTest extends AppSearchHostTestBase {
}
@Test
- @Ignore
- // TODO(b/285969557) Re-enable test after figuring out a better way to wait for lifecycle events
- // to complete
public void testMultiUser_CiDisabled_cancelsFullUpdateJobs() throws Exception {
setCiEnabled(getDevice(), false);
startUserAndInstallPackage();
@@ -102,9 +101,6 @@ public class ContactsIndexerMultiUserTest extends AppSearchHostTestBase {
}
@Test
- @Ignore
- // TODO(b/285969557) Re-enable test after figuring out a better way to wait for lifecycle events
- // to complete
public void testMultiUser_CiDisabledAndThenEnabled_schedulesFullUpdateJobs() throws Exception {
setCiEnabled(getDevice(), false);
setCiEnabled(getDevice(), true);
diff --git a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/LegacyStorageHostTest.java b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/LegacyStorageHostTest.java
index 5638e41c0de..e0dc9463ee1 100644
--- a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/LegacyStorageHostTest.java
+++ b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/LegacyStorageHostTest.java
@@ -304,6 +304,11 @@ public class LegacyStorageHostTest extends BaseHostTestCase {
runDeviceTest("testUpdateToExternalDirsViaRelativePath");
}
+ @Test
+ public void testInsertToOtherAppPrivateDirFails() throws Exception {
+ runDeviceTest("testInsertToOtherAppPrivateDirFails");
+ }
+
private void allowAppOps(String... ops) throws Exception {
for (String op : ops) {
executeShellCommand("cmd appops set --uid android.scopedstorage.cts.legacy "
diff --git a/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java b/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
index 40c9063f0a6..33a838ed42d 100644
--- a/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
+++ b/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
@@ -1139,6 +1139,35 @@ public class LegacyStorageTest {
verifyUpdateToExternalPrivateDirsViaRelativePath_denied();
}
+ @Test
+ public void testInsertToOtherAppPrivateDirFails() throws Exception {
+ try {
+ ContentValues values = new ContentValues();
+ values.put(MediaStore.Files.FileColumns.DATA,
+ "/storage/emulated/0/Android/media/com.example.aospoc/../../../../../../../."
+ + "./../../storage/emulated/0/Android/data/com.android"
+ + ".gallery3d/secret.txt/../../../../../../../../../../../../."
+ + "./storage/emulated/0/Android/data/com.android.gallery3d/text.txt");
+
+ getContentResolver().insert(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL),
+ values);
+ fail("Insertion expected to fail for private path");
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ ContentValues values = new ContentValues();
+ values.put(MediaStore.Files.FileColumns.RELATIVE_PATH,
+ "Android/data/com.example.aospoc/");
+ values.put(MediaStore.Files.FileColumns.DISPLAY_NAME, "text.txt");
+
+ getContentResolver().insert(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL),
+ values);
+ fail("Insertion expected to fail for private path");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
private static void assertCanCreateFile(File file) throws IOException {
if (file.exists()) {
file.delete();
diff --git a/tests/PhotoPicker/src/android/photopicker/cts/PickerProviderMediaGenerator.java b/tests/PhotoPicker/src/android/photopicker/cts/PickerProviderMediaGenerator.java
index 216b5de1d1f..32a874a9974 100644
--- a/tests/PhotoPicker/src/android/photopicker/cts/PickerProviderMediaGenerator.java
+++ b/tests/PhotoPicker/src/android/photopicker/cts/PickerProviderMediaGenerator.java
@@ -19,6 +19,7 @@ package android.photopicker.cts;
import static android.provider.CloudMediaProviderContract.AlbumColumns;
import static android.provider.CloudMediaProviderContract.EXTRA_ALBUM_ID;
import static android.provider.CloudMediaProviderContract.EXTRA_MEDIA_COLLECTION_ID;
+import static android.provider.CloudMediaProviderContract.EXTRA_PAGE_SIZE;
import static android.provider.CloudMediaProviderContract.EXTRA_SYNC_GENERATION;
import static android.provider.CloudMediaProviderContract.MediaCollectionInfo;
import static android.provider.CloudMediaProviderContract.MediaColumns;
@@ -91,23 +92,25 @@ public class PickerProviderMediaGenerator {
mPrivateDir = context.getFilesDir();
}
- public Cursor getMedia(long generation, String albumId, String mimeType, long sizeBytes) {
+ public Cursor getMedia(long generation, String albumId, String mimeType, long sizeBytes,
+ int pageSize) {
final Cursor cursor = getCursor(mMedia, generation, albumId, mimeType, sizeBytes,
/* isDeleted */ false);
- cursor.setExtras(buildCursorExtras(mCollectionId, generation > 0, albumId != null));
+ cursor.setExtras(buildCursorExtras(mCollectionId, generation > 0, albumId != null,
+ pageSize > -1));
return cursor;
}
public Cursor getAlbums(String mimeType, long sizeBytes) {
final Cursor cursor = getCursor(mAlbums, mimeType, sizeBytes);
- cursor.setExtras(buildCursorExtras(mCollectionId, false, false));
+ cursor.setExtras(buildCursorExtras(mCollectionId, false, false, false));
return cursor;
}
public Cursor getDeletedMedia(long generation) {
final Cursor cursor = getCursor(mDeletedMedia, generation, /* albumId */ null,
/* mimeType */ null, /* sizeBytes */ 0, /* isDeleted */ true);
- cursor.setExtras(buildCursorExtras(mCollectionId, generation > 0, false));
+ cursor.setExtras(buildCursorExtras(mCollectionId, generation > 0, false, false));
return cursor;
}
@@ -128,7 +131,7 @@ public class PickerProviderMediaGenerator {
}
public Bundle buildCursorExtras(String mediaCollectionId, boolean honoredSyncGeneration,
- boolean honoredAlbumdId) {
+ boolean honoredAlbumdId, boolean honoredPageSize) {
final ArrayList<String> honoredArgs = new ArrayList<>();
if (honoredSyncGeneration) {
honoredArgs.add(EXTRA_SYNC_GENERATION);
@@ -137,6 +140,10 @@ public class PickerProviderMediaGenerator {
honoredArgs.add(EXTRA_ALBUM_ID);
}
+ if (honoredPageSize) {
+ honoredArgs.add(EXTRA_PAGE_SIZE);
+ }
+
final Bundle bundle = new Bundle();
bundle.putString(EXTRA_MEDIA_COLLECTION_ID, mediaCollectionId);
bundle.putStringArrayList(ContentResolver.EXTRA_HONORED_ARGS, honoredArgs);
@@ -425,6 +432,7 @@ public class PickerProviderMediaGenerator {
public final String mimeType;
public final long sizeBytes;
public final long generation;
+ public final int pageSize;
public QueryExtras(Bundle bundle) {
if (bundle == null) {
@@ -435,6 +443,7 @@ public class PickerProviderMediaGenerator {
mimeType = bundle.getString(Intent.EXTRA_MIME_TYPES, null);
sizeBytes = bundle.getLong(CloudMediaProviderContract.EXTRA_SIZE_LIMIT_BYTES, 0);
generation = bundle.getLong(CloudMediaProviderContract.EXTRA_SYNC_GENERATION, 0);
+ pageSize = bundle.getInt(CloudMediaProviderContract.EXTRA_PAGE_SIZE, -1);
}
}
}
diff --git a/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderPrimary.java b/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderPrimary.java
index 3f801950dcf..1b90695098e 100644
--- a/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderPrimary.java
+++ b/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderPrimary.java
@@ -65,7 +65,7 @@ public class CloudProviderPrimary extends CloudMediaProvider {
final QueryExtras queryExtras = new QueryExtras(extras);
return mMediaGenerator.getMedia(queryExtras.generation, queryExtras.albumId,
- queryExtras.mimeType, queryExtras.sizeBytes);
+ queryExtras.mimeType, queryExtras.sizeBytes, queryExtras.pageSize);
}
@Override
diff --git a/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderSecondary.java b/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderSecondary.java
index f5bde67be1b..a951e7cc2c4 100644
--- a/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderSecondary.java
+++ b/tests/PhotoPicker/src/android/photopicker/cts/cloudproviders/CloudProviderSecondary.java
@@ -50,7 +50,7 @@ public class CloudProviderSecondary extends CloudMediaProvider {
final QueryExtras queryExtras = new QueryExtras(extras);
return mMediaGenerator.getMedia(queryExtras.generation, queryExtras.albumId,
- queryExtras.mimeType, queryExtras.sizeBytes);
+ queryExtras.mimeType, queryExtras.sizeBytes, queryExtras.pageSize);
}
@Override
diff --git a/tests/app/StorageDelegator/Android.bp b/tests/app/StorageDelegator/Android.bp
index 9e1b7468c04..bd389584d91 100644
--- a/tests/app/StorageDelegator/Android.bp
+++ b/tests/app/StorageDelegator/Android.bp
@@ -28,6 +28,7 @@ android_test {
// Tag this module as a cts test artifact
test_suites: [
+ "cts",
"general-tests",
"sts",
],
diff --git a/tests/app/app/Android.bp b/tests/app/app/Android.bp
index 4044073d3b8..098f2b5571d 100644
--- a/tests/app/app/Android.bp
+++ b/tests/app/app/Android.bp
@@ -124,6 +124,7 @@ android_test {
],
// Tag this module as a cts test artifact
test_suites: [
+ "cts",
"general-tests",
"sts",
],
diff --git a/tests/autofillservice/src/android/autofillservice/cts/dialog/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/dialog/LoginActivityTest.java
index bab038cc97a..0e43f33592d 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/dialog/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/dialog/LoginActivityTest.java
@@ -36,6 +36,7 @@ import static android.view.View.AUTOFILL_HINT_USERNAME;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assume.assumeTrue;
import android.autofillservice.cts.R;
@@ -50,13 +51,16 @@ import android.autofillservice.cts.testcore.Helper;
import android.autofillservice.cts.testcore.IdMode;
import android.autofillservice.cts.testcore.InstrumentedAutoFillService.FillRequest;
import android.content.Intent;
+import android.graphics.drawable.Icon;
import android.platform.test.annotations.FlakyTest;
import android.util.Log;
import android.view.View;
+import android.widget.RemoteViews;
import androidx.test.uiautomator.UiObject2;
import com.android.compatibility.common.util.CddTest;
+import com.android.compatibility.common.util.RetryableException;
import org.junit.After;
import org.junit.Test;
@@ -977,6 +981,51 @@ public class LoginActivityTest extends AutoFillServiceTestCase.ManualActivityLau
assertThat(v.isCredential()).isFalse();
}
+ @Test
+ public void remoteViews_doesNotSpillAcrossUsers() throws Exception {
+ enableFillDialogFeature(sContext);
+ enableService();
+
+ RemoteViews header = createPresentation("Dialog Header");
+ RemoteViews dialogRv = createPresentation("Dialog Presentation");
+ // bad url, should not be displayed
+ header.setImageViewIcon(R.id.icon, Icon.createWithContentUri(
+ "content://1000@com.android.contacts/display_photo/1"));
+ dialogRv.setImageViewIcon(R.id.icon, Icon.createWithContentUri(
+ "content://1000@com.android.contacts/display_photo/1"));
+
+ // Set response with a dataset
+ final CannedFillResponse.Builder builder = new CannedFillResponse.Builder()
+ .addDataset(new CannedDataset.Builder()
+ .setField(ID_USERNAME, "dude")
+ .setField(ID_PASSWORD, "sweet")
+ .setPresentation(createPresentation("Dropdown Presentation"))
+ .setDialogPresentation(dialogRv)
+ .build())
+ .setDialogHeader(header)
+ .setDialogTriggerIds(ID_PASSWORD);
+ sReplier.addResponse(builder.build());
+
+ // Start activity and autofill
+ LoginActivity activity = startLoginActivity();
+ mUiBot.waitForIdleSync();
+
+ sReplier.getNextFillRequest();
+ mUiBot.waitForIdleSync();
+
+ // Click on password field to trigger fill dialog
+ mUiBot.selectByRelativeId(ID_PASSWORD);
+ mUiBot.waitForIdleSync();
+
+ // Asserts that the header is not shown
+ assertThrows(RetryableException.class,
+ () -> mUiBot.findFillDialogHeaderPicker());
+
+ // Asserts that the
+ assertThrows(RetryableException.class,
+ () -> mUiBot.findFillDialogDatasetPicker());
+ }
+
private FieldsNoPasswordActivity startNoPasswordActivity() throws Exception {
final Intent intent = new Intent(mContext, FieldsNoPasswordActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
diff --git a/tests/autofillservice/src/android/autofillservice/cts/dropdown/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/dropdown/LoginActivityTest.java
index 6e324034603..5d71d8c7fb1 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/dropdown/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/dropdown/LoginActivityTest.java
@@ -75,6 +75,8 @@ import static com.android.compatibility.common.util.ShellUtils.tap;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
+import static org.junit.Assert.assertThrows;
+
import android.app.PendingIntent;
import android.app.assist.AssistStructure.ViewNode;
import android.autofillservice.cts.R;
@@ -104,6 +106,7 @@ import android.content.IntentFilter;
import android.content.IntentSender;
import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.SystemClock;
import android.platform.test.annotations.AppModeFull;
@@ -1468,6 +1471,46 @@ public class LoginActivityTest extends LoginActivityCommonTestCase {
mActivity.assertAutoFilled();
}
+ @Test
+ public void remoteViews_doesNotSpillAcrossUsers() throws Exception {
+ // Set service.
+ enableService();
+
+
+ RemoteViews firstRv = createPresentation("hello");
+ RemoteViews secondRv = createPresentation("world");
+
+ // bad url, should not be displayed
+ firstRv.setImageViewIcon(R.id.icon,
+ Icon.createWithContentUri("content://1000@com.android.contacts/display_photo/1"));
+ secondRv.setImageViewIcon(R.id.icon,
+ Icon.createWithContentUri("content://1000@com.android.contacts/display_photo/1"));
+
+ // Set expectations.
+ sReplier.addResponse(new CannedFillResponse.Builder()
+ .addDataset(new CannedDataset.Builder()
+ .setField(ID_USERNAME, "dude", firstRv)
+ .setField(ID_PASSWORD, "sweet", secondRv)
+ .build())
+ .setHeader(firstRv)
+ .setFooter(secondRv)
+ .build());
+
+ mActivity.expectAutoFill("dude", "sweet");
+
+ // Trigger auto-fill.
+ requestFocusOnUsername();
+ sReplier.getNextFillRequest();
+
+ // Asser that the dataset is not shown
+ assertThrows(RetryableException.class,
+ () -> mUiBot.assertDatasets("The Dude"));
+
+ // Assert that header/footer is not shown
+ assertThrows(RetryableException.class,
+ () -> mUiBot.assertDatasetsWithBorders("hello", "world", "The Dude"));
+ }
+
/**
* Tests the scenario where the service uses custom remote views for different fields (username
* and password), but each dataset has a different number of fields.
diff --git a/tests/autofillservice/src/android/autofillservice/cts/testcore/UiBot.java b/tests/autofillservice/src/android/autofillservice/cts/testcore/UiBot.java
index ec19cf46b44..95a232a0717 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/testcore/UiBot.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/testcore/UiBot.java
@@ -1477,11 +1477,11 @@ public class UiBot {
return waitForObject(FILL_DIALOG_SELECTOR, UI_DATASET_PICKER_TIMEOUT);
}
- private UiObject2 findFillDialogDatasetPicker() throws Exception {
+ public UiObject2 findFillDialogDatasetPicker() throws Exception {
return waitForObject(FILL_DIALOG_DATASET_SELECTOR, UI_DATASET_PICKER_TIMEOUT);
}
- private UiObject2 findFillDialogHeaderPicker() throws Exception {
+ public UiObject2 findFillDialogHeaderPicker() throws Exception {
return waitForObject(FILL_DIALOG_HEADER_SELECTOR, UI_DATASET_PICKER_TIMEOUT);
}
diff --git a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
index 7bdd2a3560b..5347ff95bae 100644
--- a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
@@ -3124,8 +3124,8 @@ public class RobustnessTest extends Camera2AndroidTestCase {
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP_MAXIMUM_RESOLUTION);
mMaxRawSize = (rawSizes.length != 0) ? CameraTestUtils.getMaxSize(rawSizes) : null;
- mMaxResolutionRawSize = (maxResConfigs != null)
- ? CameraTestUtils.getMaxSize(
+ mMaxResolutionRawSize = sm.isUltraHighResolutionSensor() ?
+ CameraTestUtils.getMaxSize(
maxResConfigs.getOutputSizes(ImageFormat.RAW_SENSOR))
: null;
@@ -3144,7 +3144,7 @@ public class RobustnessTest extends Camera2AndroidTestCase {
mMaxJpegSizes[RECORD] = getMaxRecordingSize(cameraId);
}
- if (maxResConfigs != null) {
+ if (sm.isUltraHighResolutionSensor()) {
mMaxYuvSizes[MAX_RES] = CameraTestUtils.getMaxSize(
maxResConfigs.getOutputSizes(ImageFormat.YUV_420_888));
mMaxJpegSizes[MAX_RES] = CameraTestUtils.getMaxSize(
@@ -3302,8 +3302,9 @@ public class RobustnessTest extends Camera2AndroidTestCase {
mMaxPrivInputSizes[INPUT_MAXIMUM] = privInputSizes != null
? CameraTestUtils.getMaxSize(privInputSizes)
: null;
- Size[] maxResPrivInputSizes = maxResConfigs != null
- ? maxResConfigs.getInputSizes(ImageFormat.PRIVATE)
+ Size[] maxResPrivInputSizes =
+ sm.isUltraHighResolutionSensor() ?
+ maxResConfigs.getInputSizes(ImageFormat.PRIVATE)
: null;
mMaxPrivInputSizes[INPUT_MAX_RES] = maxResPrivInputSizes != null
? CameraTestUtils.getMaxSize(maxResPrivInputSizes)
@@ -3313,8 +3314,8 @@ public class RobustnessTest extends Camera2AndroidTestCase {
mMaxYuvInputSizes[INPUT_MAXIMUM] = yuvInputSizes != null
? CameraTestUtils.getMaxSize(yuvInputSizes)
: null;
- Size[] maxResYuvInputSizes = maxResConfigs != null
- ? maxResConfigs.getInputSizes(ImageFormat.YUV_420_888)
+ Size[] maxResYuvInputSizes = sm.isUltraHighResolutionSensor() ?
+ maxResConfigs.getInputSizes(ImageFormat.YUV_420_888)
: null;
mMaxYuvInputSizes[INPUT_MAX_RES] = maxResYuvInputSizes != null
? CameraTestUtils.getMaxSize(maxResYuvInputSizes)
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
index ebcfbb9fc21..24e7ba61a90 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
@@ -510,6 +510,12 @@ public final class ScreenCaptureDisabledTest {
sLocalDevicePolicyManager.getScreenCaptureDisabled(/* admin= */ null)).isTrue();
} finally {
+ TestApis.flags().set(
+ NAMESPACE_DEVICE_POLICY_MANAGER, ENABLE_DEVICE_POLICY_ENGINE_FLAG, "false");
+ sDeviceState.dpc().devicePolicyManager().setScreenCaptureDisabled(
+ sDeviceState.dpc().componentName(), /* disabled= */ false);
+ TestApis.flags().set(
+ NAMESPACE_DEVICE_POLICY_MANAGER, ENABLE_DEVICE_POLICY_ENGINE_FLAG, "true");
sDeviceState.dpc().devicePolicyManager().setScreenCaptureDisabled(
sDeviceState.dpc().componentName(), /* disabled= */ false);
TestApis.flags().set(
diff --git a/tests/devicepolicy/telephony/src/android/devicepolicy/cts/telephony/WorkProfileTelephonyTest.java b/tests/devicepolicy/telephony/src/android/devicepolicy/cts/telephony/WorkProfileTelephonyTest.java
index 5782d74fefa..35a371c073d 100644
--- a/tests/devicepolicy/telephony/src/android/devicepolicy/cts/telephony/WorkProfileTelephonyTest.java
+++ b/tests/devicepolicy/telephony/src/android/devicepolicy/cts/telephony/WorkProfileTelephonyTest.java
@@ -62,7 +62,6 @@ import android.telecom.Call;
import android.telecom.InCallService;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
-import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -140,9 +139,8 @@ public final class WorkProfileTelephonyTest {
try (PermissionContext p = TestApis.permissions().withPermission(READ_PHONE_NUMBERS)) {
SubscriptionManager subscriptionManager = sContext.getSystemService(
SubscriptionManager.class);
- mDestinationNumber = PhoneNumberUtils.formatNumberToE164(
- subscriptionManager.getPhoneNumber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID),
- mTelephonyManager.getSimCountryIso());
+ mDestinationNumber =
+ subscriptionManager.getPhoneNumber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
}
}
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
index 4c3521ebc22..c9f5566fee4 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
@@ -856,7 +856,7 @@ public class PinnedStackTests extends ActivityManagerTestBase {
launchActivity(PIP_ACTIVITY);
mBroadcastActionTrigger.doAction(ACTION_ENTER_PIP);
waitForEnterPipAnimationComplete(PIP_ACTIVITY);
- int defaultDisplayWindowingMode = getDefaultDisplayWindowingMode(PIP_ACTIVITY);
+ int defaultDisplayWindowingMode = getDisplayAreaWindowingMode(PIP_ACTIVITY);
// Launch second PIP activity
launchActivity(PIP_ACTIVITY2, extraString(EXTRA_ENTER_PIP, "true"));
@@ -1840,10 +1840,8 @@ public class PinnedStackTests extends ActivityManagerTestBase {
assertTrue(displayRect.contains(pinnedStackBounds));
}
- private int getDefaultDisplayWindowingMode(ComponentName activityName) {
- Task task = mWmState.getTaskByActivity(activityName);
- return mWmState.getDisplay(task.mDisplayId)
- .getWindowingMode();
+ private int getDisplayAreaWindowingMode(ComponentName activityName) {
+ return mWmState.getTaskDisplayArea(activityName).getWindowingMode();
}
/**
diff --git a/tests/tests/content/src/android/content/pm/cts/PackageManagerShellCommandIncrementalTest.java b/tests/tests/content/src/android/content/pm/cts/PackageManagerShellCommandIncrementalTest.java
index 581f838c7e5..58d84368385 100644
--- a/tests/tests/content/src/android/content/pm/cts/PackageManagerShellCommandIncrementalTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/PackageManagerShellCommandIncrementalTest.java
@@ -403,7 +403,7 @@ public class PackageManagerShellCommandIncrementalTest {
try {
mSession.start(Executors.newSingleThreadExecutor(),
IncrementalDeviceConnection.Factory.reliableExpectInstallationFailure());
- mSession.waitForAnyCompletion(3, TimeUnit.SECONDS);
+ mSession.waitForAnyCompletion(30, TimeUnit.SECONDS);
} finally {
getUiAutomation().dropShellPermissionIdentity();
}
diff --git a/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt
index fc9b77a5e43..88a8a325bef 100644
--- a/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt
+++ b/tests/tests/hibernation/src/android/hibernation/cts/AppHibernationUtils.kt
@@ -126,23 +126,19 @@ fun runBootCompleteReceiver(context: Context, testTag: String) {
}
fun runAppHibernationJob(context: Context, tag: String) {
- // Sometimes first run observes stale package data
- // so run twice to prevent that
- repeat(2) {
- val userId = Process.myUserHandle().identifier
- val permissionControllerPackageName =
- context.packageManager.permissionControllerPackageName
- runShellCommandOrThrow("cmd jobscheduler run -u " +
- "$userId -f " +
- "$permissionControllerPackageName 2")
- eventually({
- Thread.sleep(JOB_RUN_WAIT_TIME)
- val jobState = runShellCommandOrThrow("cmd jobscheduler get-job-state -u " +
- "$userId " +
- "$permissionControllerPackageName 2")
- assertTrue("Job expected waiting but is $jobState", jobState.contains("waiting"))
- }, JOB_RUN_TIMEOUT)
- }
+ val userId = Process.myUserHandle().identifier
+ val permissionControllerPackageName =
+ context.packageManager.permissionControllerPackageName
+ runShellCommandOrThrow("cmd jobscheduler run -u " +
+ "$userId -f " +
+ "$permissionControllerPackageName 2")
+ eventually({
+ Thread.sleep(JOB_RUN_WAIT_TIME)
+ val jobState = runShellCommandOrThrow("cmd jobscheduler get-job-state -u " +
+ "$userId " +
+ "$permissionControllerPackageName 2")
+ assertTrue("Job expected waiting but is $jobState", jobState.contains("waiting"))
+ }, JOB_RUN_TIMEOUT)
}
fun runPermissionEventCleanupJob(context: Context) {
diff --git a/tests/tests/media/decoder/src/android/media/decoder/cts/DecodeOnlyTest.java b/tests/tests/media/decoder/src/android/media/decoder/cts/DecodeOnlyTest.java
index 34387673dc3..018b284d9f7 100644
--- a/tests/tests/media/decoder/src/android/media/decoder/cts/DecodeOnlyTest.java
+++ b/tests/tests/media/decoder/src/android/media/decoder/cts/DecodeOnlyTest.java
@@ -35,6 +35,7 @@ import android.media.cts.MediaTestBase;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.Looper;
import android.platform.test.annotations.AppModeFull;
@@ -54,16 +55,19 @@ import org.junit.runner.RunWith;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.time.Duration;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Queue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
@MediaHeavyPresubmitTest
@AppModeFull(reason = "There should be no instant apps specific behavior related to decoders")
-// BUFFER_FLAG_DECODE_ONLY was added in Android U.
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE, codeName = "UpsideDownCake")
@RunWith(AndroidJUnit4.class)
@ApiTest(apis = {"android.media.MediaCodec#BUFFER_FLAG_DECODE_ONLY"})
@@ -170,7 +174,6 @@ public class DecodeOnlyTest extends MediaTestBase {
testNonTunneledTrickPlay(VP9_VIDEO);
}
-
private void testNonTunneledTrickPlay(String fileName) throws Exception {
Preconditions.assertTestFileExists(MEDIA_DIR_STRING + fileName);
// create the video extractor
@@ -184,7 +187,6 @@ public class DecodeOnlyTest extends MediaTestBase {
MediaFormat videoFormat = videoExtractor.getTrackFormat(videoTrackIndex);
String mime = videoFormat.getString(MediaFormat.KEY_MIME);
MediaCodec videoCodec = MediaCodec.createDecoderByType(mime);
- videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
AtomicBoolean done = new AtomicBoolean(false);
List<Long> expectedPresentationTimes = new ArrayList<>();
@@ -250,6 +252,7 @@ public class DecodeOnlyTest extends MediaTestBase {
}
});
+ videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
// start the video the codec with track selected
videoCodec.start();
@@ -289,7 +292,6 @@ public class DecodeOnlyTest extends MediaTestBase {
codecName != null);
videoFormat.setInteger(MediaFormat.KEY_AUDIO_SESSION_ID, audioSessionId);
MediaCodec videoCodec = MediaCodec.createByCodecName(codecName);
- videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
// create the audio extractor
MediaExtractor audioExtractor = createMediaExtractor(fileName);
@@ -302,7 +304,6 @@ public class DecodeOnlyTest extends MediaTestBase {
MediaFormat audioFormat = audioExtractor.getTrackFormat(audioTrackIndex);
String mime = audioFormat.getString(MediaFormat.KEY_MIME);
MediaCodec audioCodec = MediaCodec.createDecoderByType(mime);
- audioCodec.configure(audioFormat, null, null, 0);
// audio track used by audio codec
AudioTrack audioTrack = createAudioTrack(audioFormat, audioSessionId);
@@ -354,9 +355,15 @@ public class DecodeOnlyTest extends MediaTestBase {
}
});
-
+ videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
AtomicBoolean done = new AtomicBoolean(false);
- audioCodec.setCallback(new AudioCallback(audioCodec, audioExtractor, audioTrack, done));
+ // Since data is written to AudioTrack in a blocking manner, run it in a separate thread to
+ // not block other operations.
+ HandlerThread audioThread = new HandlerThread("audioThread");
+ audioThread.start();
+ audioCodec.setCallback(new AudioCallback(audioCodec, audioExtractor, audioTrack, done),
+ new Handler(audioThread.getLooper()));
+ audioCodec.configure(audioFormat, null, null, 0);
List<Long> renderedPresentationTimes = new ArrayList<>();
@@ -424,7 +431,6 @@ public class DecodeOnlyTest extends MediaTestBase {
codecName != null);
videoFormat.setInteger(MediaFormat.KEY_AUDIO_SESSION_ID, audioSessionId);
MediaCodec videoCodec = MediaCodec.createByCodecName(codecName);
- videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
// create the audio extractor
MediaExtractor audioExtractor = createMediaExtractor(fileName);
@@ -437,50 +443,77 @@ public class DecodeOnlyTest extends MediaTestBase {
MediaFormat audioFormat = audioExtractor.getTrackFormat(audioTrackIndex);
String mime = audioFormat.getString(MediaFormat.KEY_MIME);
MediaCodec audioCodec = MediaCodec.createDecoderByType(mime);
- audioCodec.configure(audioFormat, null, null, 0);
// audio track used by audio codec
AudioTrack audioTrack = createAudioTrack(audioFormat, audioSessionId);
// Frames at 2s of each file are not key frame
AtomicLong seekTime = new AtomicLong(2000 * 1000);
- boolean isPeeking = setKeyTunnelPeek(videoCodec, initialPeek ? 1 : 0);
videoExtractor.seekTo(seekTime.get(), MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
audioExtractor.seekTo(seekTime.get(), MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
List<Long> expectedPresentationTimes = new ArrayList<>();
- AtomicBoolean done = new AtomicBoolean(false);
+ // Setting it to true so that buffers are not queued in the beginning.
+ AtomicBoolean done = new AtomicBoolean(true);
AtomicBoolean hasDecodeOnlyFrames = new AtomicBoolean(false);
- videoCodec.setCallback(new MediaCodec.Callback() {
- // before queueing a frame, check if it is the last frame and set the EOS flag
- // to the frame if that's the case. If the frame is to be only decoded
- // (any frame before the seek timestamp), then set the DECODE_ONLY flag to the frame.
- // Only frames not tagged with EOS or DECODE_ONLY are expected to be rendered and added
- // to expectedPresentationTimes
+ class VideoAsyncHandler extends MediaCodec.Callback {
+ private final Queue<Integer> mAvailableInputIndices = new ArrayDeque<>();
+ private final Lock mLock = new ReentrantLock();
+
+ private void queueInput(MediaCodec codec, int index) {
+ ByteBuffer inputBuffer = codec.getInputBuffer(index);
+ int sampleSize = videoExtractor.readSampleData(inputBuffer, 0);
+ long presentationTime = videoExtractor.getSampleTime();
+ int flags = videoExtractor.getSampleFlags();
+ if (sampleSize < 0) {
+ flags = MediaCodec.BUFFER_FLAG_END_OF_STREAM;
+ sampleSize = 0;
+ } else if (presentationTime < seekTime.get()) {
+ flags = MediaCodec.BUFFER_FLAG_DECODE_ONLY;
+ hasDecodeOnlyFrames.set(true);
+ } else {
+ expectedPresentationTimes.add(presentationTime);
+ }
+ codec.queueInputBuffer(index, 0, sampleSize, presentationTime, flags);
+ videoExtractor.advance();
+ }
+
@Override
public void onInputBufferAvailable(MediaCodec codec, int index) {
- if (!done.get()) {
- ByteBuffer inputBuffer = videoCodec.getInputBuffer(index);
- int sampleSize = videoExtractor.readSampleData(inputBuffer, 0);
- long presentationTime = videoExtractor.getSampleTime();
- int flags = videoExtractor.getSampleFlags();
- if (sampleSize < 0) {
- flags = MediaCodec.BUFFER_FLAG_END_OF_STREAM;
- sampleSize = 0;
- } else if (presentationTime < seekTime.get()) {
- flags = MediaCodec.BUFFER_FLAG_DECODE_ONLY;
- hasDecodeOnlyFrames.set(true);
+ mLock.lock();
+ try {
+ if (!done.get()) {
+ queueInput(codec, index);
} else {
- expectedPresentationTimes.add(presentationTime);
+ mAvailableInputIndices.offer(index);
}
- videoCodec.queueInputBuffer(index, 0, sampleSize, presentationTime, flags);
- videoExtractor.advance();
+ } finally {
+ mLock.unlock();
+ }
+ }
+
+ public void startProcess() {
+ mLock.lock();
+ try {
+ done.set(false);
+ while (!mAvailableInputIndices.isEmpty()) {
+ queueInput(videoCodec, mAvailableInputIndices.poll());
+ }
+ } finally {
+ mLock.unlock();
+ }
+ }
+
+ public void clearBufferQueue() {
+ mLock.lock();
+ try {
+ mAvailableInputIndices.clear();
+ } finally {
+ mLock.unlock();
}
}
- // nothing to do here - in tunneled mode, the frames are rendered directly by the
- // hardware, they are not sent back to the codec for extra processing
@Override
public void onOutputBufferAvailable(MediaCodec codec, int index,
MediaCodec.BufferInfo info) {
@@ -496,9 +529,18 @@ public class DecodeOnlyTest extends MediaTestBase {
public void onOutputFormatChanged(MediaCodec codec, MediaFormat format) {
}
- });
+ }
- audioCodec.setCallback(new AudioCallback(audioCodec, audioExtractor, audioTrack, done));
+ VideoAsyncHandler videoAsyncHandler = new VideoAsyncHandler();
+ videoCodec.setCallback(videoAsyncHandler);
+ videoCodec.configure(videoFormat, getActivity().getSurfaceHolder().getSurface(), null, 0);
+ // Since data is written to AudioTrack in a blocking manner, run it in a separate thread to
+ // not block other operations.
+ HandlerThread audioThread = new HandlerThread("audioThread");
+ audioThread.start();
+ audioCodec.setCallback(new AudioCallback(audioCodec, audioExtractor, audioTrack, done),
+ new Handler(audioThread.getLooper()));
+ audioCodec.configure(audioFormat, null, null, 0);
List<Long> renderedPresentationTimes = new ArrayList<>();
// play for 500ms
@@ -518,6 +560,10 @@ public class DecodeOnlyTest extends MediaTestBase {
// start media playback
videoCodec.start();
audioCodec.start();
+ // Set peeking value after MediaCodec.start() is called.
+ boolean isPeeking = setKeyTunnelPeek(videoCodec, initialPeek ? 1 : 0);
+ // start to queue video frames
+ videoAsyncHandler.startProcess();
// When video codecs are started, large chunks of contiguous physical memory need to be
// allocated, which, on low-RAM devices, can trigger high CPU usage for moving memory
@@ -564,8 +610,7 @@ public class DecodeOnlyTest extends MediaTestBase {
Thread.sleep(500);
videoCodec.flush();
audioCodec.flush();
- // Set peek on when it was off, and set it off when it was on.
- isPeeking = setKeyTunnelPeek(videoCodec, isPeeking ? 0 : 1);
+ videoAsyncHandler.clearBufferQueue();
// Frames at 7s of each file are not key frame, and there is non-zero key frame before it
seekTime.set(7000 * 1000);
@@ -587,12 +632,14 @@ public class DecodeOnlyTest extends MediaTestBase {
}, new Handler(Looper.getMainLooper()));
// Restart media playback
- done.set(false);
firstTunnelFrameReady.set(false);
videoCodec.start();
audioCodec.start();
+ // Set peek on when it was off, and set it off when it was on.
+ isPeeking = setKeyTunnelPeek(videoCodec, isPeeking ? 0 : 1);
+ videoAsyncHandler.startProcess();
sleepUntil(firstTunnelFrameReady::get, Duration.ofSeconds(firstFrameReadyTimeoutSeconds));
- assertTrue(String.format("onFirstTunnelFrameReady not called within %d milliseconds",
+ assertTrue(String.format("onFirstTunnelFrameReady not called within %d seconds",
firstFrameReadyTimeoutSeconds), firstTunnelFrameReady.get());
// Sleep for 1s here to ensure that either (1) when peek is on, high-latency display
@@ -735,9 +782,27 @@ public class DecodeOnlyTest extends MediaTestBase {
byte[] audioArray = new byte[info.size];
outputBuffer.get(audioArray);
outputBuffer.clear();
- mAudioTrack.write(ByteBuffer.wrap(audioArray), info.size,
- AudioTrack.WRITE_BLOCKING,
- info.presentationTimeUs * 1000);
+ ByteBuffer audioData = ByteBuffer.wrap(audioArray);
+ int writtenSize = 0;
+ while (true) {
+ int written = mAudioTrack.write(audioData, info.size - writtenSize,
+ AudioTrack.WRITE_BLOCKING, info.presentationTimeUs * 1000);
+ if (written >= 0) {
+ writtenSize += written;
+ if (writtenSize >= info.size) {
+ break;
+ }
+ // When audio track is not in playing state, the write operation does not
+ // block in WRITE_BLOCKING mode. And when audio track is full, the audio
+ // data can not be fully written. Must sleep here to wait for free spaces.
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException ignored) {
+ }
+ } else {
+ Assert.fail("AudioTrack write failure.");
+ }
+ }
mAudioCodec.releaseOutputBuffer(index, false);
}
}
diff --git a/tests/tests/os/Android.bp b/tests/tests/os/Android.bp
index b78514d0be1..fd7ff3a447d 100644
--- a/tests/tests/os/Android.bp
+++ b/tests/tests/os/Android.bp
@@ -61,6 +61,7 @@ android_test {
"cts",
"general-tests",
"sts",
+ "mts-documentsui",
],
sdk_version: "test_current",
libs: [
diff --git a/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java b/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
index 91219651a4b..593d3c98624 100644
--- a/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
+++ b/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
@@ -271,7 +271,9 @@ public class CtsSharesheetDeviceTest {
// Note: EII and ECT cap is not tested here
showsExtraInitialIntents();
- showsExtraChooserTargets();
+ if (!mActivityManager.isLowRamDevice()) {
+ showsExtraChooserTargets();
+ }
isSharingShortcutDirectShareEnabled();
}, () -> {
@@ -659,6 +661,10 @@ public class CtsSharesheetDeviceTest {
@Test
@ApiTest(apis = "android.content.Intent#EXTRA_CHOOSER_TARGETS")
public void testChooserTargets() throws Throwable {
+ assumeFalse(
+ "EXTRA_CHOOSER_TARGETS not required on low RAM devices",
+ mActivityManager.isLowRamDevice());
+
final CountDownLatch appStarted = new CountDownLatch(1);
final AtomicReference<Intent> targetLaunchIntent = new AtomicReference<>();
@@ -698,6 +704,10 @@ public class CtsSharesheetDeviceTest {
@Test
@ApiTest(apis = "android.content.Intent#EXTRA_CHOOSER_TARGETS")
public void testChooserTargetsRefinement() throws Throwable {
+ assumeFalse(
+ "EXTRA_CHOOSER_TARGETS not required on low RAM devices",
+ mActivityManager.isLowRamDevice());
+
final CountDownLatch broadcastInvoked = new CountDownLatch(1);
final CountDownLatch appStarted = new CountDownLatch(1);
final AtomicReference<Intent> targetLaunchIntent = new AtomicReference<>();
diff --git a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveConnectionInfoAndReturnStatusService.java b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveConnectionInfoAndReturnStatusService.java
index 23080541a58..f150cf24f05 100644
--- a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveConnectionInfoAndReturnStatusService.java
+++ b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveConnectionInfoAndReturnStatusService.java
@@ -34,6 +34,11 @@ public class RetrieveConnectionInfoAndReturnStatusService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
ResultReceiver resultReceiver =
jobParameters.getTransientExtras().getParcelable(RESULT_RECEIVER_EXTRA);
+ try {
+ Thread.sleep(5_000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
WifiManager wifiManager = getSystemService(WifiManager.class);
boolean succeeded;
try {
diff --git a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveScanResultsAndReturnStatusService.java b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveScanResultsAndReturnStatusService.java
index 4918e39df52..e932277e227 100644
--- a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveScanResultsAndReturnStatusService.java
+++ b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveScanResultsAndReturnStatusService.java
@@ -34,6 +34,11 @@ public class RetrieveScanResultsAndReturnStatusService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
ResultReceiver resultReceiver =
jobParameters.getTransientExtras().getParcelable(RESULT_RECEIVER_EXTRA);
+ try {
+ Thread.sleep(5_000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
WifiManager wifiManager = getSystemService(WifiManager.class);
boolean succeeded;
try {
diff --git a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveTransportInfoAndReturnStatusService.java b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveTransportInfoAndReturnStatusService.java
index 1476455a091..4c53083ab33 100644
--- a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveTransportInfoAndReturnStatusService.java
+++ b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/RetrieveTransportInfoAndReturnStatusService.java
@@ -20,11 +20,8 @@ import static android.net.wifi.cts.app.RetrieveTransportInfoAndReturnStatusActiv
import android.app.job.JobParameters;
import android.app.job.JobService;
-import android.content.Intent;
import android.net.ConnectivityManager;
-import android.net.wifi.WifiManager;
import android.os.ResultReceiver;
-import android.util.Log;
/**
* A service that retrieves transport Info and returns status.
@@ -38,6 +35,11 @@ public class RetrieveTransportInfoAndReturnStatusService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
ResultReceiver resultReceiver =
jobParameters.getTransientExtras().getParcelable(RESULT_RECEIVER_EXTRA);
+ try {
+ Thread.sleep(5_000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
ConnectivityManager connectivityManager = getSystemService(ConnectivityManager.class);
resultReceiver.send(
canRetrieveSsidFromTransportInfo(TAG, connectivityManager) ? 1 : 0, null);
diff --git a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/TriggerScanAndReturnStatusService.java b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/TriggerScanAndReturnStatusService.java
index 2f6a2eda0d1..18d2f439552 100644
--- a/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/TriggerScanAndReturnStatusService.java
+++ b/tests/tests/wifi/CtsWifiLocationTestApp/src/android/net/wifi/cts/app/TriggerScanAndReturnStatusService.java
@@ -34,6 +34,11 @@ public class TriggerScanAndReturnStatusService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
ResultReceiver resultReceiver =
jobParameters.getTransientExtras().getParcelable(RESULT_RECEIVER_EXTRA);
+ try {
+ Thread.sleep(5_000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
WifiManager wifiManager = getSystemService(WifiManager.class);
boolean succeeded;
try {
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 9dd00fb6b02..74fdf642e09 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
@@ -73,6 +73,7 @@ import androidx.test.filters.SdkSuppress;
import androidx.test.platform.app.InstrumentationRegistry;
import com.android.compatibility.common.util.ApiLevelUtil;
+import com.android.compatibility.common.util.ApiTest;
import com.android.compatibility.common.util.ShellIdentityUtils;
import java.util.ArrayDeque;
@@ -1121,7 +1122,9 @@ public class SingleDeviceTest extends WifiJUnit3TestBase {
* Validate successful suspend/resume with a publish session.
*/
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
- public void testSuspendResumeSuccessWithPublishSession() {
+ @ApiTest(apis = {"android.net.wifi.aware.DiscoverySession#suspend",
+ "android.net.wifi.aware.DiscoverySession#resume"})
+ public void testSuspendResumeFailWithoutNdpOnPublishSession() {
if (!TestUtils.shouldTestWifiAware(getContext())) {
return;
}
@@ -1155,18 +1158,12 @@ public class SingleDeviceTest extends WifiJUnit3TestBase {
// 2. suspend
discoverySession.suspend();
- assertTrue("Publish session suspended",
- discoveryCb.waitForCallback(
- DiscoverySessionCallbackTest.ON_SESSION_SUSPEND_SUCCEEDED));
- assertFalse(discoveryCb.waitForCallback(
+ assertTrue(discoveryCb.waitForCallback(
DiscoverySessionCallbackTest.ON_SESSION_SUSPEND_FAILED));
// 3. resume
discoverySession.resume();
- assertTrue("Publish session resumed",
- discoveryCb.waitForCallback(
- DiscoverySessionCallbackTest.ON_SESSION_RESUME_SUCCEEDED));
- assertFalse(discoveryCb.waitForCallback(
+ assertTrue(discoveryCb.waitForCallback(
DiscoverySessionCallbackTest.ON_SESSION_RESUME_FAILED));
// 4. destroy
@@ -1422,7 +1419,9 @@ public class SingleDeviceTest extends WifiJUnit3TestBase {
* Validate successful suspend/resume with a subscribe session.
*/
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
- public void testSuspendResumeSuccessWithSubscribeSession() {
+ @ApiTest(apis = {"android.net.wifi.aware.DiscoverySession#suspend",
+ "android.net.wifi.aware.DiscoverySession#resume"})
+ public void testSuspendResumeFailWithoutNdpOnSubscribeSession() {
if (!TestUtils.shouldTestWifiAware(getContext())) {
return;
}
@@ -1457,18 +1456,12 @@ public class SingleDeviceTest extends WifiJUnit3TestBase {
// 2. suspend
discoverySession.suspend();
- assertTrue("Subscribe session suspended",
- discoveryCb.waitForCallback(
- DiscoverySessionCallbackTest.ON_SESSION_SUSPEND_SUCCEEDED));
- assertFalse(discoveryCb.waitForCallback(
+ assertTrue(discoveryCb.waitForCallback(
DiscoverySessionCallbackTest.ON_SESSION_SUSPEND_FAILED));
// 3. resume
discoverySession.resume();
- assertTrue("Subscribe session resumed",
- discoveryCb.waitForCallback(
- DiscoverySessionCallbackTest.ON_SESSION_RESUME_SUCCEEDED));
- assertFalse(discoveryCb.waitForCallback(
+ assertTrue(discoveryCb.waitForCallback(
DiscoverySessionCallbackTest.ON_SESSION_RESUME_FAILED));
// 4. destroy
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/ConnectedNetworkScorerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/ConnectedNetworkScorerTest.java
index 02128cedf6c..d6a89f1daae 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/ConnectedNetworkScorerTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/ConnectedNetworkScorerTest.java
@@ -74,8 +74,9 @@ import com.android.compatibility.common.util.ShellIdentityUtils;
import com.google.common.collect.Range;
-import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -96,81 +97,93 @@ import java.util.concurrent.TimeUnit;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
- private Context mContext;
- private WifiManager mWifiManager;
- private ConnectivityManager mConnectivityManager;
- private UiDevice mUiDevice;
- private TestHelper mTestHelper;
- private TelephonyManager mTelephonyManager;
+ private static Context sContext;
+ private static WifiManager sWifiManager;
+ private static ConnectivityManager sConnectivityManager;
+ private static UiDevice sUiDevice;
+ private static TestHelper sTestHelper;
+ private static TelephonyManager sTelephonyManager;
- private boolean mWasVerboseLoggingEnabled;
+ private static boolean sWasVerboseLoggingEnabled;
private static final int WIFI_CONNECT_TIMEOUT_MILLIS = 30_000;
private static final int TIMEOUT = 12_000;
private static final int WAIT_DURATION = 5_000;
- @Before
- public void setUp() throws Exception {
- mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ private static boolean sShouldRunTest = false;
+ private static boolean sWasScanThrottleEnabled;
- // skip the test if WiFi is not supported
- assumeTrue(WifiFeature.isWifiSupported(mContext));
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ sContext = InstrumentationRegistry.getInstrumentation().getContext();
+
+ if (!WifiFeature.isWifiSupported(sContext)) {
+ return;
+ }
+ sShouldRunTest = true;
- mWifiManager = mContext.getSystemService(WifiManager.class);
- assertThat(mWifiManager).isNotNull();
+ sWifiManager = sContext.getSystemService(WifiManager.class);
+ assertThat(sWifiManager).isNotNull();
// Location mode must be enabled, otherwise the connection info will be redacted.
- assertThat(Objects.requireNonNull(mContext.getSystemService(LocationManager.class))
+ assertThat(Objects.requireNonNull(sContext.getSystemService(LocationManager.class))
.isLocationEnabled()).isTrue();
- mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
+ sConnectivityManager = sContext.getSystemService(ConnectivityManager.class);
// turn on verbose logging for tests
- mWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.isVerboseLoggingEnabled());
+ sWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isVerboseLoggingEnabled());
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setVerboseLoggingEnabled(true));
+ sWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isScanThrottleEnabled());
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setVerboseLoggingEnabled(true));
+ () -> sWifiManager.setScanThrottleEnabled(false));
// enable Wifi
- if (!mWifiManager.isWifiEnabled()) {
- ShellIdentityUtils.invokeWithShellPermissions(() -> mWifiManager.setWifiEnabled(true));
+ if (!sWifiManager.isWifiEnabled()) {
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.setWifiEnabled(true));
}
- PollingCheck.check("Wifi not enabled", TIMEOUT, () -> mWifiManager.isWifiEnabled());
+ PollingCheck.check("Wifi not enabled", TIMEOUT, () -> sWifiManager.isWifiEnabled());
// turn screen on
- mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ sUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mTestHelper = new TestHelper(mContext, mUiDevice);
- mTestHelper.turnScreenOn();
-
- // Clear any existing app state before each test.
- if (WifiBuildCompat.isPlatformOrWifiModuleAtLeastS(mContext)) {
- ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.removeAppState(myUid(), mContext.getPackageName()));
- }
+ sTestHelper = new TestHelper(sContext, sUiDevice);
+ sTestHelper.turnScreenOn();
// check we have >= 1 saved network
List<WifiConfiguration> savedNetworks = ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.getConfiguredNetworks());
+ () -> sWifiManager.getConfiguredNetworks());
assertWithMessage("Need at least one saved network").that(savedNetworks).isNotEmpty();
+ sTelephonyManager = sContext.getSystemService(TelephonyManager.class);
+ }
+ @Before
+ public void setUp() throws Exception {
+ assumeTrue(sShouldRunTest);
+ // Clear any existing app state before each test.
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.removeAppState(myUid(), sContext.getPackageName()));
// ensure Wifi is connected
- ShellIdentityUtils.invokeWithShellPermissions(() -> mWifiManager.reconnect());
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.reconnect());
PollingCheck.check(
"Wifi not connected",
WIFI_CONNECT_TIMEOUT_MILLIS,
- () -> mWifiManager.getConnectionInfo().getNetworkId() != -1);
- mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() != -1);
}
- @After
- public void tearDown() throws Exception {
- if (!WifiFeature.isWifiSupported(mContext)) return;
- if (!mWifiManager.isWifiEnabled()) {
- ShellIdentityUtils.invokeWithShellPermissions(() -> mWifiManager.setWifiEnabled(true));
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ if (!sShouldRunTest) return;
+ if (!sWifiManager.isWifiEnabled()) {
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.setWifiEnabled(true));
}
- mTestHelper.turnScreenOff();
+ sTestHelper.turnScreenOff();
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setVerboseLoggingEnabled(sWasVerboseLoggingEnabled));
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
+ () -> sWifiManager.setScanThrottleEnabled(sWasScanThrottleEnabled));
}
private static class TestUsabilityStatsListener implements
@@ -210,7 +223,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
new TestUsabilityStatsListener(countDownLatch);
try {
uiAutomation.adoptShellPermissionIdentity();
- mWifiManager.addOnWifiUsabilityStatsListener(
+ sWifiManager.addOnWifiUsabilityStatsListener(
Executors.newSingleThreadExecutor(), usabilityStatsListener);
// Wait for new usability stats (while connected & screen on this is triggered
// by platform periodically).
@@ -226,7 +239,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertThat(statsEntry.getTotalTxRetries()).isAtLeast(0L);
assertThat(statsEntry.getTotalTxBad()).isAtLeast(0L);
assertThat(statsEntry.getTotalRxSuccess()).isAtLeast(0L);
- if (mWifiManager.isEnhancedPowerReportingSupported()) {
+ if (sWifiManager.isEnhancedPowerReportingSupported()) {
assertThat(statsEntry.getTotalRadioOnTimeMillis()).isAtLeast(0L);
assertThat(statsEntry.getTotalRadioTxTimeMillis()).isAtLeast(0L);
assertThat(statsEntry.getTotalRadioRxTimeMillis()).isAtLeast(0L);
@@ -296,9 +309,9 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertEquals(10, contentionStats.getContentionNumSamples());
// Note that -1 is also a possible returned value for utilization ratio.
assertThat(statsEntry.getChannelUtilizationRatio()).isIn(Range.closed(-1, 255));
- if (mTelephonyManager != null) {
+ if (sTelephonyManager != null) {
boolean isCellularDataAvailable =
- mTelephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED;
+ sTelephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED;
assertEquals(isCellularDataAvailable, statsEntry.isCellularDataAvailable());
} else {
assertFalse(statsEntry.isCellularDataAvailable());
@@ -466,7 +479,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertThat(statsEntry.isSameRegisteredCell()).isFalse();
}
} finally {
- mWifiManager.removeOnWifiUsabilityStatsListener(usabilityStatsListener);
+ sWifiManager.removeOnWifiUsabilityStatsListener(usabilityStatsListener);
uiAutomation.dropShellPermissionIdentity();
}
}
@@ -480,7 +493,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
try {
uiAutomation.adoptShellPermissionIdentity();
// update scoring with dummy values.
- mWifiManager.updateWifiUsabilityScore(0, 50, 50);
+ sWifiManager.updateWifiUsabilityScore(0, 50, 50);
} finally {
uiAutomation.dropShellPermissionIdentity();
}
@@ -495,7 +508,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
try {
uiAutomation.adoptShellPermissionIdentity();
- assertTrue(mWifiManager.setWifiScoringEnabled(true));
+ assertTrue(sWifiManager.setWifiScoringEnabled(true));
} finally {
uiAutomation.dropShellPermissionIdentity();
}
@@ -629,10 +642,10 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
try {
uiAutomation.adoptShellPermissionIdentity();
// Clear any external scorer already active on the device.
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.clearWifiConnectedNetworkScorer();
Thread.sleep(500);
- mWifiManager.setWifiConnectedNetworkScorer(
+ sWifiManager.setWifiConnectedNetworkScorer(
Executors.newSingleThreadExecutor(), connectedNetworkScorer);
// Since we're already connected, wait for onStart to be invoked.
assertThat(countDownLatchScorer.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
@@ -647,7 +660,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
scoreUpdateObserver.notifyScoreUpdate(connectedNetworkScorer.startSessionId, 50);
// Register the usability listener
- mWifiManager.addOnWifiUsabilityStatsListener(
+ sWifiManager.addOnWifiUsabilityStatsListener(
Executors.newSingleThreadExecutor(), usabilityStatsListener);
// Trigger a usability stats update.
scoreUpdateObserver.triggerUpdateOfWifiUsabilityStats(
@@ -669,12 +682,12 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
scoreUpdateObserver.blocklistCurrentBssid(-1);
}
// Now disconnect from the network.
- mWifiManager.disconnect();
+ sWifiManager.disconnect();
// Wait for it to be disconnected.
PollingCheck.check(
"Wifi not disconnected",
TIMEOUT,
- () -> mWifiManager.getConnectionInfo().getNetworkId() == -1);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() == -1);
disconnected = true;
// Wait for stop to be invoked and ensure that the session id matches.
@@ -691,16 +704,16 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
connectedNetworkScorer.onStop(200);
assertEquals(200, connectedNetworkScorer.stopSessionId.intValue());
} finally {
- mWifiManager.removeOnWifiUsabilityStatsListener(usabilityStatsListener);
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.removeOnWifiUsabilityStatsListener(usabilityStatsListener);
+ sWifiManager.clearWifiConnectedNetworkScorer();
if (disconnected) {
- mWifiManager.reconnect();
+ sWifiManager.reconnect();
// Wait for it to be reconnected.
PollingCheck.check(
"Wifi not reconnected",
WIFI_CONNECT_TIMEOUT_MILLIS,
- () -> mWifiManager.getConnectionInfo().getNetworkId() != -1);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() != -1);
}
uiAutomation.dropShellPermissionIdentity();
}
@@ -721,10 +734,10 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
try {
uiAutomation.adoptShellPermissionIdentity();
// Clear any external scorer already active on the device.
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.clearWifiConnectedNetworkScorer();
Thread.sleep(500);
- mWifiManager.setWifiConnectedNetworkScorer(
+ sWifiManager.setWifiConnectedNetworkScorer(
Executors.newSingleThreadExecutor(), connectedNetworkScorer);
// Since we're already connected, wait for onStart to be invoked.
assertThat(countDownLatchScorer.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
@@ -740,7 +753,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
connectedNetworkScorer.resetCountDownLatch(countDownLatchScorer);
// Restart wifi subsystem.
- mWifiManager.restartWifiSubsystem();
+ sWifiManager.restartWifiSubsystem();
// wait for scorer to stop session due to network disconnection.
assertThat(countDownLatchScorer.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
@@ -752,7 +765,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
PollingCheck.check(
"Wifi not connected",
WIFI_CONNECT_TIMEOUT_MILLIS * 2,
- () -> mWifiManager.getConnectionInfo().getNetworkId() != -1);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() != -1);
// Followed by a new onStart() after the connection.
// Note: There is a 5 second delay between stop/start when restartWifiSubsystem() is
@@ -764,7 +777,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertThat(connectedNetworkScorer.scoreUpdateObserver).isSameInstanceAs(
prevScoreUpdateObserver);
} finally {
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.clearWifiConnectedNetworkScorer();
uiAutomation.dropShellPermissionIdentity();
}
}
@@ -793,27 +806,27 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
READ_WIFI_CREDENTIAL);
// Clear any external scorer already active on the device.
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.clearWifiConnectedNetworkScorer();
Thread.sleep(500);
- savedNetworks = mWifiManager.getPrivilegedConfiguredNetworks();
+ savedNetworks = sWifiManager.getPrivilegedConfiguredNetworks();
WifiConfiguration testNetwork =
- TestHelper.findMatchingSavedNetworksWithBssid(mWifiManager, savedNetworks, 1)
+ TestHelper.findMatchingSavedNetworksWithBssid(sWifiManager, savedNetworks, 1)
.get(0);
// Disconnect & disable auto-join on the saved network to prevent auto-connect from
// interfering with the test.
for (WifiConfiguration savedNetwork : savedNetworks) {
- mWifiManager.disableNetwork(savedNetwork.networkId);
+ sWifiManager.disableNetwork(savedNetwork.networkId);
}
// Wait for Wifi to be disconnected.
PollingCheck.check(
"Wifi not disconnected",
20000,
- () -> mWifiManager.getConnectionInfo().getNetworkId() == -1);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() == -1);
assertThat(testNetwork).isNotNull();
// Register the external scorer.
- mWifiManager.setWifiConnectedNetworkScorer(
+ sWifiManager.setWifiConnectedNetworkScorer(
Executors.newSingleThreadExecutor(), connectedNetworkScorer);
// Now connect using the provided connection initiator
@@ -824,7 +837,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertThat(connectedNetworkScorer.startSessionId).isNull();
// Now disconnect from the network.
- mConnectivityManager.unregisterNetworkCallback(networkCallback);
+ sConnectivityManager.unregisterNetworkCallback(networkCallback);
networkCallback = null;
// We should not receive the stop either
@@ -834,14 +847,14 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
assertThat(connectedNetworkScorer.stopSessionId).isNull();
} finally {
executorService.shutdownNow();
- mWifiManager.clearWifiConnectedNetworkScorer();
+ sWifiManager.clearWifiConnectedNetworkScorer();
if (networkCallback != null) {
- mConnectivityManager.unregisterNetworkCallback(networkCallback);
+ sConnectivityManager.unregisterNetworkCallback(networkCallback);
}
// Re-enable the networks after the test.
if (savedNetworks != null) {
for (WifiConfiguration savedNetwork : savedNetworks) {
- mWifiManager.enableNetwork(savedNetwork.networkId, false);
+ sWifiManager.enableNetwork(savedNetwork.networkId, false);
}
}
uiAutomation.dropShellPermissionIdentity();
@@ -859,9 +872,9 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
// Connect using wifi network specifier.
WifiNetworkSpecifier specifier =
TestHelper.createSpecifierBuilderWithCredentialFromSavedNetwork(
- testNetwork, false)
+ testNetwork, true)
.build();
- return mTestHelper.testConnectionFlowWithSpecifierWithShellIdentity(
+ return sTestHelper.testConnectionFlowWithSpecifierWithShellIdentity(
testNetwork, specifier, false);
}
);
@@ -882,7 +895,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
if (restrictedNetworkCapabilities.contains(NET_CAPABILITY_OEM_PRIVATE)) {
suggestionBuilder.setOemPrivate(true);
}
- return mTestHelper.testConnectionFlowWithSuggestionWithShellIdentity(
+ return sTestHelper.testConnectionFlowWithSuggestionWithShellIdentity(
testNetwork, suggestionBuilder.build(), executorService,
restrictedNetworkCapabilities, false/* restrictedNetwork */);
}
@@ -930,8 +943,8 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
WifiSsid ssid = WifiSsid.fromBytes(new byte[]{0x12, 0x34, 0x56});
byte[] oui = new byte[]{0x00, 0x01, 0x02};
List<DhcpOption> options = new ArrayList<DhcpOption>();
- mWifiManager.addCustomDhcpOptions(ssid, oui, options);
- mWifiManager.removeCustomDhcpOptions(ssid, oui);
+ sWifiManager.addCustomDhcpOptions(ssid, oui, options);
+ sWifiManager.removeCustomDhcpOptions(ssid, oui);
} finally {
uiAutomation.dropShellPermissionIdentity();
}
@@ -950,7 +963,7 @@ public class ConnectedNetworkScorerTest extends WifiJUnit4TestBase {
WifiSsid ssid = WifiSsid.fromBytes(new byte[]{0x12, 0x34, 0x56});
byte[] oui = new byte[]{0x00, 0x01, 0x02};
List<DhcpOption> options = new ArrayList<DhcpOption>();
- mWifiManager.addCustomDhcpOptions(ssid, oui, options);
+ sWifiManager.addCustomDhcpOptions(ssid, oui, options);
fail("Expected SecurityException");
} catch (SecurityException e) {
// expected
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java b/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java
index 5d5e9bb6df7..fca2868830d 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/TestHelper.java
@@ -673,6 +673,7 @@ public class TestHelper {
@Override
public void onUserSelectionCallbackRegistration(
WifiManager.NetworkRequestUserSelectionCallback userSelectionCallback) {
+ Log.d(TAG, "onUserSelectionCallbackRegistration");
synchronized (mLock) {
onRegistrationCalled = true;
this.userSelectionCallback = userSelectionCallback;
@@ -682,6 +683,7 @@ public class TestHelper {
@Override
public void onAbort() {
+ Log.d(TAG, "onAbort");
synchronized (mLock) {
onAbortCalled = true;
mLock.notify();
@@ -690,6 +692,7 @@ public class TestHelper {
@Override
public void onMatch(List<ScanResult> scanResults) {
+ Log.d(TAG, "onMatch");
synchronized (mLock) {
// This can be invoked multiple times. So, ignore after the first one to avoid
// disturbing the rest of the test sequence.
@@ -702,6 +705,7 @@ public class TestHelper {
@Override
public void onUserSelectionConnectSuccess(WifiConfiguration config) {
+ Log.d(TAG, "onUserSelectionConnectSuccess");
synchronized (mLock) {
onConnectSuccessCalled = true;
mLock.notify();
@@ -710,6 +714,7 @@ public class TestHelper {
@Override
public void onUserSelectionConnectFailure(WifiConfiguration config) {
+ Log.d(TAG, "onUserSelectionConnectFailure");
synchronized (mLock) {
onConnectFailureCalled = true;
mLock.notify();
@@ -821,6 +826,7 @@ public class TestHelper {
Thread.sleep(1_000);
// Start the UI interactions.
uiThread.start();
+ assertThat(localOnlyListener.await(DURATION_MILLIS)).isFalse();
// now wait for callback
assertThat(testNetworkCallback.waitForAnyCallback(DURATION_NETWORK_CONNECTION_MILLIS))
.isTrue();
@@ -840,7 +846,6 @@ public class TestHelper {
assertThat(wifiInfo.isPrimary()).isTrue();
}
}
- assertThat(localOnlyListener.await(DURATION_NETWORK_CONNECTION_MILLIS)).isFalse();
assertThat(localOnlyListener.onFailureCalled).isFalse();
}
} catch (Throwable e /* catch assertions & exceptions */) {
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoBackgroundTest.java
index 3d3a7c2b19e..45ef709d4b4 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoBackgroundTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * Copyright (C) 2023 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.
@@ -43,41 +43,31 @@ import com.android.compatibility.common.util.ShellIdentityUtils;
import com.android.compatibility.common.util.SystemUtil;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.List;
-/**
- * Tests location sensitive APIs exposed by Wi-Fi.
- * Ensures that permissions on these APIs are properly enforced.
- */
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
@SmallTest
@RunWith(AndroidJUnit4.class)
-public class WifiLocationInfoTest extends WifiJUnit4TestBase {
+public class WifiLocationInfoBackgroundTest extends WifiJUnit4TestBase{
private static final String TAG = "WifiLocationInfoTest";
private static final String WIFI_LOCATION_TEST_APP_APK_PATH =
"/data/local/tmp/cts/wifi/CtsWifiLocationTestApp.apk";
private static final String WIFI_LOCATION_TEST_APP_PACKAGE_NAME =
"android.net.wifi.cts.app";
- private static final String WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_ACTIVITY =
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".TriggerScanAndReturnStatusActivity";
private static final String WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_SERVICE =
WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".TriggerScanAndReturnStatusService";
- private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_ACTIVITY =
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveScanResultsAndReturnStatusActivity";
private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_SERVICE =
WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveScanResultsAndReturnStatusService";
- private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_ACTIVITY =
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveConnectionInfoAndReturnStatusActivity";
private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_SERVICE =
WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveConnectionInfoAndReturnStatusService";
- private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_ACTIVITY =
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveTransportInfoAndReturnStatusActivity";
private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_SERVICE =
WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveTransportInfoAndReturnStatusService";
@@ -88,179 +78,139 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
public final ActivityTestRule<WaitForResultActivity> mActivityRule =
new ActivityTestRule<>(WaitForResultActivity.class);
- private Context mContext;
- private WifiManager mWifiManager;
- private boolean mWasVerboseLoggingEnabled;
- private boolean mWasScanThrottleEnabled;
- private PowerManager mPower;
- private PowerManager.WakeLock mLock;
+ private static Context sContext;
+ private static WifiManager sWifiManager;
+ private static boolean sWasVerboseLoggingEnabled;
+ private static boolean sWasScanThrottleEnabled;
+ private static PowerManager sPower;
+ private static PowerManager.WakeLock sLock;
- @Before
- public void setUp() throws Exception {
- mContext = InstrumentationRegistry.getInstrumentation().getContext();
- // skip the test if WiFi is not supported
- assumeTrue(WifiFeature.isWifiSupported(mContext));
+ private static boolean sShouldRunTest = false;
- mWifiManager = mContext.getSystemService(WifiManager.class);
- assertThat(mWifiManager).isNotNull();
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ sContext = InstrumentationRegistry.getInstrumentation().getContext();
+ if (!WifiFeature.isWifiSupported(sContext)) {
+ return;
+ }
+ sShouldRunTest = true;
- installApp(WIFI_LOCATION_TEST_APP_APK_PATH);
+ sWifiManager = sContext.getSystemService(WifiManager.class);
+ assertThat(sWifiManager).isNotNull();
// turn on verbose logging for tests
- mWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.isVerboseLoggingEnabled());
+ sWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isVerboseLoggingEnabled());
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setVerboseLoggingEnabled(true));
+ () -> sWifiManager.setVerboseLoggingEnabled(true));
// Disable scan throttling for tests.
- mWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.isScanThrottleEnabled());
+ sWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isScanThrottleEnabled());
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setScanThrottleEnabled(false));
+ () -> sWifiManager.setScanThrottleEnabled(false));
// enable Wifi
- if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
- PollingCheck.check("Wifi not enabled", DURATION_MS, () -> mWifiManager.isWifiEnabled());
+ if (!sWifiManager.isWifiEnabled()) setWifiEnabled(true);
+ PollingCheck.check("Wifi not enabled", DURATION_MS, () -> sWifiManager.isWifiEnabled());
// check we have >= 1 saved network
List<WifiConfiguration> savedNetworks = ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.getConfiguredNetworks());
+ () -> sWifiManager.getConfiguredNetworks());
assertWithMessage("Need at least one saved network").that(savedNetworks).isNotEmpty();
// ensure Wifi is connected
- ShellIdentityUtils.invokeWithShellPermissions(() -> mWifiManager.reconnect());
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.reconnect());
PollingCheck.check(
"Wifi not connected",
WIFI_CONNECT_TIMEOUT_MILLIS,
- () -> mWifiManager.getConnectionInfo().getNetworkId() != -1);
- mPower = mContext.getSystemService(PowerManager.class);
- mLock = mPower.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+ () -> sWifiManager.getConnectionInfo().getNetworkId() != -1);
+ sPower = sContext.getSystemService(PowerManager.class);
+ sLock = sPower.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+ turnScreenOff();
}
- @After
- public void tearDown() throws Exception {
- if (!WifiFeature.isWifiSupported(mContext)) return;
+ @Before
+ public void setUp() throws InterruptedException {
+ // skip the test if WiFi is not supported
+ assumeTrue(sShouldRunTest);
+ installApp(WIFI_LOCATION_TEST_APP_APK_PATH);
+ }
+
+ @After
+ public void teardown() throws InterruptedException {
+ if (!sShouldRunTest) {
+ return;
+ }
uninstallApp(WIFI_LOCATION_TEST_APP_PACKAGE_NAME);
+ }
- if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ if (!sShouldRunTest) return;
+ if (!sWifiManager.isWifiEnabled()) setWifiEnabled(true);
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setScanThrottleEnabled(mWasScanThrottleEnabled));
+ () -> sWifiManager.setScanThrottleEnabled(sWasScanThrottleEnabled));
ShellIdentityUtils.invokeWithShellPermissions(
- () -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
- if (mLock != null && mLock.isHeld()) {
- mLock.release();
- }
+ () -> sWifiManager.setVerboseLoggingEnabled(sWasVerboseLoggingEnabled));
+ turnScreenOn();
}
- private void setWifiEnabled(boolean enable) throws Exception {
- ShellIdentityUtils.invokeWithShellPermissions(() -> mWifiManager.setWifiEnabled(enable));
+ private static void setWifiEnabled(boolean enable) throws Exception {
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.setWifiEnabled(enable));
}
- private void turnScreenOn() throws Exception {
- if (mLock.isHeld()) mLock.release();
- InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
- "input keyevent KEYCODE_WAKEUP");
- InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(""
- + "wm dismiss-keyguard");
- // Since the screen on/off intent is ordered, they will not be sent right now.
- Thread.sleep(5_000);
+ private static void turnScreenOn() throws Exception {
+ if (sLock.isHeld()) sLock.release();
+ SystemUtil.runShellCommand("input keyevent KEYCODE_WAKEUP");
+ SystemUtil.runShellCommand("wm dismiss-keyguard");
}
- private void turnScreenOff() throws Exception {
- if (!mLock.isHeld()) mLock.acquire();
- InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
- "input keyevent KEYCODE_SLEEP");
- // Since the screen on/off intent is ordered, they will not be sent right now.
- Thread.sleep(5_000);
+ private static void turnScreenOff() throws Exception {
+ if (!sLock.isHeld()) sLock.acquire();
+ SystemUtil.runShellCommand("input keyevent KEYCODE_SLEEP");
}
- private void installApp(String apk) throws InterruptedException {
+ private static void installApp(String apk) throws InterruptedException {
String installResult = SystemUtil.runShellCommand("pm install -r -d " + apk);
assertThat(installResult.trim()).isEqualTo("Success");
}
- private void uninstallApp(String pkg) throws InterruptedException {
+ private static void uninstallApp(String pkg) throws InterruptedException {
String uninstallResult = SystemUtil.runShellCommand(
"pm uninstall " + pkg);
assertThat(uninstallResult.trim()).isEqualTo("Success");
}
- private void startFgActivityAndAssertStatusIs(
- ComponentName componentName, boolean status) throws Exception {
- turnScreenOn();
-
- WaitForResultActivity activity = mActivityRule.getActivity();
- activity.startActivityToWaitForResult(componentName);
- assertThat(activity.waitForActivityResult(DURATION_MS)).isEqualTo(status);
- }
-
private void startBgServiceAndAssertStatusIs(
ComponentName componentName, boolean status) throws Exception {
- turnScreenOff();
-
WaitForResultActivity activity = mActivityRule.getActivity();
activity.startServiceToWaitForResult(componentName);
assertThat(activity.waitForServiceResult(DURATION_MS)).isEqualTo(status);
}
- private void triggerScanFgActivityAndAssertStatusIs(boolean status) throws Exception {
- startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
- WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_ACTIVITY), status);
- }
-
private void triggerScanBgServiceAndAssertStatusIs(boolean status) throws Exception {
startBgServiceAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_SERVICE), status);
}
- private void retrieveScanResultsFgActivityAndAssertStatusIs(boolean status) throws Exception {
- startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
- WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_ACTIVITY), status);
- }
-
private void retrieveScanResultsBgServiceAndAssertStatusIs(boolean status) throws Exception {
startBgServiceAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_SERVICE), status);
}
- private void retrieveConnectionInfoFgActivityAndAssertStatusIs(boolean status)
- throws Exception {
- startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
- WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_ACTIVITY), status);
- }
-
private void retrieveConnectionInfoBgServiceAndAssertStatusIs(boolean status) throws Exception {
startBgServiceAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_SERVICE), status);
}
- private void retrieveTransportInfoFgActivityAndAssertStatusIs(boolean status)
- throws Exception {
- startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
- WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_ACTIVITY), status);
- }
-
private void retrieveTransportInfoBgServiceAndAssertStatusIs(boolean status) throws Exception {
startBgServiceAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_SERVICE), status);
}
@Test
- public void testScanTriggerNotAllowedForForegroundActivityWithNoLocationPermission()
- throws Exception {
- triggerScanFgActivityAndAssertStatusIs(false);
- }
-
- @Test
- public void testScanTriggerAllowedForForegroundActivityWithFineLocationPermission()
- throws Exception {
- InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
- triggerScanFgActivityAndAssertStatusIs(true);
- }
-
- @Test
- public void testScanTriggerAllowedForBackgroundServiceWithBackgroundLocationPermission()
+ public void testScanTriggerAllowedWithBackgroundLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -270,7 +220,7 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
}
@Test
- public void testScanTriggerNotAllowedForBackgroundServiceWithFineLocationPermission()
+ public void testScanTriggerNotAllowedWithFineLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -278,21 +228,7 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
}
@Test
- public void testScanResultsRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
- throws Exception {
- retrieveScanResultsFgActivityAndAssertStatusIs(false);
- }
-
- @Test
- public void testScanResultsRetrievalAllowedForForegroundActivityWithFineLocationPermission()
- throws Exception {
- InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
- retrieveScanResultsFgActivityAndAssertStatusIs(true);
- }
-
- @Test
- public void testScanResultsRetrievalAllowedForBackgroundServiceWithBackgroundLocationPermission()
+ public void testScanResultsRetrievalAllowedWithBackgroundLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -302,7 +238,7 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
}
@Test
- public void testScanResultsRetrievalNotAllowedForBackgroundServiceWithFineLocationPermission()
+ public void testScanResultsRetrievalNotAllowedWithFineLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -310,22 +246,7 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
}
@Test
- public void testConnectionInfoRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
- throws Exception {
- retrieveConnectionInfoFgActivityAndAssertStatusIs(false);
- }
-
- @Test
- public void testConnectionInfoRetrievalAllowedForForegroundActivityWithFineLocationPermission()
- throws Exception {
- InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
- retrieveConnectionInfoFgActivityAndAssertStatusIs(true);
- }
-
- @Test
- public void
- testConnectionInfoRetrievalAllowedForBackgroundServiceWithBackgroundLocationPermission()
+ public void testConnectionInfoRetrievalAllowedWithBackgroundLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -335,34 +256,17 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
}
@Test
- public void
- testConnectionInfoRetrievalNotAllowedForBackgroundServiceWithFineLocationPermission()
+ public void testConnectionInfoRetrievalNotAllowedWithFineLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
retrieveConnectionInfoBgServiceAndAssertStatusIs(false);
}
- @SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
- @Test
- public void testTransportInfoRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
- throws Exception {
- retrieveTransportInfoFgActivityAndAssertStatusIs(false);
- }
-
- @SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
- @Test
- public void testTransportInfoRetrievalAllowedForForegroundActivityWithFineLocationPermission()
- throws Exception {
- InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
- WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
- retrieveTransportInfoFgActivityAndAssertStatusIs(true);
- }
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
@Test
- public void
- testTransportInfoRetrievalAllowedForBackgroundServiceWithBackgroundLocationPermission()
+ public void testTransportInfoRetrievalAllowedWithBackgroundLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
@@ -373,8 +277,7 @@ public class WifiLocationInfoTest extends WifiJUnit4TestBase {
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
@Test
- public void
- testTransportInfoRetrievalNotAllowedForBackgroundServiceWithFineLocationPermission()
+ public void testTransportInfoRetrievalNotAllowedWithFineLocationPermission()
throws Exception {
InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoForegroundTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoForegroundTest.java
new file mode 100644
index 00000000000..1e7968bd8e0
--- /dev/null
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiLocationInfoForegroundTest.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2020 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.net.wifi.cts;
+
+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import static org.junit.Assume.assumeTrue;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.os.PowerManager;
+import android.platform.test.annotations.AppModeFull;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SdkSuppress;
+import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.rule.ActivityTestRule;
+
+import com.android.compatibility.common.util.PollingCheck;
+import com.android.compatibility.common.util.ShellIdentityUtils;
+import com.android.compatibility.common.util.SystemUtil;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+/**
+ * Tests location sensitive APIs exposed by Wi-Fi.
+ * Ensures that permissions on these APIs are properly enforced.
+ */
+@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class WifiLocationInfoForegroundTest extends WifiJUnit4TestBase {
+ private static final String TAG = "WifiLocationInfoTest";
+
+ private static final String WIFI_LOCATION_TEST_APP_APK_PATH =
+ "/data/local/tmp/cts/wifi/CtsWifiLocationTestApp.apk";
+ private static final String WIFI_LOCATION_TEST_APP_PACKAGE_NAME =
+ "android.net.wifi.cts.app";
+ private static final String WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_ACTIVITY =
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".TriggerScanAndReturnStatusActivity";
+ private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_ACTIVITY =
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveScanResultsAndReturnStatusActivity";
+ private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_ACTIVITY =
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveConnectionInfoAndReturnStatusActivity";
+ private static final String WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_ACTIVITY =
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME + ".RetrieveTransportInfoAndReturnStatusActivity";
+
+ private static final int DURATION_MS = 10_000;
+ private static final int WIFI_CONNECT_TIMEOUT_MILLIS = 30_000;
+
+ @Rule
+ public final ActivityTestRule<WaitForResultActivity> mActivityRule =
+ new ActivityTestRule<>(WaitForResultActivity.class);
+
+ private static Context sContext;
+ private static WifiManager sWifiManager;
+ private static boolean sWasVerboseLoggingEnabled;
+ private static boolean sWasScanThrottleEnabled;
+ private static PowerManager sPower;
+ private static PowerManager.WakeLock sLock;
+
+ private static boolean sShouldRunTest = false;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ sContext = InstrumentationRegistry.getInstrumentation().getContext();
+ if (!WifiFeature.isWifiSupported(sContext)) {
+ return;
+ }
+ sShouldRunTest = true;
+
+ sWifiManager = sContext.getSystemService(WifiManager.class);
+ assertThat(sWifiManager).isNotNull();
+
+ // turn on verbose logging for tests
+ sWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isVerboseLoggingEnabled());
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setVerboseLoggingEnabled(true));
+ // Disable scan throttling for tests.
+ sWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.isScanThrottleEnabled());
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setScanThrottleEnabled(false));
+
+ // enable Wifi
+ if (!sWifiManager.isWifiEnabled()) setWifiEnabled(true);
+ PollingCheck.check("Wifi not enabled", DURATION_MS, () -> sWifiManager.isWifiEnabled());
+
+ // check we have >= 1 saved network
+ List<WifiConfiguration> savedNetworks = ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.getConfiguredNetworks());
+ assertWithMessage("Need at least one saved network").that(savedNetworks).isNotEmpty();
+
+ // ensure Wifi is connected
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.reconnect());
+ PollingCheck.check(
+ "Wifi not connected",
+ WIFI_CONNECT_TIMEOUT_MILLIS,
+ () -> sWifiManager.getConnectionInfo().getNetworkId() != -1);
+ sPower = sContext.getSystemService(PowerManager.class);
+ sLock = sPower.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+ turnScreenOn();
+ }
+
+ @Before
+ public void setUp() throws InterruptedException {
+ // skip the test if WiFi is not supported
+ assumeTrue(sShouldRunTest);
+ installApp(WIFI_LOCATION_TEST_APP_APK_PATH);
+
+ }
+
+ @After
+ public void teardown() throws InterruptedException {
+ if (!sShouldRunTest) {
+ return;
+ }
+ uninstallApp(WIFI_LOCATION_TEST_APP_PACKAGE_NAME);
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ if (!sShouldRunTest) return;
+ if (!sWifiManager.isWifiEnabled()) setWifiEnabled(true);
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setScanThrottleEnabled(sWasScanThrottleEnabled));
+ ShellIdentityUtils.invokeWithShellPermissions(
+ () -> sWifiManager.setVerboseLoggingEnabled(sWasVerboseLoggingEnabled));
+ }
+
+ private static void setWifiEnabled(boolean enable) throws Exception {
+ ShellIdentityUtils.invokeWithShellPermissions(() -> sWifiManager.setWifiEnabled(enable));
+ }
+
+ private static void turnScreenOn() throws Exception {
+ if (sLock.isHeld()) sLock.release();
+ SystemUtil.runShellCommand("input keyevent KEYCODE_WAKEUP");
+ SystemUtil.runShellCommand("wm dismiss-keyguard");
+ }
+
+ private static void installApp(String apk) throws InterruptedException {
+ String installResult = SystemUtil.runShellCommand("pm install -r -d " + apk);
+ assertThat(installResult.trim()).isEqualTo("Success");
+ }
+
+ private static void uninstallApp(String pkg) throws InterruptedException {
+ String uninstallResult = SystemUtil.runShellCommand(
+ "pm uninstall " + pkg);
+ assertThat(uninstallResult.trim()).isEqualTo("Success");
+ }
+
+ private void startFgActivityAndAssertStatusIs(
+ ComponentName componentName, boolean status) throws Exception {
+ turnScreenOn();
+
+ WaitForResultActivity activity = mActivityRule.getActivity();
+ activity.startActivityToWaitForResult(componentName);
+ assertThat(activity.waitForActivityResult(DURATION_MS)).isEqualTo(status);
+ }
+
+ private void triggerScanFgActivityAndAssertStatusIs(boolean status) throws Exception {
+ startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
+ WIFI_LOCATION_TEST_APP_TRIGGER_SCAN_ACTIVITY), status);
+ }
+
+ private void retrieveScanResultsFgActivityAndAssertStatusIs(boolean status) throws Exception {
+ startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
+ WIFI_LOCATION_TEST_APP_RETRIEVE_SCAN_RESULTS_ACTIVITY), status);
+ }
+
+ private void retrieveConnectionInfoFgActivityAndAssertStatusIs(boolean status)
+ throws Exception {
+ startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
+ WIFI_LOCATION_TEST_APP_RETRIEVE_CONNECTION_INFO_ACTIVITY), status);
+ }
+
+ private void retrieveTransportInfoFgActivityAndAssertStatusIs(boolean status)
+ throws Exception {
+ startFgActivityAndAssertStatusIs(new ComponentName(WIFI_LOCATION_TEST_APP_PACKAGE_NAME,
+ WIFI_LOCATION_TEST_APP_RETRIEVE_TRANSPORT_INFO_ACTIVITY), status);
+ }
+
+ @Test
+ public void testScanTriggerNotAllowedForForegroundActivityWithNoLocationPermission()
+ throws Exception {
+ triggerScanFgActivityAndAssertStatusIs(false);
+ }
+
+ @Test
+ public void testScanTriggerAllowedForForegroundActivityWithFineLocationPermission()
+ throws Exception {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
+ triggerScanFgActivityAndAssertStatusIs(true);
+ }
+
+ @Test
+ public void testScanResultsRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
+ throws Exception {
+ retrieveScanResultsFgActivityAndAssertStatusIs(false);
+ }
+
+ @Test
+ public void testScanResultsRetrievalAllowedForForegroundActivityWithFineLocationPermission()
+ throws Exception {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
+ retrieveScanResultsFgActivityAndAssertStatusIs(true);
+ }
+
+ @Test
+ public void testConnectionInfoRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
+ throws Exception {
+ retrieveConnectionInfoFgActivityAndAssertStatusIs(false);
+ }
+
+ @Test
+ public void testConnectionInfoRetrievalAllowedForForegroundActivityWithFineLocationPermission()
+ throws Exception {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
+ retrieveConnectionInfoFgActivityAndAssertStatusIs(true);
+ }
+
+ @SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
+ @Test
+ public void testTransportInfoRetrievalNotAllowedForForegroundActivityWithNoLocationPermission()
+ throws Exception {
+ retrieveTransportInfoFgActivityAndAssertStatusIs(false);
+ }
+
+ @SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
+ @Test
+ public void testTransportInfoRetrievalAllowedForForegroundActivityWithFineLocationPermission()
+ throws Exception {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation().grantRuntimePermission(
+ WIFI_LOCATION_TEST_APP_PACKAGE_NAME, ACCESS_FINE_LOCATION);
+ retrieveTransportInfoFgActivityAndAssertStatusIs(true);
+ }
+}
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
index ece91c27238..0d3033b08f1 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
@@ -5935,7 +5935,7 @@ public class WifiManagerTest extends WifiJUnit4TestBase {
try {
uiAutomation.adoptShellPermissionIdentity();
boolean enabled = DeviceConfig.getBoolean(DEVICE_CONFIG_NAMESPACE,
- "application_qos_policy_api_enabled", false);
+ "application_qos_policy_api_enabled", true);
// If the feature flag is disabled, verify that all policies are rejected.
if (!enabled) {
diff --git a/tools/cts-tradefed/Android.bp b/tools/cts-tradefed/Android.bp
index c0ae41a0c1e..b699bdec0f4 100644
--- a/tools/cts-tradefed/Android.bp
+++ b/tools/cts-tradefed/Android.bp
@@ -34,7 +34,7 @@ tradefed_binary_host {
wrapper: "etc/cts-tradefed",
short_name: "CTS",
full_name: "Compatibility Test Suite",
- version: "14_r1",
+ version: "14_r2",
static_libs: ["cts-tradefed-harness"],
required: ["compatibility-host-util"],
}