Follow config overlay's order of aspect ratio options

Fix flaky UserAspectRatioAppsPageProviderTest by using advanceUntilIdle
to make sure all coroutines are finished before asserting.

Bug: 325911424
Test: atest UserAspectRatioDetailsTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:32815ad699448c5c5b1f38df6d2d2a881d4251c1)
Merged-In: I83e9a7f31536c1a006789722b0310f3364d14337
Change-Id: I83e9a7f31536c1a006789722b0310f3364d14337
This commit is contained in:
Graciela Wissen Putri
2024-02-29 17:55:52 +00:00
committed by Cherrypicker Worker
parent a6f283382a
commit a0f573a35e
6 changed files with 79 additions and 22 deletions

View File

@@ -44,6 +44,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.SparseIntArray;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -76,6 +77,7 @@ public class UserAspectRatioManager {
/** Apps that have launcher entry defined in manifest */
private final Map<Integer, String> mUserAspectRatioMap;
private final Map<Integer, CharSequence> mUserAspectRatioA11yMap;
private final SparseIntArray mUserAspectRatioOrder;
public UserAspectRatioManager(@NonNull Context context) {
this(context, AppGlobals.getPackageManager());
@@ -86,6 +88,7 @@ public class UserAspectRatioManager {
mContext = context;
mIPm = pm;
mUserAspectRatioA11yMap = new ArrayMap<>();
mUserAspectRatioOrder = new SparseIntArray();
mUserAspectRatioMap = getUserMinAspectRatioMapping();
}
@@ -152,6 +155,14 @@ public class UserAspectRatioManager {
return getUserMinAspectRatioEntry(aspectRatio, packageName, userId);
}
/**
* @return the order of the aspect ratio option corresponding to
* config_userAspectRatioOverrideValues
*/
int getUserMinAspectRatioOrder(@PackageManager.UserMinAspectRatio int option) {
return mUserAspectRatioOrder.get(option);
}
/**
* Whether user aspect ratio option is specified in
* {@link R.array.config_userAspectRatioOverrideValues}
@@ -224,7 +235,6 @@ public class UserAspectRatioManager {
&& isFullscreenCompatChangeEnabled(pkgName, userId);
}
@VisibleForTesting
boolean isFullscreenCompatChangeEnabled(String pkgName, int userId) {
return CompatChanges.isChangeEnabled(
OVERRIDE_ANY_ORIENTATION_TO_USER, pkgName, UserHandle.of(userId));
@@ -281,6 +291,7 @@ public class UserAspectRatioManager {
mUserAspectRatioA11yMap.put(aspectRatioVal, accessibleSequence);
}
userMinAspectRatioMap.put(aspectRatioVal, aspectRatioString);
mUserAspectRatioOrder.put(aspectRatioVal, i);
}
}
if (!userMinAspectRatioMap.containsKey(USER_MIN_ASPECT_RATIO_UNSET)) {
@@ -290,6 +301,8 @@ public class UserAspectRatioManager {
if (mIsUserMinAspectRatioAppDefaultFlagEnabled) {
userMinAspectRatioMap.put(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
userMinAspectRatioMap.get(USER_MIN_ASPECT_RATIO_UNSET));
mUserAspectRatioOrder.put(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
mUserAspectRatioOrder.get(USER_MIN_ASPECT_RATIO_UNSET));
if (mUserAspectRatioA11yMap.containsKey(USER_MIN_ASPECT_RATIO_UNSET)) {
mUserAspectRatioA11yMap.put(USER_MIN_ASPECT_RATIO_APP_DEFAULT,
mUserAspectRatioA11yMap.get(USER_MIN_ASPECT_RATIO_UNSET));