Popup a dialog to display user IMEI information

- Add new dialog fragment to show imei 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: I6d4273726e2271049a0ab69c2375dac0ac393e04
This commit is contained in:
jeffreyhuang
2017-10-25 14:44:44 -07:00
parent ef7eb162cf
commit c2f8ab587e
16 changed files with 1093 additions and 5 deletions

View File

@@ -0,0 +1,143 @@
/*
* 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.imei;
import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
import static android.telephony.TelephonyManager.PHONE_TYPE_GSM;
import static org.mockito.ArgumentMatchers.anyInt;
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 android.telephony.TelephonyManager;
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;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AbstractImeiInfoPreferenceControllerTest {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Mock
private Fragment mFragment;
private Context mContext;
private AbstractImeiInfoPreferenceControllerImpl mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = new AbstractImeiInfoPreferenceControllerImpl(mContext, mFragment);
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void displayPreference_cdmaPhone_shouldSetCdmaTitleAndMeid() {
mController = spy(mController);
final String meid = "125132215123";
when(mTelephonyManager.getPhoneType()).thenReturn(PHONE_TYPE_CDMA);
doReturn(meid).when(mController).getMeid();
mController.displayPreference(mScreen);
verify(mPreference).setTitle(mController.getTitleForCdmaPhone());
verify(mPreference).setSummary(meid);
}
@Test
public void displayPreference_gsmPhone_shouldSetGsmTitleAndImei() {
final String imei = "125132215123";
when(mTelephonyManager.getPhoneType()).thenReturn(PHONE_TYPE_GSM);
when(mTelephonyManager.getImei(anyInt())).thenReturn(imei);
mController.displayPreference(mScreen);
verify(mPreference).setTitle(mController.getTitleForGsmPhone());
verify(mPreference).setSummary(imei);
}
@Test
public void handlePreferenceTreeClick_shouldStartDialogFragment() {
when(mFragment.getChildFragmentManager()).thenReturn(
mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS));
when(mPreference.getTitle()).thenReturn("SomeTitle");
mController.displayPreference(mScreen);
mController.handlePreferenceTreeClick(mPreference);
verify(mFragment).getChildFragmentManager();
}
public class AbstractImeiInfoPreferenceControllerImpl extends
AbstractImeiInfoPreferenceController {
public AbstractImeiInfoPreferenceControllerImpl(Context context, Fragment fragment) {
super(context, fragment);
}
@Override
public String getPreferenceKey() {
return "foobar";
}
@Override
protected String getTitleForCdmaPhone() {
return "foo";
}
@Override
protected String getTitleForGsmPhone() {
return "bar";
}
@Override
protected int getSimSlot() {
return 0;
}
}
}

View File

@@ -0,0 +1,133 @@
/*
* 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.imei;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_CDMA_SETTINGS;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_GSM_SETTINGS;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_ICC_ID_LABEL;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_ICC_ID_VALUE;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_IMEI_SV_VALUE;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_IMEI_VALUE;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_MEID_NUMBER_VALUE;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_MIN_NUMBER_VALUE;
import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_PRL_VERSION_VALUE;
import static org.mockito.ArgumentMatchers.any;
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 static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
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 ImeiInfoDialogControllerTest {
private static final String PRL_VERSION = "some_prl_version";
private static final String MEID_NUMBER = "12871234124";
private static final String IMEI_NUMBER = "2341982751254";
private static final String MIN_NUMBER = "123417851315";
private static final String ICCID_NUMBER = "3845672472";
private static final String IMEI_SV_NUMBER = "12";
@Mock
private ImeiInfoDialogFragment mDialog;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private SubscriptionInfo mSubscriptionInfo;
private Context mContext;
private ImeiInfoDialogController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
when(mDialog.getContext()).thenReturn(mContext);
mController = spy(new ImeiInfoDialogController(mDialog, 0 /* phone id */));
ReflectionHelpers.setField(mController, "mSubscriptionInfo", mSubscriptionInfo);
doReturn(PRL_VERSION).when(mController).getCdmaPrlVersion();
doReturn(MEID_NUMBER).when(mController).getMeid();
when(mTelephonyManager.getCdmaMin(anyInt())).thenReturn(MIN_NUMBER);
when(mSubscriptionInfo.getIccId()).thenReturn(ICCID_NUMBER);
when(mTelephonyManager.getDeviceSoftwareVersion(anyInt())).thenReturn(IMEI_SV_NUMBER);
when(mTelephonyManager.getImei(anyInt())).thenReturn(IMEI_NUMBER);
}
@Test
public void populateImeiInfo_cdmaLteEnabled_shouldSetMeidAndImeiAndMin() {
doReturn(true).when(mController).isCdmaLteEnabled();
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
mController.populateImeiInfo();
verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
verify(mDialog).setText(ID_MIN_NUMBER_VALUE, MIN_NUMBER);
verify(mDialog).setText(ID_PRL_VERSION_VALUE, PRL_VERSION);
verify(mDialog).setText(ID_ICC_ID_VALUE, ICCID_NUMBER);
verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
}
@Test
public void populateImeiInfo_cdmaLteDisabled_shouldSetMeidAndMinAndRemoveGsmSettings() {
doReturn(false).when(mController).isCdmaLteEnabled();
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
mController.populateImeiInfo();
verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
verify(mDialog).setText(ID_MIN_NUMBER_VALUE, MIN_NUMBER);
verify(mDialog).setText(ID_PRL_VERSION_VALUE, PRL_VERSION);
verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
verify(mDialog).removeViewFromScreen(ID_ICC_ID_VALUE);
verify(mDialog).removeViewFromScreen(ID_ICC_ID_LABEL);
}
@Test
public void populateImeinfo_gsm_shouldSetImeiAndRemoveCdmaSettings() {
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);
mController.populateImeiInfo();
verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
verify(mDialog).removeViewFromScreen(ID_CDMA_SETTINGS);
verify(mDialog).removeViewFromScreen(ID_ICC_ID_VALUE);
verify(mDialog).removeViewFromScreen(ID_ICC_ID_LABEL);
}
}

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.imei;
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 ImeiInfoDualSimPreferenceControllerTest {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Mock
private Fragment mFragment;
private Context mContext;
private ImeiInfoDualSimPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = new ImeiInfoDualSimPreferenceController(mContext, mFragment);
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void getTitleForCdmaPhone_shouldReturnCdmaMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
R.string.meid_multi_sim_sim_slot_2));
}
@Test
public void getTitleForGsmPhone_shouldReturnGsmMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
R.string.imei_multi_sim_slot_2));
}
}

View File

@@ -0,0 +1,105 @@
/*
* 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.imei;
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 ImeiInfoPreferenceControllerV2Test {
@Mock
private Preference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Mock
private Fragment mFragment;
private Context mContext;
private ImeiInfoPreferenceControllerV2 mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
mController = new ImeiInfoPreferenceControllerV2(mContext, mFragment);
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void getTitleForCdmaPhone_noMultiSim_shouldReturnCdmaNoMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", false);
assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
R.string.status_meid_number));
}
@Test
public void getTitleForCdmaPhone_multiSim_shouldReturnCdmaMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
R.string.meid_multi_sim_sim_slot_1));
}
@Test
public void getTitleForGsmPhone_noMultiSim_shouldReturnGsmNoMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", false);
assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
R.string.status_imei));
}
@Test
public void getTitleForGsmPhone_multiSim_shouldReturnGsmMultiSimString() {
ReflectionHelpers.setField(mController, "mIsMultiSim", true);
assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
R.string.imei_multi_sim_slot_1));
}
}