Snap for 7714994 from cd2016c7a0 to sc-qpr1-release

Change-Id: I1ff0c8771c91636b41abd2de8a93d35e8f5a6d4a
This commit is contained in:
Android Build Coastguard Worker
2021-09-09 01:08:13 +00:00
8 changed files with 539 additions and 158 deletions

View File

@@ -2,7 +2,7 @@
"v": "5.7.13",
"fr": 60,
"ip": 0,
"op": 481,
"op": 541,
"w": 300,
"h": 289,
"nm": "enrollment_edu_02",
@@ -877,13 +877,13 @@
0
]
},
"t": 399,
"t": 429,
"s": [
100
]
},
{
"t": 410,
"t": 440,
"s": [
0
]
@@ -908,9 +908,9 @@
"hd": false
}
],
"ip": 388,
"op": 481,
"st": 202,
"ip": 418,
"op": 630,
"st": 232,
"bm": 0
},
{
@@ -1786,13 +1786,13 @@
0
]
},
"t": 350,
"t": 380,
"s": [
100
]
},
{
"t": 364,
"t": 394,
"s": [
0
]
@@ -1812,9 +1812,9 @@
"hd": false
}
],
"ip": 339,
"op": 388,
"st": 202,
"ip": 369,
"op": 418,
"st": 232,
"bm": 0
},
{
@@ -2685,13 +2685,13 @@
0
]
},
"t": 305,
"t": 335,
"s": [
100
]
},
{
"t": 318,
"t": 348,
"s": [
0
]
@@ -2716,9 +2716,9 @@
"hd": false
}
],
"ip": 294,
"op": 339,
"st": 101,
"ip": 324,
"op": 369,
"st": 131,
"bm": 0
},
{
@@ -3594,13 +3594,13 @@
0
]
},
"t": 255,
"t": 285,
"s": [
100
]
},
{
"t": 269,
"t": 299,
"s": [
0
]
@@ -3620,9 +3620,9 @@
"hd": false
}
],
"ip": 248,
"op": 294,
"st": 101,
"ip": 278,
"op": 324,
"st": 131,
"bm": 0
},
{
@@ -4493,13 +4493,13 @@
0
]
},
"t": 202,
"t": 232,
"s": [
100
]
},
{
"t": 215,
"t": 245,
"s": [
0
]
@@ -4524,9 +4524,9 @@
"hd": false
}
],
"ip": 188,
"op": 248,
"st": 0,
"ip": 218,
"op": 278,
"st": 30,
"bm": 0
},
{
@@ -5402,13 +5402,13 @@
0
]
},
"t": 155,
"t": 185,
"s": [
100
]
},
{
"t": 169,
"t": 199,
"s": [
0
]
@@ -5428,9 +5428,9 @@
"hd": false
}
],
"ip": 130,
"op": 188,
"st": 0,
"ip": 160,
"op": 218,
"st": 30,
"bm": 0
},
{
@@ -6301,13 +6301,13 @@
0
]
},
"t": 108,
"t": 138,
"s": [
100
]
},
{
"t": 119,
"t": 149,
"s": [
0
]
@@ -6333,8 +6333,8 @@
}
],
"ip": 0,
"op": 130,
"st": 0,
"op": 160,
"st": 30,
"bm": 0
},
{
@@ -7210,13 +7210,13 @@
0
]
},
"t": 62,
"t": 92,
"s": [
100
]
},
{
"t": 76,
"t": 106,
"s": [
0
]
@@ -7237,8 +7237,8 @@
}
],
"ip": 0,
"op": 130,
"st": 0,
"op": 160,
"st": 30,
"bm": 0
},
{
@@ -8112,8 +8112,8 @@
}
],
"ip": 0,
"op": 481,
"st": 0,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -8181,7 +8181,7 @@
0
]
},
"t": 62,
"t": 92,
"s": [
17.82,
17.82,
@@ -8213,7 +8213,7 @@
0
]
},
"t": 72,
"t": 102,
"s": [
16.92,
16.92,
@@ -8245,7 +8245,7 @@
0
]
},
"t": 108,
"t": 138,
"s": [
16.92,
16.92,
@@ -8277,7 +8277,7 @@
0
]
},
"t": 118,
"t": 148,
"s": [
17.82,
17.82,
@@ -8309,7 +8309,7 @@
0
]
},
"t": 155,
"t": 185,
"s": [
17.82,
17.82,
@@ -8341,7 +8341,7 @@
0
]
},
"t": 165,
"t": 195,
"s": [
16.92,
16.92,
@@ -8373,7 +8373,7 @@
0
]
},
"t": 202,
"t": 232,
"s": [
16.92,
16.92,
@@ -8405,7 +8405,7 @@
0
]
},
"t": 212,
"t": 242,
"s": [
17.82,
17.82,
@@ -8437,7 +8437,7 @@
0
]
},
"t": 255,
"t": 285,
"s": [
17.82,
17.82,
@@ -8469,7 +8469,7 @@
0
]
},
"t": 265,
"t": 295,
"s": [
16.92,
16.92,
@@ -8501,7 +8501,7 @@
0
]
},
"t": 305,
"t": 335,
"s": [
16.92,
16.92,
@@ -8533,7 +8533,7 @@
0
]
},
"t": 315,
"t": 345,
"s": [
17.82,
17.82,
@@ -8565,7 +8565,7 @@
0
]
},
"t": 350,
"t": 380,
"s": [
17.82,
17.82,
@@ -8597,7 +8597,7 @@
0
]
},
"t": 360,
"t": 390,
"s": [
16.92,
16.92,
@@ -8629,7 +8629,7 @@
0
]
},
"t": 399,
"t": 429,
"s": [
16.92,
16.92,
@@ -8637,7 +8637,7 @@
]
},
{
"t": 409,
"t": 439,
"s": [
17.82,
17.82,
@@ -8699,7 +8699,7 @@
0.167
]
},
"t": 62,
"t": 92,
"s": [
0.247058838489,
0.305882352941,
@@ -8724,7 +8724,7 @@
0.167
]
},
"t": 68,
"t": 98,
"s": [
0.105882360421,
0.152941176471,
@@ -8749,7 +8749,7 @@
0.167
]
},
"t": 108,
"t": 138,
"s": [
0.105882360421,
0.152941176471,
@@ -8774,7 +8774,7 @@
0.167
]
},
"t": 113,
"t": 143,
"s": [
0.247058838489,
0.305882352941,
@@ -8799,7 +8799,7 @@
0.167
]
},
"t": 155,
"t": 185,
"s": [
0.247058838489,
0.305882352941,
@@ -8824,7 +8824,7 @@
0.167
]
},
"t": 160,
"t": 190,
"s": [
0.117647059262,
0.152941182256,
@@ -8849,7 +8849,7 @@
0.167
]
},
"t": 202,
"t": 232,
"s": [
0.117647059262,
0.152941182256,
@@ -8874,7 +8874,7 @@
0.167
]
},
"t": 207,
"t": 237,
"s": [
0.258823543787,
0.305882364511,
@@ -8899,7 +8899,7 @@
0.167
]
},
"t": 255,
"t": 285,
"s": [
0.258823543787,
0.305882364511,
@@ -8924,7 +8924,7 @@
0.167
]
},
"t": 260,
"t": 290,
"s": [
0.117647059262,
0.152941182256,
@@ -8949,7 +8949,7 @@
0.167
]
},
"t": 305,
"t": 335,
"s": [
0.117647059262,
0.152941182256,
@@ -8974,7 +8974,7 @@
0.167
]
},
"t": 310,
"t": 340,
"s": [
0.258823543787,
0.305882364511,
@@ -8999,7 +8999,7 @@
0.167
]
},
"t": 350,
"t": 380,
"s": [
0.258823543787,
0.305882364511,
@@ -9024,7 +9024,7 @@
0.167
]
},
"t": 355,
"t": 385,
"s": [
0.117647059262,
0.152941182256,
@@ -9049,7 +9049,7 @@
0.167
]
},
"t": 399,
"t": 429,
"s": [
0.117647059262,
0.152941182256,
@@ -9058,7 +9058,7 @@
]
},
{
"t": 404,
"t": 434,
"s": [
0.258823543787,
0.305882364511,
@@ -9139,8 +9139,8 @@
}
],
"ip": 0,
"op": 481,
"st": 0,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -9565,7 +9565,7 @@
0.167
]
},
"t": 30,
"t": 60,
"s": [
100
]
@@ -9587,7 +9587,7 @@
0.167
]
},
"t": 40,
"t": 70,
"s": [
0
]
@@ -9609,13 +9609,13 @@
0.167
]
},
"t": 459,
"t": 489,
"s": [
0
]
},
{
"t": 469,
"t": 499,
"s": [
100
]
@@ -9688,8 +9688,8 @@
}
],
"ip": 0,
"op": 481,
"st": 0,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -9835,13 +9835,13 @@
0.167
]
},
"t": 457,
"t": 487,
"s": [
100
]
},
{
"t": 460,
"t": 490,
"s": [
0
]
@@ -9946,13 +9946,13 @@
0
]
},
"t": 403,
"t": 433,
"s": [
0
]
},
{
"t": 417,
"t": 447,
"s": [
100
]
@@ -9972,9 +9972,9 @@
"hd": false
}
],
"ip": 399,
"op": 460,
"st": 0,
"ip": 429,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -10042,7 +10042,7 @@
0
]
},
"t": 399,
"t": 429,
"s": [
7.2,
7.2,
@@ -10074,7 +10074,7 @@
0
]
},
"t": 407,
"t": 437,
"s": [
19.525,
19.525,
@@ -10106,7 +10106,7 @@
0
]
},
"t": 424,
"t": 454,
"s": [
17.185,
17.185,
@@ -10138,7 +10138,7 @@
0
]
},
"t": 450,
"t": 480,
"s": [
17.185,
17.185,
@@ -10146,7 +10146,7 @@
]
},
{
"t": 460,
"t": 490,
"s": [
7.2,
7.2,
@@ -10218,13 +10218,13 @@
0.167
]
},
"t": 452,
"t": 482,
"s": [
100
]
},
{
"t": 460,
"t": 490,
"s": [
0
]
@@ -10277,13 +10277,13 @@
0.167
]
},
"t": 452,
"t": 482,
"s": [
100
]
},
{
"t": 460,
"t": 490,
"s": [
0
]
@@ -10355,9 +10355,9 @@
"hd": false
}
],
"ip": 399,
"op": 460,
"st": 0,
"ip": 429,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -10468,13 +10468,13 @@
0.167
]
},
"t": 450,
"t": 480,
"s": [
100
]
},
{
"t": 456,
"t": 486,
"s": [
0
]
@@ -10553,9 +10553,9 @@
"hd": false
}
],
"ip": 447,
"op": 481,
"st": 0,
"ip": 477,
"op": 630,
"st": 30,
"bm": 0
},
{
@@ -10748,7 +10748,7 @@
0
]
},
"t": 350,
"t": 380,
"s": [
0
]
@@ -10770,13 +10770,13 @@
0
]
},
"t": 399,
"t": 429,
"s": [
22.5
]
},
{
"t": 410,
"t": 440,
"s": [
26
]
@@ -10796,9 +10796,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -10909,13 +10909,13 @@
0.167
]
},
"t": 39,
"t": 69,
"s": [
0
]
},
{
"t": 49,
"t": 79,
"s": [
100
]
@@ -11017,9 +11017,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -11212,7 +11212,7 @@
0
]
},
"t": 255,
"t": 285,
"s": [
0
]
@@ -11234,7 +11234,7 @@
0
]
},
"t": 305,
"t": 335,
"s": [
22.5
]
@@ -11256,13 +11256,13 @@
0
]
},
"t": 399,
"t": 429,
"s": [
22.5
]
},
{
"t": 410,
"t": 440,
"s": [
26
]
@@ -11282,9 +11282,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -11395,13 +11395,13 @@
0.167
]
},
"t": 39,
"t": 69,
"s": [
0
]
},
{
"t": 49,
"t": 79,
"s": [
100
]
@@ -11503,9 +11503,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -11698,7 +11698,7 @@
0
]
},
"t": 155,
"t": 185,
"s": [
0
]
@@ -11720,7 +11720,7 @@
0
]
},
"t": 202,
"t": 232,
"s": [
22.5
]
@@ -11742,13 +11742,13 @@
0
]
},
"t": 399,
"t": 429,
"s": [
22.5
]
},
{
"t": 410,
"t": 440,
"s": [
26
]
@@ -11768,9 +11768,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -11881,13 +11881,13 @@
0.167
]
},
"t": 39,
"t": 69,
"s": [
0
]
},
{
"t": 49,
"t": 79,
"s": [
100
]
@@ -11989,9 +11989,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -12184,7 +12184,7 @@
0
]
},
"t": 62,
"t": 92,
"s": [
0
]
@@ -12206,7 +12206,7 @@
0
]
},
"t": 108,
"t": 138,
"s": [
22.5
]
@@ -12228,13 +12228,13 @@
0
]
},
"t": 399,
"t": 429,
"s": [
22.5
]
},
{
"t": 410,
"t": 440,
"s": [
26
]
@@ -12254,9 +12254,9 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
},
{
@@ -12367,13 +12367,13 @@
0.167
]
},
"t": 39,
"t": 69,
"s": [
0
]
},
{
"t": 49,
"t": 79,
"s": [
100
]
@@ -12475,11 +12475,11 @@
"hd": false
}
],
"ip": 0,
"op": 447,
"st": 0,
"ip": -7,
"op": 477,
"st": 30,
"bm": 0
}
],
"markers": []
}
}

