Popup a dialog to display sim status information

- Create layout files for the dialog
 - Create a new controller to launch the dialog activity
 - Create a new controller to update the contents of the dialog
 - Deprecate old files that are no longer used in about phone v2

Bug: 36458278
Test: make RunSettingsRoboTests -j40
Change-Id: Iaf4f5e53c83b27f148acb076f38bfeabff41087e
This commit is contained in:
jeffreyhuang
2017-10-27 14:41:56 -07:00
parent ef7eb162cf
commit 7d7e98a214
16 changed files with 1334 additions and 3 deletions

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2017 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.deviceinfo.simstatus;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AbstractSimStatusPreferenceControllerTest {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private UserManager mUserManager;
@Mock
private Fragment mFragment;
private Context mContext;
private AbstractSimStatusPreferenceControllerImpl mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = new AbstractSimStatusPreferenceControllerImpl(mContext, mFragment);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void displayPreference_shouldSetTitleAndSummary() {
mController.displayPreference(mScreen);
verify(mPreference).setTitle(mController.getPreferenceTitle());
verify(mPreference).setSummary(anyString());
}
@Test
public void handlePreferenceTreeClick_shouldStartDialogFragment() {
when(mFragment.getChildFragmentManager()).thenReturn(
mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS));
when(mPreference.getTitle()).thenReturn("foo");
mController.displayPreference(mScreen);
mController.handlePreferenceTreeClick(mPreference);
verify(mFragment).getChildFragmentManager();
}
public class AbstractSimStatusPreferenceControllerImpl extends
AbstractSimStatusPreferenceController {
public AbstractSimStatusPreferenceControllerImpl(Context context, Fragment fragment) {
super(context, fragment);
}
@Override
public String getPreferenceKey() {
return "foo";
}
@Override
protected String getPreferenceTitle() {
return "bar";
}
@Override
protected int getSimSlot() {
return 0;
}
}
}

View File

