Snap for 8561975 from c6f7599158 to tm-release

Change-Id: Iddb61c3dfd06673cba36811c2dc4e07bc1f17958
This commit is contained in:
Android Build Coastguard Worker
2022-05-09 23:09:04 +00:00
37 changed files with 546 additions and 160 deletions

View File

@@ -15,9 +15,9 @@
--> -->
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/widget_frame"
android:layout_width="120dp" android:layout_width="120dp"
android:layout_height="112dp"> android:layout_height="112dp"
android:importantForAccessibility="no">
<FrameLayout <FrameLayout
android:id="@+id/button" android:id="@+id/button"
@@ -41,7 +41,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:labelFor="@android:id/icon"
android:textSize="14sp" android:textSize="14sp"
android:importantForAccessibility="no"
style="@style/TextAppearance.PreferenceTitle.SettingsLib"/> style="@style/TextAppearance.PreferenceTitle.SettingsLib"/>
</RelativeLayout> </RelativeLayout>

View File

@@ -20,6 +20,7 @@
android:title="@string/app_locale_picker_title"> android:title="@string/app_locale_picker_title">
<com.android.settingslib.widget.TopIntroPreference <com.android.settingslib.widget.TopIntroPreference
android:key="app_locale_disclaimer"
android:title="@string/desc_app_locale_disclaimer" android:title="@string/desc_app_locale_disclaimer"
android:order="1"/> android:order="1"/>

View File

@@ -58,14 +58,14 @@
android:title="@string/wifi_security" android:title="@string/wifi_security"
android:selectable="false"/> android:selectable="false"/>
<DropDownPreference <ListPreference
android:key="metered" android:key="metered"
android:icon="@drawable/ic_attach_money_black_24dp" android:icon="@drawable/ic_attach_money_black_24dp"
android:title="@string/wifi_metered_title" android:title="@string/wifi_metered_title"
android:entries="@array/wifi_metered_entries" android:entries="@array/wifi_metered_entries"
android:entryValues="@array/wifi_metered_values"/> android:entryValues="@array/wifi_metered_values"/>
<DropDownPreference <ListPreference
android:key="privacy" android:key="privacy"
android:icon="@drawable/ic_wifi_privacy_24dp" android:icon="@drawable/ic_wifi_privacy_24dp"
android:title="@string/wifi_privacy_settings" android:title="@string/wifi_privacy_settings"

View File

