Merge "[Settings] Add ImsQueryProvisioningStat for VT"

This commit is contained in:
Bonian Chen
2020-02-04 12:18:49 +00:00
committed by Android (Google) Code Review
10 changed files with 362 additions and 68 deletions

View File

@@ -0,0 +1,38 @@
/*
* 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 org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class MockImsQueryResult {
public static class BooleanResult implements ImsQuery {
private boolean mResult;
public BooleanResult(boolean result) {
super();
mResult = result;
}
public boolean query() {
return mResult;
}
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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 com.android.ims.ImsManager;
/**
* Controller class for mock VT status
*/
public class MockVtQueryImsState extends VtQueryImsState {
private ImsQuery mIsTtyOnVolteEnabled;
private ImsQuery mIsProvisionedOnDevice;
private ImsQuery mIsEnabledByUser;
/**
* Constructor
*
* @param context {@code Context}
* @param subId subscription's id
*/
public MockVtQueryImsState(Context context, int subId) {
super(context, subId);
}
public ImsManager getImsManager(int subId) {
return super.getImsManager(subId);
}
public void setIsTtyOnVolteEnabled(boolean enabled) {
mIsTtyOnVolteEnabled = new MockImsQueryResult.BooleanResult(enabled);
}
@Override
ImsQuery isTtyOnVolteEnabled(int subId) {
if (mIsTtyOnVolteEnabled != null) {
return mIsTtyOnVolteEnabled;
}
return super.isTtyOnVolteEnabled(subId);
}
public void setIsProvisionedOnDevice(boolean isProvisioned) {
mIsProvisionedOnDevice = new MockImsQueryResult.BooleanResult(isProvisioned);
}
@Override
ImsQuery isProvisionedOnDevice(int subId) {
if (mIsProvisionedOnDevice != null) {
return mIsProvisionedOnDevice;
}
return super.isProvisionedOnDevice(subId);
}
public void setIsEnabledByUser(boolean enabled) {
mIsEnabledByUser = new MockImsQueryResult.BooleanResult(enabled);
}
@Override
ImsQuery isEnabledByUser(int subId) {
if (mIsEnabledByUser != null) {
return mIsEnabledByUser;
}
return super.isEnabledByUser(subId);
}
}

View File

@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import android.content.Context;
@@ -29,14 +28,13 @@ import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.feature.ImsFeature;
import android.telephony.ims.feature.MmTelFeature;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.ims.ImsManager;
import com.android.settings.network.ims.MockVtQueryImsState;
import com.android.settings.network.ims.VolteQueryImsState;
import com.android.settings.network.ims.VtQueryImsState;
import org.junit.Before;
import org.junit.Test;
@@ -61,7 +59,7 @@ public class VideoCallingPreferenceControllerTest {
@Mock
private PreferenceScreen mPreferenceScreen;
private VtQueryImsState mQueryImsState;
private MockVtQueryImsState mQueryImsState;
private VolteQueryImsState mQueryVoLteState;
private VideoCallingPreferenceController mController;
@@ -74,7 +72,6 @@ public class VideoCallingPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
doReturn(mCarrierConfigManager).when(mContext)
.getSystemService(CarrierConfigManager.class);
@@ -85,29 +82,22 @@ 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));
mQueryImsState = spy(new MockVtQueryImsState(mContext, SUB_ID));
doReturn(true).when(mQueryImsState).isEnabledByUser();
doReturn(mImsManager).when(mQueryImsState).getImsManager(anyInt());
mQueryVoLteState = spy(new VolteQueryImsState(mContext, SUB_ID));
doReturn(true).when(mQueryVoLteState).isEnabledByUser();
mPreference = new SwitchPreference(mContext);
mController = spy(new VideoCallingPreferenceController(mContext, "wifi_calling") {
@Override
ProvisioningManager getProvisioningManager(int subId) {
return mProvisioningManager;
}
});
mController = spy(new VideoCallingPreferenceController(mContext, "wifi_calling"));
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();
doReturn(true).when(mProvisioningManager)
.getProvisioningStatusForCapability(
eq(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO), anyInt());
mQueryImsState.setIsProvisionedOnDevice(true);
doReturn(ImsFeature.STATE_READY).when(mImsManager).getImsServiceState();
doReturn(true).when(mTelephonyManager).isDataEnabled();
@@ -116,14 +106,15 @@ public class VideoCallingPreferenceControllerTest {
@Test
public void isVideoCallEnabled_allFlagsOn_returnTrue() {
assertThat(mController.isVideoCallEnabled(SUB_ID, mImsManager)).isTrue();
assertThat(mController.isVideoCallEnabled(SUB_ID)).isTrue();
}
@Test
public void isVideoCallEnabled_disabledByPlatform_returnFalse() {
mQueryImsState.setIsProvisionedOnDevice(false);
doReturn(false).when(mImsManager).isVtEnabledByPlatform();
assertThat(mController.isVideoCallEnabled(SUB_ID, mImsManager)).isFalse();
assertThat(mController.isVideoCallEnabled(SUB_ID)).isFalse();
}
@Test
@@ -132,7 +123,7 @@ public class VideoCallingPreferenceControllerTest {
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS, false);
doReturn(false).when(mTelephonyManager).isDataEnabled();
assertThat(mController.isVideoCallEnabled(SUB_ID, mImsManager)).isFalse();
assertThat(mController.isVideoCallEnabled(SUB_ID)).isFalse();
}
@Test