[Settings] replace isNonTtyOrTtyOnVolteEnabled() and isWfcEnabledByUser() in WFC

1. Code refactor
2. Replace ImsManager#isNonTtyOrTtyOnVolteEnabled() by combination of
   TelecomManager#getCurrentTtyMode() and
   ImsMmTelManager#isTtyOverVolteEnabled()
3. Replace ImsManager#isWfcEnabledByUser() by
ImsMmTelManager#isVoWiFiSettingEnabled()

Bug: 140542283
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=WifiCallingSettingsForSubTest
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=WifiCallingSliceHelperTest
Change-Id: I57c91a095fc4d454d92e8d78e0b647b4f098c6a3
This commit is contained in:
Bonian Chen
2020-01-21 23:10:17 +08:00
parent ff1863451f
commit c4413a850f
4 changed files with 79 additions and 33 deletions

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network.ims;
import android.telephony.ims.ImsMmTelManager;
/**
* An {@code ImsQuery} for accessing IMS WFC enabled settings from user
*/
public class ImsQueryWfcUserSetting extends ImsDirectQueryImpl {
/**
* Constructor
* @param subId subscription id
*/
public ImsQueryWfcUserSetting(int subId) {
mSubId = subId;
}
private volatile int mSubId;
/**
* Query running within a {@code Callable}
*
* @return result of query
*/
public Boolean call() {
final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(mSubId);
return imsMmTelManager.isVoWiFiSettingEnabled();
}
}

View File