View File

@@ -7952,9 +7952,13 @@
<!-- Enhaced 4G LTE Mode title for carriers who want to show 4G Calling. [CHAR LIMIT=50] -->
<string name="enhanced_4g_lte_mode_title_4g_calling">4G Calling</string>
<!-- Enhaced 4G LTE Mode summary. [CHAR LIMIT=100] -->
<string name="enhanced_4g_lte_mode_summary">Use LTE services to improve voice and other communications (recommended)</string>
<string name="enhanced_4g_lte_mode_summary">Use LTE services to improve voice calls (recommended)</string>
<!-- Enhaced 4G LTE Mode summary for 4g calling. [CHAR LIMIT=100] -->
<string name="enhanced_4g_lte_mode_summary_4g_calling">Use 4G services to improve voice and other communications (recommended)</string>
<string name="enhanced_4g_lte_mode_summary_4g_calling">Use 4G services to improve voice calls (recommended)</string>
<!-- NR advanced calling(VoNR or Vo5G) title. [CHAR LIMIT=50] -->
<string name="nr_advanced_calling_title">Vo5G</string>
<!-- NR advanced calling(VoNR or Vo5G) summary. [CHAR LIMIT=NONE] -->
<string name="nr_advanced_calling_summary">Use 5G for voice calls</string>
<!-- Title of a preference determining whether or not the user has allowed the device to share
their contacts' phone numbers with their carrier in order to implement contact discovery,
which is a service that exchanges contacts with the carrier to determine if your
@@ -8349,6 +8353,9 @@
<!-- List of synonyms for the enhance 4G LTE titles, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_enhance_4g_lte">volte, advanced calling, 4g calling</string>
<!-- List of synonyms for the NR advanced calling(VoNR or Vo5G) titles, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_nr_advanced_calling">vo5g, vonr, advanced calling, 5g calling</string>
<!-- List of synonyms for add language, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_add_language">add language, add a language</string>

