Snap for 10421851 from 5d207a7b4b to udc-qpr1-release
Change-Id: I6fc1160180a347673d452f875700790f49ab3bbe
This commit is contained in:
@@ -20,4 +20,5 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginHorizontal="16dp"/>
|
android:layout_marginHorizontal="16dp"
|
||||||
|
android:contentDescription="@*android:string/checked"/>
|
||||||
@@ -7180,6 +7180,18 @@
|
|||||||
<!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
|
<!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
|
||||||
<string name="notification_volume_option_title">Notification volume</string>
|
<string name="notification_volume_option_title">Notification volume</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of ring volume title in silent mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=8994620163934249882] -->
|
||||||
|
<string name="ringer_content_description_silent_mode">Ringer silent</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of ring volume title in vibrate mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=6261841170896561364] -->
|
||||||
|
<string name="ringer_content_description_vibrate_mode">Ringer vibrate</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of notification volume title in vibrate mode. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="notification_volume_content_description_vibrate_mode">Notification volume muted, notifications will vibrate</string>
|
||||||
|
|
||||||
|
<!-- Sound: Content description of volume title in silent mode [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="volume_content_description_silent_mode"> <xliff:g id="volume type" example="notification volume">%1$s</xliff:g> muted</string>
|
||||||
|
|
||||||
<!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
|
<!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
|
||||||
<string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
|
<string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.settings.localepicker;
|
|||||||
|
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.app.LocaleManager;
|
import android.app.LocaleManager;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -37,15 +38,22 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.applications.AppLocaleUtil;
|
import com.android.settings.applications.AppLocaleUtil;
|
||||||
import com.android.settings.applications.appinfo.AppLocaleDetails;
|
import com.android.settings.applications.appinfo.AppLocaleDetails;
|
||||||
import com.android.settings.core.SettingsBaseActivity;
|
import com.android.settings.core.SettingsBaseActivity;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
public class AppLocalePickerActivity extends SettingsBaseActivity
|
public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||||
implements LocalePickerWithRegion.LocaleSelectedListener, MenuItem.OnActionExpandListener {
|
implements LocalePickerWithRegion.LocaleSelectedListener, MenuItem.OnActionExpandListener {
|
||||||
private static final String TAG = AppLocalePickerActivity.class.getSimpleName();
|
private static final String TAG = AppLocalePickerActivity.class.getSimpleName();
|
||||||
|
private static final int SIM_LOCALE = 1 << 0;
|
||||||
|
private static final int SYSTEM_LOCALE = 1 << 1;
|
||||||
|
private static final int APP_LOCALE = 1 << 2;
|
||||||
|
private static final int IME_LOCALE = 1 << 3;
|
||||||
|
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private LocalePickerWithRegion mLocalePickerWithRegion;
|
private LocalePickerWithRegion mLocalePickerWithRegion;
|
||||||
private AppLocaleDetails mAppLocaleDetails;
|
private AppLocaleDetails mAppLocaleDetails;
|
||||||
private View mAppLocaleDetailContainer;
|
private View mAppLocaleDetailContainer;
|
||||||
|
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -71,6 +79,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
|||||||
|
|
||||||
setTitle(R.string.app_locale_picker_title);
|
setTitle(R.string.app_locale_picker_title);
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
mMetricsFeatureProvider = FeatureFactory.getFactory(this).getMetricsFeatureProvider();
|
||||||
|
|
||||||
mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
|
mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
|
||||||
this,
|
this,
|
||||||
@@ -99,6 +108,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
|||||||
if (localeInfo == null || localeInfo.getLocale() == null || localeInfo.isSystemLocale()) {
|
if (localeInfo == null || localeInfo.getLocale() == null || localeInfo.isSystemLocale()) {
|
||||||
setAppDefaultLocale("");
|
setAppDefaultLocale("");
|
||||||
} else {
|
} else {
|
||||||
|
logLocaleSource(localeInfo);
|
||||||
setAppDefaultLocale(localeInfo.getLocale().toLanguageTag());
|
setAppDefaultLocale(localeInfo.getLocale().toLanguageTag());
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
@@ -177,4 +187,32 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logLocaleSource(LocaleStore.LocaleInfo localeInfo) {
|
||||||
|
if (!localeInfo.isSuggested() || localeInfo.isAppCurrentLocale()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int localeSource = 0;
|
||||||
|
if (hasSuggestionType(localeInfo,
|
||||||
|
LocaleStore.LocaleInfo.SUGGESTION_TYPE_SYSTEM_AVAILABLE_LANGUAGE)) {
|
||||||
|
localeSource |= SYSTEM_LOCALE;
|
||||||
|
}
|
||||||
|
if (hasSuggestionType(localeInfo,
|
||||||
|
LocaleStore.LocaleInfo.SUGGESTION_TYPE_OTHER_APP_LANGUAGE)) {
|
||||||
|
localeSource |= APP_LOCALE;
|
||||||
|
}
|
||||||
|
if (hasSuggestionType(localeInfo, LocaleStore.LocaleInfo.SUGGESTION_TYPE_IME_LANGUAGE)) {
|
||||||
|
localeSource |= IME_LOCALE;
|
||||||
|
}
|
||||||
|
if (hasSuggestionType(localeInfo, LocaleStore.LocaleInfo.SUGGESTION_TYPE_SIM)) {
|
||||||
|
localeSource |= SIM_LOCALE;
|
||||||
|
}
|
||||||
|
mMetricsFeatureProvider.action(this,
|
||||||
|
SettingsEnums.ACTION_CHANGE_APP_LANGUAGE_FROM_SUGGESTED, localeSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasSuggestionType(LocaleStore.LocaleInfo localeInfo,
|
||||||
|
int suggestionType) {
|
||||||
|
return localeInfo.isSuggestionOfType(suggestionType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ class LocaleDragAndDropAdapter
|
|||||||
if (fromPosition != toPosition) {
|
if (fromPosition != toPosition) {
|
||||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
|
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
|
||||||
.action(mContext, SettingsEnums.ACTION_REORDER_LANGUAGE,
|
.action(mContext, SettingsEnums.ACTION_REORDER_LANGUAGE,
|
||||||
mDragLocale.getLocale().getDisplayName() + " move to " + toPosition);
|
mDragLocale.getLocale().toLanguageTag() + " move to " + toPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyItemChanged(fromPosition); // to update the numbers
|
notifyItemChanged(fromPosition); // to update the numbers
|
||||||
@@ -259,7 +259,7 @@ class LocaleDragAndDropAdapter
|
|||||||
if (localeInfo.getChecked()) {
|
if (localeInfo.getChecked()) {
|
||||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
|
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider()
|
||||||
.action(mContext, SettingsEnums.ACTION_REMOVE_LANGUAGE,
|
.action(mContext, SettingsEnums.ACTION_REMOVE_LANGUAGE,
|
||||||
localeInfo.getLocale().getDisplayName());
|
localeInfo.getLocale().toLanguageTag());
|
||||||
mFeedItemList.remove(i);
|
mFeedItemList.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
|||||||
mAdapter.addLocale(localeInfo);
|
mAdapter.addLocale(localeInfo);
|
||||||
updateVisibilityOfRemoveMenu();
|
updateVisibilityOfRemoveMenu();
|
||||||
mMetricsFeatureProvider.action(getContext(), SettingsEnums.ACTION_ADD_LANGUAGE,
|
mMetricsFeatureProvider.action(getContext(), SettingsEnums.ACTION_ADD_LANGUAGE,
|
||||||
localeInfo.getLocale().getDisplayName());
|
localeInfo.getLocale().toLanguageTag());
|
||||||
} else if (requestCode == DIALOG_CONFIRM_SYSTEM_DEFAULT) {
|
} else if (requestCode == DIALOG_CONFIRM_SYSTEM_DEFAULT) {
|
||||||
localeInfo = mAdapter.getFeedItemList().get(0);
|
localeInfo = mAdapter.getFeedItemList().get(0);
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
@@ -218,7 +218,7 @@ public class LocaleListEditor extends RestrictedSettingsFragment implements View
|
|||||||
localeDialogFragment.show(mFragmentManager, TAG_DIALOG_NOT_AVAILABLE);
|
localeDialogFragment.show(mFragmentManager, TAG_DIALOG_NOT_AVAILABLE);
|
||||||
mMetricsFeatureProvider.action(getContext(),
|
mMetricsFeatureProvider.action(getContext(),
|
||||||
SettingsEnums.ACTION_NOT_SUPPORTED_SYSTEM_LANGUAGE,
|
SettingsEnums.ACTION_NOT_SUPPORTED_SYSTEM_LANGUAGE,
|
||||||
localeInfo.getLocale().getDisplayName());
|
localeInfo.getLocale().toLanguageTag());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mAdapter.notifyListChanged(localeInfo);
|
mAdapter.notifyListChanged(localeInfo);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import static com.android.internal.util.CollectionUtils.emptyIfNull;
|
|||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
@@ -61,6 +62,10 @@ import java.util.stream.Stream;
|
|||||||
public class SubscriptionUtil {
|
public class SubscriptionUtil {
|
||||||
private static final String TAG = "SubscriptionUtil";
|
private static final String TAG = "SubscriptionUtil";
|
||||||
private static final String PROFILE_GENERIC_DISPLAY_NAME = "CARD";
|
private static final String PROFILE_GENERIC_DISPLAY_NAME = "CARD";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String SUB_ID = "sub_id";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_UNIQUE_SUBSCRIPTION_DISPLAYNAME = "unique_subscription_displayName";
|
||||||
private static List<SubscriptionInfo> sAvailableResultsForTesting;
|
private static List<SubscriptionInfo> sAvailableResultsForTesting;
|
||||||
private static List<SubscriptionInfo> sActiveResultsForTesting;
|
private static List<SubscriptionInfo> sActiveResultsForTesting;
|
||||||
|
|
||||||
@@ -265,20 +270,21 @@ public class SubscriptionUtil {
|
|||||||
// Map of SubscriptionId to DisplayName
|
// Map of SubscriptionId to DisplayName
|
||||||
final Supplier<Stream<DisplayInfo>> originalInfos =
|
final Supplier<Stream<DisplayInfo>> originalInfos =
|
||||||
() -> getAvailableSubscriptions(context)
|
() -> getAvailableSubscriptions(context)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(i -> {
|
.filter(i -> {
|
||||||
// Filter out null values.
|
// Filter out null values.
|
||||||
return (i != null && i.getDisplayName() != null);
|
return (i != null && i.getDisplayName() != null);
|
||||||
})
|
})
|
||||||
.map(i -> {
|
.map(i -> {
|
||||||
DisplayInfo info = new DisplayInfo();
|
DisplayInfo info = new DisplayInfo();
|
||||||
info.subscriptionInfo = i;
|
info.subscriptionInfo = i;
|
||||||
String displayName = i.getDisplayName().toString();
|
String displayName = i.getDisplayName().toString();
|
||||||
info.originalName = TextUtils.equals(displayName, PROFILE_GENERIC_DISPLAY_NAME)
|
info.originalName =
|
||||||
? context.getResources().getString(R.string.sim_card)
|
TextUtils.equals(displayName, PROFILE_GENERIC_DISPLAY_NAME)
|
||||||
: displayName.trim();
|
? context.getResources().getString(R.string.sim_card)
|
||||||
return info;
|
: displayName.trim();
|
||||||
});
|
return info;
|
||||||
|
});
|
||||||
|
|
||||||
// TODO(goldmanj) consider using a map of DisplayName to SubscriptionInfos.
|
// TODO(goldmanj) consider using a map of DisplayName to SubscriptionInfos.
|
||||||
// A Unique set of display names
|
// A Unique set of display names
|
||||||
@@ -292,6 +298,14 @@ public class SubscriptionUtil {
|
|||||||
// If a display name is duplicate, append the final 4 digits of the phone number.
|
// If a display name is duplicate, append the final 4 digits of the phone number.
|
||||||
// Creates a mapping of Subscription id to original display name + phone number display name
|
// Creates a mapping of Subscription id to original display name + phone number display name
|
||||||
final Supplier<Stream<DisplayInfo>> uniqueInfos = () -> originalInfos.get().map(info -> {
|
final Supplier<Stream<DisplayInfo>> uniqueInfos = () -> originalInfos.get().map(info -> {
|
||||||
|
String cachedDisplayName = getDisplayNameFromSharedPreference(
|
||||||
|
context, info.subscriptionInfo.getSubscriptionId());
|
||||||
|
if (!TextUtils.isEmpty(cachedDisplayName)) {
|
||||||
|
Log.d(TAG, "use cached display name : " + cachedDisplayName);
|
||||||
|
info.uniqueName = cachedDisplayName;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
if (duplicateOriginalNames.contains(info.originalName)) {
|
if (duplicateOriginalNames.contains(info.originalName)) {
|
||||||
// This may return null, if the user cannot view the phone number itself.
|
// This may return null, if the user cannot view the phone number itself.
|
||||||
final String phoneNumber = getBidiFormattedPhoneNumber(context,
|
final String phoneNumber = getBidiFormattedPhoneNumber(context,
|
||||||
@@ -299,15 +313,17 @@ public class SubscriptionUtil {
|
|||||||
String lastFourDigits = "";
|
String lastFourDigits = "";
|
||||||
if (phoneNumber != null) {
|
if (phoneNumber != null) {
|
||||||
lastFourDigits = (phoneNumber.length() > 4)
|
lastFourDigits = (phoneNumber.length() > 4)
|
||||||
? phoneNumber.substring(phoneNumber.length() - 4) : phoneNumber;
|
? phoneNumber.substring(phoneNumber.length() - 4) : phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(lastFourDigits)) {
|
if (TextUtils.isEmpty(lastFourDigits)) {
|
||||||
info.uniqueName = info.originalName;
|
info.uniqueName = info.originalName;
|
||||||
} else {
|
} else {
|
||||||
info.uniqueName = info.originalName + " " + lastFourDigits;
|
info.uniqueName = info.originalName + " " + lastFourDigits;
|
||||||
|
Log.d(TAG, "Cache display name [" + info.uniqueName + "] for sub id "
|
||||||
|
+ info.subscriptionInfo.getSubscriptionId());
|
||||||
|
saveDisplayNameToSharedPreference(
|
||||||
|
context, info.subscriptionInfo.getSubscriptionId(), info.uniqueName);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
info.uniqueName = info.originalName;
|
info.uniqueName = info.originalName;
|
||||||
}
|
}
|
||||||
@@ -371,6 +387,27 @@ public class SubscriptionUtil {
|
|||||||
return getUniqueSubscriptionDisplayName(info.getSubscriptionId(), context);
|
return getUniqueSubscriptionDisplayName(info.getSubscriptionId(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static SharedPreferences getDisplayNameSharedPreferences(Context context) {
|
||||||
|
return context.getSharedPreferences(
|
||||||
|
KEY_UNIQUE_SUBSCRIPTION_DISPLAYNAME, Context.MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SharedPreferences.Editor getDisplayNameSharedPreferenceEditor(Context context) {
|
||||||
|
return getDisplayNameSharedPreferences(context).edit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void saveDisplayNameToSharedPreference(
|
||||||
|
Context context, int subId, CharSequence displayName) {
|
||||||
|
getDisplayNameSharedPreferenceEditor(context)
|
||||||
|
.putString(SUB_ID + subId, String.valueOf(displayName))
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDisplayNameFromSharedPreference(Context context, int subid) {
|
||||||
|
return getDisplayNameSharedPreferences(context).getString(SUB_ID + subid, "");
|
||||||
|
}
|
||||||
|
|
||||||
public static String getDisplayName(SubscriptionInfo info) {
|
public static String getDisplayName(SubscriptionInfo info) {
|
||||||
final CharSequence name = info.getDisplayName();
|
final CharSequence name = info.getDisplayName();
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
|
|||||||
|
|
||||||
public MediaVolumePreferenceController(Context context) {
|
public MediaVolumePreferenceController(Context context) {
|
||||||
super(context, KEY_MEDIA_VOLUME);
|
super(context, KEY_MEDIA_VOLUME);
|
||||||
|
mVolumePreferenceListener = this::updateContentDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,6 +110,18 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateContentDescription() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
if (mPreference.isMuted()) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.volume_content_description_silent_mode,
|
||||||
|
mPreference.getTitle()));
|
||||||
|
} else {
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SliceAction getSliceEndItem(Context context) {
|
public SliceAction getSliceEndItem(Context context) {
|
||||||
if (!isSupportEndItem()) {
|
if (!isSupportEndItem()) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -75,6 +76,7 @@ public class NotificationVolumePreferenceController extends
|
|||||||
|
|
||||||
updateEffectsSuppressor();
|
updateEffectsSuppressor();
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,23 +122,37 @@ public class NotificationVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void selectPreferenceIconState() {
|
protected int getEffectiveRingerMode() {
|
||||||
|
if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
} else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
|
||||||
|
if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
|
||||||
|
// Ring is in normal, but notification is in silent.
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mRingerMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateContentDescription() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
int ringerMode = getEffectiveRingerMode();
|
||||||
mMuteIcon = mVibrateIconId;
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
mPreference.showIcon(mVibrateIconId);
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||||
} else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
|
mPreference.updateContentDescription(
|
||||||
|| mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
mContext.getString(
|
||||||
mMuteIcon = mSilentIconId;
|
R.string.notification_volume_content_description_vibrate_mode));
|
||||||
mPreference.showIcon(mSilentIconId);
|
} else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
|
||||||
} else { // ringmode normal: could be that we are still silent
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||||
if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
|
mPreference.updateContentDescription(
|
||||||
// ring is in normal, but notification is in silent
|
mContext.getString(R.string.volume_content_description_silent_mode,
|
||||||
mMuteIcon = mSilentIconId;
|
mPreference.getTitle()));
|
||||||
mPreference.showIcon(mSilentIconId);
|
} else {
|
||||||
} else {
|
// Set a11y mode to none in order not to trigger talkback while changing
|
||||||
mPreference.showIcon(mNormalIconId);
|
// notification volume in normal mode.
|
||||||
}
|
mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_NONE);
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +185,7 @@ public class NotificationVolumePreferenceController extends
|
|||||||
break;
|
break;
|
||||||
case NOTIFICATION_VOLUME_CHANGED:
|
case NOTIFICATION_VOLUME_CHANGED:
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.os.Vibrator;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
||||||
mVibrator = null;
|
mVibrator = null;
|
||||||
}
|
}
|
||||||
|
mVolumePreferenceListener = this::updateContentDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateEffectsSuppressor() {
|
protected void updateEffectsSuppressor() {
|
||||||
@@ -123,6 +125,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
mRingerMode = ringerMode;
|
mRingerMode = ringerMode;
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +134,11 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
*/
|
*/
|
||||||
protected void selectPreferenceIconState() {
|
protected void selectPreferenceIconState() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
|
int ringerMode = getEffectiveRingerMode();
|
||||||
|
if (ringerMode == AudioManager.RINGER_MODE_NORMAL) {
|
||||||
mPreference.showIcon(mNormalIconId);
|
mPreference.showIcon(mNormalIconId);
|
||||||
} else {
|
} else {
|
||||||
if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
mMuteIcon = mVibrateIconId;
|
mMuteIcon = mVibrateIconId;
|
||||||
} else {
|
} else {
|
||||||
mMuteIcon = mSilentIconId;
|
mMuteIcon = mSilentIconId;
|
||||||
@@ -144,6 +148,28 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getEffectiveRingerMode() {
|
||||||
|
if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
return AudioManager.RINGER_MODE_SILENT;
|
||||||
|
}
|
||||||
|
return mRingerMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateContentDescription() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
int ringerMode = getEffectiveRingerMode();
|
||||||
|
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.ringer_content_description_vibrate_mode));
|
||||||
|
} else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
|
||||||
|
mPreference.updateContentDescription(
|
||||||
|
mContext.getString(R.string.ringer_content_description_silent_mode));
|
||||||
|
} else {
|
||||||
|
mPreference.updateContentDescription(mPreference.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract boolean hintsMatch(int hints);
|
protected abstract boolean hintsMatch(int hints);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class SeparateRingVolumePreferenceController extends
|
|||||||
mReceiver.register(true);
|
mReceiver.register(true);
|
||||||
updateEffectsSuppressor();
|
updateEffectsSuppressor();
|
||||||
selectPreferenceIconState();
|
selectPreferenceIconState();
|
||||||
|
updateContentDescription();
|
||||||
|
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
||||||
|
|||||||
@@ -47,10 +47,13 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
|
|
||||||
protected SeekBar mSeekBar;
|
protected SeekBar mSeekBar;
|
||||||
private int mStream;
|
private int mStream;
|
||||||
private SeekBarVolumizer mVolumizer;
|
@VisibleForTesting
|
||||||
|
SeekBarVolumizer mVolumizer;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
private Listener mListener;
|
||||||
private ImageView mIconView;
|
private ImageView mIconView;
|
||||||
private TextView mSuppressionTextView;
|
private TextView mSuppressionTextView;
|
||||||
|
private TextView mTitle;
|
||||||
private String mSuppressionText;
|
private String mSuppressionText;
|
||||||
private boolean mMuted;
|
private boolean mMuted;
|
||||||
private boolean mZenMuted;
|
private boolean mZenMuted;
|
||||||
@@ -98,6 +101,10 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setListener(Listener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
public void onActivityResume() {
|
public void onActivityResume() {
|
||||||
if (mStopped) {
|
if (mStopped) {
|
||||||
init();
|
init();
|
||||||
@@ -118,6 +125,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
|
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
|
||||||
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
|
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
|
||||||
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
|
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
|
||||||
|
mTitle = (TextView) view.findViewById(com.android.internal.R.id.title);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +150,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mMuted = muted;
|
mMuted = muted;
|
||||||
mZenMuted = zenMuted;
|
mZenMuted = zenMuted;
|
||||||
updateIconView();
|
updateIconView();
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onUpdateMuteState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onStartTrackingTouch(SeekBarVolumizer sbv) {
|
public void onStartTrackingTouch(SeekBarVolumizer sbv) {
|
||||||
@@ -165,6 +176,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mVolumizer.setSeekBar(mSeekBar);
|
mVolumizer.setSeekBar(mSeekBar);
|
||||||
updateIconView();
|
updateIconView();
|
||||||
updateSuppressionText();
|
updateSuppressionText();
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onUpdateMuteState();
|
||||||
|
}
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
mSeekBar.setEnabled(false);
|
mSeekBar.setEnabled(false);
|
||||||
mVolumizer.stop();
|
mVolumizer.stop();
|
||||||
@@ -175,7 +189,7 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
if (mIconView == null) return;
|
if (mIconView == null) return;
|
||||||
if (mIconResId != 0) {
|
if (mIconResId != 0) {
|
||||||
mIconView.setImageResource(mIconResId);
|
mIconView.setImageResource(mIconResId);
|
||||||
} else if (mMuteIconResId != 0 && mMuted && !mZenMuted) {
|
} else if (mMuteIconResId != 0 && isMuted()) {
|
||||||
mIconView.setImageResource(mMuteIconResId);
|
mIconView.setImageResource(mMuteIconResId);
|
||||||
} else {
|
} else {
|
||||||
mIconView.setImageDrawable(getIcon());
|
mIconView.setImageDrawable(getIcon());
|
||||||
@@ -208,6 +222,10 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
updateSuppressionText();
|
updateSuppressionText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isMuted() {
|
||||||
|
return mMuted && !mZenMuted;
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateSuppressionText() {
|
protected void updateSuppressionText() {
|
||||||
if (mSuppressionTextView != null && mSeekBar != null) {
|
if (mSuppressionTextView != null && mSeekBar != null) {
|
||||||
mSuppressionTextView.setText(mSuppressionText);
|
mSuppressionTextView.setText(mSuppressionText);
|
||||||
@@ -216,6 +234,19 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update content description of title to improve talkback announcements.
|
||||||
|
*/
|
||||||
|
protected void updateContentDescription(CharSequence contentDescription) {
|
||||||
|
if (mTitle == null) return;
|
||||||
|
mTitle.setContentDescription(contentDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setAccessibilityLiveRegion(int mode) {
|
||||||
|
if (mTitle == null) return;
|
||||||
|
mTitle.setAccessibilityLiveRegion(mode);
|
||||||
|
}
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onSampleStarting(SeekBarVolumizer sbv);
|
void onSampleStarting(SeekBarVolumizer sbv);
|
||||||
void onStreamValueChanged(int stream, int progress);
|
void onStreamValueChanged(int stream, int progress);
|
||||||
@@ -225,4 +256,15 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
*/
|
*/
|
||||||
void onStartTrackingTouch(SeekBarVolumizer sbv);
|
void onStartTrackingTouch(SeekBarVolumizer sbv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener to view updates in volumeSeekbarPreference.
|
||||||
|
*/
|
||||||
|
public interface Listener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener to mute state updates.
|
||||||
|
*/
|
||||||
|
void onUpdateMuteState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public abstract class VolumeSeekBarPreferenceController extends
|
|||||||
protected VolumeSeekBarPreference mPreference;
|
protected VolumeSeekBarPreference mPreference;
|
||||||
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
||||||
protected AudioHelper mHelper;
|
protected AudioHelper mHelper;
|
||||||
|
protected VolumeSeekBarPreference.Listener mVolumePreferenceListener;
|
||||||
|
|
||||||
public VolumeSeekBarPreferenceController(Context context, String key) {
|
public VolumeSeekBarPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -62,6 +63,7 @@ public abstract class VolumeSeekBarPreferenceController extends
|
|||||||
protected void setupVolPreference(PreferenceScreen screen) {
|
protected void setupVolPreference(PreferenceScreen screen) {
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
mPreference.setCallback(mVolumePreferenceCallback);
|
mPreference.setCallback(mVolumePreferenceCallback);
|
||||||
|
mPreference.setListener(mVolumePreferenceListener);
|
||||||
mPreference.setStream(getAudioStream());
|
mPreference.setStream(getAudioStream());
|
||||||
mPreference.setMuteIcon(getMuteIcon());
|
mPreference.setMuteIcon(getMuteIcon());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -617,6 +617,9 @@ public class WifiP2pSettings extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onDeviceAvailable() {
|
private void onDeviceAvailable() {
|
||||||
|
if (mWifiP2pManager == null || sChannel == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mWifiP2pManager.requestNetworkInfo(sChannel, networkInfo -> {
|
mWifiP2pManager.requestNetworkInfo(sChannel, networkInfo -> {
|
||||||
if (sChannel == null) return;
|
if (sChannel == null) return;
|
||||||
mWifiP2pManager.requestConnectionInfo(sChannel, wifip2pinfo -> {
|
mWifiP2pManager.requestConnectionInfo(sChannel, wifip2pinfo -> {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package com.android.settings.localepicker;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -27,6 +29,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ApplicationPackageManager;
|
import android.app.ApplicationPackageManager;
|
||||||
import android.app.LocaleConfig;
|
import android.app.LocaleConfig;
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@@ -45,6 +48,7 @@ import androidx.annotation.ArrayRes;
|
|||||||
import com.android.internal.app.LocaleStore;
|
import com.android.internal.app.LocaleStore;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
import com.android.settings.applications.AppInfoBase;
|
||||||
import com.android.settings.applications.AppLocaleUtil;
|
import com.android.settings.applications.AppLocaleUtil;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -79,6 +83,7 @@ import java.util.Locale;
|
|||||||
public class AppLocalePickerActivityTest {
|
public class AppLocalePickerActivityTest {
|
||||||
private static final String TEST_PACKAGE_NAME = "com.android.settings";
|
private static final String TEST_PACKAGE_NAME = "com.android.settings";
|
||||||
private static final Uri TEST_PACKAGE_URI = Uri.parse("package:" + TEST_PACKAGE_NAME);
|
private static final Uri TEST_PACKAGE_URI = Uri.parse("package:" + TEST_PACKAGE_NAME);
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
LocaleStore.LocaleInfo mLocaleInfo;
|
LocaleStore.LocaleInfo mLocaleInfo;
|
||||||
@@ -99,6 +104,7 @@ public class AppLocalePickerActivityTest {
|
|||||||
when(mLocaleConfig.getStatus()).thenReturn(LocaleConfig.STATUS_SUCCESS);
|
when(mLocaleConfig.getStatus()).thenReturn(LocaleConfig.STATUS_SUCCESS);
|
||||||
when(mLocaleConfig.getSupportedLocales()).thenReturn(LocaleList.forLanguageTags("en-US"));
|
when(mLocaleConfig.getSupportedLocales()).thenReturn(LocaleList.forLanguageTags("en-US"));
|
||||||
ReflectionHelpers.setStaticField(AppLocaleUtil.class, "sLocaleConfig", mLocaleConfig);
|
ReflectionHelpers.setStaticField(AppLocaleUtil.class, "sLocaleConfig", mLocaleConfig);
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -210,6 +216,37 @@ public class AppLocalePickerActivityTest {
|
|||||||
assertThat(controller.get().isFinishing()).isTrue();
|
assertThat(controller.get().isFinishing()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onLocaleSelected_logLocaleSource() {
|
||||||
|
ActivityController<TestAppLocalePickerActivity> controller =
|
||||||
|
initActivityController(true);
|
||||||
|
LocaleList.setDefault(LocaleList.forLanguageTags("ja-JP,en-CA,en-US"));
|
||||||
|
Locale locale = new Locale("en", "US");
|
||||||
|
when(mLocaleInfo.getLocale()).thenReturn(locale);
|
||||||
|
when(mLocaleInfo.isSystemLocale()).thenReturn(false);
|
||||||
|
when(mLocaleInfo.isSuggested()).thenReturn(true);
|
||||||
|
when(mLocaleInfo.isSuggestionOfType(LocaleStore.LocaleInfo.SUGGESTION_TYPE_SIM)).thenReturn(
|
||||||
|
true);
|
||||||
|
when(mLocaleInfo.isSuggestionOfType(
|
||||||
|
LocaleStore.LocaleInfo.SUGGESTION_TYPE_SYSTEM_AVAILABLE_LANGUAGE)).thenReturn(
|
||||||
|
true);
|
||||||
|
when(mLocaleInfo.isSuggestionOfType(
|
||||||
|
LocaleStore.LocaleInfo.SUGGESTION_TYPE_OTHER_APP_LANGUAGE)).thenReturn(
|
||||||
|
true);
|
||||||
|
when(mLocaleInfo.isSuggestionOfType(
|
||||||
|
LocaleStore.LocaleInfo.SUGGESTION_TYPE_IME_LANGUAGE)).thenReturn(
|
||||||
|
true);
|
||||||
|
|
||||||
|
controller.create();
|
||||||
|
AppLocalePickerActivity mActivity = controller.get();
|
||||||
|
mActivity.onLocaleSelected(mLocaleInfo);
|
||||||
|
|
||||||
|
int localeSource = 15; // SIM_LOCALE | SYSTEM_LOCALE |IME_LOCALE|APP_LOCALE
|
||||||
|
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||||
|
any(), eq(SettingsEnums.ACTION_CHANGE_APP_LANGUAGE_FROM_SUGGESTED),
|
||||||
|
eq(localeSource));
|
||||||
|
}
|
||||||
|
|
||||||
private ActivityController<TestAppLocalePickerActivity> initActivityController(
|
private ActivityController<TestAppLocalePickerActivity> initActivityController(
|
||||||
boolean hasPackageName) {
|
boolean hasPackageName) {
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private VolumeSeekBarPreference.Callback mCallback;
|
private VolumeSeekBarPreference.Callback mCallback;
|
||||||
@Mock
|
@Mock
|
||||||
|
private VolumeSeekBarPreference.Listener mListener;
|
||||||
|
@Mock
|
||||||
private AudioHelper mHelper;
|
private AudioHelper mHelper;
|
||||||
|
|
||||||
private VolumeSeekBarPreferenceControllerTestable mController;
|
private VolumeSeekBarPreferenceControllerTestable mController;
|
||||||
@@ -59,7 +61,7 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
||||||
when(mPreference.getKey()).thenReturn("key");
|
when(mPreference.getKey()).thenReturn("key");
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, true,
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, true,
|
||||||
mPreference.getKey());
|
mPreference.getKey(), mListener);
|
||||||
mController.setAudioHelper(mHelper);
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,18 +72,20 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
verify(mPreference).setCallback(mCallback);
|
verify(mPreference).setCallback(mCallback);
|
||||||
verify(mPreference).setStream(VolumeSeekBarPreferenceControllerTestable.AUDIO_STREAM);
|
verify(mPreference).setStream(VolumeSeekBarPreferenceControllerTestable.AUDIO_STREAM);
|
||||||
verify(mPreference).setMuteIcon(VolumeSeekBarPreferenceControllerTestable.MUTE_ICON);
|
verify(mPreference).setMuteIcon(VolumeSeekBarPreferenceControllerTestable.MUTE_ICON);
|
||||||
|
verify(mPreference).setListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
|
||||||
mPreference.getKey());
|
mPreference.getKey(), mListener);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
verify(mPreference, never()).setCallback(any(VolumeSeekBarPreference.Callback.class));
|
verify(mPreference, never()).setCallback(any(VolumeSeekBarPreference.Callback.class));
|
||||||
verify(mPreference, never()).setStream(anyInt());
|
verify(mPreference, never()).setStream(anyInt());
|
||||||
verify(mPreference, never()).setMuteIcon(anyInt());
|
verify(mPreference, never()).setMuteIcon(anyInt());
|
||||||
|
verify(mPreference, never()).setListener(mListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,10 +161,12 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
private boolean mAvailable;
|
private boolean mAvailable;
|
||||||
|
|
||||||
VolumeSeekBarPreferenceControllerTestable(Context context,
|
VolumeSeekBarPreferenceControllerTestable(Context context,
|
||||||
VolumeSeekBarPreference.Callback callback, boolean available, String key) {
|
VolumeSeekBarPreference.Callback callback, boolean available, String key,
|
||||||
|
VolumeSeekBarPreference.Listener listener) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
setCallback(callback);
|
setCallback(callback);
|
||||||
mAvailable = available;
|
mAvailable = available;
|
||||||
|
mVolumePreferenceListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,11 +18,14 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.doCallRealMethod;
|
import static org.mockito.Mockito.doCallRealMethod;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.preference.SeekBarVolumizer;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -34,18 +37,28 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VolumeSeekBarPreferenceTest {
|
public class VolumeSeekBarPreferenceTest {
|
||||||
|
|
||||||
|
private static final CharSequence CONTENT_DESCRIPTION = "TEST";
|
||||||
@Mock
|
@Mock
|
||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
@Mock
|
@Mock
|
||||||
private VolumeSeekBarPreference mPreference;
|
private VolumeSeekBarPreference mPreference;
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private SeekBar mSeekBar;
|
||||||
|
@Mock
|
||||||
|
private SeekBarVolumizer mVolumizer;
|
||||||
|
private VolumeSeekBarPreference.Listener mListener;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
||||||
|
doCallRealMethod().when(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
mPreference.mSeekBar = mSeekBar;
|
||||||
mPreference.mAudioManager = mAudioManager;
|
mPreference.mAudioManager = mAudioManager;
|
||||||
|
mPreference.mVolumizer = mVolumizer;
|
||||||
|
mListener = () -> mPreference.updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -65,4 +78,24 @@ public class VolumeSeekBarPreferenceTest {
|
|||||||
verify(mPreference).setMin(min);
|
verify(mPreference).setMin(min);
|
||||||
verify(mPreference).setProgress(progress);
|
verify(mPreference).setProgress(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init_listenerIsCalled() {
|
||||||
|
doCallRealMethod().when(mPreference).setListener(mListener);
|
||||||
|
doCallRealMethod().when(mPreference).init();
|
||||||
|
|
||||||
|
mPreference.setListener(mListener);
|
||||||
|
mPreference.init();
|
||||||
|
|
||||||
|
verify(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init_listenerNotSet_noException() {
|
||||||
|
doCallRealMethod().when(mPreference).init();
|
||||||
|
|
||||||
|
mPreference.init();
|
||||||
|
|
||||||
|
verify(mPreference, never()).updateContentDescription(CONTENT_DESCRIPTION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -150,6 +151,13 @@ public class WifiP2pSettingsTest {
|
|||||||
verify(mWifiP2pManager, times(1)).requestNetworkInfo(any(), any());
|
verify(mWifiP2pManager, times(1)).requestNetworkInfo(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDeviceInfoAvailable_nullChannel_shouldBeIgnored() {
|
||||||
|
mFragment.sChannel = null;
|
||||||
|
mFragment.onDeviceInfoAvailable(mock(WifiP2pDevice.class));
|
||||||
|
verify(mWifiP2pManager, never()).requestNetworkInfo(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beSearching_getP2pStateDisabledIntent_shouldBeFalse() {
|
public void beSearching_getP2pStateDisabledIntent_shouldBeFalse() {
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
|
|||||||
@@ -16,26 +16,32 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static com.android.settings.network.SubscriptionUtil.KEY_UNIQUE_SUBSCRIPTION_DISPLAYNAME;
|
||||||
|
import static com.android.settings.network.SubscriptionUtil.SUB_ID;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -444,6 +450,35 @@ public class SubscriptionUtilTest {
|
|||||||
assertTrue(TextUtils.isEmpty(name));
|
assertTrue(TextUtils.isEmpty(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUniqueDisplayName_hasRecord_useRecordBeTheResult() {
|
||||||
|
final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
|
||||||
|
final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
|
||||||
|
when(info1.getSubscriptionId()).thenReturn(SUBID_1);
|
||||||
|
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
|
||||||
|
when(info1.getDisplayName()).thenReturn(CARRIER_1);
|
||||||
|
when(info2.getDisplayName()).thenReturn(CARRIER_1);
|
||||||
|
when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
|
||||||
|
Arrays.asList(info1, info2));
|
||||||
|
|
||||||
|
SharedPreferences sp = mock(SharedPreferences.class);
|
||||||
|
when(mContext.getSharedPreferences(
|
||||||
|
KEY_UNIQUE_SUBSCRIPTION_DISPLAYNAME, Context.MODE_PRIVATE)).thenReturn(sp);
|
||||||
|
when(sp.getString(eq(SUB_ID + SUBID_1), anyString())).thenReturn(CARRIER_1 + "6789");
|
||||||
|
when(sp.getString(eq(SUB_ID + SUBID_2), anyString())).thenReturn(CARRIER_1 + "4321");
|
||||||
|
|
||||||
|
|
||||||
|
final CharSequence nameOfSub1 =
|
||||||
|
SubscriptionUtil.getUniqueSubscriptionDisplayName(info1, mContext);
|
||||||
|
final CharSequence nameOfSub2 =
|
||||||
|
SubscriptionUtil.getUniqueSubscriptionDisplayName(info2, mContext);
|
||||||
|
|
||||||
|
assertThat(nameOfSub1).isNotNull();
|
||||||
|
assertThat(nameOfSub2).isNotNull();
|
||||||
|
assertEquals(CARRIER_1 + "6789", nameOfSub1.toString());
|
||||||
|
assertEquals(CARRIER_1 + "4321", nameOfSub2.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isInactiveInsertedPSim_nullSubInfo_doesNotCrash() {
|
public void isInactiveInsertedPSim_nullSubInfo_doesNotCrash() {
|
||||||
assertThat(SubscriptionUtil.isInactiveInsertedPSim(null)).isFalse();
|
assertThat(SubscriptionUtil.isInactiveInsertedPSim(null)).isFalse();
|
||||||
|
|||||||
Reference in New Issue
Block a user