@@ -0,0 +1,202 @@
/*
* Copyright (C) 2017 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.deviceinfo.simstatus;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.CELLULAR_NETWORK_TYPE_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.NETWORK_PROVIDER_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.OPERATOR_INFO_LABEL_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.OPERATOR_INFO_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.PHONE_NUMBER_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.ROAMING_INFO_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.SERVICE_STATE_VALUE_ID;
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController
.SIGNAL_STRENGTH_VALUE_ID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SimStatusDialogControllerTest {
@Mock
private SimStatusDialogFragment mDialog;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private SubscriptionInfo mSubscriptionInfo;
@Mock
private ServiceState mServiceState;
@Mock
private PhoneStateListener mPhoneStateListener;
@Mock
private SignalStrength mSignalStrength;
private SimStatusDialogController mController;
private Context mContext;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mDialog.getContext()).thenReturn(mContext);
mController = spy(
new SimStatusDialogController(mDialog, new Lifecycle(), 0 /* phone id */));
doReturn(mServiceState).when(mController).getCurrentServiceState();
doReturn(0).when(mController).getDbm(any());
doReturn(0).when(mController).getAsuLevel(any());
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
doReturn("").when(mController).getPhoneNumber();
doReturn(mSignalStrength).when(mController).getSignalStrength();
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
ReflectionHelpers.setField(mController, "mSubscriptionInfo", mSubscriptionInfo);
}
@Test
public void initialize_updateNetworkProviderWithFoobarCarrier_shouldUpdateCarrierWithFoobar() {
final String carrierName = "foobar";
when(mServiceState.getOperatorAlphaLong()).thenReturn(carrierName);
mController.initialize();
verify(mDialog).setText(NETWORK_PROVIDER_VALUE_ID, carrierName);
}
@Test
public void initialize_updatePhoneNumberWith1111111111_shouldUpdatePhoneNumber() {
final String phoneNumber = "1111111111";
doReturn(phoneNumber).when(mController).getPhoneNumber();
mController.initialize();
verify(mDialog).setText(PHONE_NUMBER_VALUE_ID, phoneNumber);
}
@Test
public void initialize_updateLatestAreaInfoWithCdmaPhone_shouldRemoveOperatorInfoSetting() {
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
mController.initialize();
verify(mDialog).removeSettingFromScreen(OPERATOR_INFO_LABEL_ID);
verify(mDialog).removeSettingFromScreen(OPERATOR_INFO_VALUE_ID);
}
@Test
public void initialize_updateServiceStateWithInService_shouldUpdateTextToBeCInService() {
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
mController.initialize();
final String inServiceText = mContext.getResources().getString(
R.string.radioInfo_service_in);
verify(mDialog).setText(SERVICE_STATE_VALUE_ID, inServiceText);
}
@Test
public void initialize_updateDataStateWithPowerOff_shouldUpdateSettingAndResetSignalStrength() {
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
mController.initialize();
final String offServiceText = mContext.getResources().getString(
R.string.radioInfo_service_off);
verify(mDialog).setText(SERVICE_STATE_VALUE_ID, offServiceText);
verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, "0");
}
@Test
public void initialize_updateSignalStrengthWith50_shouldUpdateSignalStrengthTo50() {
final int signalDbm = 50;
final int signalAsu = 50;
doReturn(signalDbm).when(mController).getDbm(mSignalStrength);
doReturn(signalAsu).when(mController).getAsuLevel(mSignalStrength);
mController.initialize();
final String signalStrengthString = mContext.getResources().getString(
R.string.sim_signal_strength, signalDbm, signalAsu);
verify(mDialog).setText(SIGNAL_STRENGTH_VALUE_ID, signalStrengthString);
}
@Test
public void initialize_updateNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
when(mTelephonyManager.getDataNetworkType(anyInt())).thenReturn(
TelephonyManager.NETWORK_TYPE_EDGE);
mController.initialize();
verify(mDialog).setText(CELLULAR_NETWORK_TYPE_VALUE_ID,
TelephonyManager.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
}
@Test
public void initialize_updateRoamingStatusIsRoaming_shouldSetSettingToRoaming() {
when(mServiceState.getRoaming()).thenReturn(true);
mController.initialize();
final String roamingOnString = mContext.getResources().getString(
R.string.radioInfo_roaming_in);
verify(mDialog).setText(ROAMING_INFO_VALUE_ID, roamingOnString);
}
@Test
public void initialize_updateRoamingStatusNotRoaming_shouldSetSettingToRoamingOff() {
when(mServiceState.getRoaming()).thenReturn(false);
mController.initialize();
final String roamingOffString = mContext.getResources().getString(
R.string.radioInfo_roaming_not);
verify(mDialog).setText(ROAMING_INFO_VALUE_ID, roamingOffString);
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2017 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.deviceinfo.simstatus;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.Fragment;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.google.common.truth.Truth;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SimStatusDualSimPreferenceControllerTest {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
private Fragment mFragment;
private Context mContext;
private SimStatusDualSimPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
doReturn(mConnectivityManager).when(mContext).getSystemService(ConnectivityManager.class);
when(mUserManager.isAdminUser()).thenReturn(true);
when(mConnectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(
true);
mController = new SimStatusDualSimPreferenceController(mContext, mFragment);
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void isAvailable_multiSim_shouldBeTrue() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
Truth.assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_notMultiSim_shouldBeFalse() {
ReflectionHelpers.setField(mController, "mIsMultiSim", false);
Truth.assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2017 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.deviceinfo.simstatus;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.Fragment;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SimStatusPreferenceControllerV2Test {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Mock
private Fragment mFragment;
private Context mContext;
private SimStatusPreferenceControllerV2 mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = new SimStatusPreferenceControllerV2(mContext, mFragment);
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void getPreferenceTitle_noMultiSim_shouldReturnSingleSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", false);
assertThat(mController.getPreferenceTitle()).isEqualTo(mContext.getResources().getString(
R.string.sim_status_title));
}
@Test
public void getPreferenceTitle_multiSim_shouldReturnMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
assertThat(mController.getPreferenceTitle()).isEqualTo(mContext.getResources().getString(
R.string.sim_status_title_sim_slot_1));
}
}