View File

@@ -247,6 +247,13 @@
android:summary="@string/enable_2g_summary"
settings:controller="com.android.settings.network.telephony.Enable2gPreferenceController" />
<SwitchPreference
android:key="nr_advanced_calling"
android:title="@string/nr_advanced_calling_title"
android:persistent="false"
android:summary="@string/nr_advanced_calling_summary"
settings:keywords="@string/keywords_nr_advanced_calling"
settings:controller="com.android.settings.network.telephony.NrAdvancedCallingPreferenceController"/>
</PreferenceCategory>
<Preference

View File

@@ -198,8 +198,9 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
@Override
public void onTetheringStarted() {
Log.d(TAG, "onTetheringStarted()");
// Set default usb functions again to make internal data persistent
mCurrentFunctions = mUsbBackend.getCurrentFunctions();
Log.d(TAG, "onTetheringStarted() : mCurrentFunctions " + mCurrentFunctions);
mUsbBackend.setDefaultUsbFunctions(mCurrentFunctions);
}

View File

@@ -193,6 +193,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
.addListener(videoCallingPreferenceController);
use(ContactDiscoveryPreferenceController.class).init(getParentFragmentManager(), mSubId,
getLifecycle());
use(NrAdvancedCallingPreferenceController.class).init(mSubId);
}
@Override

