[Settings] add VtQueryImsState for IMS
1. Code refactor 2. Introduce VtQueryImsState and VolteQueryImsState for user enable/disable configuration Bug: 140542283 Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=VideoCallingPreferenceControllerTest Change-Id: I72ec009a8808875fef144a24486b94ef4a7fd35c
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();
|
||||
}
|
||||
}
|
57
src/com/android/settings/network/ims/VtQueryImsState.java
Normal file
57
src/com/android/settings/network/ims/VtQueryImsState.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.network.ims;
|
||||
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
|
||||
/**
|
||||
* Controller class for querying VT status
|
||||
*/
|
||||
public class VtQueryImsState {
|
||||
|
||||
private Context mContext;
|
||||
private int mSubId;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context {@code Context}
|
||||
* @param subId subscription's id
|
||||
*/
|
||||
public VtQueryImsState(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.isVtEnabledByUser();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
@@ -34,6 +36,8 @@ import androidx.preference.SwitchPreference;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.network.MobileDataEnabledListener;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.ims.VolteQueryImsState;
|
||||
import com.android.settings.network.ims.VtQueryImsState;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -46,6 +50,8 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
MobileDataEnabledListener.Client,
|
||||
Enhanced4gBasePreferenceController.On4gLteUpdateListener {
|
||||
|
||||
private static final String TAG = "VideoCallingPreference";
|
||||
|
||||
private Preference mPreference;
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
@VisibleForTesting
|
||||
@@ -64,7 +70,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
return SubscriptionManager.isValidSubscriptionId(subId)
|
||||
&& isVideoCallEnabled(subId)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
@@ -98,28 +104,41 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
final boolean videoCallEnabled = isVideoCallEnabled(mSubId, mImsManager);
|
||||
switchPreference.setVisible(videoCallEnabled);
|
||||
if (videoCallEnabled) {
|
||||
final boolean is4gLteEnabled = mImsManager.isEnhanced4gLteModeSettingEnabledByUser()
|
||||
final boolean videoCallEditable = queryVoLteState(mSubId).isEnabledByUser()
|
||||
&& mImsManager.isNonTtyOrTtyOnVolteEnabled();
|
||||
preference.setEnabled(is4gLteEnabled &&
|
||||
mCallState == TelephonyManager.CALL_STATE_IDLE);
|
||||
switchPreference.setChecked(is4gLteEnabled && mImsManager.isVtEnabledByUser());
|
||||
preference.setEnabled(videoCallEditable
|
||||
&& mCallState == TelephonyManager.CALL_STATE_IDLE);
|
||||
switchPreference.setChecked(videoCallEditable && isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mImsManager.setVtSetting(isChecked);
|
||||
return true;
|
||||
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||
return false;
|
||||
}
|
||||
final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(mSubId);
|
||||
if (imsMmTelManager == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
imsMmTelManager.setVtSettingEnabled(isChecked);
|
||||
return true;
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Log.w(TAG, "Unable to set VT status " + isChecked + ". subId=" + mSubId,
|
||||
exception);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mImsManager.isVtEnabledByUser();
|
||||
return queryImsState(mSubId).isEnabledByUser();
|
||||
}
|
||||
|
||||
public VideoCallingPreferenceController init(int subId) {
|
||||
mSubId = subId;
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||
mImsManager = ImsManager.getInstance(mContext,
|
||||
SubscriptionUtil.getPhoneId(mContext, mSubId));
|
||||
}
|
||||
@@ -128,7 +147,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
}
|
||||
|
||||
private boolean isVideoCallEnabled(int subId) {
|
||||
final ImsManager imsManager = subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
final ImsManager imsManager = SubscriptionManager.isValidSubscriptionId(subId)
|
||||
? ImsManager.getInstance(mContext, SubscriptionUtil.getPhoneId(mContext, subId))
|
||||
: null;
|
||||
return isVideoCallEnabled(subId, imsManager);
|
||||
@@ -156,7 +175,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
boolean isVideoCallEnabled(int subId, ImsManager imsManager) {
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
||||
TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||
if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
telephonyManager = telephonyManager.createForSubscriptionId(subId);
|
||||
}
|
||||
return carrierConfig != null && imsManager != null
|
||||
@@ -189,7 +208,7 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
|
||||
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);
|
||||
@@ -207,4 +226,14 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
||||
public void onMobileDataEnabledChange() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
VtQueryImsState queryImsState(int subId) {
|
||||
return new VtQueryImsState(mContext, subId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
VolteQueryImsState queryVoLteState(int subId) {
|
||||
return new VolteQueryImsState(mContext, subId);
|
||||
}
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.settings.network.ims.VolteQueryImsState;
|
||||
import com.android.settings.network.ims.VtQueryImsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -59,6 +61,9 @@ public class VideoCallingPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
private VtQueryImsState mQueryImsState;
|
||||
private VolteQueryImsState mQueryVoLteState;
|
||||
|
||||
private VideoCallingPreferenceController mController;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private SwitchPreference mPreference;
|
||||
@@ -80,15 +85,23 @@ public class VideoCallingPreferenceControllerTest {
|
||||
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS, true);
|
||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
mQueryImsState = spy(new VtQueryImsState(mContext, SUB_ID));
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
|
||||
mQueryVoLteState = spy(new VolteQueryImsState(mContext, SUB_ID));
|
||||
doReturn(true).when(mQueryVoLteState).isEnabledByUser();
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = new VideoCallingPreferenceController(mContext, "wifi_calling") {
|
||||
mController = spy(new VideoCallingPreferenceController(mContext, "wifi_calling") {
|
||||
@Override
|
||||
ProvisioningManager getProvisioningManager(int subId) {
|
||||
return mProvisioningManager;
|
||||
}
|
||||
};
|
||||
});
|
||||
mController.init(SUB_ID);
|
||||
mController.mImsManager = mImsManager;
|
||||
doReturn(mQueryImsState).when(mController).queryImsState(anyInt());
|
||||
doReturn(mQueryVoLteState).when(mController).queryVoLteState(anyInt());
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
|
||||
doReturn(true).when(mImsManager).isVtEnabledByPlatform();
|
||||
@@ -124,7 +137,8 @@ public class VideoCallingPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_4gLteOff_disabled() {
|
||||
doReturn(false).when(mImsManager).isEnhanced4gLteModeSettingEnabledByUser();
|
||||
doReturn(false).when(mQueryImsState).isEnabledByUser();
|
||||
doReturn(false).when(mQueryVoLteState).isEnabledByUser();
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -134,8 +148,8 @@ public class VideoCallingPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_4gLteOnWithoutCall_checked() {
|
||||
doReturn(true).when(mImsManager).isVtEnabledByUser();
|
||||
doReturn(true).when(mImsManager).isEnhanced4gLteModeSettingEnabledByUser();
|
||||
doReturn(true).when(mQueryImsState).isEnabledByUser();
|
||||
doReturn(true).when(mQueryVoLteState).isEnabledByUser();
|
||||
doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled();
|
||||
mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
|
||||
|
||||
|
Reference in New Issue
Block a user