@@ -22,6 +22,9 @@ import android.content.Intent;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
public class DefaultRingtonePreference extends RingtonePreference { public class DefaultRingtonePreference extends RingtonePreference {
private static final String TAG = "DefaultRingtonePreference"; private static final String TAG = "DefaultRingtonePreference";
@@ -43,6 +46,24 @@ public class DefaultRingtonePreference extends RingtonePreference {
@Override @Override
protected void onSaveRingtone(Uri ringtoneUri) { protected void onSaveRingtone(Uri ringtoneUri) {
String mimeType = getContext().getContentResolver().getType(ringtoneUri);
if (mimeType == null) {
Log.e(TAG, "onSaveRingtone for URI:" + ringtoneUri
+ " ignored: failure to find mimeType (no access from this context?)");
return;
}
if (!(mimeType.startsWith("audio/") || mimeType.equals("application/ogg"))) {
Log.e(TAG, "onSaveRingtone for URI:" + ringtoneUri
+ " ignored: associated mimeType:" + mimeType + " is not an audio type");
return;
}
setActualDefaultRingtoneUri(ringtoneUri);
}
@VisibleForTesting
void setActualDefaultRingtoneUri(Uri ringtoneUri) {
RingtoneManager.setActualDefaultRingtoneUri(mUserContext, getRingtoneType(), ringtoneUri); RingtoneManager.setActualDefaultRingtoneUri(mUserContext, getRingtoneType(), ringtoneUri);
} }

View File

@@ -18,11 +18,14 @@ package com.android.settings.applications;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.LocaleConfig;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.LocaleList;
import android.util.FeatureFlagUtils;
import android.util.Log; import android.util.Log;
import com.android.settings.R; import com.android.settings.R;
@@ -46,12 +49,17 @@ public class AppLocaleUtil {
boolean isDisallowedPackage = isDisallowedPackage(context, packageName); boolean isDisallowedPackage = isDisallowedPackage(context, packageName);
boolean hasLauncherEntry = hasLauncherEntry(packageName, infos); boolean hasLauncherEntry = hasLauncherEntry(packageName, infos);
boolean isSignedWithPlatformKey = isSignedWithPlatformKey(context, packageName); boolean isSignedWithPlatformKey = isSignedWithPlatformKey(context, packageName);
boolean isAppLocaleSupported = isAppLocaleSupported(context, packageName);
Log.i(TAG, "Can display preference - [" + packageName + "] :" Log.i(TAG, "Can display preference - [" + packageName + "] :"
+ " isDisallowedPackage : " + isDisallowedPackage + " isDisallowedPackage : " + isDisallowedPackage
+ " / isSignedWithPlatformKey : " + isSignedWithPlatformKey + " / isSignedWithPlatformKey : " + isSignedWithPlatformKey
+ " / hasLauncherEntry : " + hasLauncherEntry); + " / hasLauncherEntry : " + hasLauncherEntry
+ " / isAppLocaleSupported : " + isAppLocaleSupported);
return !isDisallowedPackage && !isSignedWithPlatformKey && hasLauncherEntry; return !isDisallowedPackage
&& !isSignedWithPlatformKey
&& hasLauncherEntry
&& isAppLocaleSupported;
} }
private static boolean isDisallowedPackage(Context context, String packageName) { private static boolean isDisallowedPackage(Context context, String packageName) {
@@ -86,4 +94,61 @@ public class AppLocaleUtil {
return infos.stream() return infos.stream()
.anyMatch(info -> info.activityInfo.packageName.equals(packageName)); .anyMatch(info -> info.activityInfo.packageName.equals(packageName));
} }
/**
* Check the function of per app language is supported by current application.
*/
public static boolean isAppLocaleSupported(Context context, String packageName) {
if (getPackageLocales(context, packageName) != null) {
return true;
}
if (FeatureFlagUtils.isEnabled(
context, FeatureFlagUtils.SETTINGS_APP_LOCALE_OPT_IN_ENABLED)) {
return false;
}
return getAssetLocales(context, packageName).length > 0;
}
/**
* Get locales fron AssetManager.
*/
public static String[] getAssetLocales(Context context, String packageName) {
try {
PackageManager packageManager = context.getPackageManager();
String[] locales = packageManager.getResourcesForApplication(
packageManager.getPackageInfo(packageName, PackageManager.MATCH_ALL)
.applicationInfo).getAssets().getNonSystemLocales();
if (locales == null) {
Log.i(TAG, "[" + packageName + "] locales are null.");
}
if (locales.length <= 0) {
Log.i(TAG, "[" + packageName + "] locales length is 0.");
return new String[0];
}
String locale = locales[0];
Log.i(TAG, "First asset locale - [" + packageName + "] " + locale);
return locales;
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Can not found the package name : " + packageName + " / " + e);
}
return new String[0];
}
/**
* Get locales from LocaleConfig.
*/
public static LocaleList getPackageLocales(Context context, String packageName) {
try {
LocaleConfig localeConfig =
new LocaleConfig(context.createPackageContext(packageName, 0));
if (localeConfig.getStatus() == LocaleConfig.STATUS_SUCCESS) {
return localeConfig.getSupportedLocales();
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Can not found the package name : " + packageName + " / " + e);
}
return null;
}
} }

View File

@@ -36,6 +36,8 @@ public abstract class AppStateBaseBridge implements ApplicationsState.Callbacks
protected final BackgroundHandler mHandler; protected final BackgroundHandler mHandler;
protected final MainHandler mMainHandler; protected final MainHandler mMainHandler;
private boolean mForceLoadAllApps;
public AppStateBaseBridge(ApplicationsState appState, Callback callback) { public AppStateBaseBridge(ApplicationsState appState, Callback callback) {
mAppState = appState; mAppState = appState;
mAppSession = mAppState != null ? mAppState.newSession(this) : null; mAppSession = mAppState != null ? mAppState.newSession(this) : null;
@@ -48,13 +50,22 @@ public abstract class AppStateBaseBridge implements ApplicationsState.Callbacks
mMainHandler = new MainHandler(Looper.getMainLooper()); mMainHandler = new MainHandler(Looper.getMainLooper());
} }
public void resume() { public void resume(boolean forceLoadAllApps) {
mForceLoadAllApps = forceLoadAllApps;
mHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ALL); mHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ALL);
mAppSession.onResume(); if (mForceLoadAllApps) {
mAppSession.onResume();
} else {
mAppSession.activateSession();
}
} }
public void pause() { public void pause() {
mAppSession.onPause(); if (mForceLoadAllApps) {
mAppSession.onPause();
} else {
mAppSession.deactivateSession();
}
} }
public void release() { public void release() {

View File

@@ -74,7 +74,7 @@ public class SpecialAppAccessPreferenceController extends BasePreferenceControll
@Override @Override
public void onStart() { public void onStart() {
mDataUsageBridge.resume(); mDataUsageBridge.resume(true /* forceLoadAllApps */);
} }
@Override @Override

View File

@@ -18,7 +18,6 @@ package com.android.settings.applications.appinfo;
import static com.android.settings.widget.EntityHeaderController.ActionType; import static com.android.settings.widget.EntityHeaderController.ActionType;
import android.app.Activity; import android.app.Activity;
import android.app.LocaleConfig;
import android.app.LocaleManager; import android.app.LocaleManager;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
@@ -31,6 +30,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList; import android.os.LocaleList;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.FeatureFlagUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -44,6 +44,7 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase; import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.AppLocaleUtil;
import com.android.settings.widget.EntityHeaderController; import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils; import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry; import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -62,10 +63,12 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
private static final String KEY_APP_DESCRIPTION = "app_locale_description"; private static final String KEY_APP_DESCRIPTION = "app_locale_description";
private static final String KEY_WARNINGS = "key_warnings"; private static final String KEY_WARNINGS = "key_warnings";
private static final String KEY_APP_DISCLAIMER = "app_locale_disclaimer";
private boolean mCreated = false; private boolean mCreated = false;
private String mPackageName; private String mPackageName;
private LayoutPreference mPrefOfDescription; private LayoutPreference mPrefOfDescription;
private Preference mPrefOfDisclaimer;
private ApplicationInfo mApplicationInfo; private ApplicationInfo mApplicationInfo;
/** /**
@@ -91,8 +94,10 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
} }
addPreferencesFromResource(R.xml.app_locale_details); addPreferencesFromResource(R.xml.app_locale_details);
mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION); mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION);
mPrefOfDisclaimer = getPreferenceScreen().findPreference(KEY_APP_DISCLAIMER);
mApplicationInfo = getApplicationInfo(mPackageName, getContext().getUserId()); mApplicationInfo = getApplicationInfo(mPackageName, getContext().getUserId());
setWarningMessage(); setWarningMessage();
setDisclaimerPreference();
} }
// Override here so we don't have an empty screen // Override here so we don't have an empty screen
@@ -171,6 +176,13 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
} }
} }
private void setDisclaimerPreference() {
if (FeatureFlagUtils.isEnabled(
getContext(), FeatureFlagUtils.SETTINGS_APP_LOCALE_OPT_IN_ENABLED)) {
mPrefOfDisclaimer.setVisible(false);
}
}
private void setDescription() { private void setDescription() {
int res = getAppDescription(); int res = getAppDescription();
if (res != -1) { if (res != -1) {
@@ -206,8 +218,8 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
} }
private int getAppDescription() { private int getAppDescription() {
LocaleList packageLocaleList = getPackageLocales(); LocaleList packageLocaleList = AppLocaleUtil.getPackageLocales(getContext(), mPackageName);
String[] assetLocaleList = getAssetLocales(); String[] assetLocaleList = AppLocaleUtil.getAssetLocales(getContext(), mPackageName);
// TODO add apended url string, "Learn more", to these both sentenses. // TODO add apended url string, "Learn more", to these both sentenses.
if ((packageLocaleList != null && packageLocaleList.isEmpty()) if ((packageLocaleList != null && packageLocaleList.isEmpty())
|| (packageLocaleList == null && assetLocaleList.length == 0)) { || (packageLocaleList == null && assetLocaleList.length == 0)) {
@@ -216,41 +228,6 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
return -1; return -1;
} }
private String[] getAssetLocales() {
try {
PackageManager packageManager = getContext().getPackageManager();
String[] locales = packageManager.getResourcesForApplication(
packageManager.getPackageInfo(mPackageName, PackageManager.MATCH_ALL)
.applicationInfo).getAssets().getNonSystemLocales();
if (locales == null) {
Log.i(TAG, "[" + mPackageName + "] locales are null.");
}
if (locales.length <= 0) {
Log.i(TAG, "[" + mPackageName + "] locales length is 0.");
return new String[0];
}
String locale = locales[0];
Log.i(TAG, "First asset locale - [" + mPackageName + "] " + locale);
return locales;
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e);
}
return new String[0];
}
private LocaleList getPackageLocales() {
try {
LocaleConfig localeConfig =
new LocaleConfig(getContext().createPackageContext(mPackageName, 0));
if (localeConfig.getStatus() == LocaleConfig.STATUS_SUCCESS) {
return localeConfig.getSupportedLocales();
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e);
}
return null;
}
/** Gets per app's default locale */ /** Gets per app's default locale */
public static Locale getAppDefaultLocale(Context context, String packageName) { public static Locale getAppDefaultLocale(Context context, String packageName) {
LocaleManager localeManager = context.getSystemService(LocaleManager.class); LocaleManager localeManager = context.getSystemService(LocaleManager.class);

View File

@@ -1185,7 +1185,7 @@ public class ManageApplications extends InstrumentedFragment
mSession.onResume(); mSession.onResume();
mLastSortMode = sort; mLastSortMode = sort;
if (mExtraInfoBridge != null) { if (mExtraInfoBridge != null) {
mExtraInfoBridge.resume(); mExtraInfoBridge.resume(false /* forceLoadAllApps */);
} }
rebuild(); rebuild();
} else { } else {

View File

@@ -92,6 +92,7 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
private PreferenceGroup mPreferenceGroup; private PreferenceGroup mPreferenceGroup;
private FooterPreference mFooterPreference; private FooterPreference mFooterPreference;
private boolean mFirstLaunch = true;
static { static {
FILTER.addAction(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); FILTER.addAction(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
@@ -120,6 +121,17 @@ public class DeviceAdminListPreferenceController extends BasePreferenceControlle
updateList(); updateList();
} }
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mFirstLaunch) {
mFirstLaunch = false;
// When first launch, updateList() is already be called in displayPreference().
} else {
updateList();
}
}
@Override @Override
public void onStart() { public void onStart() {
mContext.registerReceiverAsUser( mContext.registerReceiverAsUser(

View File

@@ -74,7 +74,7 @@ public class PremiumSmsAccess extends EmptyTextSettings
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mSmsBackend.resume(); mSmsBackend.resume(true /* forceLoadAllApps */);
} }
@Override @Override

View File

@@ -58,6 +58,7 @@ public class CategoryMixin implements LifecycleObserver {
private final PackageReceiver mPackageReceiver = new PackageReceiver(); private final PackageReceiver mPackageReceiver = new PackageReceiver();
private final List<CategoryListener> mCategoryListeners = new ArrayList<>(); private final List<CategoryListener> mCategoryListeners = new ArrayList<>();
private int mCategoriesUpdateTaskCount; private int mCategoriesUpdateTaskCount;
private boolean mFirstOnResume = true;
public CategoryMixin(Context context) { public CategoryMixin(Context context) {
mContext = context; mContext = context;
@@ -75,6 +76,12 @@ public class CategoryMixin implements LifecycleObserver {
filter.addDataScheme(DATA_SCHEME_PKG); filter.addDataScheme(DATA_SCHEME_PKG);
mContext.registerReceiver(mPackageReceiver, filter); mContext.registerReceiver(mPackageReceiver, filter);
if (mFirstOnResume) {
// Skip since all tiles have been refreshed in DashboardFragment.onCreatePreferences().
Log.d(TAG, "Skip categories update");
mFirstOnResume = false;
return;
}
updateCategories(); updateCategories();
} }

View File

@@ -235,13 +235,13 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
public void onDataChanged() { public void onDataChanged() {
switch (method) { switch (method) {
case METHOD_GET_DYNAMIC_TITLE: case METHOD_GET_DYNAMIC_TITLE:
refreshTitle(uri, pref); refreshTitle(uri, pref, this);
break; break;
case METHOD_GET_DYNAMIC_SUMMARY: case METHOD_GET_DYNAMIC_SUMMARY:
refreshSummary(uri, pref); refreshSummary(uri, pref, this);
break; break;
case METHOD_IS_CHECKED: case METHOD_IS_CHECKED:
refreshSwitch(uri, pref); refreshSwitch(uri, pref, this);
break; break;
} }
} }
@@ -262,19 +262,18 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
final Uri uri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_TITLE_URI, final Uri uri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_TITLE_URI,
METHOD_GET_DYNAMIC_TITLE); METHOD_GET_DYNAMIC_TITLE);
refreshTitle(uri, preference);
return createDynamicDataObserver(METHOD_GET_DYNAMIC_TITLE, uri, preference); return createDynamicDataObserver(METHOD_GET_DYNAMIC_TITLE, uri, preference);
} }
return null; return null;
} }
private void refreshTitle(Uri uri, Preference preference) { private void refreshTitle(Uri uri, Preference preference, DynamicDataObserver observer) {
ThreadUtils.postOnBackgroundThread(() -> { ThreadUtils.postOnBackgroundThread(() -> {
final Map<String, IContentProvider> providerMap = new ArrayMap<>(); final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String titleFromUri = TileUtils.getTextFromUri( final String titleFromUri = TileUtils.getTextFromUri(
mContext, uri, providerMap, META_DATA_PREFERENCE_TITLE); mContext, uri, providerMap, META_DATA_PREFERENCE_TITLE);
if (!TextUtils.equals(titleFromUri, preference.getTitle())) { if (!TextUtils.equals(titleFromUri, preference.getTitle())) {
ThreadUtils.postOnMainThread(() -> preference.setTitle(titleFromUri)); observer.post(() -> preference.setTitle(titleFromUri));
} }
}); });
} }
@@ -291,19 +290,18 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
final Uri uri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_SUMMARY_URI, final Uri uri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_SUMMARY_URI,
METHOD_GET_DYNAMIC_SUMMARY); METHOD_GET_DYNAMIC_SUMMARY);
refreshSummary(uri, preference);
return createDynamicDataObserver(METHOD_GET_DYNAMIC_SUMMARY, uri, preference); return createDynamicDataObserver(METHOD_GET_DYNAMIC_SUMMARY, uri, preference);
} }
return null; return null;
} }
private void refreshSummary(Uri uri, Preference preference) { private void refreshSummary(Uri uri, Preference preference, DynamicDataObserver observer) {
ThreadUtils.postOnBackgroundThread(() -> { ThreadUtils.postOnBackgroundThread(() -> {
final Map<String, IContentProvider> providerMap = new ArrayMap<>(); final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String summaryFromUri = TileUtils.getTextFromUri( final String summaryFromUri = TileUtils.getTextFromUri(
mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY); mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY);
if (!TextUtils.equals(summaryFromUri, preference.getSummary())) { if (!TextUtils.equals(summaryFromUri, preference.getSummary())) {
ThreadUtils.postOnMainThread(() -> preference.setSummary(summaryFromUri)); observer.post(() -> preference.setSummary(summaryFromUri));
} }
}); });
} }
@@ -323,7 +321,6 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
final Uri isCheckedUri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_SWITCH_URI, final Uri isCheckedUri = TileUtils.getCompleteUri(tile, META_DATA_PREFERENCE_SWITCH_URI,
METHOD_IS_CHECKED); METHOD_IS_CHECKED);
setSwitchEnabled(preference, false); setSwitchEnabled(preference, false);
refreshSwitch(isCheckedUri, preference);
return createDynamicDataObserver(METHOD_IS_CHECKED, isCheckedUri, preference); return createDynamicDataObserver(METHOD_IS_CHECKED, isCheckedUri, preference);
} }
@@ -350,12 +347,12 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
}); });
} }
private void refreshSwitch(Uri uri, Preference preference) { private void refreshSwitch(Uri uri, Preference preference, DynamicDataObserver observer) {
ThreadUtils.postOnBackgroundThread(() -> { ThreadUtils.postOnBackgroundThread(() -> {
final Map<String, IContentProvider> providerMap = new ArrayMap<>(); final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final boolean checked = TileUtils.getBooleanFromUri(mContext, uri, providerMap, final boolean checked = TileUtils.getBooleanFromUri(mContext, uri, providerMap,
EXTRA_SWITCH_CHECKED_STATE); EXTRA_SWITCH_CHECKED_STATE);
ThreadUtils.postOnMainThread(() -> { observer.post(() -> {
setSwitchChecked(preference, checked); setSwitchChecked(preference, checked);
setSwitchEnabled(preference, true); setSwitchEnabled(preference, true);
}); });

View File

@@ -16,7 +16,6 @@
package com.android.settings.dashboard; package com.android.settings.dashboard;
import android.app.Activity; import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
@@ -57,6 +56,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/** /**
* Base fragment for dashboard style UI containing a list of static and dynamic setting items. * Base fragment for dashboard style UI containing a list of static and dynamic setting items.
@@ -66,6 +67,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
BasePreferenceController.UiBlockListener { BasePreferenceController.UiBlockListener {
public static final String CATEGORY = "category"; public static final String CATEGORY = "category";
private static final String TAG = "DashboardFragment"; private static final String TAG = "DashboardFragment";
private static final long TIMEOUT_MILLIS = 50L;
@VisibleForTesting @VisibleForTesting
final ArrayMap<String, List<DynamicDataObserver>> mDashboardTilePrefKeys = new ArrayMap<>(); final ArrayMap<String, List<DynamicDataObserver>> mDashboardTilePrefKeys = new ArrayMap<>();
@@ -461,8 +463,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
// Create a list to track which tiles are to be removed. // Create a list to track which tiles are to be removed.
final Map<String, List<DynamicDataObserver>> remove = new ArrayMap(mDashboardTilePrefKeys); final Map<String, List<DynamicDataObserver>> remove = new ArrayMap(mDashboardTilePrefKeys);
// Install dashboard tiles. // Install dashboard tiles and collect pending observers.
final boolean forceRoundedIcons = shouldForceRoundedIcon(); final boolean forceRoundedIcons = shouldForceRoundedIcon();
final List<DynamicDataObserver> pendingObservers = new ArrayList<>();
for (Tile tile : tiles) { for (Tile tile : tiles) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile); final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
@@ -472,26 +475,30 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
if (!displayTile(tile)) { if (!displayTile(tile)) {
continue; continue;
} }
final List<DynamicDataObserver> observers;
if (mDashboardTilePrefKeys.containsKey(key)) { if (mDashboardTilePrefKeys.containsKey(key)) {
// Have the key already, will rebind. // Have the key already, will rebind.
final Preference preference = screen.findPreference(key); final Preference preference = screen.findPreference(key);
mDashboardFeatureProvider.bindPreferenceToTileAndGetObservers(getActivity(), this, observers = mDashboardFeatureProvider.bindPreferenceToTileAndGetObservers(
forceRoundedIcons, preference, tile, key, getActivity(), this, forceRoundedIcons, preference, tile, key,
mPlaceholderPreferenceController.getOrder()); mPlaceholderPreferenceController.getOrder());
} else { } else {
// Don't have this key, add it. // Don't have this key, add it.
final Preference pref = createPreference(tile); final Preference pref = createPreference(tile);
final List<DynamicDataObserver> observers = observers = mDashboardFeatureProvider.bindPreferenceToTileAndGetObservers(
mDashboardFeatureProvider.bindPreferenceToTileAndGetObservers(getActivity(), getActivity(), this, forceRoundedIcons, pref, tile, key,
this, forceRoundedIcons, pref, tile, key, mPlaceholderPreferenceController.getOrder());
mPlaceholderPreferenceController.getOrder());
screen.addPreference(pref); screen.addPreference(pref);
registerDynamicDataObservers(observers); registerDynamicDataObservers(observers);
mDashboardTilePrefKeys.put(key, observers); mDashboardTilePrefKeys.put(key, observers);
} }
if (observers != null) {
pendingObservers.addAll(observers);
}
remove.remove(key); remove.remove(key);
} }
// Finally remove tiles that are gone.
// Remove tiles that are gone.
for (Map.Entry<String, List<DynamicDataObserver>> entry : remove.entrySet()) { for (Map.Entry<String, List<DynamicDataObserver>> entry : remove.entrySet()) {
final String key = entry.getKey(); final String key = entry.getKey();
mDashboardTilePrefKeys.remove(key); mDashboardTilePrefKeys.remove(key);
@@ -501,6 +508,20 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
} }
unregisterDynamicDataObservers(entry.getValue()); unregisterDynamicDataObservers(entry.getValue());
} }
// Wait for pending observers to update UI.
if (!pendingObservers.isEmpty()) {
final CountDownLatch mainLatch = new CountDownLatch(1);
new Thread(() -> {
pendingObservers.forEach(observer ->
awaitObserverLatch(observer.getCountDownLatch()));
mainLatch.countDown();
}).start();
Log.d(tag, "Start waiting observers");
awaitObserverLatch(mainLatch);
Log.d(tag, "Stop waiting observers");
pendingObservers.forEach(DynamicDataObserver::updateUi);
}
} }
@Override @Override
@@ -546,4 +567,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
resolver.unregisterContentObserver(observer); resolver.unregisterContentObserver(observer);
}); });
} }
private void awaitObserverLatch(CountDownLatch latch) {
try {
latch.await(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// Do nothing
}
}
} }

View File

@@ -20,13 +20,24 @@ import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import com.android.settingslib.utils.ThreadUtils;
import java.util.concurrent.CountDownLatch;
/** /**
* Observer for updating injected dynamic data. * Observer for updating injected dynamic data.
*/ */
public abstract class DynamicDataObserver extends ContentObserver { public abstract class DynamicDataObserver extends ContentObserver {
private Runnable mUpdateRunnable;
private CountDownLatch mCountDownLatch;
private boolean mUpdateDelegated;
protected DynamicDataObserver() { protected DynamicDataObserver() {
super(new Handler(Looper.getMainLooper())); super(new Handler(Looper.getMainLooper()));
mCountDownLatch = new CountDownLatch(1);
// Load data for the first time
onDataChanged();
} }
/** Returns the uri of the callback. */ /** Returns the uri of the callback. */
@@ -35,8 +46,30 @@ public abstract class DynamicDataObserver extends ContentObserver {
/** Called when data changes. */ /** Called when data changes. */
public abstract void onDataChanged(); public abstract void onDataChanged();
/** Calls the runnable to update UI */
public synchronized void updateUi() {
mUpdateDelegated = true;
if (mUpdateRunnable != null) {
mUpdateRunnable.run();
}
}
/** Returns the count-down latch */
public CountDownLatch getCountDownLatch() {
return mCountDownLatch;
}
@Override @Override
public void onChange(boolean selfChange) { public void onChange(boolean selfChange) {
onDataChanged(); onDataChanged();
} }
protected synchronized void post(Runnable runnable) {
if (mUpdateDelegated) {
ThreadUtils.postOnMainThread(runnable);
} else {
mUpdateRunnable = runnable;
mCountDownLatch.countDown();
}
}
} }

View File

@@ -120,7 +120,7 @@ public class UserAdapter extends BaseAdapter {
private void bindViewHolder(ViewHolder holder, int position) { private void bindViewHolder(ViewHolder holder, int position) {
UserDetails userDetails = getItem(position); UserDetails userDetails = getItem(position);
holder.getIconView().setImageDrawable(userDetails.mIcon); holder.getIconView().setImageDrawable(userDetails.mIcon);
holder.getTitleView().setText(userDetails.mTitle); holder.setTitle(userDetails.mTitle);
} }
@Override @Override
@@ -206,18 +206,19 @@ public class UserAdapter extends BaseAdapter {
static class ViewHolder extends RecyclerView.ViewHolder { static class ViewHolder extends RecyclerView.ViewHolder {
private final ImageView mIconView; private final ImageView mIconView;
private final TextView mTitleView; private final TextView mTitleView;
private final View mButtonView;
private ViewHolder(View view) { private ViewHolder(View view) {
super(view); super(view);
mIconView = view.findViewById(android.R.id.icon); mIconView = view.findViewById(android.R.id.icon);
mTitleView = view.findViewById(android.R.id.title); mTitleView = view.findViewById(android.R.id.title);
mButtonView = view.findViewById(R.id.button);
} }
private ViewHolder(View view, OnClickListener onClickListener) { private ViewHolder(View view, OnClickListener onClickListener) {
this(view); this(view);
View button = view.findViewById(R.id.button); if (mButtonView != null) {
if (button != null) { mButtonView.setOnClickListener(v -> onClickListener.onClick(getAdapterPosition()));
button.setOnClickListener(v -> onClickListener.onClick(getAdapterPosition()));
} }
} }
@@ -225,8 +226,11 @@ public class UserAdapter extends BaseAdapter {
return mIconView; return mIconView;
} }
private TextView getTitleView() { private void setTitle(CharSequence title) {
return mTitleView; mTitleView.setText(title);
if (mButtonView != null) {
mButtonView.setContentDescription(title);
}
} }
} }

View File

@@ -83,7 +83,7 @@ public class DataSaverSummary extends SettingsPreferenceFragment
mDataSaverBackend.refreshAllowlist(); mDataSaverBackend.refreshAllowlist();
mDataSaverBackend.refreshDenylist(); mDataSaverBackend.refreshDenylist();
mDataSaverBackend.addListener(this); mDataSaverBackend.addListener(this);
mDataUsageBridge.resume(); mDataUsageBridge.resume(true /* forceLoadAllApps */);
} }
@Override @Override

View File

@@ -91,7 +91,7 @@ public class UnrestrictedDataAccessPreferenceController extends BasePreferenceCo
@Override @Override
public void onStart() { public void onStart() {
mDataUsageBridge.resume(); mDataUsageBridge.resume(true /* forceLoadAllApps */);
} }
@Override @Override

View File

@@ -209,7 +209,8 @@ public class BatteryEntry {
if (packages != null && packages.length == 1) { if (packages != null && packages.length == 1) {
mDefaultPackageName = packages[0]; mDefaultPackageName = packages[0];
} else { } else {
mDefaultPackageName = uidBatteryConsumer.getPackageWithHighestDrain(); mDefaultPackageName = isSystemUid(uid)
? PACKAGE_SYSTEM : uidBatteryConsumer.getPackageWithHighestDrain();
} }
} }
if (mDefaultPackageName != null) { if (mDefaultPackageName != null) {
@@ -352,13 +353,8 @@ public class BatteryEntry {
} }
final PackageManager pm = context.getPackageManager(); final PackageManager pm = context.getPackageManager();
final String[] packages; final String[] packages = isSystemUid(uid)
if (uid == Process.SYSTEM_UID) { ? new String[] {PACKAGE_SYSTEM} : pm.getPackagesForUid(uid);
packages = new String[] {PACKAGE_SYSTEM};
} else {
packages = pm.getPackagesForUid(uid);
}
if (packages != null) { if (packages != null) {
final String[] packageLabels = new String[packages.length]; final String[] packageLabels = new String[packages.length];
System.arraycopy(packages, 0, packageLabels, 0, packages.length); System.arraycopy(packages, 0, packageLabels, 0, packages.length);
@@ -615,4 +611,8 @@ public class BatteryEntry {
} }
return new NameAndIcon(name, null /* icon */, iconId); return new NameAndIcon(name, null /* icon */, iconId);
} }
private static boolean isSystemUid(int uid) {
return uid == Process.SYSTEM_UID;
}
} }

View File

@@ -176,7 +176,7 @@ public class BluetoothDevicesSlice implements CustomSliceable {
List<CachedBluetoothDevice> getPairedBluetoothDevices() { List<CachedBluetoothDevice> getPairedBluetoothDevices() {
final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>(); final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
// If Bluetooth is disable, skip getting the Bluetooth devices. // If Bluetooth is disabled, skip getting the Bluetooth devices.
if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled."); Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled.");
return bluetoothDeviceList; return bluetoothDeviceList;

View File

@@ -16,6 +16,8 @@
package com.android.settings.language; package com.android.settings.language;
import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_DICTIONARY_FOR_WORK;
import static android.app.admin.DevicePolicyResources.Strings.Settings.SPELL_CHECKER_FOR_WORK;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_KEYBOARDS_AND_TOOLS; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_KEYBOARDS_AND_TOOLS;
import android.app.Activity; import android.app.Activity;
@@ -80,6 +82,12 @@ public class LanguageAndInputSettings extends DashboardFragment {
replaceEnterpriseStringTitle("language_and_input_for_work_category", replaceEnterpriseStringTitle("language_and_input_for_work_category",
WORK_PROFILE_KEYBOARDS_AND_TOOLS, WORK_PROFILE_KEYBOARDS_AND_TOOLS,
R.string.language_and_input_for_work_category_title); R.string.language_and_input_for_work_category_title);
replaceEnterpriseStringTitle("spellcheckers_settings_for_work_pref",
SPELL_CHECKER_FOR_WORK,
R.string.spellcheckers_settings_for_work_title);
replaceEnterpriseStringTitle("user_dictionary_settings_for_work_pref",
PERSONAL_DICTIONARY_FOR_WORK,
R.string.user_dict_settings_for_work_title);
} }
@Override @Override

View File

@@ -20,7 +20,6 @@ package com.android.settings.notification;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME; import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_PACKAGE_TITLE;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID; import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID;
import android.Manifest; import android.Manifest;
@@ -30,10 +29,13 @@ import android.app.NotificationManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Slog; import android.util.Slog;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
@@ -63,15 +65,38 @@ public class NotificationAccessConfirmationActivity extends Activity
mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME); mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL); mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
String pkgTitle = getIntent().getStringExtra(EXTRA_PACKAGE_TITLE); CharSequence mAppLabel;
if (mComponentName == null || mComponentName.getPackageName() == null) {
finish();
return;
}
try {
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
mComponentName.getPackageName(), 0);
mAppLabel = applicationInfo.loadSafeLabel(getPackageManager(),
PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
PackageItemInfo.SAFE_LABEL_FLAG_TRIM
| PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
} catch (PackageManager.NameNotFoundException e) {
Slog.e(LOG_TAG, "Couldn't find app with package name for " + mComponentName, e);
finish();
return;
}
if (TextUtils.isEmpty(mAppLabel)) {
finish();
return;
}
AlertController.AlertParams p = new AlertController.AlertParams(this); AlertController.AlertParams p = new AlertController.AlertParams(this);
p.mTitle = getString( p.mTitle = getString(
R.string.notification_listener_security_warning_title, R.string.notification_listener_security_warning_title,
pkgTitle); mAppLabel);
p.mMessage = getString( p.mMessage = getString(
R.string.notification_listener_security_warning_summary, R.string.notification_listener_security_warning_summary,
pkgTitle); mAppLabel);
p.mPositiveButtonText = getString(R.string.allow); p.mPositiveButtonText = getString(R.string.allow);
p.mPositiveButtonListener = (a, b) -> onAllow(); p.mPositiveButtonListener = (a, b) -> onAllow();
p.mNegativeButtonText = getString(R.string.deny); p.mNegativeButtonText = getString(R.string.deny);

View File

@@ -57,7 +57,7 @@ public class SpatialAudioParentPreferenceController extends BasePreferenceContro
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
boolean speakerOn = mSpatialAudioPreferenceController.isAvailable() boolean speakerOn = mSpatialAudioPreferenceController.isAvailable()
&& mSpatialAudioWiredHeadphonesController.isChecked(); && mSpatialAudioPreferenceController.isChecked();
boolean wiredHeadphonesOn = mSpatialAudioWiredHeadphonesController.isAvailable() boolean wiredHeadphonesOn = mSpatialAudioWiredHeadphonesController.isAvailable()
&& mSpatialAudioWiredHeadphonesController.isChecked(); && mSpatialAudioWiredHeadphonesController.isChecked();
if (speakerOn && wiredHeadphonesOn) { if (speakerOn && wiredHeadphonesOn) {

View File

@@ -18,6 +18,7 @@ package com.android.settings.notification.zen;
import android.app.AutomaticZenRule; import android.app.AutomaticZenRule;
import android.content.Context; import android.content.Context;
import android.util.ArrayMap;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@@ -28,7 +29,6 @@ import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class ZenModeAutomaticRulesPreferenceController extends public class ZenModeAutomaticRulesPreferenceController extends
AbstractZenModeAutomaticRulePreferenceController { AbstractZenModeAutomaticRulePreferenceController {
@@ -38,6 +38,10 @@ public class ZenModeAutomaticRulesPreferenceController extends
@VisibleForTesting @VisibleForTesting
protected PreferenceCategory mPreferenceCategory; protected PreferenceCategory mPreferenceCategory;
// Map of rule key -> preference so that we can update each preference as needed
@VisibleForTesting
protected Map<String, ZenRulePreference> mZenRulePreferences = new ArrayMap<>();
public ZenModeAutomaticRulesPreferenceController(Context context, Fragment parent, Lifecycle public ZenModeAutomaticRulesPreferenceController(Context context, Fragment parent, Lifecycle
lifecycle) { lifecycle) {
super(context, KEY, parent, lifecycle); super(context, KEY, parent, lifecycle);
@@ -58,38 +62,73 @@ public class ZenModeAutomaticRulesPreferenceController extends
super.displayPreference(screen); super.displayPreference(screen);
mPreferenceCategory = screen.findPreference(getPreferenceKey()); mPreferenceCategory = screen.findPreference(getPreferenceKey());
mPreferenceCategory.setPersistent(false); mPreferenceCategory.setPersistent(false);
// if mPreferenceCategory was un-set, make sure to clear out mZenRulePreferences too, just
// in case
if (mPreferenceCategory.getPreferenceCount() == 0) {
mZenRulePreferences.clear();
}
} }
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
Map.Entry<String, AutomaticZenRule>[] sortedRules = getRules(); Map.Entry<String, AutomaticZenRule>[] sortedRules = getRules();
final int currNumPreferences = mPreferenceCategory.getPreferenceCount();
if (currNumPreferences == sortedRules.length) { // refresh the whole preference category list if the total number of rules has changed, or
// if any individual rules have changed, so we can rebuild the list & keep things in sync
boolean refreshPrefs = false;
if (mPreferenceCategory.getPreferenceCount() != sortedRules.length) {
refreshPrefs = true;
} else {
// check whether any rules in sortedRules are not in mZenRulePreferences; that should
// be enough to see whether something has changed
for (int i = 0; i < sortedRules.length; i++) { for (int i = 0; i < sortedRules.length; i++) {
ZenRulePreference pref = (ZenRulePreference) mPreferenceCategory.getPreference(i); if (!mZenRulePreferences.containsKey(sortedRules[i].getKey())) {
// we are either: refreshPrefs = true;
// 1. updating everything about the rule
// 2. rule was added or deleted, so reload the entire list
if (Objects.equals(pref.mId, sortedRules[i].getKey())) {
AutomaticZenRule rule = sortedRules[i].getValue();
pref.updatePreference(rule);
} else {
reloadAllRules(sortedRules);
break; break;
} }
} }
} else {
reloadAllRules(sortedRules);
} }
}
@VisibleForTesting // if we need to refresh the whole list, clear the preference category and also start a
void reloadAllRules(Map.Entry<String, AutomaticZenRule>[] rules) { // new map of preferences according to the preference category contents
mPreferenceCategory.removeAll(); // we need to not update the existing one yet, as we'll need to know what preferences
for (Map.Entry<String, AutomaticZenRule> rule : rules) { // previously existed in order to update and re-attach them to the preference category
ZenRulePreference pref = createZenRulePreference(rule); Map<String, ZenRulePreference> newPrefs = new ArrayMap<>();
mPreferenceCategory.addPreference(pref); if (refreshPrefs) {
mPreferenceCategory.removeAll();
}
// Loop through each rule, either updating the existing rule or creating the rule's
// preference if needed (and, in the case where we need to rebuild the preference category
// list, do so as well)
for (int i = 0; i < sortedRules.length; i++) {
String key = sortedRules[i].getKey();
if (mZenRulePreferences.containsKey(key)) {
// existing rule; update its info if it's changed since the last display
AutomaticZenRule rule = sortedRules[i].getValue();
ZenRulePreference pref = mZenRulePreferences.get(key);
pref.updatePreference(rule);
// only add to preference category if the overall set of rules has changed so this
// needs to be rearranged
if (refreshPrefs) {
mPreferenceCategory.addPreference(pref);
newPrefs.put(key, pref);
}
} else {
// new rule; create a new ZenRulePreference & add it to the preference category
// and the map so we'll know about it later
ZenRulePreference pref = createZenRulePreference(sortedRules[i]);
mPreferenceCategory.addPreference(pref);
newPrefs.put(key, pref);
}
}
// If anything was new, then make sure we overwrite mZenRulePreferences with our new data
if (refreshPrefs) {
mZenRulePreferences = newPrefs;
} }
} }

View File

@@ -23,6 +23,7 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_LOW;
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM; import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE; import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.LOCK_SETTINGS_NEW_PROFILE_LOCK_TITLE; import static android.app.admin.DevicePolicyResources.Strings.Settings.LOCK_SETTINGS_NEW_PROFILE_LOCK_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.LOCK_SETTINGS_UPDATE_PROFILE_LOCK_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_IT_ADMIN_CANT_RESET_SCREEN_LOCK;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SCREEN_LOCK_SETUP_MESSAGE; import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SCREEN_LOCK_SETUP_MESSAGE;
@@ -347,7 +348,10 @@ public class ChooseLockGeneric extends SettingsActivity {
// it's an update. // it's an update.
updateExistingLock = mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId); updateExistingLock = mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId);
if (updateExistingLock) { if (updateExistingLock) {
getActivity().setTitle(R.string.lock_settings_picker_update_profile_lock_title); getActivity().setTitle(mDpm.getResources().getString(
LOCK_SETTINGS_UPDATE_PROFILE_LOCK_TITLE,
() -> getString(
R.string.lock_settings_picker_update_profile_lock_title)));
} else { } else {
getActivity().setTitle(mDpm.getResources().getString( getActivity().setTitle(mDpm.getResources().getString(
LOCK_SETTINGS_NEW_PROFILE_LOCK_TITLE, LOCK_SETTINGS_NEW_PROFILE_LOCK_TITLE,

View File

@@ -21,7 +21,7 @@ import android.content.Context;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.DropDownPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -30,13 +30,13 @@ import com.android.settings.wifi.WifiDialog2;
import com.android.wifitrackerlib.WifiEntry; import com.android.wifitrackerlib.WifiEntry;
/** /**
* {@link AbstractPreferenceController} that controls whether the wifi network is metered or not * A controller that controls whether the Wi-Fi network is metered or not.
*/ */
public class WifiMeteredPreferenceController2 extends BasePreferenceController implements public class WifiMeteredPreferenceController2 extends BasePreferenceController implements
Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener { Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener {
private static final String KEY_WIFI_METERED = "metered"; private static final String KEY_WIFI_METERED = "metered";
private WifiEntry mWifiEntry; private final WifiEntry mWifiEntry;
private Preference mPreference; private Preference mPreference;
public WifiMeteredPreferenceController2(Context context, WifiEntry wifiEntry) { public WifiMeteredPreferenceController2(Context context, WifiEntry wifiEntry) {
@@ -46,11 +46,11 @@ public class WifiMeteredPreferenceController2 extends BasePreferenceController i
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
final DropDownPreference dropDownPreference = (DropDownPreference) preference; final ListPreference listPreference = (ListPreference) preference;
final int meteredOverride = getMeteredOverride(); final int meteredOverride = getMeteredOverride();
preference.setSelectable(mWifiEntry.canSetMeteredChoice()); preference.setSelectable(mWifiEntry.canSetMeteredChoice());
dropDownPreference.setValue(Integer.toString(meteredOverride)); listPreference.setValue(Integer.toString(meteredOverride));
updateSummary(dropDownPreference, meteredOverride); updateSummary(listPreference, meteredOverride);
} }
@Override @Override
@@ -66,7 +66,7 @@ public class WifiMeteredPreferenceController2 extends BasePreferenceController i
// Stage the backup of the SettingsProvider package which backs this up // Stage the backup of the SettingsProvider package which backs this up
BackupManager.dataChanged("com.android.providers.settings"); BackupManager.dataChanged("com.android.providers.settings");
updateSummary((DropDownPreference) preference, getMeteredOverride()); updateSummary((ListPreference) preference, getMeteredOverride());
return true; return true;
} }
@@ -79,7 +79,7 @@ public class WifiMeteredPreferenceController2 extends BasePreferenceController i
return WifiEntry.METERED_CHOICE_AUTO; return WifiEntry.METERED_CHOICE_AUTO;
} }
private void updateSummary(DropDownPreference preference, int meteredOverride) { private void updateSummary(ListPreference preference, int meteredOverride) {
preference.setSummary(preference.getEntries()[meteredOverride]); preference.setSummary(preference.getEntries()[meteredOverride]);
} }

View File

@@ -21,7 +21,7 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.DropDownPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -31,14 +31,13 @@ import com.android.settings.wifi.WifiDialog2;
import com.android.wifitrackerlib.WifiEntry; import com.android.wifitrackerlib.WifiEntry;
/** /**
* {@link AbstractPreferenceController} that controls whether the wifi network is mac randomized * A controller that controls whether the Wi-Fi network is mac randomized or not.
* or not
*/ */
public class WifiPrivacyPreferenceController2 extends BasePreferenceController implements public class WifiPrivacyPreferenceController2 extends BasePreferenceController implements
Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener { Preference.OnPreferenceChangeListener, WifiDialog2.WifiDialog2Listener {
private static final String KEY_WIFI_PRIVACY = "privacy"; private static final String KEY_WIFI_PRIVACY = "privacy";
private WifiManager mWifiManager; private final WifiManager mWifiManager;
private WifiEntry mWifiEntry; private WifiEntry mWifiEntry;
private Preference mPreference; private Preference mPreference;
@@ -66,16 +65,16 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
final DropDownPreference dropDownPreference = (DropDownPreference) preference; final ListPreference listPreference = (ListPreference) preference;
final int randomizationLevel = getRandomizationValue(); final int randomizationLevel = getRandomizationValue();
final boolean isSelectable = mWifiEntry.canSetPrivacy(); final boolean isSelectable = mWifiEntry.canSetPrivacy();
preference.setSelectable(isSelectable); preference.setSelectable(isSelectable);
dropDownPreference.setValue(Integer.toString(randomizationLevel)); listPreference.setValue(Integer.toString(randomizationLevel));
updateSummary(dropDownPreference, randomizationLevel); updateSummary(listPreference, randomizationLevel);
// If the preference cannot be selectable, display a temporary network in the summary. // If the preference cannot be selectable, display a temporary network in the summary.
if (!isSelectable) { if (!isSelectable) {
dropDownPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary); listPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary);
} }
} }
@@ -90,7 +89,7 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
mWifiEntry.disconnect(null /* callback */); mWifiEntry.disconnect(null /* callback */);
mWifiEntry.connect(null /* callback */); mWifiEntry.connect(null /* callback */);
} }
updateSummary((DropDownPreference) preference, privacy); updateSummary((ListPreference) preference, privacy);
return true; return true;
} }
@@ -124,7 +123,7 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
? WifiEntry.PRIVACY_RANDOMIZED_MAC : WifiEntry.PRIVACY_DEVICE_MAC; ? WifiEntry.PRIVACY_RANDOMIZED_MAC : WifiEntry.PRIVACY_DEVICE_MAC;
} }
private void updateSummary(DropDownPreference preference, int macRandomized) { private void updateSummary(ListPreference preference, int macRandomized) {
// Translates value here to set RANDOMIZATION_PERSISTENT as first item in UI for better UX. // Translates value here to set RANDOMIZATION_PERSISTENT as first item in UI for better UX.
final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized); final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized);
preference.setSummary(preference.getEntries()[prefMacRandomized]); preference.setSummary(preference.getEntries()[prefMacRandomized]);

