Merge "[2/n] Add aspect ratio app list page under apps" into udc-qpr-dev am: 4e86d0d6b3 am: dc86dbe24b

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23819684

Change-Id: If7c6f4fa26ea014e40e737f07daae8b72481e2c2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Graciela Putri
2023-07-21 22:58:58 +00:00
committed by Automerger Merge Worker
12 changed files with 796 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.appcompat;
import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
/**
* Preference controller for
* {@link com.android.settings.spa.app.appcompat.UserAspectRatioAppsPageProvider}
*/
public class UserAspectRatioAppsPreferenceController extends BasePreferenceController {
public UserAspectRatioAppsPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return UserAspectRatioManager.isFeatureEnabled(mContext)
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
public CharSequence getSummary() {
return mContext.getResources().getString(R.string.screen_size_summary, Build.MODEL);
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.appcompat;
import android.app.AppGlobals;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.RemoteException;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import java.util.Map;
/**
* Helper class for handling app aspect ratio override
* {@link PackageManager.UserMinAspectRatio} set by user
*/
public class UserAspectRatioManager {
private static final Intent LAUNCHER_ENTRY_INTENT =
new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// TODO(b/288142656): Enable user aspect ratio settings by default
private static final boolean DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS = false;
@VisibleForTesting
static final String KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS =
"enable_app_compat_user_aspect_ratio_settings";
private final Context mContext;
private final IPackageManager mIPm;
/** Apps that have launcher entry defined in manifest */
private final List<ResolveInfo> mInfoHasLauncherEntryList;
private final Map<Integer, String> mUserAspectRatioMap;
public UserAspectRatioManager(@NonNull Context context) {
mContext = context;
mIPm = AppGlobals.getPackageManager();
mInfoHasLauncherEntryList = context.getPackageManager().queryIntentActivities(
UserAspectRatioManager.LAUNCHER_ENTRY_INTENT, PackageManager.GET_META_DATA);
mUserAspectRatioMap = getUserMinAspectRatioMapping();
}
/**
* Whether user aspect ratio settings is enabled for device.
*/
public static boolean isFeatureEnabled(Context context) {
final boolean isBuildTimeFlagEnabled = context.getResources().getBoolean(
com.android.internal.R.bool.config_appCompatUserAppAspectRatioSettingsIsEnabled);
return isBuildTimeFlagEnabled && getValueFromDeviceConfig();
}
/**
* @return user-specific {@link PackageManager.UserMinAspectRatio} override for an app
*/
@PackageManager.UserMinAspectRatio
public int getUserMinAspectRatioValue(@NonNull String packageName, int uid)
throws RemoteException {
return mIPm.getUserMinAspectRatio(packageName, uid);
}
/**
* @return corresponding string for {@link PackageManager.UserMinAspectRatio} value
*/
@NonNull
public String getUserMinAspectRatioEntry(@PackageManager.UserMinAspectRatio int aspectRatio) {
return mUserAspectRatioMap.getOrDefault(
aspectRatio, mContext.getString(R.string.user_aspect_ratio_app_default));
}
/**
* Whether an app's aspect ratio can be overridden by user. Only apps with launcher entry
* will be overridable.
*/
public boolean canDisplayAspectRatioUi(@NonNull ApplicationInfo app) {
boolean hasLauncherEntry = mInfoHasLauncherEntryList.stream()
.anyMatch(info -> info.activityInfo.packageName.equals(app.packageName));
return hasLauncherEntry;
}
private static boolean getValueFromDeviceConfig() {
return DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
KEY_ENABLE_USER_ASPECT_RATIO_SETTINGS,
DEFAULT_VALUE_ENABLE_USER_ASPECT_RATIO_SETTINGS);
}
@NonNull
private Map<Integer, String> getUserMinAspectRatioMapping() {
final String[] userMinAspectRatioStrings = mContext.getResources().getStringArray(
R.array.config_userAspectRatioOverrideEntries);
final int[] userMinAspectRatioValues = mContext.getResources().getIntArray(
R.array.config_userAspectRatioOverrideValues);
if (userMinAspectRatioStrings.length != userMinAspectRatioValues.length) {
throw new RuntimeException(
"config_userAspectRatioOverride options cannot be different length");
}
final Map<Integer, String> userMinAspectRatioMap = new ArrayMap<>();
for (int i = 0; i < userMinAspectRatioValues.length; i++) {
final int aspectRatioVal = userMinAspectRatioValues[i];
switch (aspectRatioVal) {
// Only map known values of UserMinAspectRatio and ignore unknown entries
case PackageManager.USER_MIN_ASPECT_RATIO_UNSET:
case PackageManager.USER_MIN_ASPECT_RATIO_SPLIT_SCREEN:
case PackageManager.USER_MIN_ASPECT_RATIO_4_3:
case PackageManager.USER_MIN_ASPECT_RATIO_16_9:
case PackageManager.USER_MIN_ASPECT_RATIO_3_2:
userMinAspectRatioMap.put(aspectRatioVal, userMinAspectRatioStrings[i]);
}
}
if (!userMinAspectRatioMap.containsKey(PackageManager.USER_MIN_ASPECT_RATIO_UNSET)) {
throw new RuntimeException("config_userAspectRatioOverrideValues options must have"
+ " USER_MIN_ASPECT_RATIO_UNSET value");
}
return userMinAspectRatioMap;
}
@VisibleForTesting
void addInfoHasLauncherEntry(@NonNull ResolveInfo infoHasLauncherEntry) {
mInfoHasLauncherEntryList.add(infoHasLauncherEntry);
}
}

View File

@@ -269,6 +269,7 @@ public class ManageApplications extends InstrumentedFragment
public static final int LIST_TYPE_CLONED_APPS = 17;
public static final int LIST_TYPE_NFC_TAG_APPS = 18;
public static final int LIST_TYPE_TURN_SCREEN_ON = 19;
public static final int LIST_TYPE_USER_ASPECT_RATIO_APPS = 20;
// List types that should show instant apps.
public static final Set<Integer> LIST_TYPES_WITH_INSTANT = new ArraySet<>(Arrays.asList(

View File

@@ -20,6 +20,7 @@ import android.content.Context
import android.util.FeatureFlagUtils
import com.android.settings.Settings.AlarmsAndRemindersActivity
import com.android.settings.Settings.AppBatteryUsageActivity
import com.android.settings.Settings.UserAspectRatioAppListActivity
import com.android.settings.Settings.ChangeNfcTagAppsActivity
import com.android.settings.Settings.ChangeWifiStateActivity
import com.android.settings.Settings.ClonedAppsListActivity
@@ -40,6 +41,7 @@ import com.android.settings.applications.appinfo.AppLocaleDetails
import com.android.settings.applications.manageapplications.ManageApplications.LIST_MANAGE_EXTERNAL_STORAGE
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_ALARMS_AND_REMINDERS
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_APPS_LOCALE
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_USER_ASPECT_RATIO_APPS
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_BATTERY_OPTIMIZATION
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_CLONED_APPS
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_GAMES
@@ -57,6 +59,7 @@ import com.android.settings.applications.manageapplications.ManageApplications.L
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_WIFI_ACCESS
import com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_WRITE_SETTINGS
import com.android.settings.spa.app.AllAppListPageProvider
import com.android.settings.spa.app.appcompat.UserAspectRatioAppsPageProvider
import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvider
import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
@@ -92,6 +95,7 @@ object ManageApplicationsUtil {
ClonedAppsListActivity::class to LIST_TYPE_CLONED_APPS,
ChangeNfcTagAppsActivity::class to LIST_TYPE_NFC_TAG_APPS,
TurnScreenOnSettingsActivity::class to LIST_TYPE_TURN_SCREEN_ON,
UserAspectRatioAppListActivity::class to LIST_TYPE_USER_ASPECT_RATIO_APPS,
)
@JvmField
@@ -114,6 +118,7 @@ object ManageApplicationsUtil {
LIST_TYPE_APPS_LOCALE -> AppLanguagesPageProvider.name
LIST_TYPE_MAIN -> AllAppListPageProvider.name
LIST_TYPE_NFC_TAG_APPS -> NfcTagAppsSettingsProvider.getAppListRoute()
LIST_TYPE_USER_ASPECT_RATIO_APPS -> UserAspectRatioAppsPageProvider.name
else -> null
}
}