Merge "Consider subId when loading Wfc string resources"

This commit is contained in:
Bonian Chen
2019-11-28 15:22:21 +00:00
committed by Gerrit Code Review
3 changed files with 75 additions and 35 deletions

View File

@@ -148,7 +148,8 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
break;
}
}
preference.setSummary(resId);
preference.setSummary(
SubscriptionManager.getResourcesForSubId(mContext, mSubId).getText(resId));
}
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
}

View File

@@ -340,19 +340,45 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
}
}
if (!isWifiOnlySupported) {
mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only);
mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only);
mButtonWfcMode.setEntrySummaries(R.array.wifi_calling_mode_summaries_without_wifi_only);
Resources res = getResourcesForSubId();
mButtonWfcMode.setTitle(res.getString(R.string.wifi_calling_mode_title));
mButtonWfcMode.setDialogTitle(res.getString(R.string.wifi_calling_mode_dialog_title));
mButtonWfcRoamingMode.setTitle(res.getString(R.string.wifi_calling_roaming_mode_title));
mButtonWfcRoamingMode.setDialogTitle(
res.getString(R.string.wifi_calling_roaming_mode_dialog_title));
if (isWifiOnlySupported) {
// Set string resources WITH option wifi only in mButtonWfcMode.
mButtonWfcMode.setEntries(
res.getStringArray(R.array.wifi_calling_mode_choices));
mButtonWfcMode.setEntryValues(res.getStringArray(R.array.wifi_calling_mode_values));
mButtonWfcMode.setEntrySummaries(
res.getStringArray(R.array.wifi_calling_mode_summaries));
// Set string resources WITH option wifi only in mButtonWfcRoamingMode.
mButtonWfcRoamingMode.setEntries(
R.array.wifi_calling_mode_choices_v2_without_wifi_only);
res.getStringArray(R.array.wifi_calling_mode_choices_v2));
mButtonWfcRoamingMode.setEntryValues(
R.array.wifi_calling_mode_values_without_wifi_only);
res.getStringArray(R.array.wifi_calling_mode_values));
mButtonWfcRoamingMode.setEntrySummaries(
R.array.wifi_calling_mode_summaries_without_wifi_only);
}
res.getStringArray(R.array.wifi_calling_mode_summaries));
} else {
// Set string resources WITHOUT option wifi only in mButtonWfcMode.
mButtonWfcMode.setEntries(
res.getStringArray(R.array.wifi_calling_mode_choices_without_wifi_only));
mButtonWfcMode.setEntryValues(
res.getStringArray(R.array.wifi_calling_mode_values_without_wifi_only));
mButtonWfcMode.setEntrySummaries(
res.getStringArray(R.array.wifi_calling_mode_summaries_without_wifi_only));
// Set string resources WITHOUT option wifi only in mButtonWfcRoamingMode.
mButtonWfcRoamingMode.setEntries(
res.getStringArray(R.array.wifi_calling_mode_choices_v2_without_wifi_only));
mButtonWfcRoamingMode.setEntryValues(
res.getStringArray(R.array.wifi_calling_mode_values_without_wifi_only));
mButtonWfcRoamingMode.setEntrySummaries(
res.getStringArray(R.array.wifi_calling_mode_summaries_without_wifi_only));
}
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
final boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
@@ -589,7 +615,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
return true;
}
private int getWfcModeSummary(int wfcMode) {
private CharSequence getWfcModeSummary(int wfcMode) {
int resId = com.android.internal.R.string.wifi_calling_off_summary;
if (mImsManager.isWfcEnabledByUser()) {
switch (wfcMode) {
@@ -606,7 +632,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
Log.e(TAG, "Unexpected WFC mode value: " + wfcMode);
}
}
return resId;
return getResourcesForSubId().getString(resId);
}
@VisibleForTesting

View File

@@ -25,6 +25,7 @@ import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.PersistableBundle;
import android.provider.Settings;
@@ -131,6 +132,7 @@ public class WifiCallingSliceHelper {
*/
public Slice createWifiCallingSlice(Uri sliceUri) {
final int subId = getDefaultVoiceSubId();
Resources res = getResourcesForSubId(subId);
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
Log.d(TAG, "Invalid subscription Id");
@@ -157,12 +159,11 @@ public class WifiCallingSliceHelper {
// Activation needed for the next action of the user
// Give instructions to go to settings app
return getNonActionableWifiCallingSlice(
mContext.getText(R.string.wifi_calling_settings_title),
mContext.getText(
R.string.wifi_calling_settings_activation_instructions),
res.getText(R.string.wifi_calling_settings_title),
res.getText(R.string.wifi_calling_settings_activation_instructions),
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
}
return getWifiCallingSlice(sliceUri, isWifiCallingEnabled);
return getWifiCallingSlice(sliceUri, isWifiCallingEnabled, subId);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
Log.e(TAG, "Unable to read the current WiFi calling status", e);
return null;
@@ -188,13 +189,14 @@ public class WifiCallingSliceHelper {
* Builds a toggle slice where the intent takes you to the wifi calling page and the toggle
* enables/disables wifi calling.
*/
private Slice getWifiCallingSlice(Uri sliceUri, boolean isWifiCallingEnabled) {
private Slice getWifiCallingSlice(Uri sliceUri, boolean isWifiCallingEnabled, int subId) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
Resources res = getResourcesForSubId(subId);
return new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
.addRow(new RowBuilder()
.setTitle(mContext.getText(R.string.wifi_calling_settings_title))
.setTitle(res.getText(R.string.wifi_calling_settings_title))
.addEndItem(
SliceAction.createToggle(
getBroadcastIntent(ACTION_WIFI_CALLING_CHANGED),
@@ -203,7 +205,7 @@ public class WifiCallingSliceHelper {
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
icon,
ListBuilder.ICON_IMAGE,
mContext.getText(R.string.wifi_calling_settings_title))))
res.getText(R.string.wifi_calling_settings_title))))
.build();
}
@@ -259,14 +261,15 @@ public class WifiCallingSliceHelper {
}
if (!isWifiCallingEnabled) {
// wifi calling is not enabled. Ask user to enable wifi calling
Resources res = getResourcesForSubId(subId);
return getNonActionableWifiCallingSlice(
mContext.getText(R.string.wifi_calling_mode_title),
mContext.getText(R.string.wifi_calling_turn_on),
res.getText(R.string.wifi_calling_mode_title),
res.getText(R.string.wifi_calling_turn_on),
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
}
// Return the slice to change wifi calling preference
return getWifiCallingPreferenceSlice(
isWifiOnlySupported, wfcMode, sliceUri);
isWifiOnlySupported, wfcMode, sliceUri, subId);
}
/**
@@ -275,40 +278,43 @@ public class WifiCallingSliceHelper {
* @param isWifiOnlySupported adds row for wifi only if this is true
* @param currentWfcPref current Preference {@link ImsConfig}
* @param sliceUri sliceUri
* @param subId subscription id
* @return Slice for actionable wifi calling preference settings
*/
private Slice getWifiCallingPreferenceSlice(boolean isWifiOnlySupported,
int currentWfcPref,
Uri sliceUri) {
Uri sliceUri,
int subId) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
Resources res = getResourcesForSubId(subId);
// Top row shows information on current preference state
final ListBuilder listBuilder = new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
.setTitle(mContext.getText(R.string.wifi_calling_mode_title))
.setSubtitle(getWifiCallingPreferenceSummary(currentWfcPref))
.setTitle(res.getText(R.string.wifi_calling_mode_title))
.setSubtitle(getWifiCallingPreferenceSummary(currentWfcPref, subId))
.setPrimaryAction(SliceAction.createDeeplink(
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
icon,
ListBuilder.ICON_IMAGE,
mContext.getText(R.string.wifi_calling_mode_title))));
res.getText(R.string.wifi_calling_mode_title))));
if (isWifiOnlySupported) {
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_only_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY,
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY, subId));
}
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_wifi_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED,
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED));
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED, subId));
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
com.android.internal.R.string.wfc_mode_cellular_preferred_summary,
ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED,
currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED, subId));
return listBuilder.build();
}
@@ -319,16 +325,18 @@ public class WifiCallingSliceHelper {
* @param listBuilder ListBuilder that will be the parent for this RowBuilder
* @param preferenceTitleResId resource Id for the preference row title
* @param action action to be added for the row
* @param subId subscription id
* @return RowBuilder for the row
*/
private RowBuilder wifiPreferenceRowBuilder(ListBuilder listBuilder,
int preferenceTitleResId, String action, boolean checked) {
int preferenceTitleResId, String action, boolean checked, int subId) {
final IconCompat icon =
IconCompat.createWithResource(mContext, R.drawable.radio_button_check);
Resources res = getResourcesForSubId(subId);
return new RowBuilder()
.setTitle(mContext.getText(preferenceTitleResId))
.setTitle(res.getText(preferenceTitleResId))
.setTitleItem(SliceAction.createToggle(getBroadcastIntent(action),
icon, mContext.getText(preferenceTitleResId), checked));
icon, res.getText(preferenceTitleResId), checked));
}
@@ -338,16 +346,17 @@ public class WifiCallingSliceHelper {
* @param wfcMode ImsConfig constant for the preference {@link ImsConfig}
* @return summary/name of the wifi calling preference
*/
private CharSequence getWifiCallingPreferenceSummary(int wfcMode) {
private CharSequence getWifiCallingPreferenceSummary(int wfcMode, int subId) {
Resources res = getResourcesForSubId(subId);
switch (wfcMode) {
case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
return mContext.getText(
return res.getText(
com.android.internal.R.string.wfc_mode_wifi_only_summary);
case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
return mContext.getText(
return res.getText(
com.android.internal.R.string.wfc_mode_wifi_preferred_summary);
case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
return mContext.getText(
return res.getText(
com.android.internal.R.string.wfc_mode_cellular_preferred_summary);
default:
return null;
@@ -573,4 +582,8 @@ public class WifiCallingSliceHelper {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}
private Resources getResourcesForSubId(int subId) {
return SubscriptionManager.getResourcesForSubId(mContext, subId);
}
}