@@ -19,8 +19,7 @@ package com.android.settings.network.ims;
import android.content.Context; import android.content.Context;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import com.android.ims.ImsManager; import androidx.annotation.VisibleForTesting;
import com.android.settings.network.SubscriptionUtil;
/** /**
* Controller class for querying Wifi calling status * Controller class for querying Wifi calling status
@@ -41,6 +40,14 @@ public class WifiCallingQueryImsState extends ImsQueryController {
mSubId = subId; mSubId = subId;
} }
/**
* Implementation of ImsQueryController#isEnabledByUser(int subId)
*/
@VisibleForTesting
ImsDirectQuery isEnabledByUser(int subId) {
return new ImsQueryWfcUserSetting(subId);
}
/** /**
* Get allowance status for user to alter configuration * Get allowance status for user to alter configuration
* *
@@ -64,8 +71,6 @@ public class WifiCallingQueryImsState extends ImsQueryController {
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
return false; return false;
} }
ImsManager imsManager = ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId( return isEnabledByUser(mSubId).directQuery();
mContext, mSubId));
return imsManager.isWfcEnabledByUser();
} }
} }

View File

@@ -115,7 +115,8 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
@Override @Override
public void onCallStateChanged(int state, String incomingNumber) { public void onCallStateChanged(int state, String incomingNumber) {
final SettingsActivity activity = (SettingsActivity) getActivity(); final SettingsActivity activity = (SettingsActivity) getActivity();
final boolean isNonTtyOrTtyOnVolteEnabled = mImsManager.isNonTtyOrTtyOnVolteEnabled(); final boolean isNonTtyOrTtyOnVolteEnabled =
queryImsState(WifiCallingSettingsForSub.this.mSubId).isAllowUserControl();
final boolean isWfcEnabled = mSwitchBar.isChecked() final boolean isWfcEnabled = mSwitchBar.isChecked()
&& isNonTtyOrTtyOnVolteEnabled; && isNonTtyOrTtyOnVolteEnabled;
boolean isCallStateIdle = boolean isCallStateIdle =
@@ -403,7 +404,7 @@ public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
final WifiCallingQueryImsState queryIms = queryImsState(mSubId); final WifiCallingQueryImsState queryIms = queryImsState(mSubId);
final boolean wfcEnabled = queryIms.isEnabledByUser() final boolean wfcEnabled = queryIms.isEnabledByUser()
&& mImsManager.isNonTtyOrTtyOnVolteEnabled(); && queryIms.isAllowUserControl();
mSwitch.setChecked(wfcEnabled); mSwitch.setChecked(wfcEnabled);
final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting(); final int wfcMode = mImsMmTelManager.getVoWiFiModeSetting();
final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting(); final int wfcRoamingMode = mImsMmTelManager.getVoWiFiRoamingModeSetting();

View File

@@ -148,35 +148,29 @@ public class WifiCallingSliceHelper {
return null; return null;
} }
try { final boolean isWifiCallingEnabled = isWifiCallingEnabled();
final boolean isWifiCallingEnabled = isWifiCallingEnabled(imsManager); final Intent activationAppIntent =
final Intent activationAppIntent = getWifiCallingCarrierActivityIntent(subId);
getWifiCallingCarrierActivityIntent(subId);
// Send this actionable wifi calling slice to toggle the setting // Send this actionable wifi calling slice to toggle the setting
// only when there is no need for wifi calling activation with the server // only when there is no need for wifi calling activation with the server
if (activationAppIntent != null && !isWifiCallingEnabled) { if (activationAppIntent != null && !isWifiCallingEnabled) {
Log.d(TAG, "Needs Activation"); Log.d(TAG, "Needs Activation");
// 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
final Resources res = getResourcesForSubId(subId); final Resources res = getResourcesForSubId(subId);
return getNonActionableWifiCallingSlice( return getNonActionableWifiCallingSlice(
res.getText(R.string.wifi_calling_settings_title), res.getText(R.string.wifi_calling_settings_title),
res.getText(R.string.wifi_calling_settings_activation_instructions), res.getText(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, subId);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
Log.e(TAG, "Unable to read the current WiFi calling status", e);
return null;
} }
return getWifiCallingSlice(sliceUri, isWifiCallingEnabled, subId);
} }
private boolean isWifiCallingEnabled(ImsManager imsManager) private boolean isWifiCallingEnabled() {
throws InterruptedException, ExecutionException, TimeoutException {
final int subId = getDefaultVoiceSubId(); final int subId = getDefaultVoiceSubId();
return queryImsState(subId).isEnabledByUser() return queryImsState(subId).isEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled(); && queryImsState(subId).isAllowUserControl();
} }
/** /**
@@ -247,7 +241,7 @@ public class WifiCallingSliceHelper {
boolean isWifiCallingEnabled = false; boolean isWifiCallingEnabled = false;
int wfcMode = -1; int wfcMode = -1;
try { try {
isWifiCallingEnabled = isWifiCallingEnabled(imsManager); isWifiCallingEnabled = isWifiCallingEnabled();
wfcMode = getWfcMode(imsMmTelManager); wfcMode = getWfcMode(imsMmTelManager);
} catch (InterruptedException | ExecutionException | TimeoutException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "Unable to get wifi calling preferred mode", e); Log.e(TAG, "Unable to get wifi calling preferred mode", e);
@@ -392,7 +386,7 @@ public class WifiCallingSliceHelper {
if (imsManager.isWfcEnabledByPlatform() if (imsManager.isWfcEnabledByPlatform()
&& isWfcProvisionedOnDevice(subId)) { && isWfcProvisionedOnDevice(subId)) {
final boolean currentValue = queryImsState(subId).isEnabledByUser() final boolean currentValue = queryImsState(subId).isEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled(); && queryImsState(subId).isAllowUserControl();
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
currentValue); currentValue);
final Intent activationAppIntent = final Intent activationAppIntent =
@@ -436,7 +430,7 @@ public class WifiCallingSliceHelper {
&& imsManager.isWfcEnabledByPlatform() && imsManager.isWfcEnabledByPlatform()
&& isWfcProvisionedOnDevice(subId) && isWfcProvisionedOnDevice(subId)
&& queryImsState(subId).isEnabledByUser() && queryImsState(subId).isEnabledByUser()
&& imsManager.isNonTtyOrTtyOnVolteEnabled()) { && queryImsState(subId).isAllowUserControl()) {
// Change the preference only when wifi calling is enabled // Change the preference only when wifi calling is enabled
// And when wifi calling preference is editable for the current carrier // And when wifi calling preference is editable for the current carrier
final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId); final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);