View File

@@ -0,0 +1,197 @@
/*
* Copyright (C) 2021 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.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
/**
* Preference controller for "Enhanced 4G LTE"
*/
public class NrAdvancedCallingPreferenceController extends TelephonyTogglePreferenceController
implements LifecycleObserver, OnStart, OnStop {
private static final String TAG = "VoNrSettings";
@VisibleForTesting
Preference mPreference;
private TelephonyManager mTelephonyManager;
private PhoneCallStateTelephonyCallback mTelephonyCallback;
private boolean mIsVonrVisibleFromCarrierConfig = false;
private boolean mIsNrEnableFromCarrierConfig = false;
private boolean mHas5gCapability = false;
private Integer mCallState;
public NrAdvancedCallingPreferenceController(Context context, String key) {
super(context, key);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
}
/**
* Initial this PreferenceController.
* @param subId The subscription Id.
* @return This PreferenceController.
*/
public NrAdvancedCallingPreferenceController init(int subId) {
Log.d(TAG, "init: ");
if (mTelephonyCallback == null) {
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
}
mSubId = subId;
if (mTelephonyManager == null) {
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
}
if (SubscriptionManager.isValidSubscriptionId(subId)) {
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
}
long supportedRadioBitmask = mTelephonyManager.getSupportedRadioAccessFamily();
mHas5gCapability =
(supportedRadioBitmask & TelephonyManager.NETWORK_TYPE_BITMASK_NR) > 0;
PersistableBundle carrierConfig = getCarrierConfigForSubId(subId);
if (carrierConfig == null) {
return this;
}
mIsVonrVisibleFromCarrierConfig = carrierConfig.getBoolean(
CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL);
int[] nrAvailabilities = carrierConfig.getIntArray(
CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY);
mIsNrEnableFromCarrierConfig = !ArrayUtils.isEmpty(nrAvailabilities);
Log.d(TAG, "mHas5gCapability: " + mHas5gCapability
+ ",mIsNrEnabledFromCarrierConfig: " + mIsNrEnableFromCarrierConfig
+ ",mIsVonrVisibleFromCarrierConfig: " + mIsVonrVisibleFromCarrierConfig);
return this;
}
@Override
public int getAvailabilityStatus(int subId) {
init(subId);
if (mHas5gCapability && mIsNrEnableFromCarrierConfig && mIsVonrVisibleFromCarrierConfig) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void onStart() {
if (mTelephonyCallback == null) {
return;
}
mTelephonyCallback.register(mTelephonyManager);
}
@Override
public void onStop() {
if (mTelephonyCallback == null) {
return;
}
mTelephonyCallback.unregister();
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (preference == null) {
return;
}
final SwitchPreference switchPreference = (SwitchPreference) preference;
switchPreference.setEnabled(isUserControlAllowed());
}
@Override
public boolean setChecked(boolean isChecked) {
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
return false;
}
Log.d(TAG, "setChecked: " + isChecked);
int result = mTelephonyManager.setVoNrEnabled(isChecked);
if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
return true;
}
Log.d(TAG, "Fail to set VoNR result= " + result + ". subId=" + mSubId);
return false;
}
@Override
public boolean isChecked() {
return mTelephonyManager.isVoNrEnabled();
}
@VisibleForTesting
protected boolean isCallStateIdle() {
return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE);
}
private boolean isUserControlAllowed() {
return isCallStateIdle();
}
private class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
TelephonyCallback.CallStateListener {
private TelephonyManager mLocalTelephonyManager;
@Override
public void onCallStateChanged(int state) {
mCallState = state;
updateState(mPreference);
}
public void register(TelephonyManager telephonyManager) {
mLocalTelephonyManager = telephonyManager;
// assign current call state so that it helps to show correct preference state even
// before first onCallStateChanged() by initial registration.
mCallState = mLocalTelephonyManager.getCallState();
mLocalTelephonyManager.registerTelephonyCallback(
mContext.getMainExecutor(), mTelephonyCallback);
}
public void unregister() {
mCallState = null;
if (mLocalTelephonyManager != null) {
mLocalTelephonyManager.unregisterTelephonyCallback(this);
}
}
}
}

