Merge "[Provider Model] Add new API to detect"
This commit is contained in:
@@ -24,9 +24,6 @@ import static com.android.settings.network.telephony.MobileNetworkUtils.NO_CELL_
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
@@ -71,7 +68,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
private String mPreferenceGroupKey;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private SubscriptionManager mManager;
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||
private MobileDataEnabledListener mDataEnabledListener;
|
||||
private DataConnectivityListener mConnectivityListener;
|
||||
@@ -112,7 +108,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
mPreferenceGroupKey = preferenceGroupKey;
|
||||
mStartOrder = startOrder;
|
||||
mManager = context.getSystemService(SubscriptionManager.class);
|
||||
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
|
||||
mSubscriptionPreferences = new ArrayMap<>();
|
||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||
mDataEnabledListener = new MobileDataEnabledListener(context, this);
|
||||
@@ -229,19 +224,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
NO_CELL_DATA_TYPE_ICON, cutOut);
|
||||
}
|
||||
|
||||
private boolean activeNetworkIsCellular() {
|
||||
final Network activeNetwork = mConnectivityManager.getActiveNetwork();
|
||||
if (activeNetwork == null) {
|
||||
return false;
|
||||
}
|
||||
final NetworkCapabilities networkCapabilities = mConnectivityManager.getNetworkCapabilities(
|
||||
activeNetwork);
|
||||
if (networkCapabilities == null) {
|
||||
return false;
|
||||
}
|
||||
return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* The summary can have either 1 or 2 lines depending on which services (calls, SMS, data) this
|
||||
* subscription is the default for.
|
||||
@@ -271,7 +253,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
final TelephonyManager telMgrForSub = mContext.getSystemService(
|
||||
TelephonyManager.class).createForSubscriptionId(subId);
|
||||
final boolean dataEnabled = telMgrForSub.isDataEnabled();
|
||||
if (dataEnabled && activeNetworkIsCellular()) {
|
||||
if (dataEnabled && MobileNetworkUtils.activeNetworkIsCellular(mContext)) {
|
||||
line2 = mContext.getString(R.string.mobile_data_active);
|
||||
} else if (!dataEnabled) {
|
||||
line2 = mContext.getString(R.string.mobile_data_off);
|
||||
|
@@ -31,6 +31,7 @@ import static com.android.settings.network.telephony.TelephonyConstants.Telephon
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO;
|
||||
import static com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -41,6 +42,9 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
@@ -69,6 +73,7 @@ import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.graph.SignalDrawable;
|
||||
@@ -202,8 +207,7 @@ public class MobileNetworkUtils {
|
||||
return bundle.getBoolean(CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static Intent buildPhoneAccountConfigureIntent(
|
||||
public static Intent buildPhoneAccountConfigureIntent(
|
||||
Context context, PhoneAccountHandle accountHandle) {
|
||||
Intent intent = buildConfigureIntent(
|
||||
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
|
||||
@@ -854,4 +858,45 @@ public class MobileNetworkUtils {
|
||||
raf = ((NR & raf) > 0) ? (NR | raf) : raf;
|
||||
return raf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from SubscriptionsPreferenceController#activeNetworkIsCellular()
|
||||
*/
|
||||
public static boolean activeNetworkIsCellular(Context context) {
|
||||
final ConnectivityManager connectivityManager =
|
||||
context.getSystemService(ConnectivityManager.class);
|
||||
final Network activeNetwork = connectivityManager.getActiveNetwork();
|
||||
if (activeNetwork == null) {
|
||||
return false;
|
||||
}
|
||||
final NetworkCapabilities networkCapabilities =
|
||||
connectivityManager.getNetworkCapabilities(activeNetwork);
|
||||
if (networkCapabilities == null) {
|
||||
return false;
|
||||
}
|
||||
return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from WifiCallingPreferenceController#isWifiCallingEnabled()
|
||||
*/
|
||||
public static boolean isWifiCallingEnabled(Context context, int subId,
|
||||
@Nullable WifiCallingQueryImsState queryImsState,
|
||||
@Nullable PhoneAccountHandle phoneAccountHandle) {
|
||||
if (phoneAccountHandle == null){
|
||||
phoneAccountHandle = context.getSystemService(TelecomManager.class)
|
||||
.getSimCallManagerForSubscription(subId);
|
||||
}
|
||||
boolean isWifiCallingEnabled;
|
||||
if (phoneAccountHandle != null) {
|
||||
final Intent intent = buildPhoneAccountConfigureIntent(context, phoneAccountHandle);
|
||||
isWifiCallingEnabled = intent != null;
|
||||
} else {
|
||||
if (queryImsState == null) {
|
||||
queryImsState = new WifiCallingQueryImsState(context, subId);
|
||||
}
|
||||
isWifiCallingEnabled = queryImsState.isReadyToWifiCalling();
|
||||
}
|
||||
return isWifiCallingEnabled;
|
||||
}
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
return SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& isWifiCallingEnabled(mContext, subId)
|
||||
&& MobileNetworkUtils.isWifiCallingEnabled(mContext, subId, null, null)
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
@@ -221,23 +221,4 @@ public class WifiCallingPreferenceController extends TelephonyBasePreferenceCont
|
||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWifiCallingEnabled(Context context, int subId) {
|
||||
final PhoneAccountHandle simCallManager =
|
||||
context.getSystemService(TelecomManager.class)
|
||||
.getSimCallManagerForSubscription(subId);
|
||||
final int phoneId = SubscriptionManager.getSlotIndex(subId);
|
||||
|
||||
boolean isWifiCallingEnabled;
|
||||
if (simCallManager != null) {
|
||||
final Intent intent = MobileNetworkUtils.buildPhoneAccountConfigureIntent(
|
||||
context, simCallManager);
|
||||
|
||||
isWifiCallingEnabled = intent != null;
|
||||
} else {
|
||||
isWifiCallingEnabled = queryImsState(subId).isReadyToWifiCalling();
|
||||
}
|
||||
|
||||
return isWifiCallingEnabled;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user