diff options
19 files changed, 459 insertions, 223 deletions
diff --git a/core/java/android/content/pm/UserProperties.java b/core/java/android/content/pm/UserProperties.java index 1d4403cb79e8..8e02ffd64e02 100644 --- a/core/java/android/content/pm/UserProperties.java +++ b/core/java/android/content/pm/UserProperties.java @@ -16,9 +16,11 @@ package android.content.pm; +import android.Manifest; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.TestApi; @@ -513,6 +515,7 @@ public final class UserProperties implements Parcelable { * Note that, internally, this does not perform an exact copy. * @hide */ + @SuppressLint("MissingPermission") public UserProperties(UserProperties orig, boolean exposeAllFields, boolean hasManagePermission, @@ -614,12 +617,10 @@ public final class UserProperties implements Parcelable { * {@link #SHOW_IN_SETTINGS_SEPARATE}, * and {@link #SHOW_IN_SETTINGS_NO}. * - * <p> The caller must have {@link android.Manifest.permission#MANAGE_USERS} to query this - * property. - * * @return whether, and how, a profile should be shown in the Settings. * @hide */ + @RequiresPermission(Manifest.permission.MANAGE_USERS) public @ShowInSettings int getShowInSettings() { if (isPresent(INDEX_SHOW_IN_SETTINGS)) return mShowInSettings; if (mDefaultProperties != null) return mDefaultProperties.mShowInSettings; @@ -690,6 +691,8 @@ public final class UserProperties implements Parcelable { /** * Returns whether a profile should be started when its parent starts (unless in quiet mode). * This only applies for users that have parents (i.e. for profiles). + * + * Only available to the SYSTEM uid. * @hide */ public boolean getStartWithParent() { @@ -708,6 +711,8 @@ public final class UserProperties implements Parcelable { * Returns whether an app in the profile should be deleted when the same package in * the parent user is being deleted. * This only applies for users that have parents (i.e. for profiles). + * + * Only available to the SYSTEM uid. * @hide */ public boolean getDeleteAppWithParent() { @@ -726,6 +731,8 @@ public final class UserProperties implements Parcelable { * Returns whether the user should always * be {@link android.os.UserManager#isUserVisible() visible}. * The intended usage is for the Communal Profile, which is running and accessible at all times. + * + * Only available to the SYSTEM uid. * @hide */ public boolean getAlwaysVisible() { @@ -747,6 +754,7 @@ public final class UserProperties implements Parcelable { * Possible return values include * {@link #INHERIT_DEVICE_POLICY_FROM_PARENT} or {@link #INHERIT_DEVICE_POLICY_NO} * + * Only available to the SYSTEM uid. * @hide */ public @InheritDevicePolicy int getInheritDevicePolicy() { @@ -777,6 +785,7 @@ public final class UserProperties implements Parcelable { * @return whether contacts access from an associated profile is enabled for the user * @hide */ + @RequiresPermission(Manifest.permission.MANAGE_USERS) public boolean getUseParentsContacts() { if (isPresent(INDEX_USE_PARENTS_CONTACTS)) return mUseParentsContacts; if (mDefaultProperties != null) return mDefaultProperties.mUseParentsContacts; @@ -796,7 +805,9 @@ public final class UserProperties implements Parcelable { /** * Returns true if user needs to update default - * {@link com.android.server.pm.CrossProfileIntentFilter} with its parents during an OTA update + * {@link com.android.server.pm.CrossProfileIntentFilter} with its parents during an OTA update. + * + * Only available to the SYSTEM uid. * @hide */ public boolean getUpdateCrossProfileIntentFiltersOnOTA() { @@ -863,6 +874,7 @@ public final class UserProperties implements Parcelable { * checks is not guaranteed when the property is false and may vary depending on user types. * @hide */ + @RequiresPermission(Manifest.permission.MANAGE_USERS) public boolean isAuthAlwaysRequiredToDisableQuietMode() { if (isPresent(INDEX_AUTH_ALWAYS_REQUIRED_TO_DISABLE_QUIET_MODE)) { return mAuthAlwaysRequiredToDisableQuietMode; @@ -894,6 +906,8 @@ public final class UserProperties implements Parcelable { * locking for a user can happen if either the device configuration is set or if this property * is set. When both, the config and the property value is false, the user storage is always * locked when the user is stopped. + * + * Only available to the SYSTEM uid. * @hide */ public boolean getAllowStoppingUserWithDelayedLocking() { @@ -915,6 +929,8 @@ public final class UserProperties implements Parcelable { /** * Returns the user's {@link CrossProfileIntentFilterAccessControlLevel}. + * + * Only available to the SYSTEM uid. * @hide */ public @CrossProfileIntentFilterAccessControlLevel int @@ -944,6 +960,7 @@ public final class UserProperties implements Parcelable { * Returns the user's {@link CrossProfileIntentResolutionStrategy}. * @return user's {@link CrossProfileIntentResolutionStrategy}. * + * Only available to the SYSTEM uid. * @hide */ public @CrossProfileIntentResolutionStrategy int getCrossProfileIntentResolutionStrategy() { @@ -1052,32 +1069,47 @@ public final class UserProperties implements Parcelable { @Override public String toString() { + StringBuilder s = new StringBuilder(); + s.append("UserProperties{"); + s.append("mPropertiesPresent="); s.append(Long.toBinaryString(mPropertiesPresent)); + try { + s.append(listPropertiesAsStringBuilder()); + } catch (SecurityException e) { + // Caller doesn't have permission to see all the properties. Just don't share them. + } + s.append("}"); + return s.toString(); + } + + private StringBuilder listPropertiesAsStringBuilder() { + final StringBuilder s = new StringBuilder(); + // Please print in increasing order of PropertyIndex. - return "UserProperties{" - + "mPropertiesPresent=" + Long.toBinaryString(mPropertiesPresent) - + ", mShowInLauncher=" + getShowInLauncher() - + ", mStartWithParent=" + getStartWithParent() - + ", mShowInSettings=" + getShowInSettings() - + ", mInheritDevicePolicy=" + getInheritDevicePolicy() - + ", mUseParentsContacts=" + getUseParentsContacts() - + ", mUpdateCrossProfileIntentFiltersOnOTA=" - + getUpdateCrossProfileIntentFiltersOnOTA() - + ", mCrossProfileIntentFilterAccessControl=" - + getCrossProfileIntentFilterAccessControl() - + ", mCrossProfileIntentResolutionStrategy=" - + getCrossProfileIntentResolutionStrategy() - + ", mMediaSharedWithParent=" + isMediaSharedWithParent() - + ", mCredentialShareableWithParent=" + isCredentialShareableWithParent() - + ", mAuthAlwaysRequiredToDisableQuietMode=" - + isAuthAlwaysRequiredToDisableQuietMode() - + ", mAllowStoppingUserWithDelayedLocking=" - + getAllowStoppingUserWithDelayedLocking() - + ", mDeleteAppWithParent=" + getDeleteAppWithParent() - + ", mAlwaysVisible=" + getAlwaysVisible() - + ", mCrossProfileContentSharingStrategy=" + getCrossProfileContentSharingStrategy() - + ", mProfileApiVisibility=" + getProfileApiVisibility() - + ", mItemsRestrictedOnHomeScreen=" + areItemsRestrictedOnHomeScreen() - + "}"; + s.append(", mShowInLauncher="); s.append(getShowInLauncher()); + s.append(", mStartWithParent="); s.append(getStartWithParent()); + s.append(", mShowInSettings="); s.append(getShowInSettings()); + s.append(", mInheritDevicePolicy="); s.append(getInheritDevicePolicy()); + s.append(", mUseParentsContacts="); s.append(getUseParentsContacts()); + s.append(", mUpdateCrossProfileIntentFiltersOnOTA="); + s.append(getUpdateCrossProfileIntentFiltersOnOTA()); + s.append(", mCrossProfileIntentFilterAccessControl="); + s.append(getCrossProfileIntentFilterAccessControl()); + s.append(", mCrossProfileIntentResolutionStrategy="); + s.append(getCrossProfileIntentResolutionStrategy()); + s.append(", mMediaSharedWithParent="); s.append(isMediaSharedWithParent()); + s.append(", mCredentialShareableWithParent="); s.append(isCredentialShareableWithParent()); + s.append(", mAuthAlwaysRequiredToDisableQuietMode="); + s.append(isAuthAlwaysRequiredToDisableQuietMode()); + s.append(", mAllowStoppingUserWithDelayedLocking="); + s.append(getAllowStoppingUserWithDelayedLocking()); + s.append(", mDeleteAppWithParent="); s.append(getDeleteAppWithParent()); + s.append(", mAlwaysVisible="); s.append(getAlwaysVisible()); + s.append(", mCrossProfileContentSharingStrategy="); + s.append(getCrossProfileContentSharingStrategy()); + s.append(", mProfileApiVisibility="); s.append(getProfileApiVisibility()); + s.append(", mItemsRestrictedOnHomeScreen="); s.append(areItemsRestrictedOnHomeScreen()); + + return s; } /** diff --git a/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioAlertUnitTest.java b/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioAlertUnitTest.java index 7afdde244073..9cfb9afa2865 100644 --- a/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioAlertUnitTest.java +++ b/core/tests/BroadcastRadioTests/src/android/hardware/radio/RadioAlertUnitTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertThrows; import android.os.Parcel; import android.platform.test.annotations.EnableFlags; +import com.google.common.primitives.Ints; import com.google.common.truth.Expect; import org.junit.Rule; @@ -34,6 +35,20 @@ public final class RadioAlertUnitTest { private static final int TEST_FLAGS = 0; private static final int CREATOR_ARRAY_SIZE = 3; + private static final int TEST_STATUS = RadioAlert.STATUS_ACTUAL; + private static final int TEST_TYPE = RadioAlert.MESSAGE_TYPE_ALERT; + private static final int[] TEST_CATEGORIES_1 = new int[]{RadioAlert.CATEGORY_CBRNE, + RadioAlert.CATEGORY_GEO}; + private static final int[] TEST_CATEGORIES_2 = new int[]{RadioAlert.CATEGORY_CBRNE, + RadioAlert.CATEGORY_FIRE}; + private static final int TEST_URGENCY_1 = RadioAlert.URGENCY_EXPECTED; + private static final int TEST_URGENCY_2 = RadioAlert.URGENCY_FUTURE; + private static final int TEST_SEVERITY_1 = RadioAlert.SEVERITY_SEVERE; + private static final int TEST_SEVERITY_2 = RadioAlert.SEVERITY_MODERATE; + private static final int TEST_CERTAINTY_1 = RadioAlert.CERTAINTY_POSSIBLE; + private static final int TEST_CERTAINTY_2 = RadioAlert.CERTAINTY_UNLIKELY; + private static final String TEST_DESCRIPTION_MESSAGE_1 = "Test Alert Description Message 1."; + private static final String TEST_DESCRIPTION_MESSAGE_2 = "Test Alert Description Message 2."; private static final String TEST_GEOCODE_VALUE_NAME = "SAME"; private static final String TEST_GEOCODE_VALUE_1 = "006109"; private static final String TEST_GEOCODE_VALUE_2 = "006009"; @@ -54,6 +69,18 @@ public final class RadioAlertUnitTest { List.of(TEST_POLYGON), List.of(TEST_GEOCODE_1)); private static final RadioAlert.AlertArea TEST_AREA_2 = new RadioAlert.AlertArea( new ArrayList<>(), List.of(TEST_GEOCODE_1, TEST_GEOCODE_2)); + private static final List<RadioAlert.AlertArea> TEST_AREA_LIST_1 = List.of(TEST_AREA_1); + private static final List<RadioAlert.AlertArea> TEST_AREA_LIST_2 = List.of(TEST_AREA_2); + private static final String TEST_LANGUAGE_1 = "en-US"; + + private static final RadioAlert.AlertInfo TEST_ALERT_INFO_1 = new RadioAlert.AlertInfo( + TEST_CATEGORIES_1, TEST_URGENCY_1, TEST_SEVERITY_1, TEST_CERTAINTY_1, + TEST_DESCRIPTION_MESSAGE_1, TEST_AREA_LIST_1, TEST_LANGUAGE_1); + private static final RadioAlert.AlertInfo TEST_ALERT_INFO_2 = new RadioAlert.AlertInfo( + TEST_CATEGORIES_2, TEST_URGENCY_2, TEST_SEVERITY_2, TEST_CERTAINTY_2, + TEST_DESCRIPTION_MESSAGE_2, TEST_AREA_LIST_2, /* language= */ null); + private static final RadioAlert TEST_ALERT = new RadioAlert(TEST_STATUS, TEST_TYPE, + List.of(TEST_ALERT_INFO_1, TEST_ALERT_INFO_2)); @Rule public final Expect mExpect = Expect.create(); @@ -374,4 +401,209 @@ public final class RadioAlertUnitTest { mExpect.withMessage("Non-alert-area object").that(TEST_AREA_1) .isNotEqualTo(TEST_GEOCODE_1); } + + @Test + public void constructor_withNullCategories_forAlertInfo_fails() { + NullPointerException thrown = assertThrows(NullPointerException.class, () -> + new RadioAlert.AlertInfo(/* categories= */ null, TEST_URGENCY_1, TEST_SEVERITY_1, + TEST_CERTAINTY_1, TEST_DESCRIPTION_MESSAGE_1, TEST_AREA_LIST_1, + TEST_LANGUAGE_1)); + + mExpect.withMessage("Exception for alert info constructor with null categories") + .that(thrown).hasMessageThat().contains("Categories can not be null"); + } + + @Test + public void constructor_withNullAreaList_forAlertInfo_fails() { + NullPointerException thrown = assertThrows(NullPointerException.class, () -> + new RadioAlert.AlertInfo(TEST_CATEGORIES_1, TEST_URGENCY_1, TEST_SEVERITY_1, + TEST_CERTAINTY_1, TEST_DESCRIPTION_MESSAGE_1, /* areaList= */ null, + TEST_LANGUAGE_1)); + + mExpect.withMessage("Exception for alert info constructor with null area list") + .that(thrown).hasMessageThat().contains("Area list can not be null"); + } + + @Test + public void getCategories_forAlertInfo() { + mExpect.withMessage("Radio alert info categories") + .that(Ints.asList(TEST_ALERT_INFO_1.getCategories())) + .containsExactlyElementsIn(Ints.asList(TEST_CATEGORIES_1)); + } + + @Test + public void getUrgency_forAlertInfo() { + mExpect.withMessage("Radio alert info urgency") + .that(TEST_ALERT_INFO_1.getUrgency()).isEqualTo(TEST_URGENCY_1); + } + + @Test + public void getSeverity_forAlertInfo() { + mExpect.withMessage("Radio alert info severity") + .that(TEST_ALERT_INFO_1.getSeverity()).isEqualTo(TEST_SEVERITY_1); + } + + @Test + public void getCertainty_forAlertInfo() { + mExpect.withMessage("Radio alert info certainty") + .that(TEST_ALERT_INFO_1.getCertainty()).isEqualTo(TEST_CERTAINTY_1); + } + + @Test + public void getDescription_forAlertInfo() { + mExpect.withMessage("Radio alert info description") + .that(TEST_ALERT_INFO_1.getDescription()).isEqualTo(TEST_DESCRIPTION_MESSAGE_1); + } + + @Test + public void getAreas_forAlertInfo() { + mExpect.withMessage("Radio alert info areas") + .that(TEST_ALERT_INFO_1.getAreas()).containsAtLeastElementsIn(TEST_AREA_LIST_1); + } + + @Test + public void getLanguage_forAlertInfo() { + mExpect.withMessage("Radio alert language") + .that(TEST_ALERT_INFO_1.getLanguage()).isEqualTo(TEST_LANGUAGE_1); + } + + @Test + public void describeContents_forAlertInfo() { + mExpect.withMessage("Contents of alert info") + .that(TEST_ALERT_INFO_1.describeContents()).isEqualTo(0); + } + + @Test + public void writeToParcel_forAlertInfoWithNullLanguage() { + Parcel parcel = Parcel.obtain(); + + TEST_ALERT_INFO_2.writeToParcel(parcel, TEST_FLAGS); + + parcel.setDataPosition(0); + RadioAlert.AlertInfo alertInfoFromParcel = RadioAlert.AlertInfo.CREATOR + .createFromParcel(parcel); + mExpect.withMessage("Alert info from parcel with null language") + .that(alertInfoFromParcel).isEqualTo(TEST_ALERT_INFO_2); + } + + @Test + public void writeToParcel_forAlertInfoWithNonnullLanguage() { + Parcel parcel = Parcel.obtain(); + + TEST_ALERT_INFO_1.writeToParcel(parcel, TEST_FLAGS); + + parcel.setDataPosition(0); + RadioAlert.AlertInfo alertInfoFromParcel = RadioAlert.AlertInfo.CREATOR + .createFromParcel(parcel); + mExpect.withMessage("Alert info with nonnull language from parcel") + .that(alertInfoFromParcel).isEqualTo(TEST_ALERT_INFO_1); + } + + @Test + public void newArray_forAlertInfoCreator() { + RadioAlert.AlertInfo[] alertInfos = RadioAlert.AlertInfo.CREATOR + .newArray(CREATOR_ARRAY_SIZE); + + mExpect.withMessage("Alert infos").that(alertInfos).hasLength(CREATOR_ARRAY_SIZE); + } + + @Test + public void hashCode_withSameAlertInfos() { + RadioAlert.AlertInfo alertInfoCompared = new RadioAlert.AlertInfo( + TEST_CATEGORIES_1, TEST_URGENCY_1, TEST_SEVERITY_1, TEST_CERTAINTY_1, + TEST_DESCRIPTION_MESSAGE_1, TEST_AREA_LIST_1, TEST_LANGUAGE_1); + + mExpect.withMessage("Hash code of the same alert info") + .that(alertInfoCompared.hashCode()).isEqualTo(TEST_ALERT_INFO_1.hashCode()); + } + + @Test + public void constructor_forRadioAlert() { + NullPointerException thrown = assertThrows(NullPointerException.class, () -> + new RadioAlert(TEST_STATUS, TEST_TYPE, /* infoList= */ null)); + + mExpect.withMessage("Exception for alert constructor with null alert info list") + .that(thrown).hasMessageThat().contains("Alert info list can not be null"); + } + + @Test + public void equals_withDifferentAlertInfo() { + mExpect.withMessage("Different alert info").that(TEST_ALERT_INFO_1) + .isNotEqualTo(TEST_ALERT_INFO_2); + } + + @Test + @SuppressWarnings("TruthIncompatibleType") + public void equals_withDifferentTypeObject_forAlertInfo() { + mExpect.withMessage("Non-alert-info object").that(TEST_ALERT_INFO_1) + .isNotEqualTo(TEST_AREA_1); + } + + @Test + public void getStatus() { + mExpect.withMessage("Radio alert status").that(TEST_ALERT.getStatus()) + .isEqualTo(TEST_STATUS); + } + + @Test + public void getMessageType() { + mExpect.withMessage("Radio alert message type") + .that(TEST_ALERT.getMessageType()).isEqualTo(TEST_TYPE); + } + + @Test + public void getInfoList() { + mExpect.withMessage("Radio alert info list").that(TEST_ALERT.getInfoList()) + .containsExactly(TEST_ALERT_INFO_1, TEST_ALERT_INFO_2); + } + + @Test + public void describeContents() { + mExpect.withMessage("Contents of radio alert") + .that(TEST_ALERT.describeContents()).isEqualTo(0); + } + + @Test + public void writeToParcel() { + Parcel parcel = Parcel.obtain(); + + TEST_ALERT.writeToParcel(parcel, TEST_FLAGS); + + parcel.setDataPosition(0); + RadioAlert alertFromParcel = RadioAlert.CREATOR.createFromParcel(parcel); + mExpect.withMessage("Alert from parcel").that(alertFromParcel) + .isEqualTo(TEST_ALERT); + } + + @Test + public void hashCode_withSameAlerts() { + RadioAlert alertCompared = new RadioAlert(TEST_STATUS, TEST_TYPE, + List.of(TEST_ALERT_INFO_1, TEST_ALERT_INFO_2)); + + mExpect.withMessage("Hash code of the same alert") + .that(alertCompared.hashCode()).isEqualTo(TEST_ALERT.hashCode()); + } + + @Test + public void newArray_forAlertCreator() { + RadioAlert[] alerts = RadioAlert.CREATOR.newArray(CREATOR_ARRAY_SIZE); + + mExpect.withMessage("Alerts").that(alerts).hasLength(CREATOR_ARRAY_SIZE); + } + + @Test + public void equals_withDifferentAlert() { + RadioAlert differentAlert = new RadioAlert(TEST_STATUS, TEST_TYPE, + List.of(TEST_ALERT_INFO_2)); + + mExpect.withMessage("Different alert").that(TEST_ALERT) + .isNotEqualTo(differentAlert); + } + + @Test + @SuppressWarnings("TruthIncompatibleType") + public void equals_withDifferentTypeObject() { + mExpect.withMessage("Non-alert object").that(TEST_ALERT) + .isNotEqualTo(TEST_ALERT_INFO_2); + } } diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt index e329aaee9a06..5e1ac1f30354 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt @@ -715,7 +715,7 @@ fun calculateWidgetSize(item: CommunalContentModel, isResizable: Boolean): Widge WidgetSizeInfo(minHeightPx, maxHeightPx) } } else { - WidgetSizeInfo(0, Int.MAX_VALUE) + WidgetSizeInfo(0, 0) } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/ResizeableItemFrameViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/ResizeableItemFrameViewModelTest.kt index 0269577af789..7816d3b131cb 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/ResizeableItemFrameViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/ResizeableItemFrameViewModelTest.kt @@ -480,6 +480,24 @@ class ResizeableItemFrameViewModelTest : SysuiTestCase() { fun testIllegalState_resizeMultipleZeroOrNegative() = testScope.runTest { updateGridLayout(singleSpanGrid.copy(resizeMultiple = 0)) } + @Test + fun testZeroHeights_cannotResize() = runTestWithSnapshots { + val zeroHeightGrid = + singleSpanGrid.copy( + totalSpans = 2, + currentSpan = 1, + currentRow = 0, + minHeightPx = 0, + maxHeightPx = 0, + ) + updateGridLayout(zeroHeightGrid) + + val topState = underTest.topDragState + val bottomState = underTest.bottomDragState + assertThat(topState.anchors.toList()).containsExactly(0 to 0f) + assertThat(bottomState.anchors.toList()).containsExactly(0 to 0f) + } + private fun TestScope.updateGridLayout(gridLayout: GridLayout) { underTest.setGridLayoutInfo( verticalItemSpacingPx = gridLayout.verticalItemSpacingPx, diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt index 1dd8ca9221a4..6a0781b3580f 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/display/data/repository/PerDisplayStoreImplTest.kt @@ -20,9 +20,8 @@ import android.view.Display import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.runBlocking @@ -37,7 +36,7 @@ import org.mockito.kotlin.mock @SmallTest class PerDisplayStoreImplTest : SysuiTestCase() { - private val kosmos = testKosmos().also { it.testDispatcher = it.unconfinedTestDispatcher } + private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val fakeDisplayRepository = kosmos.displayRepository diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLegacySettingSyncerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLegacySettingSyncerTest.kt index 0145f1748b10..4a422f05a45a 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLegacySettingSyncerTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLegacySettingSyncerTest.kt @@ -23,8 +23,9 @@ import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.kosmos.unconfinedTestDispatcher -import com.android.systemui.kosmos.unconfinedTestScope +import com.android.systemui.kosmos.testDispatcher +import com.android.systemui.kosmos.testScope +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.res.R import com.android.systemui.settings.FakeUserTracker import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots @@ -33,7 +34,7 @@ import com.android.systemui.util.FakeSharedPreferences import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever -import com.android.systemui.util.settings.unconfinedDispatcherFakeSettings +import com.android.systemui.util.settings.fakeSettings import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceUntilIdle @@ -51,10 +52,10 @@ import org.mockito.MockitoAnnotations @RunWith(AndroidJUnit4::class) class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { - private val kosmos = testKosmos() - private val testDispatcher = kosmos.unconfinedTestDispatcher - private val testScope = kosmos.unconfinedTestScope - private val settings = kosmos.unconfinedDispatcherFakeSettings + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + private val testDispatcher = kosmos.testDispatcher + private val testScope = kosmos.testScope + private val settings = kosmos.fakeSettings @Mock private lateinit var sharedPrefs: FakeSharedPreferences @@ -79,13 +80,7 @@ class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { context = context, userFileManager = mock { - whenever( - getSharedPreferences( - anyString(), - anyInt(), - anyInt(), - ) - ) + whenever(getSharedPreferences(anyString(), anyInt(), anyInt())) .thenReturn(FakeSharedPreferences()) }, userTracker = FakeUserTracker(), @@ -109,17 +104,14 @@ class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { testScope.runTest { val job = underTest.startSyncing() - settings.putInt( - Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, - 1, - ) + settings.putInt(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 1) assertThat( selectionManager .getSelections() .getOrDefault( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, - emptyList() + emptyList(), ) ) .contains(BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS) @@ -132,21 +124,15 @@ class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { testScope.runTest { val job = underTest.startSyncing() - settings.putInt( - Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, - 1, - ) - settings.putInt( - Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, - 0, - ) + settings.putInt(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 1) + settings.putInt(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS, 0) assertThat( selectionManager .getSelections() .getOrDefault( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, - emptyList() + emptyList(), ) ) .doesNotContain(BuiltInKeyguardQuickAffordanceKeys.HOME_CONTROLS) @@ -161,7 +147,7 @@ class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { selectionManager.setSelections( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - listOf(BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET) + listOf(BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET), ) advanceUntilIdle() @@ -177,11 +163,11 @@ class KeyguardQuickAffordanceLegacySettingSyncerTest : SysuiTestCase() { selectionManager.setSelections( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - listOf(BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET) + listOf(BuiltInKeyguardQuickAffordanceKeys.QUICK_ACCESS_WALLET), ) selectionManager.setSelections( KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - emptyList() + emptyList(), ) assertThat(settings.getInt(Settings.Secure.LOCKSCREEN_SHOW_WALLET)).isEqualTo(0) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt index 385089122fc4..499592051731 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt @@ -651,6 +651,7 @@ class SceneContainerStartableTest : SysuiTestCase() { } @Test + @DisableFlags(Flags.FLAG_TRANSITION_RACE_CONDITION) fun switchToAOD_whenAvailable_whenDeviceSleepsLocked() = testScope.runTest { kosmos.lockscreenSceneTransitionInteractor.start() @@ -680,6 +681,7 @@ class SceneContainerStartableTest : SysuiTestCase() { } @Test + @DisableFlags(Flags.FLAG_TRANSITION_RACE_CONDITION) fun switchToDozing_whenAodUnavailable_whenDeviceSleepsLocked() = testScope.runTest { kosmos.lockscreenSceneTransitionInteractor.start() @@ -701,6 +703,56 @@ class SceneContainerStartableTest : SysuiTestCase() { } @Test + @EnableFlags(Flags.FLAG_TRANSITION_RACE_CONDITION) + fun switchToAOD_whenAvailable_whenDeviceSleepsLocked_transitionFlagEnabled() = + testScope.runTest { + kosmos.lockscreenSceneTransitionInteractor.start() + val asleepState by collectLastValue(kosmos.keyguardInteractor.asleepKeyguardState) + val transitionState = + prepareState(isDeviceUnlocked = false, initialSceneKey = Scenes.Shade) + kosmos.keyguardRepository.setAodAvailable(true) + runCurrent() + assertThat(asleepState).isEqualTo(KeyguardState.AOD) + underTest.start() + powerInteractor.setAsleepForTest() + runCurrent() + transitionState.value = + ObservableTransitionState.Transition( + fromScene = Scenes.Shade, + toScene = Scenes.Lockscreen, + currentScene = flowOf(Scenes.Lockscreen), + progress = flowOf(0.5f), + isInitiatedByUserInput = true, + isUserInputOngoing = flowOf(false), + ) + runCurrent() + + assertThat(kosmos.keyguardTransitionRepository.currentTransitionInfo.to) + .isEqualTo(KeyguardState.AOD) + } + + @Test + @EnableFlags(Flags.FLAG_TRANSITION_RACE_CONDITION) + fun switchToDozing_whenAodUnavailable_whenDeviceSleepsLocked_transitionFlagEnabled() = + testScope.runTest { + kosmos.lockscreenSceneTransitionInteractor.start() + val asleepState by collectLastValue(kosmos.keyguardInteractor.asleepKeyguardState) + val transitionState = + prepareState(isDeviceUnlocked = false, initialSceneKey = Scenes.Shade) + kosmos.keyguardRepository.setAodAvailable(false) + runCurrent() + assertThat(asleepState).isEqualTo(KeyguardState.DOZING) + underTest.start() + powerInteractor.setAsleepForTest() + runCurrent() + transitionState.value = Transition(from = Scenes.Shade, to = Scenes.Lockscreen) + runCurrent() + + assertThat(kosmos.keyguardTransitionRepository.currentTransitionInfo.to) + .isEqualTo(KeyguardState.DOZING) + } + + @Test fun switchToGoneWhenDoubleTapPowerGestureIsTriggeredFromGone() = testScope.runTest { val currentSceneKey by collectLastValue(sceneInteractor.currentScene) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarOrchestratorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarOrchestratorTest.kt index 79230977b68e..659e53f4addd 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarOrchestratorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/core/StatusBarOrchestratorTest.kt @@ -22,9 +22,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.bouncer.data.repository.fakeKeyguardBouncerRepository -import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.plugins.DarkIconDispatcher import com.android.systemui.plugins.mockPluginDependencyProvider import com.android.systemui.plugins.statusbar.StatusBarStateController @@ -57,7 +56,7 @@ import org.mockito.kotlin.verify @RunWith(AndroidJUnit4::class) class StatusBarOrchestratorTest : SysuiTestCase() { - private val kosmos = testKosmos().also { it.testDispatcher = it.unconfinedTestDispatcher } + private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val fakeStatusBarModePerDisplayRepository = kosmos.fakeStatusBarModePerDisplayRepository private val mockPluginDependencyProvider = kosmos.mockPluginDependencyProvider diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayStatusBarContentInsetsProviderStoreTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayStatusBarContentInsetsProviderStoreTest.kt index 0eebab0de831..4a26fdf20e6e 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayStatusBarContentInsetsProviderStoreTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/data/repository/MultiDisplayStatusBarContentInsetsProviderStoreTest.kt @@ -21,9 +21,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.display.data.repository.displayRepository -import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest @@ -37,7 +36,7 @@ import org.mockito.kotlin.verify @RunWith(AndroidJUnit4::class) class MultiDisplayStatusBarContentInsetsProviderStoreTest : SysuiTestCase() { - private val kosmos = testKosmos().also { it.testDispatcher = it.unconfinedTestDispatcher } + private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val fakeDisplayRepository = kosmos.displayRepository private val underTest = kosmos.multiDisplayStatusBarContentInsetsProviderStore diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt index 1af0f79f2dde..b03c679a9c23 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/user/data/repository/UserRepositoryImplTest.kt @@ -24,14 +24,15 @@ import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase -import com.android.systemui.kosmos.unconfinedTestDispatcher -import com.android.systemui.kosmos.unconfinedTestScope +import com.android.systemui.kosmos.testDispatcher +import com.android.systemui.kosmos.testScope +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.settings.FakeUserTracker import com.android.systemui.testKosmos import com.android.systemui.user.data.model.SelectedUserModel import com.android.systemui.user.data.model.SelectionStatus import com.android.systemui.user.data.model.UserSwitcherSettingsModel -import com.android.systemui.util.settings.unconfinedDispatcherFakeGlobalSettings +import com.android.systemui.util.settings.fakeGlobalSettings import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -52,10 +53,10 @@ import org.mockito.MockitoAnnotations @RunWith(AndroidJUnit4::class) class UserRepositoryImplTest : SysuiTestCase() { - private val kosmos = testKosmos() - private val testDispatcher = kosmos.unconfinedTestDispatcher - private val testScope = kosmos.unconfinedTestScope - private val globalSettings = kosmos.unconfinedDispatcherFakeGlobalSettings + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + private val testDispatcher = kosmos.testDispatcher + private val testScope = kosmos.testScope + private val globalSettings = kosmos.fakeGlobalSettings @Mock private lateinit var manager: UserManager @@ -131,11 +132,7 @@ class UserRepositoryImplTest : SysuiTestCase() { whenever(mainUser.identifier).thenReturn(mainUserId) underTest = create(testScope.backgroundScope) - val initialExpectedValue = - setUpUsers( - count = 3, - selectedIndex = 0, - ) + val initialExpectedValue = setUpUsers(count = 3, selectedIndex = 0) var userInfos: List<UserInfo>? = null var selectedUserInfo: UserInfo? = null val job1 = underTest.userInfos.onEach { userInfos = it }.launchIn(this) @@ -146,11 +143,7 @@ class UserRepositoryImplTest : SysuiTestCase() { assertThat(selectedUserInfo).isEqualTo(initialExpectedValue[0]) assertThat(underTest.lastSelectedNonGuestUserId).isEqualTo(selectedUserInfo?.id) - val secondExpectedValue = - setUpUsers( - count = 4, - selectedIndex = 1, - ) + val secondExpectedValue = setUpUsers(count = 4, selectedIndex = 1) underTest.refreshUsers() assertThat(userInfos).isEqualTo(secondExpectedValue) assertThat(selectedUserInfo).isEqualTo(secondExpectedValue[1]) @@ -158,11 +151,7 @@ class UserRepositoryImplTest : SysuiTestCase() { val selectedNonGuestUserId = selectedUserInfo?.id val thirdExpectedValue = - setUpUsers( - count = 2, - isLastGuestUser = true, - selectedIndex = 1, - ) + setUpUsers(count = 2, isLastGuestUser = true, selectedIndex = 1) underTest.refreshUsers() assertThat(userInfos).isEqualTo(thirdExpectedValue) assertThat(selectedUserInfo).isEqualTo(thirdExpectedValue[1]) @@ -177,12 +166,7 @@ class UserRepositoryImplTest : SysuiTestCase() { fun refreshUsers_sortsByCreationTime_guestUserLast() = testScope.runTest { underTest = create(testScope.backgroundScope) - val unsortedUsers = - setUpUsers( - count = 3, - selectedIndex = 0, - isLastGuestUser = true, - ) + val unsortedUsers = setUpUsers(count = 3, selectedIndex = 0, isLastGuestUser = true) unsortedUsers[0].creationTime = 999 unsortedUsers[1].creationTime = 900 unsortedUsers[2].creationTime = 950 @@ -207,10 +191,7 @@ class UserRepositoryImplTest : SysuiTestCase() { ): List<UserInfo> { val userInfos = (0 until count).map { index -> - createUserInfo( - index, - isGuest = isLastGuestUser && index == count - 1, - ) + createUserInfo(index, isGuest = isLastGuestUser && index == count - 1) } whenever(manager.aliveUsers).thenReturn(userInfos) tracker.set(userInfos, selectedIndex) @@ -224,16 +205,10 @@ class UserRepositoryImplTest : SysuiTestCase() { var selectedUserInfo: UserInfo? = null val job = underTest.selectedUserInfo.onEach { selectedUserInfo = it }.launchIn(this) - setUpUsers( - count = 2, - selectedIndex = 0, - ) + setUpUsers(count = 2, selectedIndex = 0) tracker.onProfileChanged() assertThat(selectedUserInfo?.id).isEqualTo(0) - setUpUsers( - count = 2, - selectedIndex = 1, - ) + setUpUsers(count = 2, selectedIndex = 1) tracker.onProfileChanged() assertThat(selectedUserInfo?.id).isEqualTo(1) job.cancel() @@ -287,10 +262,7 @@ class UserRepositoryImplTest : SysuiTestCase() { job.cancel() } - private fun createUserInfo( - id: Int, - isGuest: Boolean, - ): UserInfo { + private fun createUserInfo(id: Int, isGuest: Boolean): UserInfo { val flags = 0 return UserInfo( id, diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayScopeRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayScopeRepositoryImplTest.kt index 5d5c1203ea80..da7a723f220e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayScopeRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayScopeRepositoryImplTest.kt @@ -23,7 +23,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.statusbar.core.StatusBarConnectedDisplays import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat @@ -38,7 +38,7 @@ import org.junit.runner.RunWith @SmallTest class DisplayScopeRepositoryImplTest : SysuiTestCase() { - private val kosmos = testKosmos().also { it.testDispatcher = it.unconfinedTestDispatcher } + private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val fakeDisplayRepository = kosmos.displayRepository diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt index ff3186abecdc..5a764892584e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayWindowPropertiesRepositoryImplTest.kt @@ -25,9 +25,8 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.display.shared.model.DisplayWindowProperties import com.android.systemui.kosmos.applicationCoroutineScope -import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.statusbar.core.StatusBarConnectedDisplays import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat @@ -44,7 +43,7 @@ import org.mockito.kotlin.mock @SmallTest class DisplayWindowPropertiesRepositoryImplTest : SysuiTestCase() { - private val kosmos = testKosmos().also { it.testDispatcher = it.unconfinedTestDispatcher } + private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val fakeDisplayRepository = kosmos.displayRepository private val testScope = kosmos.testScope diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt index fa69fdd38b8e..929b0aad3299 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt @@ -50,8 +50,9 @@ import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAfforda import com.android.systemui.keyguard.ui.preview.KeyguardPreviewRenderer import com.android.systemui.keyguard.ui.preview.KeyguardPreviewRendererFactory import com.android.systemui.keyguard.ui.preview.KeyguardRemotePreviewManager -import com.android.systemui.kosmos.unconfinedTestDispatcher -import com.android.systemui.kosmos.unconfinedTestScope +import com.android.systemui.kosmos.testDispatcher +import com.android.systemui.kosmos.testScope +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.plugins.ActivityStarter import com.android.systemui.res.R import com.android.systemui.scene.domain.interactor.sceneInteractor @@ -67,7 +68,6 @@ import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.fakeSettings -import com.android.systemui.util.settings.unconfinedDispatcherFakeSettings import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow @@ -89,10 +89,10 @@ import org.mockito.MockitoAnnotations @TestableLooper.RunWithLooper(setAsMainLooper = true) class CustomizationProviderTest : SysuiTestCase() { - private val kosmos = testKosmos() - private val testDispatcher = kosmos.unconfinedTestDispatcher - private val testScope = kosmos.unconfinedTestScope - private val fakeSettings = kosmos.unconfinedDispatcherFakeSettings + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + private val testDispatcher = kosmos.testDispatcher + private val testScope = kosmos.testScope + private val fakeSettings = kosmos.fakeSettings @Mock private lateinit var lockPatternUtils: LockPatternUtils @Mock private lateinit var keyguardStateController: KeyguardStateController @@ -129,13 +129,7 @@ class CustomizationProviderTest : SysuiTestCase() { context = context, userFileManager = mock<UserFileManager>().apply { - whenever( - getSharedPreferences( - anyString(), - anyInt(), - anyInt(), - ) - ) + whenever(getSharedPreferences(anyString(), anyInt(), anyInt())) .thenReturn(FakeSharedPreferences()) }, userTracker = userTracker, @@ -288,10 +282,7 @@ class CustomizationProviderTest : SysuiTestCase() { val affordanceId = AFFORDANCE_2 val affordanceName = AFFORDANCE_2_NAME - insertSelection( - slotId = slotId, - affordanceId = affordanceId, - ) + insertSelection(slotId = slotId, affordanceId = affordanceId) assertThat(querySelections()) .isEqualTo( @@ -311,14 +302,8 @@ class CustomizationProviderTest : SysuiTestCase() { assertThat(querySlots()) .isEqualTo( listOf( - Slot( - id = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, - capacity = 1, - ), - Slot( - id = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - capacity = 1, - ), + Slot(id = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START, capacity = 1), + Slot(id = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, capacity = 1), ) ) runCurrent() @@ -330,16 +315,8 @@ class CustomizationProviderTest : SysuiTestCase() { assertThat(queryAffordances()) .isEqualTo( listOf( - Affordance( - id = AFFORDANCE_1, - name = AFFORDANCE_1_NAME, - iconResourceId = 1, - ), - Affordance( - id = AFFORDANCE_2, - name = AFFORDANCE_2_NAME, - iconResourceId = 2, - ), + Affordance(id = AFFORDANCE_1, name = AFFORDANCE_1_NAME, iconResourceId = 1), + Affordance(id = AFFORDANCE_2, name = AFFORDANCE_2_NAME, iconResourceId = 2), ) ) } @@ -361,10 +338,7 @@ class CustomizationProviderTest : SysuiTestCase() { "${Contract.LockScreenQuickAffordances.SelectionTable.Columns.SLOT_ID} = ? AND" + " ${Contract.LockScreenQuickAffordances.SelectionTable.Columns.AFFORDANCE_ID}" + " = ?", - arrayOf( - KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - AFFORDANCE_2, - ), + arrayOf(KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, AFFORDANCE_2), ) assertThat(querySelections()) @@ -394,9 +368,7 @@ class CustomizationProviderTest : SysuiTestCase() { context.contentResolver.delete( Contract.LockScreenQuickAffordances.SelectionTable.URI, Contract.LockScreenQuickAffordances.SelectionTable.Columns.SLOT_ID, - arrayOf( - KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END, - ), + arrayOf(KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END), ) assertThat(querySelections()) @@ -428,31 +400,22 @@ class CustomizationProviderTest : SysuiTestCase() { assertThat(result.containsKey(KeyguardRemotePreviewManager.KEY_PREVIEW_CALLBACK)) } - private fun insertSelection( - slotId: String, - affordanceId: String, - ) { + private fun insertSelection(slotId: String, affordanceId: String) { context.contentResolver.insert( Contract.LockScreenQuickAffordances.SelectionTable.URI, ContentValues().apply { put(Contract.LockScreenQuickAffordances.SelectionTable.Columns.SLOT_ID, slotId) put( Contract.LockScreenQuickAffordances.SelectionTable.Columns.AFFORDANCE_ID, - affordanceId + affordanceId, ) - } + }, ) } private fun querySelections(): List<Selection> { return context.contentResolver - .query( - Contract.LockScreenQuickAffordances.SelectionTable.URI, - null, - null, - null, - null, - ) + .query(Contract.LockScreenQuickAffordances.SelectionTable.URI, null, null, null, null) ?.use { cursor -> buildList { val slotIdColumnIndex = @@ -491,13 +454,7 @@ class CustomizationProviderTest : SysuiTestCase() { private fun querySlots(): List<Slot> { return context.contentResolver - .query( - Contract.LockScreenQuickAffordances.SlotTable.URI, - null, - null, - null, - null, - ) + .query(Contract.LockScreenQuickAffordances.SlotTable.URI, null, null, null, null) ?.use { cursor -> buildList { val idColumnIndex = @@ -526,13 +483,7 @@ class CustomizationProviderTest : SysuiTestCase() { private fun queryAffordances(): List<Affordance> { return context.contentResolver - .query( - Contract.LockScreenQuickAffordances.AffordanceTable.URI, - null, - null, - null, - null, - ) + .query(Contract.LockScreenQuickAffordances.AffordanceTable.URI, null, null, null, null) ?.use { cursor -> buildList { val idColumnIndex = @@ -564,22 +515,11 @@ class CustomizationProviderTest : SysuiTestCase() { } ?: emptyList() } - data class Slot( - val id: String, - val capacity: Int, - ) - - data class Affordance( - val id: String, - val name: String, - val iconResourceId: Int, - ) - - data class Selection( - val slotId: String, - val affordanceId: String, - val affordanceName: String, - ) + data class Slot(val id: String, val capacity: Int) + + data class Affordance(val id: String, val name: String, val iconResourceId: Int) + + data class Selection(val slotId: String, val affordanceId: String, val affordanceName: String) companion object { private const val AFFORDANCE_1 = "affordance_1" diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt index 570c64065c4a..33b61a098bc5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaCarouselControllerTest.kt @@ -48,7 +48,7 @@ import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticati import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope -import com.android.systemui.kosmos.unconfinedTestDispatcher +import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.media.controls.MediaTestUtils import com.android.systemui.media.controls.domain.pipeline.EMPTY_SMARTSPACE_MEDIA_DATA import com.android.systemui.media.controls.domain.pipeline.MediaDataManager @@ -73,7 +73,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.testKosmos import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.settings.GlobalSettings -import com.android.systemui.util.settings.unconfinedDispatcherFakeSettings +import com.android.systemui.util.settings.fakeSettings import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import java.util.Locale @@ -119,9 +119,9 @@ private const val PLAYING_LOCAL = "playing local" @TestableLooper.RunWithLooper(setAsMainLooper = true) @RunWith(ParameterizedAndroidJunit4::class) class MediaCarouselControllerTest(flags: FlagsParameterization) : SysuiTestCase() { - private val kosmos = testKosmos() - private val testDispatcher = kosmos.unconfinedTestDispatcher - private val secureSettings = kosmos.unconfinedDispatcherFakeSettings + private val kosmos = testKosmos().useUnconfinedTestDispatcher() + private val testDispatcher = kosmos.testDispatcher + private val secureSettings = kosmos.fakeSettings @Mock lateinit var mediaControlPanelFactory: Provider<MediaControlPanel> @Mock lateinit var mediaViewControllerFactory: Provider<MediaViewController> diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/kosmos/GeneralKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/kosmos/GeneralKosmos.kt index f8df7074142d..a9a80b52f591 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/kosmos/GeneralKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/kosmos/GeneralKosmos.kt @@ -8,9 +8,26 @@ import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher var Kosmos.testDispatcher by Fixture { StandardTestDispatcher() } -var Kosmos.unconfinedTestDispatcher by Fixture { UnconfinedTestDispatcher() } + +/** + * Force this Kosmos to use a [StandardTestDispatcher], regardless of the current Kosmos default. In + * short, no launch blocks will be run on this dispatcher until `TestCoroutineScheduler.runCurrent` + * is called. See [StandardTestDispatcher] for details. + * + * For details on this migration, see http://go/thetiger + */ +fun Kosmos.useStandardTestDispatcher() = apply { testDispatcher = StandardTestDispatcher() } + +/** + * Force this Kosmos to use an [UnconfinedTestDispatcher], regardless of the current Kosmos default. + * In short, launch blocks will be executed eagerly without waiting for + * `TestCoroutineScheduler.runCurrent`. See [UnconfinedTestDispatcher] for details. + * + * For details on this migration, see http://go/thetiger + */ +fun Kosmos.useUnconfinedTestDispatcher() = apply { testDispatcher = UnconfinedTestDispatcher() } + var Kosmos.testScope by Fixture { TestScope(testDispatcher) } -var Kosmos.unconfinedTestScope by Fixture { TestScope(unconfinedTestDispatcher) } var Kosmos.applicationCoroutineScope by Fixture { testScope.backgroundScope } var Kosmos.testCase: SysuiTestCase by Fixture() var Kosmos.backgroundCoroutineContext: CoroutineContext by Fixture { diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeGlobalSettingsKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeGlobalSettingsKosmos.kt index 73d423cc3e7a..35fa2af7639f 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeGlobalSettingsKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeGlobalSettingsKosmos.kt @@ -19,10 +19,5 @@ package com.android.systemui.util.settings import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture import com.android.systemui.kosmos.testDispatcher -import com.android.systemui.kosmos.unconfinedTestDispatcher val Kosmos.fakeGlobalSettings: FakeGlobalSettings by Fixture { FakeGlobalSettings(testDispatcher) } - -val Kosmos.unconfinedDispatcherFakeGlobalSettings: FakeGlobalSettings by Fixture { - FakeGlobalSettings(unconfinedTestDispatcher) -} diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeSettingsKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeSettingsKosmos.kt index e1daf9bdc773..76ef20253078 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeSettingsKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeSettingsKosmos.kt @@ -19,13 +19,8 @@ package com.android.systemui.util.settings import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos.Fixture import com.android.systemui.kosmos.testDispatcher -import com.android.systemui.kosmos.unconfinedTestDispatcher import com.android.systemui.settings.userTracker val Kosmos.fakeSettings: FakeSettings by Fixture { FakeSettings(testDispatcher) { userTracker.userId } } - -val Kosmos.unconfinedDispatcherFakeSettings: FakeSettings by Fixture { - FakeSettings(unconfinedTestDispatcher) { userTracker.userId } -} diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java index dbdc614bdc9e..906e584af1ad 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java +++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java @@ -2641,8 +2641,8 @@ public class AudioDeviceBroker { Log.w(TAG, "failed to broadcast ACTION_SPEAKERPHONE_STATE_CHANGED: " + e); } } - mAudioService.postUpdateRingerModeServiceInt(); dispatchCommunicationDevice(); + mAudioService.postUpdateRingerModeServiceInt(); } @GuardedBy("mDeviceStateLock") diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java index 1331ae173b18..b110ff6b6bc4 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserPropertiesTest.java @@ -160,6 +160,7 @@ public class UserManagerServiceUserPropertiesTest { // Make a possibly-not-full-permission (i.e. partial) copy and check that it is correct. final UserProperties copy = new UserProperties(orig, exposeAll, hasManage, hasQuery); + assertThat(copy.toString()).isNotNull(); verifyTestCopyLacksPermissions(orig, copy, exposeAll, hasManage, hasQuery); if (permLevel < 1) { // PropertiesPresent should definitely be different since not all items were copied. |