From 92e808e62a1ecdefa5d2a61302ee5d1b6c6f337d Mon Sep 17 00:00:00 2001 From: Tyler Dewey Date: Wed, 19 Feb 2025 12:28:00 +0000 Subject: Fix preference animations when expressive design is off. Modify SettingsPreferenceGroupAdapter to not impact things when its used while expressive design is off. Safety Center (and I think Settings app) currently use this adapter whether or not expressive design is enabled, and the class already has some handling for that case. Bug: 382425714 Test: manual and treehugger Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled Change-Id: I72846a75ef3adc9d16147fd3daff5b18c3d8c92a --- .../widget/SettingsPreferenceGroupAdapter.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt index 2672787a0519..d1c88de3f399 100644 --- a/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt +++ b/packages/SettingsLib/SettingsTheme/src/com/android/settingslib/widget/SettingsPreferenceGroupAdapter.kt @@ -71,18 +71,27 @@ open class SettingsPreferenceGroupAdapter(preferenceGroup: PreferenceGroup) : override fun onPreferenceHierarchyChange(preference: Preference) { super.onPreferenceHierarchyChange(preference) - // Post after super class has posted their sync runnable to update preferences. - mHandler.removeCallbacks(syncRunnable) - mHandler.post(syncRunnable) + if (SettingsThemeHelper.isExpressiveTheme(preference.context)) { + // Post after super class has posted their sync runnable to update preferences. + mHandler.removeCallbacks(syncRunnable) + mHandler.post(syncRunnable) + } } @SuppressLint("RestrictedApi") override fun onBindViewHolder(holder: PreferenceViewHolder, position: Int) { super.onBindViewHolder(holder, position) - updateBackground(holder, position) + + if (SettingsThemeHelper.isExpressiveTheme(holder.itemView.context)) { + updateBackground(holder, position) + } } private fun updatePreferencesList() { + if (!SettingsThemeHelper.isExpressiveTheme(mPreferenceGroup.context)) { + return + } + val oldList = ArrayList(mRoundCornerMappingList) mRoundCornerMappingList = ArrayList() mappingPreferenceGroup(mRoundCornerMappingList, mPreferenceGroup) -- cgit v1.2.3-59-g8ed1b From ad37fc770a21958ec238050279cd8fa739b95f84 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Sat, 15 Jun 2024 07:00:00 +0000 Subject: Swap sans-serif-medium for testing purpose Bug: 331949220 Test: atest android.theme.cts.ThemeHostTest Test: Done by Samsung Flag: EXEMPT bugfix Change-Id: Id969a2712fa93f60a142041038a8b247532fdfb0 --- graphics/java/android/graphics/Typeface.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index d1aca34c7b8d..39cd4a89aae6 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -80,6 +80,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.BiConsumer; /** * The Typeface class specifies the typeface and intrinsic style of a font. @@ -1550,14 +1551,21 @@ public class Typeface { setDefault(defaults.get(0)); ArrayList oldGenerics = new ArrayList<>(); - oldGenerics.add(sSystemFontMap.get("sans-serif")); - sSystemFontMap.put("sans-serif", genericFamilies.get(0)); + BiConsumer swapTypeface = (typeface, key) -> { + oldGenerics.add(sSystemFontMap.get(key)); + sSystemFontMap.put(key, typeface); + }; - oldGenerics.add(sSystemFontMap.get("serif")); - sSystemFontMap.put("serif", genericFamilies.get(1)); + Typeface sansSerif = genericFamilies.get(0); + swapTypeface.accept(sansSerif, "sans-serif"); + swapTypeface.accept(Typeface.create(sansSerif, 100, false), "sans-serif-thin"); + swapTypeface.accept(Typeface.create(sansSerif, 300, false), "sans-serif-light"); + swapTypeface.accept(Typeface.create(sansSerif, 500, false), "sans-serif-medium"); + swapTypeface.accept(Typeface.create(sansSerif, 700, false), "sans-serif-bold"); + swapTypeface.accept(Typeface.create(sansSerif, 900, false), "sans-serif-black"); - oldGenerics.add(sSystemFontMap.get("monospace")); - sSystemFontMap.put("monospace", genericFamilies.get(2)); + swapTypeface.accept(genericFamilies.get(1), "serif"); + swapTypeface.accept(genericFamilies.get(2), "monospace"); return new Pair<>(oldDefaults, oldGenerics); } -- cgit v1.2.3-59-g8ed1b From 3d9e4a555b1b1ed00097a3301aa11e5102fc002c Mon Sep 17 00:00:00 2001 From: chelseahao Date: Tue, 11 Mar 2025 11:45:37 +0800 Subject: Fix accessibility issue. User primary color in the loading bar to increase contrast. Only affecting the progress bar in internet and bt qs dialog. Test: atest Flag: EXEMPT minor visual change Bug: 379998489 Change-Id: Ia54f52a0c4236d1973a777e63cd65259afc8d86c --- .../vector_drawable_progress_indeterminate_horizontal_trimmed.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml b/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml index aec204f45aa7..7f6dc49505bb 100644 --- a/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml +++ b/packages/SystemUI/res/drawable/vector_drawable_progress_indeterminate_horizontal_trimmed.xml @@ -38,7 +38,7 @@ + android:fillColor="@androidprv:color/materialColorPrimary" /> \ No newline at end of file -- cgit v1.2.3-59-g8ed1b From efe0b92d409f4c49c41a29a771e363b6485578b9 Mon Sep 17 00:00:00 2001 From: Kazuki Takise Date: Fri, 7 Mar 2025 18:00:38 +0900 Subject: Maintain CompatUIInfo in CompatUIController CompatUIInfo (esp. TaskListener) is needed for DisplayCompatShowRestartDialog, but WindowDecoration, which invokes the functionality, doens't have access to TaskListener. Initially we proposed the approach to expose ShellTaskOrg#getTaskListener() but as TaskListener is already exposed with onCompatInfoChanged(), it turns out they asked us to reuse it. This change adds mTaskIdToCompatUIInfoMap in CompatUIInfo for this purpose. Flag: com.android.window.flags.enable_restart_menu_for_connected_displays Bug: 32086679 Test: CompatUIControllerTest Change-Id: I222ef8680907e77f752448f902f98f3b4c646c39 --- .../wm/shell/compatui/CompatUIController.java | 17 ++++++++++++- .../wm/shell/compatui/impl/CompatUIRequests.kt | 5 +--- .../wm/shell/compatui/CompatUIControllerTest.java | 29 ++++++++++++++-------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java index 4413c8715c0d..d5f4a3885dbb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIController.java @@ -111,6 +111,12 @@ public class CompatUIController implements OnDisplaysChangedListener, private final SparseArray mTaskIdToRestartDialogWindowManagerMap = new SparseArray<>(0); + /** + * {@link SparseArray} that maps task ids to {@link CompatUIInfo}. + */ + private final SparseArray mTaskIdToCompatUIInfoMap = + new SparseArray<>(0); + /** * {@link Set} of task ids for which we need to display a restart confirmation dialog */ @@ -261,7 +267,11 @@ public class CompatUIController implements OnDisplaysChangedListener, private void handleDisplayCompatShowRestartDialog( CompatUIRequests.DisplayCompatShowRestartDialog request) { - onRestartButtonClicked(new Pair<>(request.getTaskInfo(), request.getTaskListener())); + final CompatUIInfo compatUIInfo = mTaskIdToCompatUIInfoMap.get(request.getTaskId()); + if (compatUIInfo == null) { + return; + } + onRestartButtonClicked(new Pair<>(compatUIInfo.getTaskInfo(), compatUIInfo.getListener())); } /** @@ -273,6 +283,11 @@ public class CompatUIController implements OnDisplaysChangedListener, public void onCompatInfoChanged(@NonNull CompatUIInfo compatUIInfo) { final TaskInfo taskInfo = compatUIInfo.getTaskInfo(); final ShellTaskOrganizer.TaskListener taskListener = compatUIInfo.getListener(); + if (taskListener == null) { + mTaskIdToCompatUIInfoMap.delete(taskInfo.taskId); + } else { + mTaskIdToCompatUIInfoMap.put(taskInfo.taskId, compatUIInfo); + } final boolean isInDisplayCompatMode = taskInfo.appCompatTaskInfo.isRestartMenuEnabledForDisplayMove(); if (taskInfo != null && !taskInfo.appCompatTaskInfo.isTopActivityInSizeCompat() diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt index da4fc99491dc..b7af596ee0ae 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/impl/CompatUIRequests.kt @@ -16,8 +16,6 @@ package com.android.wm.shell.compatui.impl -import android.app.TaskInfo -import com.android.wm.shell.ShellTaskOrganizer import com.android.wm.shell.compatui.api.CompatUIRequest internal const val DISPLAY_COMPAT_SHOW_RESTART_DIALOG = 0 @@ -27,7 +25,6 @@ internal const val DISPLAY_COMPAT_SHOW_RESTART_DIALOG = 0 */ sealed class CompatUIRequests(override val requestId: Int) : CompatUIRequest { /** Sent when the restart handle menu is clicked, and a restart dialog is requested. */ - data class DisplayCompatShowRestartDialog(val taskInfo: TaskInfo, - val taskListener: ShellTaskOrganizer.TaskListener) : + data class DisplayCompatShowRestartDialog(val taskId: Int) : CompatUIRequests(DISPLAY_COMPAT_SHOW_RESTART_DIALOG) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java index 597e4a55ed0e..9035df28aa7c 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/CompatUIControllerTest.java @@ -680,7 +680,8 @@ public class CompatUIControllerTest extends ShellTestCase { // Create transparent task final TaskInfo taskInfo1 = createTaskInfo(DISPLAY_ID, newTaskId, /* hasSizeCompat= */ true, - /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ true); + /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ true, + /* isRestartMenuEnabledForDisplayMove */ true); // Simulate new task being shown mController.updateActiveTaskInfo(taskInfo1); @@ -742,32 +743,38 @@ public class CompatUIControllerTest extends ShellTestCase { @Test @RequiresFlagsDisabled(Flags.FLAG_APP_COMPAT_UI_FRAMEWORK) public void testSendCompatUIRequest_createRestartDialog() { - TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ false); - doReturn(true).when(mMockRestartDialogLayout) - .needsToBeRecreated(any(TaskInfo.class), - any(ShellTaskOrganizer.TaskListener.class)); + final TaskInfo taskInfo = createTaskInfo(DISPLAY_ID, TASK_ID, /* hasSizeCompat= */ true, + /* isVisible */ true, /* isFocused */ true, /* isTopActivityTransparent */ false, + /* isRestartMenuEnabledForDisplayMove */ true); doReturn(true).when(mCompatUIConfiguration).isRestartDialogEnabled(); doReturn(true).when(mCompatUIConfiguration).shouldShowRestartDialogAgain(eq(taskInfo)); - mController.sendCompatUIRequest(new CompatUIRequests.DisplayCompatShowRestartDialog( - taskInfo, mMockTaskListener)); + mController.onCompatInfoChanged(new CompatUIInfo(taskInfo, mMockTaskListener)); verify(mController).createRestartDialogWindowManager(any(), eq(taskInfo), eq(mMockTaskListener)); + verify(mMockRestartDialogLayout).setRequestRestartDialog(false); + + mController.sendCompatUIRequest( + new CompatUIRequests.DisplayCompatShowRestartDialog(taskInfo.taskId)); + verify(mMockRestartDialogLayout).setRequestRestartDialog(true); } private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat) { return createTaskInfo(displayId, taskId, hasSizeCompat, /* isVisible */ false, - /* isFocused */ false, /* isTopActivityTransparent */ false); + /* isFocused */ false, /* isTopActivityTransparent */ false, + /* isRestartMenuEnabledForDisplayMove */ false); } private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat, boolean isVisible, boolean isFocused) { return createTaskInfo(displayId, taskId, hasSizeCompat, - isVisible, isFocused, /* isTopActivityTransparent */ false); + isVisible, isFocused, /* isTopActivityTransparent */ false, + /* isRestartMenuEnabledForDisplayMove */ false); } private static TaskInfo createTaskInfo(int displayId, int taskId, boolean hasSizeCompat, - boolean isVisible, boolean isFocused, boolean isTopActivityTransparent) { + boolean isVisible, boolean isFocused, boolean isTopActivityTransparent, + boolean isRestartMenuEnabledForDisplayMove) { RunningTaskInfo taskInfo = new RunningTaskInfo(); taskInfo.taskId = taskId; taskInfo.displayId = displayId; @@ -777,6 +784,8 @@ public class CompatUIControllerTest extends ShellTestCase { taskInfo.isTopActivityTransparent = isTopActivityTransparent; taskInfo.appCompatTaskInfo.setLetterboxEducationEnabled(true); taskInfo.appCompatTaskInfo.setTopActivityLetterboxed(true); + taskInfo.appCompatTaskInfo.setRestartMenuEnabledForDisplayMove( + isRestartMenuEnabledForDisplayMove); return taskInfo; } } -- cgit v1.2.3-59-g8ed1b From b0d729f4abd7256f75ff88ebc77a585726422122 Mon Sep 17 00:00:00 2001 From: nayanrath Date: Tue, 11 Mar 2025 11:05:33 -0700 Subject: Adding Dark or Transparent theme for the splash screen of Credential Manager BUG: 379815309 Test: manual After: http://b/379815309#attachment63533070 (cherry picked from https://partner-android-review.googlesource.com/q/commit:9ad18b8a967cac8ae1c081f93ed605249bc9c78d) Merged-In: Ie0ede038228b2c30d65e8a5e7fa80369487261ed Change-Id: Ie0ede038228b2c30d65e8a5e7fa80369487261ed --- .../CredentialManager/wear/AndroidManifest.xml | 6 ++++-- .../CredentialManager/wear/res/values/themes.xml | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 packages/CredentialManager/wear/res/values/themes.xml diff --git a/packages/CredentialManager/wear/AndroidManifest.xml b/packages/CredentialManager/wear/AndroidManifest.xml index b480ac30d2cb..c91bf13bf98e 100644 --- a/packages/CredentialManager/wear/AndroidManifest.xml +++ b/packages/CredentialManager/wear/AndroidManifest.xml @@ -32,7 +32,8 @@ android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:label="@string/app_name" - android:supportsRtl="true"> + android:supportsRtl="true" + android:theme="@style/Theme.CredentialSelector"> @@ -42,7 +43,8 @@ android:exported="true" android:label="@string/app_name" android:launchMode="singleTop" - android:permission="android.permission.LAUNCH_CREDENTIAL_SELECTOR" /> + android:permission="android.permission.LAUNCH_CREDENTIAL_SELECTOR" + android:theme="@style/Theme.CredentialSelector"/> diff --git a/packages/CredentialManager/wear/res/values/themes.xml b/packages/CredentialManager/wear/res/values/themes.xml new file mode 100644 index 000000000000..22329e9ff2ce --- /dev/null +++ b/packages/CredentialManager/wear/res/values/themes.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file -- cgit v1.2.3-59-g8ed1b From edf4c63b34efef9c56c83088a23feb137e9c6beb Mon Sep 17 00:00:00 2001 From: Yiyi Shen Date: Tue, 21 Jan 2025 15:43:56 +0800 Subject: [Audiosharing] Use getBroadcastToUnicastFallbackGroup to get primary Flag: com.android.settingslib.flags.adopt_primary_group_management_api_v2 Test: atest Bug: 397568136 Change-Id: I49bf1148ab2e78633f35311282f3c61e476b7b51 --- .../settingslib/bluetooth/BluetoothUtils.java | 28 ++++++++- .../bluetooth/CachedBluetoothDevice.java | 2 +- .../settingslib/bluetooth/BluetoothUtilsTest.java | 52 +++++++++++++++- .../bluetooth/CachedBluetoothDeviceTest.java | 69 ++++++++++++++++++++++ 4 files changed, 145 insertions(+), 6 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index ae9ad958b287..33dcb051d194 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -1068,18 +1068,42 @@ public class BluetoothUtils { /** Get primary device Uri in broadcast. */ @NonNull public static String getPrimaryGroupIdUriForBroadcast() { + // TODO: once API is stable, deprecate SettingsProvider solution return "bluetooth_le_broadcast_fallback_active_group_id"; } - /** Get primary device group id in broadcast. */ + /** Get primary device group id in broadcast from SettingsProvider. */ @WorkerThread public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver) { + // TODO: once API is stable, deprecate SettingsProvider solution return Settings.Secure.getInt( contentResolver, getPrimaryGroupIdUriForBroadcast(), BluetoothCsipSetCoordinator.GROUP_ID_INVALID); } + /** + * Get primary device group id in broadcast. + * + * If Flags.adoptPrimaryGroupManagementApiV2 is enabled, get group id by API, + * Otherwise, still get value from SettingsProvider. + */ + @WorkerThread + public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver, + @Nullable LocalBluetoothManager manager) { + if (Flags.adoptPrimaryGroupManagementApiV2()) { + LeAudioProfile leaProfile = manager == null ? null : + manager.getProfileManager().getLeAudioProfile(); + if (leaProfile == null) { + Log.d(TAG, "getPrimaryGroupIdForBroadcast: profile is null"); + return BluetoothCsipSetCoordinator.GROUP_ID_INVALID; + } + return leaProfile.getBroadcastToUnicastFallbackGroup(); + } else { + return getPrimaryGroupIdForBroadcast(contentResolver); + } + } + /** Get develop option value for audio sharing preview. */ @WorkerThread public static boolean getAudioSharingPreviewValue(@Nullable ContentResolver contentResolver) { @@ -1101,7 +1125,7 @@ public class BluetoothUtils { LocalBluetoothLeBroadcast broadcast = localBtManager.getProfileManager().getLeAudioBroadcastProfile(); if (broadcast == null || !broadcast.isEnabled(null)) return null; - int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver); + int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver, localBtManager); if (primaryGroupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) return null; LocalBluetoothLeBroadcastAssistant assistant = localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 5f88bcd8d65d..4de313cb8e8b 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -1358,7 +1358,7 @@ public class CachedBluetoothDevice implements Comparable // Gets summary for the buds which are in the audio sharing. int groupId = BluetoothUtils.getGroupId(this); int primaryGroupId = BluetoothUtils.getPrimaryGroupIdForBroadcast( - mContext.getContentResolver()); + mContext.getContentResolver(), mBluetoothManager); if ((primaryGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) ? (groupId == primaryGroupId) : isActiveDevice(BluetoothProfile.LE_AUDIO)) { // The buds are primary buds diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java index b7814127b716..8fc4aa81b53f 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java @@ -936,15 +936,60 @@ public class BluetoothUtilsTest { } @Test + @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) + public void getSecondaryDeviceForBroadcast_adoptAPI_noSecondary_returnNull() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1); + when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mCachedBluetoothDevice.getGroupId()).thenReturn(1); + BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); + when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(state)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mBluetoothDevice)); + + assertThat( + BluetoothUtils.getSecondaryDeviceForBroadcast( + mContext.getContentResolver(), mLocalBluetoothManager)) + .isNull(); + } + + @Test + @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) + public void getSecondaryDeviceForBroadcast_adoptAPI_returnCorrectDevice() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1); + CachedBluetoothDevice cachedBluetoothDevice = mock(CachedBluetoothDevice.class); + BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); + when(cachedBluetoothDevice.getDevice()).thenReturn(bluetoothDevice); + when(cachedBluetoothDevice.getGroupId()).thenReturn(1); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mCachedBluetoothDevice.getGroupId()).thenReturn(2); + when(mDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedBluetoothDevice); + when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); + BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); + List bisSyncState = new ArrayList<>(); + bisSyncState.add(1L); + when(state.getBisSyncState()).thenReturn(bisSyncState); + when(mAssistant.getAllSources(any(BluetoothDevice.class))) + .thenReturn(ImmutableList.of(state)); + when(mAssistant.getAllConnectedDevices()) + .thenReturn(ImmutableList.of(mBluetoothDevice, bluetoothDevice)); + + assertThat( + BluetoothUtils.getSecondaryDeviceForBroadcast( + mContext.getContentResolver(), mLocalBluetoothManager)) + .isEqualTo(mCachedBluetoothDevice); + } + + @Test + @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) public void getSecondaryDeviceForBroadcast_noSecondary_returnNull() { Settings.Secure.putInt( mContext.getContentResolver(), BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), 1); when(mBroadcast.isEnabled(any())).thenReturn(true); - CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class); - when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager); - when(deviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); + when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getGroupId()).thenReturn(1); BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class); @@ -958,6 +1003,7 @@ public class BluetoothUtilsTest { } @Test + @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) public void getSecondaryDeviceForBroadcast_returnCorrectDevice() { Settings.Secure.putInt( mContext.getContentResolver(), diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index f57ee0c0930e..e29adc151a28 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -42,6 +42,8 @@ import android.content.Context; import android.graphics.drawable.BitmapDrawable; import android.hardware.input.InputManager; import android.media.AudioManager; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import android.text.Spannable; @@ -163,6 +165,7 @@ public class CachedBluetoothDeviceTest { when(mHidProfile.getProfileId()).thenReturn(BluetoothProfile.HID_HOST); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager); when(mBroadcast.isEnabled(any())).thenReturn(false); + when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile); when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); mCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mDevice)); @@ -2004,6 +2007,70 @@ public class CachedBluetoothDeviceTest { } @Test + @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) + public void getConnectionSummary_adoptAPI_isBroadcastPrimary_fallbackDevice_returnActive() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + when(mCachedDevice.getDevice()).thenReturn(mDevice); + when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1); + + List bisSyncState = new ArrayList<>(); + bisSyncState.add(1L); + when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); + List sourceList = new ArrayList<>(); + sourceList.add(mLeBroadcastReceiveState); + when(mAssistant.getAllSources(any())).thenReturn(sourceList); + + when(mCachedDevice.getGroupId()).thenReturn(1); + + assertThat(mCachedDevice.getConnectionSummary(false)) + .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level)); + } + + @Test + @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) + public void getConnectionSummary_adoptAPI_isBroadcastPrimary_activeDevice_returnActive() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + when(mCachedDevice.getDevice()).thenReturn(mDevice); + when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn( + BluetoothCsipSetCoordinator.GROUP_ID_INVALID); + + List bisSyncState = new ArrayList<>(); + bisSyncState.add(1L); + when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); + List sourceList = new ArrayList<>(); + sourceList.add(mLeBroadcastReceiveState); + when(mAssistant.getAllSources(any())).thenReturn(sourceList); + + when(mCachedDevice.getGroupId()).thenReturn(1); + when(mCachedDevice.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true); + + assertThat(mCachedDevice.getConnectionSummary(false)) + .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level)); + } + + @Test + @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) + public void getConnectionSummary_adoptAPI_isBroadcastNotPrimary_returnActiveMedia() { + when(mBroadcast.isEnabled(any())).thenReturn(true); + when(mCachedDevice.getDevice()).thenReturn(mDevice); + when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1); + + List bisSyncState = new ArrayList<>(); + bisSyncState.add(1L); + when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); + List sourceList = new ArrayList<>(); + sourceList.add(mLeBroadcastReceiveState); + when(mAssistant.getAllSources(any())).thenReturn(sourceList); + + when(mCachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID); + + assertThat(mCachedDevice.getConnectionSummary(false)) + .isEqualTo( + mContext.getString(R.string.bluetooth_active_media_only_no_battery_level)); + } + + @Test + @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) public void getConnectionSummary_isBroadcastPrimary_fallbackDevice_returnActive() { when(mBroadcast.isEnabled(any())).thenReturn(true); when(mCachedDevice.getDevice()).thenReturn(mDevice); @@ -2026,6 +2093,7 @@ public class CachedBluetoothDeviceTest { } @Test + @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) public void getConnectionSummary_isBroadcastPrimary_activeDevice_returnActive() { when(mBroadcast.isEnabled(any())).thenReturn(true); when(mCachedDevice.getDevice()).thenReturn(mDevice); @@ -2049,6 +2117,7 @@ public class CachedBluetoothDeviceTest { } @Test + @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2) public void getConnectionSummary_isBroadcastNotPrimary_returnActiveMedia() { when(mBroadcast.isEnabled(any())).thenReturn(true); when(mCachedDevice.getDevice()).thenReturn(mDevice); -- cgit v1.2.3-59-g8ed1b From 3a0ce1930fabf2c9ab4510849553753453ea744c Mon Sep 17 00:00:00 2001 From: Marvin Ramin Date: Tue, 4 Mar 2025 14:46:15 +0100 Subject: Move MediaProjectionStoppingTest to internal instrumentation tests Bug: 400932931 Test: atest MediaProjectionStoppingTest Flag: TEST_ONLY Change-Id: I7df5bb1426c7f1f58b89d1704d03c25d14606a1f --- media/tests/projection/Android.bp | 8 +- media/tests/projection/AndroidManifest.xml | 2 + media/tests/projection/AndroidTest.xml | 9 + .../projection/MediaProjectionStoppingTest.java | 293 +++++++++++++++++++++ 4 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 media/tests/projection/src/android/media/projection/MediaProjectionStoppingTest.java diff --git a/media/tests/projection/Android.bp b/media/tests/projection/Android.bp index 94db2c02eb28..48621e4e2094 100644 --- a/media/tests/projection/Android.bp +++ b/media/tests/projection/Android.bp @@ -16,7 +16,6 @@ android_test { name: "MediaProjectionTests", srcs: ["**/*.java"], - libs: [ "android.test.base.stubs.system", "android.test.mock.stubs.system", @@ -30,6 +29,7 @@ android_test { "frameworks-base-testutils", "mockito-target-extended-minus-junit4", "platform-test-annotations", + "cts-mediaprojection-common", "testng", "testables", "truth", @@ -42,7 +42,11 @@ android_test { "libstaticjvmtiagent", ], - test_suites: ["device-tests"], + data: [ + ":CtsMediaProjectionTestCasesHelperApp", + ], + + test_suites: ["general-tests"], platform_apis: true, diff --git a/media/tests/projection/AndroidManifest.xml b/media/tests/projection/AndroidManifest.xml index 0c9760400ce0..514fb5f689c9 100644 --- a/media/tests/projection/AndroidManifest.xml +++ b/media/tests/projection/AndroidManifest.xml @@ -20,6 +20,8 @@ android:sharedUserId="com.android.uid.test"> + + diff --git a/media/tests/projection/AndroidTest.xml b/media/tests/projection/AndroidTest.xml index f64930a0eb3f..99b42d1cd263 100644 --- a/media/tests/projection/AndroidTest.xml +++ b/media/tests/projection/AndroidTest.xml @@ -22,6 +22,15 @@