Merge "Add opt-out properties for aspect ratio settings" into udc-qpr-dev am: 83c8f47ddd
am: 725efb1a5a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24309274 Change-Id: I5cdb28b8929b0ab8dba829ee6e12d880ca6cc27b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -201,11 +201,12 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
if (!mUserAspectRatioManager.containsAspectRatioOption(aspectRatio)) {
|
||||
if (!mUserAspectRatioManager.hasAspectRatioOption(aspectRatio, mPackageName)) {
|
||||
pref.setVisible(false);
|
||||
return;
|
||||
}
|
||||
pref.setTitle(mUserAspectRatioManager.getUserMinAspectRatioEntry(aspectRatio));
|
||||
pref.setTitle(mUserAspectRatioManager.getUserMinAspectRatioEntry(aspectRatio,
|
||||
mPackageName));
|
||||
pref.setOnClickListener(this);
|
||||
mAspectRatioPreferences.add(pref);
|
||||
}
|
||||
|
@@ -16,6 +16,11 @@
|
||||
|
||||
package com.android.settings.applications.appcompat;
|
||||
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE;
|
||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
|
||||
import android.app.AppGlobals;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -63,7 +68,7 @@ public class UserAspectRatioManager {
|
||||
public UserAspectRatioManager(@NonNull Context context) {
|
||||
mContext = context;
|
||||
mIPm = AppGlobals.getPackageManager();
|
||||
mInfoHasLauncherEntryList = context.getPackageManager().queryIntentActivities(
|
||||
mInfoHasLauncherEntryList = mContext.getPackageManager().queryIntentActivities(
|
||||
UserAspectRatioManager.LAUNCHER_ENTRY_INTENT, PackageManager.GET_META_DATA);
|
||||
mUserAspectRatioMap = getUserMinAspectRatioMapping();
|
||||
}
|
||||
@@ -85,7 +90,7 @@ public class UserAspectRatioManager {
|
||||
public int getUserMinAspectRatioValue(@NonNull String packageName, int uid)
|
||||
throws RemoteException {
|
||||
final int aspectRatio = mIPm.getUserMinAspectRatio(packageName, uid);
|
||||
return containsAspectRatioOption(aspectRatio)
|
||||
return hasAspectRatioOption(aspectRatio, packageName)
|
||||
? aspectRatio : PackageManager.USER_MIN_ASPECT_RATIO_UNSET;
|
||||
}
|
||||
|
||||
@@ -93,8 +98,9 @@ public class UserAspectRatioManager {
|
||||
* @return corresponding string for {@link PackageManager.UserMinAspectRatio} value
|
||||
*/
|
||||
@NonNull
|
||||
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio) {
|
||||
if (!containsAspectRatioOption(aspectRatio)) {
|
||||
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio,
|
||||
String packageName) {
|
||||
if (!hasAspectRatioOption(aspectRatio, packageName)) {
|
||||
return mUserAspectRatioMap.get(PackageManager.USER_MIN_ASPECT_RATIO_UNSET);
|
||||
}
|
||||
return mUserAspectRatioMap.get(aspectRatio);
|
||||
@@ -107,7 +113,7 @@ public class UserAspectRatioManager {
|
||||
public String getUserMinAspectRatioEntry(@NonNull String packageName, int uid)
|
||||
throws RemoteException {
|
||||
final int aspectRatio = getUserMinAspectRatioValue(packageName, uid);
|
||||
return getUserMinAspectRatioEntry(aspectRatio);
|
||||
return getUserMinAspectRatioEntry(aspectRatio, packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,9 +121,10 @@ public class UserAspectRatioManager {
|
||||
* {@link R.array.config_userAspectRatioOverrideValues}
|
||||
* and is enabled by device config
|
||||
*/
|
||||
public boolean containsAspectRatioOption(@PackageManager.UserMinAspectRatio int option) {
|
||||
public boolean hasAspectRatioOption(@PackageManager.UserMinAspectRatio int option,
|
||||
String packageName) {
|
||||
if (option == PackageManager.USER_MIN_ASPECT_RATIO_FULLSCREEN
|
||||
&& !isFullscreenOptionEnabled()) {
|
||||
&& !isFullscreenOptionEnabled(packageName)) {
|
||||
return false;
|
||||
}
|
||||
return mUserAspectRatioMap.containsKey(option);
|
||||
@@ -136,21 +143,26 @@ public class UserAspectRatioManager {
|
||||
* will be overridable.
|
||||
*/
|
||||
public boolean canDisplayAspectRatioUi(@NonNull ApplicationInfo app) {
|
||||
Boolean appAllowsUserAspectRatioOverride = readComponentProperty(
|
||||
mContext.getPackageManager(), app.packageName,
|
||||
PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_OVERRIDE);
|
||||
boolean hasLauncherEntry = mInfoHasLauncherEntryList.stream()
|
||||
.anyMatch(info -> info.activityInfo.packageName.equals(app.packageName));
|
||||
return hasLauncherEntry;
|
||||
return !FALSE.equals(appAllowsUserAspectRatioOverride) && hasLauncherEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether fullscreen option in per-app user aspect ratio settings is enabled
|
||||
*/
|
||||
@VisibleForTesting
|
||||
boolean isFullscreenOptionEnabled() {
|
||||
boolean isFullscreenOptionEnabled(String packageName) {
|
||||
Boolean appAllowsFullscreenOption = readComponentProperty(mContext.getPackageManager(),
|
||||
packageName, PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO_FULLSCREEN_OVERRIDE);
|
||||
final boolean isBuildTimeFlagEnabled = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_appCompatUserAppAspectRatioFullscreenIsEnabled);
|
||||
return isBuildTimeFlagEnabled && getValueFromDeviceConfig(
|
||||
KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
|
||||
return !FALSE.equals(appAllowsFullscreenOption) && isBuildTimeFlagEnabled
|
||||
&& getValueFromDeviceConfig(KEY_ENABLE_USER_ASPECT_RATIO_FULLSCREEN,
|
||||
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_FULLSCREEN);
|
||||
}
|
||||
|
||||
private static boolean getValueFromDeviceConfig(String name, boolean defaultValue) {
|
||||
@@ -217,6 +229,17 @@ public class UserAspectRatioManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Boolean readComponentProperty(PackageManager pm, String packageName,
|
||||
String propertyName) {
|
||||
try {
|
||||
return pm.getProperty(propertyName, packageName).getBoolean();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// No such property name
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addInfoHasLauncherEntry(@NonNull ResolveInfo infoHasLauncherEntry) {
|
||||
mInfoHasLauncherEntryList.add(infoHasLauncherEntry);
|
||||
|
@@ -121,7 +121,7 @@ fun UserAspectRatioAppList(
|
||||
|
||||
data class UserAspectRatioAppListItemModel(
|
||||
override val app: ApplicationInfo,
|
||||
val override: Int,
|
||||
val userOverride: Int,
|
||||
val suggested: Boolean,
|
||||
val canDisplay: Boolean,
|
||||
) : AppRecord
|
||||
@@ -136,7 +136,7 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
recordList: List<UserAspectRatioAppListItemModel>
|
||||
): List<SpinnerOption> {
|
||||
val hasSuggested = recordList.any { it.suggested }
|
||||
val hasOverride = recordList.any { it.override != USER_MIN_ASPECT_RATIO_UNSET }
|
||||
val hasOverride = recordList.any { it.userOverride != USER_MIN_ASPECT_RATIO_UNSET }
|
||||
val options = mutableListOf(SpinnerItem.All)
|
||||
// Add suggested filter first as default
|
||||
if (hasSuggested) options.add(0, SpinnerItem.Suggested)
|
||||
@@ -164,7 +164,7 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
app = app,
|
||||
suggested = !app.isSystemApp && getPackageAndActivityInfo(
|
||||
app)?.isFixedOrientationOrAspectRatio() == true,
|
||||
override = userAspectRatioManager.getUserMinAspectRatioValue(
|
||||
userOverride = userAspectRatioManager.getUserMinAspectRatioValue(
|
||||
app.packageName, uid),
|
||||
canDisplay = userAspectRatioManager.canDisplayAspectRatioUi(app),
|
||||
)
|
||||
@@ -178,16 +178,17 @@ class UserAspectRatioAppListModel(private val context: Context)
|
||||
): Flow<List<UserAspectRatioAppListItemModel>> = recordListFlow.filterItem(
|
||||
when (SpinnerItem.values().getOrNull(option)) {
|
||||
SpinnerItem.Suggested -> ({ it.canDisplay && it.suggested })
|
||||
SpinnerItem.Overridden -> ({ it.override != USER_MIN_ASPECT_RATIO_UNSET })
|
||||
SpinnerItem.Overridden -> ({ it.userOverride != USER_MIN_ASPECT_RATIO_UNSET })
|
||||
else -> ({ it.canDisplay })
|
||||
}
|
||||
)
|
||||
|
||||
@Composable
|
||||
override fun getSummary(option: Int, record: UserAspectRatioAppListItemModel) : State<String> =
|
||||
remember(record.override) {
|
||||
remember(record.userOverride) {
|
||||
flow {
|
||||
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.override))
|
||||
emit(userAspectRatioManager.getUserMinAspectRatioEntry(record.userOverride,
|
||||
record.app.packageName))
|
||||
}.flowOn(Dispatchers.IO)
|
||||
}.collectAsStateWithLifecycle(initialValue = stringResource(R.string.summary_placeholder))
|
||||
|
||||
|
Reference in New Issue
Block a user