Merge "[Settings] add VolteQueryImsState for IMS"
This commit is contained in:
58
src/com/android/settings/network/ims/VolteQueryImsState.java
Normal file
58
src/com/android/settings/network/ims/VolteQueryImsState.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 Volte status
|
||||
*/
|
||||
public class VolteQueryImsState {
|
||||
|
||||
private Context mContext;
|
||||
private int mSubId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context {@code Context}
|
||||
* @param subId subscription's id
|
||||
*/
|
||||
public VolteQueryImsState(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.isEnhanced4gLteModeSettingEnabledByUser();
|
||||
}
|
||||
}
|
@@ -22,9 +22,11 @@ import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.ims.ImsMmTelManager;
|
||||
import android.telephony.ims.ProvisioningManager;
|
||||
import android.telephony.ims.feature.MmTelFeature;
|
||||
import android.telephony.ims.stub.ImsRegistrationImplBase;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -33,6 +35,7 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.ims.VolteQueryImsState;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -46,7 +49,10 @@ import java.util.List;
|
||||
public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private Preference mPreference;
|
||||
private static final String TAG = "Enhanced4g";
|
||||
|
||||
@VisibleForTesting
|
||||
Preference mPreference;
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
@VisibleForTesting
|
||||
@@ -70,12 +76,12 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
}
|
||||
|
||||
public Enhanced4gBasePreferenceController init(int subId) {
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && mSubId == subId) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(mSubId) && mSubId == subId) {
|
||||
return this;
|
||||
}
|
||||
mSubId = subId;
|
||||
mCarrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||
mImsManager = ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId(
|
||||
mContext, mSubId));
|
||||
}
|
||||
@@ -102,7 +108,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
||||
final boolean isVisible = subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
final boolean isVisible = SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& mImsManager != null && carrierConfig != null
|
||||
&& mImsManager.isVolteEnabledByPlatform()
|
||||
&& isVolteProvisionedOnDevice(mSubId)
|
||||
@@ -134,14 +140,27 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
super.updateState(preference);
|
||||
final SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
|
||||
final VolteQueryImsState queryState = queryImsState(mSubId);
|
||||
switchPreference.setEnabled(isPrefEnabled());
|
||||
switchPreference.setChecked(mImsManager.isEnhanced4gLteModeSettingEnabledByUser()
|
||||
switchPreference.setChecked(queryState.isEnabledByUser()
|
||||
&& mImsManager.isNonTtyOrTtyOnVolteEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mImsManager.setEnhanced4gLteModeSetting(isChecked);
|
||||
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||
return false;
|
||||
}
|
||||
final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(mSubId);
|
||||
if (imsMmTelManager == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
imsMmTelManager.setAdvancedCallingSettingEnabled(isChecked);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Log.w(TAG, "fail to set VoLTE=" + isChecked + ". subId=" + mSubId, exception);
|
||||
return false;
|
||||
}
|
||||
for (final On4gLteUpdateListener lsn : m4gLteListeners) {
|
||||
lsn.on4gLteUpdated();
|
||||
}
|
||||
@@ -150,7 +169,8 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mImsManager.isEnhanced4gLteModeSettingEnabledByUser();
|
||||
final VolteQueryImsState queryState = queryImsState(mSubId);
|
||||
return queryState.isEnabledByUser();
|
||||
}
|
||||
|
||||
public Enhanced4gBasePreferenceController addListener(On4gLteUpdateListener lsn) {
|
||||
@@ -166,17 +186,26 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
return m4gCurrentMode == getMode();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
VolteQueryImsState queryImsState(int subId) {
|
||||
return new VolteQueryImsState(mContext, subId);
|
||||
}
|
||||
|
||||
private boolean isPrefEnabled() {
|
||||
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
&& (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE)
|
||||
return SubscriptionManager.isValidSubscriptionId(mSubId)
|
||||
&& isUserControlAllowed()
|
||||
&& mImsManager != null
|
||||
&& mImsManager.isNonTtyOrTtyOnVolteEnabled()
|
||||
&& mImsManager.isNonTtyOrTtyOnVolteEnabled();
|
||||
}
|
||||
|
||||
private boolean isUserControlAllowed() {
|
||||
return (mCallState != null) && (mCallState == TelephonyManager.CALL_STATE_IDLE)
|
||||
&& mCarrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
|
||||
}
|
||||
|
||||
private boolean isVolteProvisionedOnDevice(int subId) {
|
||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return true;
|
||||
}
|
||||
final ProvisioningManager provisioningMgr = getProvisioningManager(subId);
|
||||
@@ -204,7 +233,7 @@ public class Enhanced4gBasePreferenceController extends TelephonyTogglePreferenc
|
||||
|
||||
public void register(Context context, int subId) {
|
||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
|
||||
}
|
||||
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
|
@@ -27,6 +27,7 @@ import android.net.Uri;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.ims.ImsMmTelManager;
|
||||
import android.telephony.ims.ProvisioningManager;
|
||||
import android.telephony.ims.feature.MmTelFeature;
|
||||
import android.telephony.ims.stub.ImsRegistrationImplBase;
|
||||
@@ -43,16 +44,10 @@ import com.android.ims.ImsManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.ims.VolteQueryImsState;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Helper class to control slices for enhanced 4g LTE settings.
|
||||
@@ -118,7 +113,7 @@ public class Enhanced4gLteSliceHelper {
|
||||
public Slice createEnhanced4gLteSlice(Uri sliceUri) {
|
||||
final int subId = getDefaultVoiceSubId();
|
||||
|
||||
if (subId <= SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
Log.d(TAG, "Invalid subscription Id");
|
||||
return null;
|
||||
}
|
||||
@@ -140,29 +135,16 @@ public class Enhanced4gLteSliceHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
final VolteQueryImsState queryState = queryImsState(subId);
|
||||
try {
|
||||
return getEnhanced4gLteSlice(sliceUri,
|
||||
isEnhanced4gLteModeEnabled(imsManager), subId);
|
||||
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
||||
queryState.isEnabledByUser(), subId);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(TAG, "Unable to read the current Enhanced 4g LTE status", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEnhanced4gLteModeEnabled(ImsManager imsManager)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
final FutureTask<Boolean> isEnhanced4gLteOnTask = new FutureTask<>(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() {
|
||||
return imsManager.isEnhanced4gLteModeSettingEnabledByUser();
|
||||
}
|
||||
});
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(isEnhanced4gLteOnTask);
|
||||
|
||||
return isEnhanced4gLteOnTask.get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a toggle slice where the intent takes you to the Enhanced 4G LTE page and the toggle
|
||||
* enables/disables Enhanced 4G LTE mode setting.
|
||||
@@ -206,23 +188,45 @@ public class Enhanced4gLteSliceHelper {
|
||||
public void handleEnhanced4gLteChanged(Intent intent) {
|
||||
final int subId = getDefaultVoiceSubId();
|
||||
|
||||
if (subId > SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
final ImsManager imsManager = getImsManager(subId);
|
||||
if (imsManager.isVolteEnabledByPlatform() && isVolteProvisionedOnDevice(subId)) {
|
||||
final boolean currentValue = imsManager.isEnhanced4gLteModeSettingEnabledByUser()
|
||||
final VolteQueryImsState queryState = queryImsState(subId);
|
||||
final boolean currentValue = queryState.isEnabledByUser()
|
||||
&& imsManager.isNonTtyOrTtyOnVolteEnabled();
|
||||
final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
|
||||
currentValue);
|
||||
if (newValue != currentValue) {
|
||||
imsManager.setEnhanced4gLteModeSetting(newValue);
|
||||
setEnhanced4gLteModeSetting(subId, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyEnhanced4gLteUpdate();
|
||||
}
|
||||
|
||||
private void notifyEnhanced4gLteUpdate() {
|
||||
// notify change in slice in any case to get re-queried. This would result in displaying
|
||||
// appropriate message with the updated setting.
|
||||
mContext.getContentResolver().notifyChange(CustomSliceRegistry.ENHANCED_4G_SLICE_URI, null);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setEnhanced4gLteModeSetting(int subId, boolean isEnabled) {
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
return;
|
||||
}
|
||||
final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(subId);
|
||||
if (imsMmTelManager == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
imsMmTelManager.setAdvancedCallingSettingEnabled(isEnabled);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Log.w(TAG, "Unable to change the Enhanced 4g LTE to " + isEnabled + ". subId=" + subId,
|
||||
exception);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getEnhanced4glteModeTitle(int subId) {
|
||||
CharSequence ret = mContext.getText(R.string.enhanced_4g_lte_mode_title);
|
||||
try {
|
||||
@@ -296,5 +300,10 @@ public class Enhanced4gLteSliceHelper {
|
||||
MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
|
||||
ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
VolteQueryImsState queryImsState(int subId) {
|
||||
return new VolteQueryImsState(mContext, subId);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user