View File

@@ -308,8 +308,12 @@ public class DashboardFeatureProviderImplTest {
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */, mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
Preference.DEFAULT_ORDER); Preference.DEFAULT_ORDER);
assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString); assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString);
assertThat(preference.getSummary()).isNotEqualTo(ShadowTileUtils.MOCK_TEXT);
observers.get(0).updateUi();
assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_TEXT);
} }
@Test @Test
@@ -324,8 +328,12 @@ public class DashboardFeatureProviderImplTest {
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */, mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
Preference.DEFAULT_ORDER); Preference.DEFAULT_ORDER);
assertThat(preference.getTitle()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString); assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString);
assertThat(preference.getTitle()).isNotEqualTo(ShadowTileUtils.MOCK_TEXT);
observers.get(0).updateUi();
assertThat(preference.getTitle()).isEqualTo(ShadowTileUtils.MOCK_TEXT);
} }
@Test @Test
@@ -379,6 +387,7 @@ public class DashboardFeatureProviderImplTest {
final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers( final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */, mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
Preference.DEFAULT_ORDER); Preference.DEFAULT_ORDER);
observers.get(0).updateUi();
ShadowTileUtils.setProviderChecked(false); ShadowTileUtils.setProviderChecked(false);
observers.get(0).onDataChanged(); observers.get(0).onDataChanged();

