[Settings] add WifiCallingQueryImsState for IMS
1. Code refactor 2. Introduce WifiCallingQueryImsState for user enable/disable configuration Bug: 140542283 Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=WifiCallingPreferenceControllerTest Change-Id: Ib337d6418fcc89f81b15b8cb464d03dccc583756
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
|
||||
/**
|
||||
* Controller class for querying Wifi calling status
|
||||
*/
|
||||
public class WifiCallingQueryImsState {
|
||||
|
||||
private Context mContext;
|
||||
private int mSubId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context {@code Context}
|
||||
* @param subId subscription's id
|
||||
*/
|
||||
public WifiCallingQueryImsState(Context context, int subId) {
|
||||
mContext = context;
|
||||
mSubId = subId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user's configuration
|
||||
*
|
||||
* @return true when user's configuration is ON otherwise false.
|
||||
*/
|
||||
public boolean isEnabledByUser() {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||
return false;
|
||||
}
|
||||
ImsManager imsManager = ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId(
|
||||
mContext, mSubId));
|
||||
return imsManager.isWfcEnabledByUser();
|
||||
}
|
||||
}
|
@@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -49,6 +50,8 @@ import java.util.List;
|
||||
public class WifiCallingPreferenceController extends TelephonyBasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String TAG = "WifiCallingPreference";
|
||||
|
||||
@VisibleForTesting
|
||||
Integer mCallState;
|
||||
@VisibleForTesting
|
||||
@@ -69,7 +72,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
return SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& MobileNetworkUtils.isWifiCallingEnabled(mContext, subId)
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
@@ -101,6 +104,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
if (mCallState == null) {
|
||||
return;
|
||||
}
|
||||
CharSequence summaryText = null;
|
||||
if (mSimCallManager != null) {
|
||||
final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mSimCallManager);
|
||||
@@ -111,25 +115,31 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
final List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
|
||||
preference.setTitle(resolutions.get(0).loadLabel(pm));
|
||||
preference.setSummary(null);
|
||||
preference.setIntent(intent);
|
||||
} else {
|
||||
final String title = SubscriptionManager.getResourcesForSubId(mContext, mSubId)
|
||||
.getString(R.string.wifi_calling_settings_title);
|
||||
preference.setTitle(title);
|
||||
summaryText = getResourceIdForWfcMode(mSubId);
|
||||
}
|
||||
preference.setSummary(summaryText);
|
||||
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
|
||||
}
|
||||
|
||||
private CharSequence getResourceIdForWfcMode(int subId) {
|
||||
int resId = com.android.internal.R.string.wifi_calling_off_summary;
|
||||
if (mImsManager.isWfcEnabledByUser()) {
|
||||
if (queryImsState(subId).isEnabledByUser()) {
|
||||
boolean useWfcHomeModeForRoaming = false;
|
||||
if (mCarrierConfigManager != null) {
|
||||
final PersistableBundle carrierConfig =
|
||||
mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||
mCarrierConfigManager.getConfigForSubId(subId);
|
||||
if (carrierConfig != null) {
|
||||
useWfcHomeModeForRoaming = carrierConfig.getBoolean(
|
||||
CarrierConfigManager
|
||||
.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL);
|
||||
}
|
||||
}
|
||||
final boolean isRoaming = getTelephonyManager(mContext, mSubId)
|
||||
final boolean isRoaming = getTelephonyManager(mContext, subId)
|
||||
.isNetworkRoaming();
|
||||
final int wfcMode = (isRoaming && !useWfcHomeModeForRoaming)
|
||||
? mImsMmTelManager.getVoWiFiRoamingModeSetting() :
|
||||
@@ -149,10 +159,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
break;
|
||||
}
|
||||
}
|
||||
preference.setSummary(
|
||||
SubscriptionManager.getResourcesForSubId(mContext, mSubId).getText(resId));
|
||||
}
|
||||
preference.setEnabled(mCallState == TelephonyManager.CALL_STATE_IDLE);
|
||||
return SubscriptionManager.getResourcesForSubId(mContext, subId).getText(resId);
|
||||
}
|
||||
|
||||
public WifiCallingPreferenceController init(int subId) {
|
||||
@@ -166,14 +173,22 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
return this;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
WifiCallingQueryImsState queryImsState(int subId) {
|
||||
return new WifiCallingQueryImsState(mContext, subId);
|
||||
}
|
||||
|
||||
protected ImsMmTelManager getImsMmTelManager(int subId) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return null;
|
||||
}
|
||||
return ImsMmTelManager.createForSubscriptionId(subId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
TelephonyManager getTelephonyManager(Context context, int subId) {
|
||||
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
|
||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return telephonyMgr;
|
||||
}
|
||||
final TelephonyManager subscriptionTelephonyMgr =
|
||||
|
@@ -19,6 +19,8 @@ package com.android.settings.network.telephony;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -38,6 +40,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@@ -63,6 +66,8 @@ public class WifiCallingPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
private WifiCallingQueryImsState mQueryImsState;
|
||||
|
||||
private WifiCallingPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
private Context mContext;
|
||||
@@ -74,6 +79,9 @@ public class WifiCallingPreferenceControllerTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
mQueryImsState = spy(new WifiCallingQueryImsState(mContext, SUB_ID));
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mController = spy(new WifiCallingPreferenceController(mContext, "wifi_calling") {
|
||||
@Override
|
||||
@@ -85,6 +93,7 @@ public class WifiCallingPreferenceControllerTest {
|
||||
mController.init(SUB_ID);
|
||||
mController.mImsManager = mImsManager;
|
||||
mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
|
||||
doReturn(mQueryImsState).when(mController).queryImsState(anyInt());
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
|
||||
when(mController.getTelephonyManager(mContext, SUB_ID)).thenReturn(mTelephonyManager);
|
||||
@@ -99,7 +108,7 @@ public class WifiCallingPreferenceControllerTest {
|
||||
@Test
|
||||
public void updateState_noSimCallManager_setCorrectSummary() {
|
||||
mController.mSimCallManager = null;
|
||||
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mImsMmTelManager.getVoWiFiRoamingModeSetting()).thenReturn(
|
||||
ImsMmTelManager.WIFI_MODE_WIFI_ONLY);
|
||||
when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
@@ -140,7 +149,7 @@ public class WifiCallingPreferenceControllerTest {
|
||||
ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
|
||||
when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
|
||||
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
@@ -157,7 +166,7 @@ public class WifiCallingPreferenceControllerTest {
|
||||
ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED);
|
||||
when(mImsMmTelManager.getVoWiFiModeSetting()).thenReturn(
|
||||
ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED);
|
||||
when(mImsManager.isWfcEnabledByUser()).thenReturn(true);
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
when(mTelephonyManager.isNetworkRoaming()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
Reference in New Issue
Block a user