[Settings] Refactor of Wifi Calling part

Refactor of Wifi Calling to avoid accessing hidden APIs.
This includes the following cherry-picks on the corresponding files:
I455685eb26df69d929ff3ed3c26ce84aa5f6b1f8
I1a67db80b114a438afda7d45af90e54af38703c3
Idd4935a6d8ceed77c15e90f96781014d1940a427
Ia5179ee1a23f054899bc74c796542bae40cdc8d5
I57c91a095fc4d454d92e8d78e0b647b4f098c6a3
I8a09264f83b9fc4fce3f79ec3aeb6ae757b004e4
I68462368669b81e10d09bbb93e74e23ea9a1f446
I9c54eb63a0df3fde38965ee7e2ae46cc1b7efd47
I0d5dcfc33b0bddacf059d1fb9af559646e32e68a
I45977c850977be84c0dc1f6461e68a1941efc1a2
I46c047359257ddd5cb3e331add4856b01c5c9739
I35246811d3e01d0b2ca197e9a1ed7081691cd982

Bug: 140542283
Test: build pass
Change-Id: I2cddeefb7cc5f1b2060e572a73560f7cd6204d0b
This commit is contained in:
Bonian Chen
2020-04-08 14:12:12 +08:00
parent 4e8786c09b
commit 5042276cf7
12 changed files with 349 additions and 288 deletions

View File