View File

@@ -16,6 +16,8 @@
package com.android.settings.notification.zen; package com.android.settings.notification.zen;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@@ -33,10 +35,7 @@ import android.provider.Settings;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.notification.zen.ZenModeAutomaticRulesPreferenceController;
import com.android.settings.notification.zen.ZenModeBackend;
import com.android.settings.notification.zen.ZenRulePreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -45,7 +44,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.internal.util.reflection.FieldSetter; import org.mockito.internal.util.reflection.FieldSetter;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
import java.util.HashMap; import java.util.HashMap;
@@ -68,7 +66,7 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
@Before @Before
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application; mContext = ApplicationProvider.getApplicationContext();
mController = spy(new ZenModeAutomaticRulesPreferenceController(mContext, mock(Fragment.class), mController = spy(new ZenModeAutomaticRulesPreferenceController(mContext, mock(Fragment.class),
null)); null));
ReflectionHelpers.setField(mController, "mBackend", mBackend); ReflectionHelpers.setField(mController, "mBackend", mBackend);
@@ -78,6 +76,16 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
doReturn(mZenRulePreference).when(mController).createZenRulePreference(any()); doReturn(mZenRulePreference).when(mController).createZenRulePreference(any());
} }
@Test
public void testDisplayPreference_resetsPreferencesWhenCategoryEmpty() {
// when the PreferenceCategory is empty (no preferences), make sure we clear out any
// stale state in the cached set of zen rule preferences
mController.mZenRulePreferences.put("test1_id", mZenRulePreference);
when(mockPref.getPreferenceCount()).thenReturn(0);
mController.displayPreference(mPreferenceScreen);
assertTrue(mController.mZenRulePreferences.isEmpty());
}
@Test @Test
public void testUpdateState_clearsPreferencesWhenAddingNewPreferences() { public void testUpdateState_clearsPreferencesWhenAddingNewPreferences() {
final int NUM_RULES = 3; final int NUM_RULES = 3;
@@ -103,6 +111,7 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
mController.updateState(mockPref); mController.updateState(mockPref);
verify(mockPref, times(1)).removeAll(); verify(mockPref, times(1)).removeAll();
verify(mockPref, times(NUM_RULES)).addPreference(any()); verify(mockPref, times(NUM_RULES)).addPreference(any());
assertEquals(NUM_RULES, mController.mZenRulePreferences.size());
} }
@Test @Test
@@ -121,12 +130,49 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
rMap.put(ruleId1, autoRule1); rMap.put(ruleId1, autoRule1);
rMap.put(ruleId2, autoRule2); rMap.put(ruleId2, autoRule2);
// Add three preferences to the set of previously-known-about ZenRulePreferences; in this
// case, test3_id is "deleted"
mController.mZenRulePreferences.put("test1_id", mZenRulePreference);
mController.mZenRulePreferences.put("test2_id", mZenRulePreference);
mController.mZenRulePreferences.put("test3_id", mZenRulePreference);
// update state should re-add all preferences since a preference was deleted // update state should re-add all preferences since a preference was deleted
when(mockPref.getPreferenceCount()).thenReturn(NUM_RULES + 2); when(mockPref.getPreferenceCount()).thenReturn(NUM_RULES + 1);
mockGetAutomaticZenRules(NUM_RULES, rMap); mockGetAutomaticZenRules(NUM_RULES, rMap);
mController.updateState(mockPref); mController.updateState(mockPref);
verify(mockPref, times(1)).removeAll(); verify(mockPref, times(1)).removeAll();
verify(mockPref, times(NUM_RULES)).addPreference(any()); verify(mockPref, times(NUM_RULES)).addPreference(any());
assertEquals(NUM_RULES, mController.mZenRulePreferences.size());
}
@Test
public void testUpdateState_clearsPreferencesWhenSameNumberButDifferentPrefs() {
final int NUM_RULES = 2;
Map<String, AutomaticZenRule> rMap = new HashMap<>();
String ruleId1 = "test1_id";
String ruleId2 = "test2_id";
AutomaticZenRule autoRule1 = new AutomaticZenRule("test_rule_1", null, null,
null, null, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, true, 10);
AutomaticZenRule autoRule2 = new AutomaticZenRule("test_rule_2", null, null,
null, null, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, true, 20);
rMap.put(ruleId1, autoRule1);
rMap.put(ruleId2, autoRule2);
// Add two preferences to the set of previously-known-about ZenRulePreferences; in this
// case, test3_id is "deleted" but test2_id is "added"
mController.mZenRulePreferences.put("test1_id", mZenRulePreference);
mController.mZenRulePreferences.put("test3_id", mZenRulePreference);
// update state should re-add all preferences since a preference was deleted
when(mockPref.getPreferenceCount()).thenReturn(NUM_RULES);
mockGetAutomaticZenRules(NUM_RULES, rMap);
mController.updateState(mockPref);
verify(mockPref, times(1)).removeAll();
verify(mockPref, times(NUM_RULES)).addPreference(any());
assertEquals(NUM_RULES, mController.mZenRulePreferences.size());
} }
@Test @Test
@@ -140,6 +186,7 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
when(mockPref.getPreferenceCount()).thenReturn(NUM_RULES); when(mockPref.getPreferenceCount()).thenReturn(NUM_RULES);
when(mockPref.getPreference(anyInt())).thenReturn(mZenRulePreference); when(mockPref.getPreference(anyInt())).thenReturn(mZenRulePreference);
mController.mZenRulePreferences.put("test1_id", mZenRulePreference);
// update state should NOT re-add all the preferences, should only update enable state // update state should NOT re-add all the preferences, should only update enable state
rule.setEnabled(false); rule.setEnabled(false);
@@ -148,7 +195,8 @@ public class ZenModeAutomaticRulesPreferenceControllerTest {
FieldSetter.setField(mZenRulePreference, ZenRulePreference.class.getDeclaredField("mId"), testId); FieldSetter.setField(mZenRulePreference, ZenRulePreference.class.getDeclaredField("mId"), testId);
mController.updateState(mockPref); mController.updateState(mockPref);
verify(mZenRulePreference, times(1)).updatePreference(any()); verify(mZenRulePreference, times(1)).updatePreference(any());
verify(mController, never()).reloadAllRules(any()); verify(mockPref, never()).removeAll();
assertEquals(NUM_RULES, mController.mZenRulePreferences.size());
} }
private void mockGetAutomaticZenRules(int numRules, Map<String, AutomaticZenRule> rules) { private void mockGetAutomaticZenRules(int numRules, Map<String, AutomaticZenRule> rules) {

View File

@@ -34,7 +34,7 @@ import java.util.Map;
@Implements(TileUtils.class) @Implements(TileUtils.class)
public class ShadowTileUtils { public class ShadowTileUtils {
public static final String MOCK_SUMMARY = "summary"; public static final String MOCK_TEXT = "text";
private static boolean sChecked; private static boolean sChecked;
private static Bundle sResult; private static Bundle sResult;
@@ -42,13 +42,14 @@ public class ShadowTileUtils {
@Implementation @Implementation
protected static String getTextFromUri(Context context, Uri uri, protected static String getTextFromUri(Context context, Uri uri,
Map<String, IContentProvider> providerMap, String key) { Map<String, IContentProvider> providerMap, String key) {
return MOCK_SUMMARY; return MOCK_TEXT;
} }
@Implementation @Implementation
protected static Pair<String, Integer> getIconFromUri(Context context, String packageName, protected static Pair<String, Integer> getIconFromUri(Context context, String packageName,
Uri uri, Map<String, IContentProvider> providerMap) { Uri uri, Map<String, IContentProvider> providerMap) {
return Pair.create(RuntimeEnvironment.application.getPackageName(), R.drawable.ic_settings_accent); return Pair.create(RuntimeEnvironment.application.getPackageName(),
R.drawable.ic_settings_accent);
} }
@Implementation @Implementation

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 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;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/** Unittest for DefaultRingtonePreference. */
@RunWith(AndroidJUnit4.class)
public class DefaultRingtonePreferenceTest {
private DefaultRingtonePreference mDefaultRingtonePreference;
@Mock
private ContentResolver mContentResolver;
@Mock
private Uri mRingtoneUri;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Context context = spy(ApplicationProvider.getApplicationContext());
doReturn(mContentResolver).when(context).getContentResolver();
mDefaultRingtonePreference = spy(new DefaultRingtonePreference(context, null /* attrs */));
doReturn(context).when(mDefaultRingtonePreference).getContext();
when(mDefaultRingtonePreference.getRingtoneType())
.thenReturn(RingtoneManager.TYPE_RINGTONE);
mDefaultRingtonePreference.setUserId(1);
}
@Test
public void onSaveRingtone_nullMimeType_shouldNotSetRingtone() {
when(mContentResolver.getType(mRingtoneUri)).thenReturn(null);
mDefaultRingtonePreference.onSaveRingtone(mRingtoneUri);
verify(mDefaultRingtonePreference, never()).setActualDefaultRingtoneUri(mRingtoneUri);
}
@Test
public void onSaveRingtone_notAudioMimeType_shouldNotSetRingtone() {
when(mContentResolver.getType(mRingtoneUri)).thenReturn("text/plain");
mDefaultRingtonePreference.onSaveRingtone(mRingtoneUri);
verify(mDefaultRingtonePreference, never()).setActualDefaultRingtoneUri(mRingtoneUri);
}
}

View File

@@ -37,6 +37,7 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -71,6 +72,7 @@ public class AppLocaleUtilTest {
} }
@Test @Test
@Ignore("b/231904717")
public void canDisplayLocaleUi_showUI() throws PackageManager.NameNotFoundException { public void canDisplayLocaleUi_showUI() throws PackageManager.NameNotFoundException {
setApplicationInfo(/*no platform key*/ false); setApplicationInfo(/*no platform key*/ false);
setActivityInfo(mAllowedPackage); setActivityInfo(mAllowedPackage);
@@ -79,6 +81,7 @@ public class AppLocaleUtilTest {
} }
@Test @Test
@Ignore("b/231904717")
public void canDisplayLocaleUi_notShowUI_hasPlatformKey() public void canDisplayLocaleUi_notShowUI_hasPlatformKey()
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
setApplicationInfo(/*has platform key*/ true); setApplicationInfo(/*has platform key*/ true);
@@ -88,6 +91,7 @@ public class AppLocaleUtilTest {
} }
@Test @Test
@Ignore("b/231904717")
public void canDisplayLocaleUi_notShowUI_noLauncherEntry() public void canDisplayLocaleUi_notShowUI_noLauncherEntry()
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
setApplicationInfo(/*no platform key*/false); setApplicationInfo(/*no platform key*/false);
@@ -97,6 +101,7 @@ public class AppLocaleUtilTest {
} }
@Test @Test
@Ignore("b/231904717")
public void canDisplayLocaleUi_notShowUI_matchDisallowedPackageList() public void canDisplayLocaleUi_notShowUI_matchDisallowedPackageList()
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
setApplicationInfo(/*no platform key*/false); setApplicationInfo(/*no platform key*/false);

View File

@@ -46,6 +46,7 @@ import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -230,6 +231,7 @@ public class NetworkProviderSimListControllerTest {
assertTrue(TextUtils.equals(mController.getSummary(SUB_ID_1, DISPLAY_NAME_1), summary)); assertTrue(TextUtils.equals(mController.getSummary(SUB_ID_1, DISPLAY_NAME_1), summary));
} }
@Ignore
@Test @Test
@UiThreadTest @UiThreadTest
public void getAvailablePhysicalSubscription_withTwoPhysicalSims_returnTwo() { public void getAvailablePhysicalSubscription_withTwoPhysicalSims_returnTwo() {

View File

@@ -56,6 +56,7 @@ import com.android.settings.wifi.slice.WifiSliceItem;
import com.android.wifitrackerlib.WifiEntry; import com.android.wifitrackerlib.WifiEntry;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -165,6 +166,7 @@ public class ProviderModelSliceHelperTest {
assertThat(testItem).isNull(); assertThat(testItem).isNull();
} }
@Ignore
@Test @Test
public void createCarrierRow_hasDdsAndActiveNetworkIsNotCellular_verifyTitleAndSummary() { public void createCarrierRow_hasDdsAndActiveNetworkIsNotCellular_verifyTitleAndSummary() {
String expectDisplayName = "Name1"; String expectDisplayName = "Name1";
@@ -181,6 +183,7 @@ public class ProviderModelSliceHelperTest {
assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle); assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle);
} }
@Ignore
@Test @Test
public void createCarrierRow_wifiOnhasDdsAndActiveNetworkIsCellular_verifyTitleAndSummary() { public void createCarrierRow_wifiOnhasDdsAndActiveNetworkIsCellular_verifyTitleAndSummary() {
String expectDisplayName = "Name1"; String expectDisplayName = "Name1";
@@ -201,6 +204,7 @@ public class ProviderModelSliceHelperTest {
assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle); assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle);
} }
@Ignore
@Test @Test
public void createCarrierRow_noNetworkAvailable_verifyTitleAndSummary() { public void createCarrierRow_noNetworkAvailable_verifyTitleAndSummary() {
String expectDisplayName = "Name1"; String expectDisplayName = "Name1";

View File

@@ -69,6 +69,7 @@ public class SubscriptionUtilTest {
when(mTelMgr.getUiccSlotsInfo()).thenReturn(null); when(mTelMgr.getUiccSlotsInfo()).thenReturn(null);
} }
@Ignore
@Test @Test
public void getAvailableSubscriptions_nullInfoFromSubscriptionManager_nonNullResult() { public void getAvailableSubscriptions_nullInfoFromSubscriptionManager_nonNullResult() {
when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(null); when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(null);
@@ -90,6 +91,7 @@ public class SubscriptionUtilTest {
assertThat(subs).hasSize(1); assertThat(subs).hasSize(1);
} }
@Ignore
@Test @Test
public void getAvailableSubscriptions_twoSubscriptions_twoResults() { public void getAvailableSubscriptions_twoSubscriptions_twoResults() {
final SubscriptionInfo info1 = mock(SubscriptionInfo.class); final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
@@ -138,6 +140,7 @@ public class SubscriptionUtilTest {
assertThat(subs).hasSize(2); assertThat(subs).hasSize(2);
} }
@Ignore
@Test @Test
public void getUniqueDisplayNames_uniqueCarriers_originalUsed() { public void getUniqueDisplayNames_uniqueCarriers_originalUsed() {
// Each subscription's default display name is unique. // Each subscription's default display name is unique.
@@ -228,6 +231,7 @@ public class SubscriptionUtilTest {
assertEquals(CARRIER_1 + " 4444", idNames.get(SUBID_2)); assertEquals(CARRIER_1 + " 4444", idNames.get(SUBID_2));
} }
@Ignore
@Test @Test
public void getUniqueDisplayNames_phoneNumberBlocked_subscriptoinIdFallback() { public void getUniqueDisplayNames_phoneNumberBlocked_subscriptoinIdFallback() {
// Both subscriptoins have the same display name. // Both subscriptoins have the same display name.
@@ -295,6 +299,7 @@ public class SubscriptionUtilTest {
assertEquals(CARRIER_1 + " 3", idNames.get(SUBID_3)); assertEquals(CARRIER_1 + " 3", idNames.get(SUBID_3));
} }
@Ignore
@Test @Test
public void getUniqueDisplayName_onlyOneSubscription_correctNameReturned() { public void getUniqueDisplayName_onlyOneSubscription_correctNameReturned() {
// Each subscription's default display name is unique. // Each subscription's default display name is unique.
@@ -394,6 +399,7 @@ public class SubscriptionUtilTest {
assertTrue(TextUtils.isEmpty(name)); assertTrue(TextUtils.isEmpty(name));
} }
@Ignore
@Test @Test
public void getUniqueDisplayName_fullSubscriptionInfo_correctNameReturned() { public void getUniqueDisplayName_fullSubscriptionInfo_correctNameReturned() {
// Each subscription's default display name is unique. // Each subscription's default display name is unique.

View File

@@ -200,7 +200,7 @@ public class SubscriptionsPreferenceControllerTest {
} }
@Test @Test
public void isAvailable_airplaneModeOnWifiOffWithCarrierNetwork_availableTrue() { public void isAvailable_airplaneModeOnWifiOffWithCarrierNetwork_availableFalse() {
setupMockSubscriptions(1); setupMockSubscriptions(1);
when(mWifiManager.isWifiEnabled()).thenReturn(false); when(mWifiManager.isWifiEnabled()).thenReturn(false);
@@ -212,7 +212,7 @@ public class SubscriptionsPreferenceControllerTest {
} }
@Test @Test
public void isAvailable_airplaneModeOff_availableFalse() { public void isAvailable_airplaneModeOff_availableTrue() {
setupMockSubscriptions(2); setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
@@ -235,12 +235,11 @@ public class SubscriptionsPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub1");
} }
@Test @Test
@UiThreadTest @UiThreadTest
public void displayPreference_providerAndHasMultiSim_showDataSubPreference() { public void displayPreference_providerAndHasMultiSim_showOnePreference() {
final List<SubscriptionInfo> sub = setupMockSubscriptions(2); final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList(); doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
@@ -249,7 +248,6 @@ public class SubscriptionsPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub1");
} }
@Test @Test
@@ -437,7 +435,7 @@ public class SubscriptionsPreferenceControllerTest {
@Test @Test
@UiThreadTest @UiThreadTest
public void dataSubscriptionChanged_providerAndHasMultiSim_showSubId1Preference() { public void dataSubscriptionChanged_providerAndHasMultiSim_showOnePreference() {
final List<SubscriptionInfo> sub = setupMockSubscriptions(2); final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList(); doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
@@ -449,12 +447,11 @@ public class SubscriptionsPreferenceControllerTest {
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub1");
} }
@Test @Test
@UiThreadTest @UiThreadTest
public void dataSubscriptionChanged_providerAndHasMultiSim_showSubId2Preference() { public void dataSubscriptionChanged_providerAndHasMultiSim_showOnlyOnePreference() {
final List<SubscriptionInfo> sub = setupMockSubscriptions(2); final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
final int subId = sub.get(0).getSubscriptionId(); final int subId = sub.get(0).getSubscriptionId();
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
@@ -464,17 +461,12 @@ public class SubscriptionsPreferenceControllerTest {
mController.onResume(); mController.onResume();
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
assertThat(mController.isAvailable()).isTrue();
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub1");
doReturn(sub.get(1)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); doReturn(sub.get(1)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
mController.mConnectionChangeReceiver.onReceive(mContext, intent); mController.mConnectionChangeReceiver.onReceive(mContext, intent);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub2");
} }
@Test @Test

View File

@@ -44,6 +44,7 @@ import com.android.settings.testutils.ResourcesUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -111,6 +112,7 @@ public class DefaultSubscriptionControllerTest {
assertThat(mController.getLabelFromCallingAccount(null)).isEqualTo(""); assertThat(mController.getLabelFromCallingAccount(null)).isEqualTo("");
} }
@Ignore
@Test @Test
public void displayPreference_twoSubscriptionsSub1Default_correctListPreferenceValues() { public void displayPreference_twoSubscriptionsSub1Default_correctListPreferenceValues() {
final SubscriptionInfo sub1 = createMockSub(111, "sub1"); final SubscriptionInfo sub1 = createMockSub(111, "sub1");
@@ -141,6 +143,7 @@ public class DefaultSubscriptionControllerTest {
Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID)); Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
} }
@Ignore
@Test @Test
public void displayPreference_twoSubscriptionsSub2Default_correctListPreferenceValues() { public void displayPreference_twoSubscriptionsSub2Default_correctListPreferenceValues() {
final SubscriptionInfo sub1 = createMockSub(111, "sub1"); final SubscriptionInfo sub1 = createMockSub(111, "sub1");
@@ -171,6 +174,7 @@ public class DefaultSubscriptionControllerTest {
Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID)); Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
} }
@Ignore
@Test @Test
public void displayPreference_threeSubsOneIsOpportunistic_correctListPreferenceValues() { public void displayPreference_threeSubsOneIsOpportunistic_correctListPreferenceValues() {
final SubscriptionInfo sub1 = createMockSub(111, "sub1"); final SubscriptionInfo sub1 = createMockSub(111, "sub1");
@@ -254,6 +258,7 @@ public class DefaultSubscriptionControllerTest {
assertThat(mController.getDefaultSubscriptionId()).isEqualTo(222); assertThat(mController.getDefaultSubscriptionId()).isEqualTo(222);
} }
@Ignore
@Test @Test
public void onSubscriptionsChanged_twoSubscriptionsDefaultChanges_selectedEntryGetsUpdated() { public void onSubscriptionsChanged_twoSubscriptionsDefaultChanges_selectedEntryGetsUpdated() {
final SubscriptionInfo sub1 = createMockSub(111, "sub1"); final SubscriptionInfo sub1 = createMockSub(111, "sub1");
@@ -314,6 +319,7 @@ public class DefaultSubscriptionControllerTest {
assertThat(mListPreference.isEnabled()).isTrue(); assertThat(mListPreference.isEnabled()).isTrue();
} }
@Ignore
@Test @Test
public void onSubscriptionsChanged_goFromTwoToThreeSubscriptions_listGetsUpdated() { public void onSubscriptionsChanged_goFromTwoToThreeSubscriptions_listGetsUpdated() {
final SubscriptionInfo sub1 = createMockSub(111, "sub1"); final SubscriptionInfo sub1 = createMockSub(111, "sub1");