Consider subId when loading Wfc string resources
Consider subId when loading string resources in screen WifiCallingSettingsForSub and Wi-Fi Calling slice. This ensures that correct string resources is loaded in multi sim scenario when operators are using customized strings. Bug: 129893058 Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiCallingPreferenceController Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiCallingSliceHelper Change-Id: Ia5b763d4b59f7e738cb741b778bb859884a85198
This commit is contained in:
@@ -148,7 +148,8 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference.setSummary(resId);
|
preference.setSummary(
|
||||||
|
SubscriptionManager.getResourcesForSubId(mContext, mSubId).getText(resId));
|
||||||
}
|
}
|
||||||
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
|
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
|
||||||
}
|
}
|
||||||
|
@@ -340,19 +340,45 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWifiOnlySupported) {
|
Resources res = getResourcesForSubId();
|
||||||
mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only);
|
mButtonWfcMode.setTitle(res.getString(R.string.wifi_calling_mode_title));
|
||||||
mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only);
|
mButtonWfcMode.setDialogTitle(res.getString(R.string.wifi_calling_mode_dialog_title));
|
||||||
mButtonWfcMode.setEntrySummaries(R.array.wifi_calling_mode_summaries_without_wifi_only);
|
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(
|
mButtonWfcRoamingMode.setEntries(
|
||||||
R.array.wifi_calling_mode_choices_v2_without_wifi_only);
|
res.getStringArray(R.array.wifi_calling_mode_choices_v2));
|
||||||
mButtonWfcRoamingMode.setEntryValues(
|
mButtonWfcRoamingMode.setEntryValues(
|
||||||
R.array.wifi_calling_mode_values_without_wifi_only);
|
res.getStringArray(R.array.wifi_calling_mode_values));
|
||||||
mButtonWfcRoamingMode.setEntrySummaries(
|
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
|
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
|
||||||
final boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
|
final boolean wfcEnabled = mImsManager.isWfcEnabledByUser()
|
||||||
@@ -589,7 +615,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getWfcModeSummary(int wfcMode) {
|
private CharSequence getWfcModeSummary(int wfcMode) {
|
||||||
int resId = com.android.internal.R.string.wifi_calling_off_summary;
|
int resId = com.android.internal.R.string.wifi_calling_off_summary;
|
||||||
if (mImsManager.isWfcEnabledByUser()) {
|
if (mImsManager.isWfcEnabledByUser()) {
|
||||||
switch (wfcMode) {
|
switch (wfcMode) {
|
||||||
@@ -606,7 +632,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
|
|||||||
Log.e(TAG, "Unexpected WFC mode value: " + wfcMode);
|
Log.e(TAG, "Unexpected WFC mode value: " + wfcMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resId;
|
return getResourcesForSubId().getString(resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -25,6 +25,7 @@ import android.app.PendingIntent;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -131,6 +132,7 @@ public class WifiCallingSliceHelper {
|
|||||||
*/
|
*/
|
||||||
public Slice createWifiCallingSlice(Uri sliceUri) {
|
public Slice createWifiCallingSlice(Uri sliceUri) {
|
||||||
final int subId = getDefaultVoiceSubId();
|
final int subId = getDefaultVoiceSubId();
|
||||||
|
Resources res = getResourcesForSubId(subId);
|
||||||
|
|
||||||
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
Log.d(TAG, "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
|
// Activation needed for the next action of the user
|
||||||
// Give instructions to go to settings app
|
// Give instructions to go to settings app
|
||||||
return getNonActionableWifiCallingSlice(
|
return getNonActionableWifiCallingSlice(
|
||||||
mContext.getText(R.string.wifi_calling_settings_title),
|
res.getText(R.string.wifi_calling_settings_title),
|
||||||
mContext.getText(
|
res.getText(R.string.wifi_calling_settings_activation_instructions),
|
||||||
R.string.wifi_calling_settings_activation_instructions),
|
|
||||||
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
|
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
|
||||||
}
|
}
|
||||||
return getWifiCallingSlice(sliceUri, isWifiCallingEnabled);
|
return getWifiCallingSlice(sliceUri, isWifiCallingEnabled, subId);
|
||||||
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
||||||
Log.e(TAG, "Unable to read the current WiFi calling status", e);
|
Log.e(TAG, "Unable to read the current WiFi calling status", e);
|
||||||
return null;
|
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
|
* Builds a toggle slice where the intent takes you to the wifi calling page and the toggle
|
||||||
* enables/disables wifi calling.
|
* 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);
|
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
|
||||||
|
Resources res = getResourcesForSubId(subId);
|
||||||
|
|
||||||
return new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
|
return new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
|
||||||
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
|
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
|
||||||
.addRow(new RowBuilder()
|
.addRow(new RowBuilder()
|
||||||
.setTitle(mContext.getText(R.string.wifi_calling_settings_title))
|
.setTitle(res.getText(R.string.wifi_calling_settings_title))
|
||||||
.addEndItem(
|
.addEndItem(
|
||||||
SliceAction.createToggle(
|
SliceAction.createToggle(
|
||||||
getBroadcastIntent(ACTION_WIFI_CALLING_CHANGED),
|
getBroadcastIntent(ACTION_WIFI_CALLING_CHANGED),
|
||||||
@@ -203,7 +205,7 @@ public class WifiCallingSliceHelper {
|
|||||||
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
|
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
|
||||||
icon,
|
icon,
|
||||||
ListBuilder.ICON_IMAGE,
|
ListBuilder.ICON_IMAGE,
|
||||||
mContext.getText(R.string.wifi_calling_settings_title))))
|
res.getText(R.string.wifi_calling_settings_title))))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,14 +261,15 @@ public class WifiCallingSliceHelper {
|
|||||||
}
|
}
|
||||||
if (!isWifiCallingEnabled) {
|
if (!isWifiCallingEnabled) {
|
||||||
// wifi calling is not enabled. Ask user to enable wifi calling
|
// wifi calling is not enabled. Ask user to enable wifi calling
|
||||||
|
Resources res = getResourcesForSubId(subId);
|
||||||
return getNonActionableWifiCallingSlice(
|
return getNonActionableWifiCallingSlice(
|
||||||
mContext.getText(R.string.wifi_calling_mode_title),
|
res.getText(R.string.wifi_calling_mode_title),
|
||||||
mContext.getText(R.string.wifi_calling_turn_on),
|
res.getText(R.string.wifi_calling_turn_on),
|
||||||
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
|
sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
|
||||||
}
|
}
|
||||||
// Return the slice to change wifi calling preference
|
// Return the slice to change wifi calling preference
|
||||||
return getWifiCallingPreferenceSlice(
|
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 isWifiOnlySupported adds row for wifi only if this is true
|
||||||
* @param currentWfcPref current Preference {@link ImsConfig}
|
* @param currentWfcPref current Preference {@link ImsConfig}
|
||||||
* @param sliceUri sliceUri
|
* @param sliceUri sliceUri
|
||||||
|
* @param subId subscription id
|
||||||
* @return Slice for actionable wifi calling preference settings
|
* @return Slice for actionable wifi calling preference settings
|
||||||
*/
|
*/
|
||||||
private Slice getWifiCallingPreferenceSlice(boolean isWifiOnlySupported,
|
private Slice getWifiCallingPreferenceSlice(boolean isWifiOnlySupported,
|
||||||
int currentWfcPref,
|
int currentWfcPref,
|
||||||
Uri sliceUri) {
|
Uri sliceUri,
|
||||||
|
int subId) {
|
||||||
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
|
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
|
||||||
|
Resources res = getResourcesForSubId(subId);
|
||||||
// Top row shows information on current preference state
|
// Top row shows information on current preference state
|
||||||
final ListBuilder listBuilder = new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
|
final ListBuilder listBuilder = new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
|
||||||
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
|
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
|
||||||
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
||||||
.setTitle(mContext.getText(R.string.wifi_calling_mode_title))
|
.setTitle(res.getText(R.string.wifi_calling_mode_title))
|
||||||
.setSubtitle(getWifiCallingPreferenceSummary(currentWfcPref))
|
.setSubtitle(getWifiCallingPreferenceSummary(currentWfcPref, subId))
|
||||||
.setPrimaryAction(SliceAction.createDeeplink(
|
.setPrimaryAction(SliceAction.createDeeplink(
|
||||||
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
|
getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY),
|
||||||
icon,
|
icon,
|
||||||
ListBuilder.ICON_IMAGE,
|
ListBuilder.ICON_IMAGE,
|
||||||
mContext.getText(R.string.wifi_calling_mode_title))));
|
res.getText(R.string.wifi_calling_mode_title))));
|
||||||
|
|
||||||
if (isWifiOnlySupported) {
|
if (isWifiOnlySupported) {
|
||||||
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
||||||
com.android.internal.R.string.wfc_mode_wifi_only_summary,
|
com.android.internal.R.string.wfc_mode_wifi_only_summary,
|
||||||
ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY,
|
ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY,
|
||||||
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY));
|
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_ONLY, subId));
|
||||||
}
|
}
|
||||||
|
|
||||||
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
||||||
com.android.internal.R.string.wfc_mode_wifi_preferred_summary,
|
com.android.internal.R.string.wfc_mode_wifi_preferred_summary,
|
||||||
ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED,
|
ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED,
|
||||||
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED));
|
currentWfcPref == ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED, subId));
|
||||||
|
|
||||||
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
listBuilder.addRow(wifiPreferenceRowBuilder(listBuilder,
|
||||||
com.android.internal.R.string.wfc_mode_cellular_preferred_summary,
|
com.android.internal.R.string.wfc_mode_cellular_preferred_summary,
|
||||||
ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED,
|
ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED,
|
||||||
currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED));
|
currentWfcPref == ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED, subId));
|
||||||
|
|
||||||
return listBuilder.build();
|
return listBuilder.build();
|
||||||
}
|
}
|
||||||
@@ -319,16 +325,18 @@ public class WifiCallingSliceHelper {
|
|||||||
* @param listBuilder ListBuilder that will be the parent for this RowBuilder
|
* @param listBuilder ListBuilder that will be the parent for this RowBuilder
|
||||||
* @param preferenceTitleResId resource Id for the preference row title
|
* @param preferenceTitleResId resource Id for the preference row title
|
||||||
* @param action action to be added for the row
|
* @param action action to be added for the row
|
||||||
|
* @param subId subscription id
|
||||||
* @return RowBuilder for the row
|
* @return RowBuilder for the row
|
||||||
*/
|
*/
|
||||||
private RowBuilder wifiPreferenceRowBuilder(ListBuilder listBuilder,
|
private RowBuilder wifiPreferenceRowBuilder(ListBuilder listBuilder,
|
||||||
int preferenceTitleResId, String action, boolean checked) {
|
int preferenceTitleResId, String action, boolean checked, int subId) {
|
||||||
final IconCompat icon =
|
final IconCompat icon =
|
||||||
IconCompat.createWithResource(mContext, R.drawable.radio_button_check);
|
IconCompat.createWithResource(mContext, R.drawable.radio_button_check);
|
||||||
|
Resources res = getResourcesForSubId(subId);
|
||||||
return new RowBuilder()
|
return new RowBuilder()
|
||||||
.setTitle(mContext.getText(preferenceTitleResId))
|
.setTitle(res.getText(preferenceTitleResId))
|
||||||
.setTitleItem(SliceAction.createToggle(getBroadcastIntent(action),
|
.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}
|
* @param wfcMode ImsConfig constant for the preference {@link ImsConfig}
|
||||||
* @return summary/name of the wifi calling preference
|
* @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) {
|
switch (wfcMode) {
|
||||||
case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
|
case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
|
||||||
return mContext.getText(
|
return res.getText(
|
||||||
com.android.internal.R.string.wfc_mode_wifi_only_summary);
|
com.android.internal.R.string.wfc_mode_wifi_only_summary);
|
||||||
case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
|
case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED:
|
||||||
return mContext.getText(
|
return res.getText(
|
||||||
com.android.internal.R.string.wfc_mode_wifi_preferred_summary);
|
com.android.internal.R.string.wfc_mode_wifi_preferred_summary);
|
||||||
case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
|
case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED:
|
||||||
return mContext.getText(
|
return res.getText(
|
||||||
com.android.internal.R.string.wfc_mode_cellular_preferred_summary);
|
com.android.internal.R.string.wfc_mode_cellular_preferred_summary);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@@ -573,4 +582,8 @@ public class WifiCallingSliceHelper {
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
|
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Resources getResourcesForSubId(int subId) {
|
||||||
|
return SubscriptionManager.getResourcesForSubId(mContext, subId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user