View File

@@ -183,7 +183,7 @@ public class UsbDefaultFragmentTest {
@Test
public void onTetheringStarted_currentFunctionsIsRndis_setsRndisAsDefaultUsbFunctions() {
mFragment.mCurrentFunctions = UsbManager.FUNCTION_RNDIS;
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_RNDIS);
mFragment.mOnStartTetheringCallback.onTetheringStarted();
@@ -192,7 +192,7 @@ public class UsbDefaultFragmentTest {
@Test
public void onTetheringStarted_currentFunctionsIsNcm_setsNcmAsDefaultUsbFunctions() {
mFragment.mCurrentFunctions = UsbManager.FUNCTION_NCM;
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NCM);
mFragment.mOnStartTetheringCallback.onTetheringStarted();

View File

@@ -0,0 +1,168 @@
/*
* Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class NrAdvancedCallingPreferenceControllerTest {
private static final int SUB_ID = 2;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private TelephonyManager mInvalidTelephonyManager;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private CarrierConfigManager mCarrierConfigManager;
private NrAdvancedCallingPreferenceController mController;
private SwitchPreference mPreference;
private PersistableBundle mCarrierConfig;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(CarrierConfigManager.class))
.thenReturn(mCarrierConfigManager);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
doReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR).when(
mTelephonyManager).getSupportedRadioAccessFamily();
doReturn(false).when(mTelephonyManager).isVoNrEnabled();
doReturn(TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED).when(
mTelephonyManager).setVoNrEnabled(anyBoolean());
mCarrierConfig = new PersistableBundle();
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
new int[]{1, 2});
mPreference = new RestrictedSwitchPreference(mContext);
mController = spy(new NrAdvancedCallingPreferenceController(mContext, "VoNr"));
mController.init(SUB_ID);
doReturn(true).when(mController).isCallStateIdle();
mPreference.setKey(mController.getPreferenceKey());
}
@Test
public void getAvailabilityStatus_vonrDisabled_returnUnavailable() {
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
mController.init(SUB_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_vonrEnabled_returnAvailable() {
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
mController.init(SUB_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_deviceNoNr_returnUnavailable() {
doReturn(TelephonyManager.NETWORK_TYPE_BITMASK_LTE).when(
mTelephonyManager).getSupportedRadioAccessFamily();
mController.init(SUB_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_carrierNoNr_returnUnavailable() {
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
new int[0]);
mController.init(SUB_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void getAvailabilityStatus_carrierConfigNrIsNull_returnUnavailable() {
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
null);
mController.init(SUB_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void updateState_callStateNotIdle_prefDisabled() {
doReturn(false).when(mController).isCallStateIdle();
mPreference.setEnabled(true);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void updateState_configOn_prefChecked() {
doReturn(TelephonyManager.ENABLE_VONR_SUCCESS).when(
mTelephonyManager).setVoNrEnabled(anyBoolean());
doReturn(true).when(mTelephonyManager).isVoNrEnabled();
mPreference.setChecked(false);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
}