Merge changes from topic "PreferredNetworkModeSearchItem" into main
* changes: Dual SIM search for Preferred network type Refactor MobileNetworkSettingsSearchIndex
This commit is contained in:
@@ -152,6 +152,7 @@
|
|||||||
android:summary="@string/contact_discovery_opt_in_summary"
|
android:summary="@string/contact_discovery_opt_in_summary"
|
||||||
settings:controller="com.android.settings.network.telephony.ContactDiscoveryPreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.ContactDiscoveryPreferenceController"/>
|
||||||
|
|
||||||
|
<!-- Settings search is handled by PreferredNetworkModeSearchItem. -->
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="preferred_network_mode_key"
|
android:key="preferred_network_mode_key"
|
||||||
android:title="@string/preferred_network_mode_title"
|
android:title="@string/preferred_network_mode_title"
|
||||||
@@ -159,8 +160,10 @@
|
|||||||
android:entries="@array/preferred_network_mode_choices"
|
android:entries="@array/preferred_network_mode_choices"
|
||||||
android:entryValues="@array/preferred_network_mode_values"
|
android:entryValues="@array/preferred_network_mode_values"
|
||||||
android:dialogTitle="@string/preferred_network_mode_dialogtitle"
|
android:dialogTitle="@string/preferred_network_mode_dialogtitle"
|
||||||
|
settings:searchable="false"
|
||||||
settings:controller="com.android.settings.network.telephony.PreferredNetworkModePreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.PreferredNetworkModePreferenceController"/>
|
||||||
|
|
||||||
|
<!-- Settings search is handled by EnabledNetworkModeSearchItem. -->
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="enabled_networks_key"
|
android:key="enabled_networks_key"
|
||||||
android:title="@string/preferred_network_mode_title"
|
android:title="@string/preferred_network_mode_title"
|
||||||
@@ -168,6 +171,7 @@
|
|||||||
android:entries="@array/enabled_networks_choices"
|
android:entries="@array/enabled_networks_choices"
|
||||||
android:entryValues="@array/enabled_networks_values"
|
android:entryValues="@array/enabled_networks_values"
|
||||||
android:dialogTitle="@string/preferred_network_mode_dialogtitle"
|
android:dialogTitle="@string/preferred_network_mode_dialogtitle"
|
||||||
|
settings:searchable="false"
|
||||||
settings:controller="com.android.settings.network.telephony.EnabledNetworkModePreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.EnabledNetworkModePreferenceController"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ package com.android.settings.network.telephony;
|
|||||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||||
|
|
||||||
|
import static com.android.settings.network.telephony.EnabledNetworkModePreferenceControllerHelperKt.getNetworkModePreferenceType;
|
||||||
import static com.android.settings.network.telephony.EnabledNetworkModePreferenceControllerHelperKt.setAllowedNetworkTypes;
|
import static com.android.settings.network.telephony.EnabledNetworkModePreferenceControllerHelperKt.setAllowedNetworkTypes;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
@@ -44,6 +46,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.internal.telephony.flags.Flags;
|
import com.android.internal.telephony.flags.Flags;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.network.AllowedNetworkTypesListener;
|
import com.android.settings.network.AllowedNetworkTypesListener;
|
||||||
import com.android.settings.network.CarrierConfigCache;
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionsChangeListener;
|
import com.android.settings.network.SubscriptionsChangeListener;
|
||||||
@@ -61,16 +64,17 @@ import java.util.stream.Stream;
|
|||||||
* Preference controller for "Enabled network mode"
|
* Preference controller for "Enabled network mode"
|
||||||
*/
|
*/
|
||||||
public class EnabledNetworkModePreferenceController extends
|
public class EnabledNetworkModePreferenceController extends
|
||||||
TelephonyBasePreferenceController implements
|
BasePreferenceController implements
|
||||||
ListPreference.OnPreferenceChangeListener, LifecycleObserver,
|
ListPreference.OnPreferenceChangeListener, LifecycleObserver,
|
||||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
||||||
|
|
||||||
private static final String LOG_TAG = "EnabledNetworkMode";
|
private static final String LOG_TAG = "EnabledNetworkMode";
|
||||||
|
|
||||||
|
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
private AllowedNetworkTypesListener mAllowedNetworkTypesListener;
|
private AllowedNetworkTypesListener mAllowedNetworkTypesListener;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private CarrierConfigCache mCarrierConfigCache;
|
|
||||||
private PreferenceEntriesBuilder mBuilder;
|
private PreferenceEntriesBuilder mBuilder;
|
||||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||||
private int mCallState = TelephonyManager.CALL_STATE_IDLE;
|
private int mCallState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
@@ -81,36 +85,16 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
public EnabledNetworkModePreferenceController(Context context, String key) {
|
public EnabledNetworkModePreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||||
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
|
||||||
if (mTelephonyCallback == null) {
|
if (mTelephonyCallback == null) {
|
||||||
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
|
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus() {
|
||||||
boolean visible;
|
return getNetworkModePreferenceType(mContext, mSubId)
|
||||||
|
== NetworkModePreferenceType.EnabledNetworkMode
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig == null
|
|
||||||
|| !CarrierConfigManager.isConfigForIdentifiedCarrier(carrierConfig)) {
|
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig.getBoolean(
|
|
||||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
|
||||||
|| carrierConfig.getBoolean(
|
|
||||||
CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)) {
|
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
|
|
||||||
visible = false;
|
|
||||||
} else if (!isCallStateIdle()) {
|
|
||||||
return AVAILABLE_UNSEARCHABLE;
|
|
||||||
} else {
|
|
||||||
visible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isCallStateIdle() {
|
protected boolean isCallStateIdle() {
|
||||||
@@ -953,9 +937,14 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the resources associated with Subscription.
|
||||||
|
*
|
||||||
|
* @return Resources associated with Subscription.
|
||||||
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PhoneCallStateTelephonyCallback getTelephonyCallback() {
|
Resources getResourcesForSubId() {
|
||||||
return mTelephonyCallback;
|
return SubscriptionManager.getResourcesForSubId(mContext, mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,9 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony
|
package com.android.settings.network.telephony
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.telephony.CarrierConfigManager
|
||||||
|
import android.telephony.SubscriptionManager
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.android.settings.R
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -33,3 +39,62 @@ fun TelephonyManager.setAllowedNetworkTypes(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class NetworkModePreferenceType {
|
||||||
|
EnabledNetworkMode,
|
||||||
|
PreferredNetworkMode,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNetworkModePreferenceType(context: Context, subId: Int): NetworkModePreferenceType {
|
||||||
|
if (!SubscriptionManager.isValidSubscriptionId(subId)) return NetworkModePreferenceType.None
|
||||||
|
data class Config(
|
||||||
|
val carrierConfigApplied: Boolean,
|
||||||
|
val hideCarrierNetworkSettings: Boolean,
|
||||||
|
val hidePreferredNetworkType: Boolean,
|
||||||
|
val worldPhone: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
|
val config =
|
||||||
|
CarrierConfigRepository(context).transformConfig(subId) {
|
||||||
|
Config(
|
||||||
|
carrierConfigApplied =
|
||||||
|
getBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL),
|
||||||
|
hideCarrierNetworkSettings =
|
||||||
|
getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL),
|
||||||
|
hidePreferredNetworkType =
|
||||||
|
getBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL),
|
||||||
|
worldPhone = getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return when {
|
||||||
|
!config.carrierConfigApplied ||
|
||||||
|
config.hideCarrierNetworkSettings ||
|
||||||
|
config.hidePreferredNetworkType -> NetworkModePreferenceType.None
|
||||||
|
config.worldPhone -> NetworkModePreferenceType.PreferredNetworkMode
|
||||||
|
else -> NetworkModePreferenceType.EnabledNetworkMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PreferredNetworkModeSearchItem(private val context: Context) :
|
||||||
|
MobileNetworkSettingsSearchItem {
|
||||||
|
private val title: String = context.getString(R.string.preferred_network_mode_title)
|
||||||
|
|
||||||
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? =
|
||||||
|
when (getNetworkModePreferenceType(context, subId)) {
|
||||||
|
NetworkModePreferenceType.PreferredNetworkMode ->
|
||||||
|
MobileNetworkSettingsSearchResult(
|
||||||
|
key = "preferred_network_mode_key",
|
||||||
|
title = title,
|
||||||
|
)
|
||||||
|
|
||||||
|
NetworkModePreferenceType.EnabledNetworkMode ->
|
||||||
|
MobileNetworkSettingsSearchResult(
|
||||||
|
key = "enabled_networks_key",
|
||||||
|
title = title,
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,11 +20,13 @@ import android.content.Context
|
|||||||
import android.telephony.SubscriptionManager
|
import android.telephony.SubscriptionManager
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import android.telephony.data.ApnSetting
|
import android.telephony.data.ApnSetting
|
||||||
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.Settings.MobileNetworkActivity.EXTRA_MMS_MESSAGE
|
import com.android.settings.Settings.MobileNetworkActivity.EXTRA_MMS_MESSAGE
|
||||||
import com.android.settings.core.TogglePreferenceController
|
import com.android.settings.core.TogglePreferenceController
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
||||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@@ -109,7 +111,7 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MmsMessageSearchItem(
|
class MmsMessageSearchItem(
|
||||||
context: Context,
|
private val context: Context,
|
||||||
private val getDefaultDataSubId: () -> Int = {
|
private val getDefaultDataSubId: () -> Int = {
|
||||||
SubscriptionManager.getDefaultDataSubscriptionId()
|
SubscriptionManager.getDefaultDataSubscriptionId()
|
||||||
},
|
},
|
||||||
@@ -117,12 +119,18 @@ constructor(
|
|||||||
private var telephonyManager: TelephonyManager =
|
private var telephonyManager: TelephonyManager =
|
||||||
context.getSystemService(TelephonyManager::class.java)!!
|
context.getSystemService(TelephonyManager::class.java)!!
|
||||||
|
|
||||||
override val key: String = EXTRA_MMS_MESSAGE
|
@VisibleForTesting
|
||||||
override val title: String = context.getString(R.string.mms_message_title)
|
fun isAvailable(subId: Int): Boolean =
|
||||||
|
|
||||||
override fun isAvailable(subId: Int): Boolean =
|
|
||||||
getAvailabilityStatus(
|
getAvailabilityStatus(
|
||||||
telephonyManager.createForSubscriptionId(subId), subId, getDefaultDataSubId)
|
telephonyManager.createForSubscriptionId(subId), subId, getDefaultDataSubId)
|
||||||
|
|
||||||
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
|
||||||
|
if (!isAvailable(subId)) return null
|
||||||
|
return MobileNetworkSettingsSearchResult(
|
||||||
|
key = EXTRA_MMS_MESSAGE,
|
||||||
|
title = context.getString(R.string.mms_message_title),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,15 +39,14 @@ class MobileNetworkSettingsSearchIndex(
|
|||||||
private val searchItemsFactory: (context: Context) -> List<MobileNetworkSettingsSearchItem> =
|
private val searchItemsFactory: (context: Context) -> List<MobileNetworkSettingsSearchItem> =
|
||||||
::createSearchItems,
|
::createSearchItems,
|
||||||
) {
|
) {
|
||||||
|
data class MobileNetworkSettingsSearchResult(
|
||||||
|
val key: String,
|
||||||
|
val title: String,
|
||||||
|
val keywords: String? = null,
|
||||||
|
)
|
||||||
|
|
||||||
interface MobileNetworkSettingsSearchItem {
|
interface MobileNetworkSettingsSearchItem {
|
||||||
val key: String
|
fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult?
|
||||||
|
|
||||||
val title: String
|
|
||||||
|
|
||||||
val keywords: String?
|
|
||||||
get() = null
|
|
||||||
|
|
||||||
fun isAvailable(subId: Int): Boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSearchIndexableData(): SearchIndexableData {
|
fun createSearchIndexableData(): SearchIndexableData {
|
||||||
@@ -71,13 +70,15 @@ class MobileNetworkSettingsSearchIndex(
|
|||||||
searchItem: MobileNetworkSettingsSearchItem,
|
searchItem: MobileNetworkSettingsSearchItem,
|
||||||
subInfos: List<SubscriptionInfo>
|
subInfos: List<SubscriptionInfo>
|
||||||
): List<SearchIndexableRaw> =
|
): List<SearchIndexableRaw> =
|
||||||
subInfos
|
subInfos.mapNotNull { subInfo ->
|
||||||
.filter { searchItem.isAvailable(it.subscriptionId) }
|
searchItem.getSearchResult(subInfo.subscriptionId)?.let { searchResult ->
|
||||||
.map { subInfo -> searchIndexableRaw(context, searchItem, subInfo) }
|
searchIndexableRaw(context, searchResult, subInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun searchIndexableRaw(
|
private fun searchIndexableRaw(
|
||||||
context: Context,
|
context: Context,
|
||||||
searchItem: MobileNetworkSettingsSearchItem,
|
searchResult: MobileNetworkSettingsSearchResult,
|
||||||
subInfo: SubscriptionInfo,
|
subInfo: SubscriptionInfo,
|
||||||
): SearchIndexableRaw {
|
): SearchIndexableRaw {
|
||||||
val key =
|
val key =
|
||||||
@@ -85,7 +86,7 @@ class MobileNetworkSettingsSearchIndex(
|
|||||||
.setFragment(
|
.setFragment(
|
||||||
SpaSearchLandingFragment.newBuilder()
|
SpaSearchLandingFragment.newBuilder()
|
||||||
.setFragmentName(MobileNetworkSettings::class.java.name)
|
.setFragmentName(MobileNetworkSettings::class.java.name)
|
||||||
.setPreferenceKey(searchItem.key)
|
.setPreferenceKey(searchResult.key)
|
||||||
.putArguments(
|
.putArguments(
|
||||||
Settings.EXTRA_SUB_ID,
|
Settings.EXTRA_SUB_ID,
|
||||||
BundleValue.newBuilder().setIntValue(subInfo.subscriptionId).build()))
|
BundleValue.newBuilder().setIntValue(subInfo.subscriptionId).build()))
|
||||||
@@ -94,8 +95,8 @@ class MobileNetworkSettingsSearchIndex(
|
|||||||
return createSearchIndexableRaw(
|
return createSearchIndexableRaw(
|
||||||
context = context,
|
context = context,
|
||||||
spaSearchLandingKey = key,
|
spaSearchLandingKey = key,
|
||||||
itemTitle = searchItem.title,
|
itemTitle = searchResult.title,
|
||||||
keywords = searchItem.keywords,
|
keywords = searchResult.keywords,
|
||||||
indexableClass = MobileNetworkSettings::class.java,
|
indexableClass = MobileNetworkSettings::class.java,
|
||||||
pageTitle = "$simsTitle > ${subInfo.displayName}",
|
pageTitle = "$simsTitle > ${subInfo.displayName}",
|
||||||
)
|
)
|
||||||
@@ -115,6 +116,7 @@ class MobileNetworkSettingsSearchIndex(
|
|||||||
listOf(
|
listOf(
|
||||||
MmsMessageSearchItem(context),
|
MmsMessageSearchItem(context),
|
||||||
NrAdvancedCallingSearchItem(context),
|
NrAdvancedCallingSearchItem(context),
|
||||||
|
PreferredNetworkModeSearchItem(context),
|
||||||
RoamingSearchItem(context),
|
RoamingSearchItem(context),
|
||||||
WifiCallingSearchItem(context),
|
WifiCallingSearchItem(context),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
||||||
import com.android.settings.spa.preference.ComposePreferenceController
|
import com.android.settings.spa.preference.ComposePreferenceController
|
||||||
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
import com.android.settingslib.spa.widget.preference.SwitchPreference
|
||||||
@@ -79,12 +80,17 @@ class NrAdvancedCallingPreferenceController @JvmOverloads constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
class NrAdvancedCallingSearchItem(private val context: Context) :
|
class NrAdvancedCallingSearchItem(private val context: Context) :
|
||||||
MobileNetworkSettingsSearchItem {
|
MobileNetworkSettingsSearchItem {
|
||||||
override val key = "nr_advanced_calling"
|
|
||||||
override val title: String = context.getString(R.string.nr_advanced_calling_title)
|
|
||||||
override val keywords: String = context.getString(R.string.keywords_nr_advanced_calling)
|
|
||||||
|
|
||||||
override fun isAvailable(subId: Int): Boolean =
|
fun isAvailable(subId: Int): Boolean = VoNrRepository(context, subId).isVoNrAvailable()
|
||||||
VoNrRepository(context, subId).isVoNrAvailable()
|
|
||||||
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
|
||||||
|
if (!isAvailable(subId)) return null
|
||||||
|
return MobileNetworkSettingsSearchResult(
|
||||||
|
key = "nr_advanced_calling",
|
||||||
|
title = context.getString(R.string.nr_advanced_calling_title),
|
||||||
|
keywords = context.getString(R.string.keywords_nr_advanced_calling),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
|
import static com.android.settings.network.telephony.EnabledNetworkModePreferenceControllerHelperKt.getNetworkModePreferenceType;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
@@ -27,16 +29,18 @@ import androidx.preference.ListPreference;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.network.CarrierConfigCache;
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller for "Preferred network mode"
|
* Preference controller for "Preferred network mode"
|
||||||
*/
|
*/
|
||||||
public class PreferredNetworkModePreferenceController extends TelephonyBasePreferenceController
|
public class PreferredNetworkModePreferenceController extends BasePreferenceController
|
||||||
implements ListPreference.OnPreferenceChangeListener {
|
implements ListPreference.OnPreferenceChangeListener {
|
||||||
private static final String TAG = "PrefNetworkModeCtrl";
|
private static final String TAG = "PrefNetworkModeCtrl";
|
||||||
|
|
||||||
|
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
private CarrierConfigCache mCarrierConfigCache;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private boolean mIsGlobalCdma;
|
private boolean mIsGlobalCdma;
|
||||||
@@ -47,25 +51,10 @@ public class PreferredNetworkModePreferenceController extends TelephonyBasePrefe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus() {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
return getNetworkModePreferenceType(mContext, mSubId)
|
||||||
boolean visible;
|
== NetworkModePreferenceType.PreferredNetworkMode
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig == null) {
|
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig.getBoolean(
|
|
||||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
|
||||||
|| carrierConfig.getBoolean(
|
|
||||||
CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)) {
|
|
||||||
visible = false;
|
|
||||||
} else if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
|
|
||||||
visible = true;
|
|
||||||
} else {
|
|
||||||
visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
||||||
import com.android.settings.spa.preference.ComposePreferenceController
|
import com.android.settings.spa.preference.ComposePreferenceController
|
||||||
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
|
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
|
||||||
@@ -98,16 +99,21 @@ constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
private const val DIALOG_TAG = "MobileDataDialog"
|
private const val DIALOG_TAG = "MobileDataDialog"
|
||||||
|
|
||||||
class RoamingSearchItem(context: Context) : MobileNetworkSettingsSearchItem {
|
class RoamingSearchItem(private val context: Context) : MobileNetworkSettingsSearchItem {
|
||||||
override val key = "button_roaming_key"
|
|
||||||
override val title: String = context.getString(R.string.roaming)
|
|
||||||
|
|
||||||
private val carrierConfigRepository = CarrierConfigRepository(context)
|
private val carrierConfigRepository = CarrierConfigRepository(context)
|
||||||
|
|
||||||
override fun isAvailable(subId: Int): Boolean =
|
fun isAvailable(subId: Int): Boolean =
|
||||||
SubscriptionManager.isValidSubscriptionId(subId) &&
|
SubscriptionManager.isValidSubscriptionId(subId) &&
|
||||||
!carrierConfigRepository.getBoolean(
|
!carrierConfigRepository.getBoolean(
|
||||||
subId, CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL)
|
subId, CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL)
|
||||||
|
|
||||||
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
|
||||||
|
if (!isAvailable(subId)) return null
|
||||||
|
return MobileNetworkSettingsSearchResult(
|
||||||
|
key = "button_roaming_key",
|
||||||
|
title = context.getString(R.string.roaming),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,6 @@
|
|||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.PersistableBundle;
|
|
||||||
import android.telephony.CarrierConfigManager;
|
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -59,29 +56,4 @@ public abstract class TelephonyBasePreferenceController extends BasePreferenceCo
|
|||||||
public void unsetAvailabilityStatus() {
|
public void unsetAvailabilityStatus() {
|
||||||
mSetSessionCount.getAndDecrement();
|
mSetSessionCount.getAndDecrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get carrier config based on specific subscription id.
|
|
||||||
*
|
|
||||||
* @param subId is the subscription id
|
|
||||||
* @return {@link PersistableBundle} of carrier config, or {@code null} when carrier config
|
|
||||||
* is not available.
|
|
||||||
*/
|
|
||||||
public PersistableBundle getCarrierConfigForSubId(int subId) {
|
|
||||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final CarrierConfigManager carrierConfigMgr =
|
|
||||||
mContext.getSystemService(CarrierConfigManager.class);
|
|
||||||
return carrierConfigMgr.getConfigForSubId(subId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the resources associated with Subscription.
|
|
||||||
*
|
|
||||||
* @return Resources associated with Subscription.
|
|
||||||
*/
|
|
||||||
public Resources getResourcesForSubId() {
|
|
||||||
return SubscriptionManager.getResourcesForSubId(mContext, mSubId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import androidx.preference.Preference
|
|||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.core.BasePreferenceController
|
import com.android.settings.core.BasePreferenceController
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
|
||||||
import com.android.settings.network.telephony.wificalling.WifiCallingRepository
|
import com.android.settings.network.telephony.wificalling.WifiCallingRepository
|
||||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||||
@@ -132,12 +133,17 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
|
|||||||
class WifiCallingSearchItem(
|
class WifiCallingSearchItem(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
) : MobileNetworkSettingsSearchItem {
|
) : MobileNetworkSettingsSearchItem {
|
||||||
override val key: String = "wifi_calling"
|
private fun isAvailable(subId: Int): Boolean = runBlocking {
|
||||||
override val title: String = context.getString(R.string.wifi_calling_settings_title)
|
|
||||||
|
|
||||||
override fun isAvailable(subId: Int): Boolean = runBlocking {
|
|
||||||
WifiCallingRepository(context, subId).wifiCallingReadyFlow().first()
|
WifiCallingRepository(context, subId).wifiCallingReadyFlow().first()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? {
|
||||||
|
if (!isAvailable(subId)) return null
|
||||||
|
return MobileNetworkSettingsSearchResult(
|
||||||
|
key = "wifi_calling",
|
||||||
|
title = context.getString(R.string.wifi_calling_settings_title),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.telephony
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.telephony.CarrierConfigManager
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.kotlin.spy
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class EnabledNetworkModePreferenceControllerHelperTest {
|
||||||
|
|
||||||
|
private var context: Context = spy(ApplicationProvider.getApplicationContext()) {}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
CarrierConfigRepository.resetForTest()
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkModePreferenceType_hideCarrierNetworkSettings_returnNone() {
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, true)
|
||||||
|
|
||||||
|
val networkModePreferenceType = getNetworkModePreferenceType(context, SUB_ID)
|
||||||
|
|
||||||
|
assertThat(networkModePreferenceType).isEqualTo(NetworkModePreferenceType.None)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkModePreferenceType_hidePreferredNetworkType_returnNone() {
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL, true)
|
||||||
|
|
||||||
|
val networkModePreferenceType = getNetworkModePreferenceType(context, SUB_ID)
|
||||||
|
|
||||||
|
assertThat(networkModePreferenceType).isEqualTo(NetworkModePreferenceType.None)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkModePreferenceType_carrierConfigNotReady_returnNone() {
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, false)
|
||||||
|
|
||||||
|
val networkModePreferenceType = getNetworkModePreferenceType(context, SUB_ID)
|
||||||
|
|
||||||
|
assertThat(networkModePreferenceType).isEqualTo(NetworkModePreferenceType.None)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkModePreferenceType_isWorldPhone_returnPreferredNetworkMode() {
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_WORLD_PHONE_BOOL, true)
|
||||||
|
|
||||||
|
val networkModePreferenceType = getNetworkModePreferenceType(context, SUB_ID)
|
||||||
|
|
||||||
|
assertThat(networkModePreferenceType)
|
||||||
|
.isEqualTo(NetworkModePreferenceType.PreferredNetworkMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getNetworkModePreferenceType_notWorldPhone_returnEnabledNetworkMode() {
|
||||||
|
CarrierConfigRepository.setBooleanForTest(
|
||||||
|
SUB_ID, CarrierConfigManager.KEY_WORLD_PHONE_BOOL, false)
|
||||||
|
|
||||||
|
val networkModePreferenceType = getNetworkModePreferenceType(context, SUB_ID)
|
||||||
|
|
||||||
|
assertThat(networkModePreferenceType)
|
||||||
|
.isEqualTo(NetworkModePreferenceType.EnabledNetworkMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val SUB_ID = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ import androidx.test.core.app.ApplicationProvider
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.Companion.isMobileNetworkSettingsSearchable
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.Companion.isMobileNetworkSettingsSearchable
|
||||||
|
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchResult
|
||||||
import com.android.settings.spa.SpaSearchLanding.BundleValue
|
import com.android.settings.spa.SpaSearchLanding.BundleValue
|
||||||
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment
|
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment
|
||||||
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey
|
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey
|
||||||
@@ -62,10 +63,12 @@ class MobileNetworkSettingsSearchIndexTest {
|
|||||||
private val mobileNetworkSettingsSearchIndex = MobileNetworkSettingsSearchIndex {
|
private val mobileNetworkSettingsSearchIndex = MobileNetworkSettingsSearchIndex {
|
||||||
listOf(
|
listOf(
|
||||||
object : MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem {
|
object : MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem {
|
||||||
override val key = KEY
|
override fun getSearchResult(subId: Int): MobileNetworkSettingsSearchResult? =
|
||||||
override val title = TITLE
|
if (subId == SUB_ID_1) {
|
||||||
|
MobileNetworkSettingsSearchResult(key = KEY, title = TITLE)
|
||||||
override fun isAvailable(subId: Int) = subId == SUB_ID_1
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ package com.android.settings.network.telephony;
|
|||||||
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
|
||||||
import static com.android.settings.network.telephony.MobileNetworkUtils.getRafFromNetworkType;
|
import static com.android.settings.network.telephony.MobileNetworkUtils.getRafFromNetworkType;
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
|
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
|
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.EVDO;
|
||||||
@@ -33,8 +30,6 @@ import static com.android.settings.network.telephony.TelephonyConstants.RadioAcc
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -123,79 +118,6 @@ public class EnabledNetworkModePreferenceControllerTest {
|
|||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_hideCarrierNetworkSettings_returnUnavailable() {
|
|
||||||
mPersistableBundle.putBoolean(
|
|
||||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
|
|
||||||
true);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_hidePreferredNetworkType_returnUnavailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL,
|
|
||||||
true);
|
|
||||||
|
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
|
||||||
when(mServiceState.getDataRegistrationState()).thenReturn(
|
|
||||||
ServiceState.STATE_OUT_OF_SERVICE);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
|
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
|
||||||
when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
|
||||||
|
|
||||||
when(mServiceState.getRoaming()).thenReturn(false);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
|
|
||||||
when(mServiceState.getRoaming()).thenReturn(true);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_carrierConfigNotReady_returnUnavailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, false);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_notWorldPhone_returnAvailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
|
|
||||||
false);
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, false);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_callStateIsIdle_returnAvailable() {
|
|
||||||
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
|
|
||||||
mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_IDLE);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
||||||
assertTrue(mPreference.isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_duringCalling_returnAvailable() {
|
|
||||||
mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
|
|
||||||
mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
|
||||||
assertFalse(mPreference.isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
@Test
|
@Test
|
||||||
public void updateState_LteWorldPhone_GlobalHasLte() {
|
public void updateState_LteWorldPhone_GlobalHasLte() {
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
|
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.GSM;
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
|
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.RAF_TD_SCDMA;
|
||||||
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
|
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.WCDMA;
|
||||||
@@ -32,7 +30,6 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -91,43 +88,6 @@ public class PreferredNetworkModePreferenceControllerTest {
|
|||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_hideCarrierNetworkSettings_returnUnavailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
|
|
||||||
true);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_worldPhone_returnAvailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
|
|
||||||
false);
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, true);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_hidePreferredNetworkType_returnUnavailable() {
|
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL,
|
|
||||||
true);
|
|
||||||
|
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
|
||||||
when(mServiceState.getDataRegistrationState()).thenReturn(
|
|
||||||
ServiceState.STATE_OUT_OF_SERVICE);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
|
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
|
||||||
when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
|
||||||
|
|
||||||
when(mServiceState.getRoaming()).thenReturn(false);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
|
|
||||||
when(mServiceState.getRoaming()).thenReturn(true);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_updateByNetworkMode() {
|
public void updateState_updateByNetworkMode() {
|
||||||
// NETWORK_MODE_TDSCDMA_GSM_WCDMA = RAF_TD_SCDMA | GSM | WCDMA
|
// NETWORK_MODE_TDSCDMA_GSM_WCDMA = RAF_TD_SCDMA | GSM | WCDMA
|
||||||
|
|||||||
Reference in New Issue
Block a user