@@ -43,10 +43,9 @@ import androidx.slice.builders.ListBuilder.RowBuilder;
import androidx.slice.builders.SliceAction;
import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.slices.SliceBroadcastReceiver;
import java.util.concurrent.Callable;
@@ -132,57 +131,39 @@ public class WifiCallingSliceHelper {
*/
public Slice createWifiCallingSlice(Uri sliceUri) {
final int subId = getDefaultVoiceSubId();
Resources res = getResourcesForSubId(subId);
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Log.d(TAG, "Invalid subscription Id");
return null;
}
final ImsManager imsManager = getImsManager(subId);
if (!imsManager.isWfcEnabledByPlatform()
|| !isWfcProvisionedOnDevice(subId)) {
if (!queryImsState(subId).isWifiCallingProvisioned()) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by Platform");
return null;
}
try {
final boolean isWifiCallingEnabled = isWifiCallingEnabled(imsManager);
final Intent activationAppIntent =
getWifiCallingCarrierActivityIntent(subId);
final boolean isWifiCallingEnabled = isWifiCallingEnabled();
final Intent activationAppIntent =
getWifiCallingCarrierActivityIntent(subId);
// Send this actionable wifi calling slice to toggle the setting
// only when there is no need for wifi calling activation with the server
if (activationAppIntent != null && !isWifiCallingEnabled) {
Log.d(TAG, "Needs Activation");
// Activation needed for the next action of the user
// Give instructions to go to settings app
return getNonActionableWifiCallingSlice(
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, subId);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
Log.e(TAG, "Unable to read the current WiFi calling status", e);
return null;
// Send this actionable wifi calling slice to toggle the setting
// only when there is no need for wifi calling activation with the server
if (activationAppIntent != null && !isWifiCallingEnabled) {
Log.d(TAG, "Needs Activation");
// Activation needed for the next action of the user
// Give instructions to go to settings app
final Resources res = getResourcesForSubId(subId);
return getNonActionableWifiCallingSlice(
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, subId);
}
private boolean isWifiCallingEnabled(ImsManager imsManager)
throws InterruptedException, ExecutionException, TimeoutException {
final FutureTask<Boolean> isWifiOnTask = new FutureTask<>(new Callable<Boolean>() {
@Override
public Boolean call() {
return imsManager.isWfcEnabledByUser();
}
});
final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(isWifiOnTask);
return isWifiOnTask.get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
&& imsManager.isNonTtyOrTtyOnVolteEnabled();
private boolean isWifiCallingEnabled() {
final WifiCallingQueryImsState queryState = queryImsState(getDefaultVoiceSubId());
return queryState.isEnabledByUser() && queryState.isAllowUserControl();
}
/**
@@ -191,7 +172,7 @@ public class WifiCallingSliceHelper {
*/
private Slice getWifiCallingSlice(Uri sliceUri, boolean isWifiCallingEnabled, int subId) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
Resources res = getResourcesForSubId(subId);
final Resources res = getResourcesForSubId(subId);
return new ListBuilder(mContext, sliceUri, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
@@ -227,7 +208,7 @@ public class WifiCallingSliceHelper {
public Slice createWifiCallingPreferenceSlice(Uri sliceUri) {
final int subId = getDefaultVoiceSubId();
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Log.d(TAG, "Invalid Subscription Id");
return null;
}
@@ -236,24 +217,22 @@ public class WifiCallingSliceHelper {
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
final ImsManager imsManager = getImsManager(subId);
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
if (!imsManager.isWfcEnabledByPlatform()
|| !isWfcProvisionedOnDevice(subId)) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
return null;
}
if (!isWifiCallingPrefEditable) {
Log.d(TAG, "Wifi calling preference is not editable");
return null;
}
if (!queryImsState(subId).isWifiCallingProvisioned()) {
Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
return null;
}
boolean isWifiCallingEnabled = false;
int wfcMode = -1;
try {
isWifiCallingEnabled = isWifiCallingEnabled(imsManager);
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
isWifiCallingEnabled = isWifiCallingEnabled();
wfcMode = getWfcMode(imsMmTelManager);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "Unable to get wifi calling preferred mode", e);
@@ -261,7 +240,7 @@ public class WifiCallingSliceHelper {
}
if (!isWifiCallingEnabled) {
// wifi calling is not enabled. Ask user to enable wifi calling
Resources res = getResourcesForSubId(subId);
final Resources res = getResourcesForSubId(subId);
return getNonActionableWifiCallingSlice(
res.getText(R.string.wifi_calling_mode_title),
res.getText(R.string.wifi_calling_turn_on),
@@ -286,7 +265,7 @@ public class WifiCallingSliceHelper {
Uri sliceUri,
int subId) {
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.wifi_signal);
Resources res = getResourcesForSubId(subId);
final 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));
@@ -332,7 +311,7 @@ public class WifiCallingSliceHelper {
int preferenceTitleResId, String action, boolean checked, int subId) {
final IconCompat icon =
IconCompat.createWithResource(mContext, R.drawable.radio_button_check);
Resources res = getResourcesForSubId(subId);
final Resources res = getResourcesForSubId(subId);
return new RowBuilder()
.setTitle(res.getText(preferenceTitleResId))
.setTitleItem(SliceAction.createToggle(getBroadcastIntent(action),
@@ -347,7 +326,7 @@ public class WifiCallingSliceHelper {
* @return summary/name of the wifi calling preference
*/
private CharSequence getWifiCallingPreferenceSummary(int wfcMode, int subId) {
Resources res = getResourcesForSubId(subId);
final Resources res = getResourcesForSubId(subId);
switch (wfcMode) {
case ImsMmTelManager.WIFI_MODE_WIFI_ONLY:
return res.getText(
@@ -363,10 +342,6 @@ public class WifiCallingSliceHelper {
}
}
protected ImsManager getImsManager(int subId) {
return ImsManager.getInstance(mContext, SubscriptionManager.getPhoneId(subId));
}
protected ImsMmTelManager getImsMmTelManager(int subId) {
return ImsMmTelManager.createForSubscriptionId(subId);
}
@@ -393,12 +368,11 @@ public class WifiCallingSliceHelper {
public void handleWifiCallingChanged(Intent intent) {
final int subId = getDefaultVoiceSubId();
if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
final ImsManager imsManager = getImsManager(subId);
if (imsManager.isWfcEnabledByPlatform()
&& isWfcProvisionedOnDevice(subId)) {
final boolean currentValue = imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled();
if (SubscriptionManager.isValidSubscriptionId(subId)) {
final WifiCallingQueryImsState queryState = queryImsState(subId);
if (queryState.isWifiCallingProvisioned()) {
final boolean currentValue = queryState.isEnabledByUser()
&& queryState.isAllowUserControl();
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
currentValue);
final Intent activationAppIntent =
@@ -407,7 +381,8 @@ public class WifiCallingSliceHelper {
// If either the action is to turn off wifi calling setting
// or there is no activation involved - Update the setting
if (newValue != currentValue) {
imsManager.setWfcSetting(newValue);
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
imsMmTelManager.setVoWiFiSettingEnabled(newValue);
}
}
}
@@ -430,18 +405,17 @@ public class WifiCallingSliceHelper {
final int subId = getDefaultVoiceSubId();
final int errorValue = -1;
if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
if (SubscriptionManager.isValidSubscriptionId(subId)) {
final boolean isWifiCallingPrefEditable = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(
CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
final ImsManager imsManager = getImsManager(subId);
final WifiCallingQueryImsState queryState = queryImsState(subId);
if (isWifiCallingPrefEditable
&& imsManager.isWfcEnabledByPlatform()
&& isWfcProvisionedOnDevice(subId)
&& imsManager.isWfcEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled()) {
&& queryState.isWifiCallingProvisioned()
&& queryState.isEnabledByUser()
&& queryState.isAllowUserControl()) {
// Change the preference only when wifi calling is enabled
// And when wifi calling preference is editable for the current carrier
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
@@ -522,11 +496,6 @@ public class WifiCallingSliceHelper {
return SubscriptionManager.getDefaultVoiceSubscriptionId();
}
@VisibleForTesting
boolean isWfcProvisionedOnDevice(int subId) {
return MobileNetworkUtils.isWfcProvisionedOnDevice(subId);
}
/**
* Returns Intent of the activation app required to activate wifi calling or null if there is no
* need for activation.
@@ -586,4 +555,9 @@ public class WifiCallingSliceHelper {
private Resources getResourcesForSubId(int subId) {
return SubscriptionManager.getResourcesForSubId(mContext, subId);
}
@VisibleForTesting
WifiCallingQueryImsState queryImsState(int subId) {
return new WifiCallingQueryImsState(mContext, subId);
}
}