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

@@ -32,6 +32,8 @@ import com.android.settings.deviceinfo.DeviceModelPreferenceController;
import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
import com.android.settings.deviceinfo.FeedbackPreferenceController;
import com.android.settings.deviceinfo.FirmwareVersionPreferenceController;
import com.android.settings.deviceinfo.imei.ImeiInfoDualSimPreferenceController;
import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
import com.android.settings.deviceinfo.KernelVersionPreferenceController;
import com.android.settings.deviceinfo.ManualPreferenceController;
import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
@@ -120,7 +122,6 @@ public class DeviceInfoSettings extends DashboardFragment implements Indexable {
Activity activity, Fragment fragment, Lifecycle lifecycle) {
if (FeatureFlagUtils.isEnabled(DEVICE_INFO_V2_FEATURE_FLAG)) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
// Device name
// Phone number
@@ -129,7 +130,9 @@ public class DeviceInfoSettings extends DashboardFragment implements Indexable {
controllers.add(new DeviceModelPreferenceController(context, fragment));
// IMEI
controllers.add(new ImeiInfoPreferenceControllerV2(context, fragment));
controllers.add(new ImeiInfoDualSimPreferenceController(context, fragment));
// Android version

View File

@@ -19,8 +19,13 @@ package com.android.settings.deviceinfo;
import android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
/**
* deprecated in favour of {@link ImeiInfoPreferenceControllerV2}
*/
@Deprecated
public class ImeiInfoPreferenceController extends AbstractSimStatusImeiInfoPreferenceController
implements PreferenceControllerMixin {

View File

@@ -22,7 +22,6 @@ import android.support.v7.preference.PreferenceScreen;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@@ -34,7 +33,12 @@ import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
/**
* deprecated in favor of {@link ImeiInfoPreferenceControllerV2}
*/
@Deprecated
public class ImeiInformation extends SettingsPreferenceFragment {
private static final String KEY_PRL_VERSION = "prl_version";

View File

@@ -0,0 +1,99 @@
/*
* 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 android.app.Fragment;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
/**
* Controller that manages preference for single and dual sim devices.
*/
public abstract class AbstractImeiInfoPreferenceController extends
AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
protected final boolean mIsMultiSim;
protected final TelephonyManager mTelephonyManager;
private Preference mPreference;
private Fragment mFragment;
public AbstractImeiInfoPreferenceController(Context context, Fragment fragment) {
super(context);
mFragment = fragment;
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mIsMultiSim = mTelephonyManager.getPhoneCount() > 1;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
if (mPreference == null) {
return;
}
final int phoneType = mTelephonyManager.getPhoneType();
if (phoneType == PHONE_TYPE_CDMA) {
mPreference.setTitle(getTitleForCdmaPhone());
mPreference.setSummary(getMeid());
} else {
// GSM phone
mPreference.setTitle(getTitleForGsmPhone());
mPreference.setSummary(mTelephonyManager.getImei(getSimSlot()));
}
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return false;
}
ImeiInfoDialogFragment.show(mFragment, getSimSlot(), mPreference.getTitle().toString());
return true;
}
/**
* @return The preference title for phones based on CDMA technology.
*/
protected abstract String getTitleForCdmaPhone();
/**
* @return The preference title for phones based on GSM technology.
*/
protected abstract String getTitleForGsmPhone();
/**
* @return The sim slot to retrieve IMEI/CDMA information about.
*/
protected abstract int getSimSlot();
@VisibleForTesting
String getMeid() {
return mTelephonyManager.getMeid(getSimSlot());
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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 android.content.Context;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.TtsSpan;
import com.android.internal.telephony.PhoneConstants;
import com.android.settings.R;
import java.util.List;
public class ImeiInfoDialogController {
@VisibleForTesting
static final int ID_PRL_VERSION_VALUE = R.id.prl_version_value;
private static final int ID_MIN_NUMBER_LABEL = R.id.min_number_label;
@VisibleForTesting
static final int ID_MIN_NUMBER_VALUE = R.id.min_number_value;
@VisibleForTesting
static final int ID_MEID_NUMBER_VALUE = R.id.meid_number_value;
@VisibleForTesting
static final int ID_ICC_ID_LABEL = R.id.icc_id_label;
@VisibleForTesting
static final int ID_ICC_ID_VALUE = R.id.icc_id_value;
@VisibleForTesting
static final int ID_IMEI_VALUE = R.id.imei_value;
@VisibleForTesting
static final int ID_IMEI_SV_VALUE = R.id.imei_sv_value;
@VisibleForTesting
static final int ID_CDMA_SETTINGS = R.id.cdma_settings;
@VisibleForTesting
static final int ID_GSM_SETTINGS = R.id.gsm_settings;
private static CharSequence getTextAsDigits(CharSequence text) {
if (TextUtils.isDigitsOnly(text)) {
final Spannable spannable = new SpannableStringBuilder(text);
final TtsSpan span = new TtsSpan.DigitsBuilder(text.toString()).build();
spannable.setSpan(span, 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text = spannable;
}
return text;
}
private final ImeiInfoDialogFragment mDialog;
private final TelephonyManager mTelephonyManager;
private final SubscriptionInfo mSubscriptionInfo;
private final int mSlotId;
public ImeiInfoDialogController(@NonNull ImeiInfoDialogFragment dialog, int slotId) {
mDialog = dialog;
mSlotId = slotId;
final Context context = dialog.getContext();
mTelephonyManager = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE);
mSubscriptionInfo = getSubscriptionInfo(context, slotId);
}
/**
* Sets IMEI/MEID information based on whether the device is CDMA or GSM.
*/
public void populateImeiInfo() {
if (mSubscriptionInfo == null) {
return;
}
if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
updateDialogForCdmaPhone();
} else {
updateDialogForGsmPhone();
}
}
private void updateDialogForCdmaPhone() {
final Resources res = mDialog.getContext().getResources();
mDialog.setText(ID_MEID_NUMBER_VALUE, getMeid());
mDialog.setText(ID_MIN_NUMBER_VALUE,
mTelephonyManager.getCdmaMin(mSubscriptionInfo.getSubscriptionId()));
if (res.getBoolean(R.bool.config_msid_enable)) {
mDialog.setText(ID_MIN_NUMBER_LABEL,
res.getString(R.string.status_msid_number));
}
mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
if (isCdmaLteEnabled()) {
// Show ICC ID and IMEI for LTE device
mDialog.setText(ID_ICC_ID_VALUE, mSubscriptionInfo.getIccId());
mDialog.setText(ID_IMEI_VALUE,
getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
mDialog.setText(ID_IMEI_SV_VALUE,
getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
} else {
// device is not GSM/UMTS, do not display GSM/UMTS features
mDialog.removeViewFromScreen(ID_GSM_SETTINGS);
mDialog.removeViewFromScreen(ID_ICC_ID_LABEL);
mDialog.removeViewFromScreen(ID_ICC_ID_VALUE);
}
}
private void updateDialogForGsmPhone() {
mDialog.setText(ID_IMEI_VALUE, getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
mDialog.setText(ID_IMEI_SV_VALUE,
getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
// device is not CDMA, do not display CDMA features
mDialog.removeViewFromScreen(ID_CDMA_SETTINGS);
mDialog.removeViewFromScreen(ID_ICC_ID_LABEL);
mDialog.removeViewFromScreen(ID_ICC_ID_VALUE);
}
private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) {
final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context)
.getActiveSubscriptionInfoList();
if (subscriptionInfoList == null) {
return null;
}
return subscriptionInfoList.get(slotId);
}
@VisibleForTesting
String getCdmaPrlVersion() {
return mTelephonyManager.getCdmaPrlVersion();
}
@VisibleForTesting
boolean isCdmaLteEnabled() {
return mTelephonyManager.getLteOnCdmaMode(mSubscriptionInfo.getSubscriptionId())
== PhoneConstants.LTE_ON_CDMA_TRUE;
}
@VisibleForTesting
String getMeid() {
return mTelephonyManager.getMeid(mSlotId);
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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 android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class ImeiInfoDialogFragment extends InstrumentedDialogFragment {
@VisibleForTesting
static final String TAG = "ImeiInfoDialog";
private static final String SLOT_ID_BUNDLE_KEY = "arg_key_slot_id";
private static final String DIALOG_TITLE_BUNDLE_KEY = "arg_key_dialog_title";
private View mRootView;
public static void show(@NonNull Fragment host, int slotId, String dialogTitle) {
final FragmentManager manager = host.getChildFragmentManager();
if (manager.findFragmentByTag(TAG) == null) {
final Bundle bundle = new Bundle();
bundle.putInt(SLOT_ID_BUNDLE_KEY, slotId);
bundle.putString(DIALOG_TITLE_BUNDLE_KEY, dialogTitle);
final ImeiInfoDialogFragment dialog = new ImeiInfoDialogFragment();
dialog.setArguments(bundle);
dialog.show(manager, TAG);
}
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DIALOG_IMEI_INFO;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle bundle = getArguments();
final int slotId = bundle.getInt(SLOT_ID_BUNDLE_KEY);
final String dialogTitle = bundle.getString(DIALOG_TITLE_BUNDLE_KEY);
final ImeiInfoDialogController controller = new ImeiInfoDialogController(this, slotId);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(dialogTitle)
.setPositiveButton(android.R.string.ok, null);
mRootView = LayoutInflater.from(builder.getContext())
.inflate(R.layout.dialog_imei_info, null /* parent */);
controller.populateImeiInfo();
return builder.setView(mRootView).create();
}
public void removeViewFromScreen(int viewId) {
final View view = mRootView.findViewById(viewId);
if (view != null) {
view.setVisibility(View.GONE);
}
}
public void setText(int viewId, CharSequence text) {
final TextView textView = mRootView.findViewById(viewId);
if (TextUtils.isEmpty(text)) {
text = getResources().getString(R.string.device_info_default);
}
if (textView != null) {
textView.setText(text);
}
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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 android.app.Fragment;
import android.content.Context;
import com.android.settings.R;
public class ImeiInfoDualSimPreferenceController extends AbstractImeiInfoPreferenceController {
private static final String KEY_IMEI_INFO_DUAL_SIM = "imei_info_sim_slot_2";
private static final int SIM_SLOT = 1;
public ImeiInfoDualSimPreferenceController(Context context, Fragment fragment) {
super(context, fragment);
}
@Override
public boolean isAvailable() {
return super.isAvailable() && mIsMultiSim;
}
@Override
public String getPreferenceKey() {
return KEY_IMEI_INFO_DUAL_SIM;
}
@Override
protected String getTitleForCdmaPhone() {
return mContext.getResources().getString(R.string.meid_multi_sim_sim_slot_2);
}
@Override
protected String getTitleForGsmPhone() {
return mContext.getResources().getString(R.string.imei_multi_sim_slot_2);
}
@Override
protected int getSimSlot() {
return SIM_SLOT;
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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 android.app.Fragment;
import android.content.Context;
import com.android.settings.R;
public class ImeiInfoPreferenceControllerV2 extends AbstractImeiInfoPreferenceController {
public static final int SIM_SLOT = 0;
private static final String KEY_IMEI_INFO = "imei_info_sim_slot_1";
public ImeiInfoPreferenceControllerV2(Context context, Fragment fragment) {
super(context, fragment);
}
@Override
public String getPreferenceKey() {
return KEY_IMEI_INFO;
}
@Override
protected String getTitleForCdmaPhone() {
return mIsMultiSim ? mContext.getResources().getString(R.string.meid_multi_sim_sim_slot_1)
: mContext.getResources().getString(R.string.status_meid_number);
}
@Override
protected String getTitleForGsmPhone() {
return mIsMultiSim ? mContext.getResources().getString(R.string.imei_multi_sim_slot_1)
: mContext.getResources().getString(R.string.status_imei);
}
@Override
protected int getSimSlot() {
return SIM_SLOT;
}
}