Dynamic preferences for sim status
- Support N-sim devices for sim status preference Bug: 36458278 Test: make RunSettingsRoboTests -j40 Change-Id: I0cea3f765f89c30a6595631ed501ab1c0010b736
This commit is contained in:
@@ -42,7 +42,6 @@ import com.android.settings.deviceinfo.SecurityPatchPreferenceController;
|
||||
import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
|
||||
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceControllerV2;
|
||||
import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
|
||||
import com.android.settings.deviceinfo.simstatus.SimStatusDualSimPreferenceController;
|
||||
import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceControllerV2;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
@@ -133,8 +132,6 @@ public class DeviceInfoSettings extends DashboardFragment implements Indexable {
|
||||
|
||||
controllers.add(new SimStatusPreferenceControllerV2(context, fragment));
|
||||
|
||||
controllers.add(new SimStatusDualSimPreferenceController(context, fragment));
|
||||
|
||||
controllers.add(new DeviceModelPreferenceController(context, fragment));
|
||||
|
||||
controllers.add(new ImeiInfoPreferenceControllerV2(context, fragment));
|
||||
|
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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 android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractSimStatusPreferenceController extends
|
||||
AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
protected final boolean mIsMultiSim;
|
||||
protected final TelephonyManager mTelephonyManager;
|
||||
private final SubscriptionManager mSubscriptionManager;
|
||||
private final Fragment mFragment;
|
||||
|
||||
private Preference mPreference;
|
||||
|
||||
public AbstractSimStatusPreferenceController(Context context, Fragment fragment) {
|
||||
super(context);
|
||||
|
||||
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mSubscriptionManager = (SubscriptionManager) context.getSystemService(
|
||||
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
||||
mFragment = fragment;
|
||||
mIsMultiSim = mTelephonyManager.getPhoneCount() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
if (mPreference == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPreference.setTitle(getPreferenceTitle());
|
||||
mPreference.setSummary(getCarrierName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SimStatusDialogFragment.show(mFragment, getSimSlot(), getPreferenceTitle());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The preference title for the displayed preference.
|
||||
*/
|
||||
protected abstract String getPreferenceTitle();
|
||||
|
||||
/**
|
||||
* @return The sim slot to retrieve sim status information about.
|
||||
*/
|
||||
protected abstract int getSimSlot();
|
||||
|
||||
private CharSequence getCarrierName() {
|
||||
final List<SubscriptionInfo> subscriptionInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subscriptionInfoList != null) {
|
||||
for (SubscriptionInfo info : subscriptionInfoList) {
|
||||
if (info.getSimSlotIndex() == getSimSlot()) {
|
||||
return info.getCarrierName();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mContext.getText(R.string.device_info_not_available);
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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 android.app.Fragment;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class SimStatusDualSimPreferenceController extends AbstractSimStatusPreferenceController {
|
||||
|
||||
private static final int SIM_SLOT = 1;
|
||||
private static final String SIM_STATUS_DUAL_SIM_KEY = "sim_status_sim_2";
|
||||
|
||||
public SimStatusDualSimPreferenceController(Context context, Fragment fragment) {
|
||||
super(context, fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return super.isAvailable() && mIsMultiSim;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPreferenceTitle() {
|
||||
return mContext.getResources().getString(R.string.sim_status_title_sim_slot_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSimSlot() {
|
||||
return SIM_SLOT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return SIM_STATUS_DUAL_SIM_KEY;
|
||||
}
|
||||
}
|
@@ -18,32 +18,107 @@ package com.android.settings.deviceinfo.simstatus;
|
||||
|
||||
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.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
|
||||
|
||||
public class SimStatusPreferenceControllerV2 extends AbstractSimStatusPreferenceController {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public static final int SIM_SLOT = 0;
|
||||
public class SimStatusPreferenceControllerV2 extends
|
||||
AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_SIM_1_STATUS = "sim_status_sim_1";
|
||||
private static final String KEY_SIM_STATUS = "sim_status";
|
||||
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
private final SubscriptionManager mSubscriptionManager;
|
||||
private final Fragment mFragment;
|
||||
private final List<Preference> mPreferenceList = new ArrayList<>();
|
||||
|
||||
public SimStatusPreferenceControllerV2(Context context, Fragment fragment) {
|
||||
super(context, fragment);
|
||||
}
|
||||
super(context);
|
||||
|
||||
@Override
|
||||
protected String getPreferenceTitle() {
|
||||
return mIsMultiSim ? mContext.getResources().getString(R.string.sim_status_title_sim_slot_1)
|
||||
: mContext.getResources().getString(R.string.sim_status_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSimSlot() {
|
||||
return SIM_SLOT;
|
||||
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mSubscriptionManager = (SubscriptionManager) context.getSystemService(
|
||||
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_SIM_1_STATUS;
|
||||
return KEY_SIM_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||
if (!isAvailable() || preference == null || !preference.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPreferenceList.add(preference);
|
||||
|
||||
final int simStatusOrder = preference.getOrder();
|
||||
// Add additional preferences for each sim in the device
|
||||
for (int simSlotNumber = 1; simSlotNumber < mTelephonyManager.getPhoneCount();
|
||||
simSlotNumber++) {
|
||||
final Preference multiSimPreference = createNewPreference(screen.getContext());
|
||||
multiSimPreference.setOrder(simStatusOrder + simSlotNumber);
|
||||
multiSimPreference.setKey(KEY_SIM_STATUS + simSlotNumber);
|
||||
screen.addPreference(multiSimPreference);
|
||||
mPreferenceList.add(multiSimPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
for (int simSlotNumber = 0; simSlotNumber < mPreferenceList.size(); simSlotNumber++) {
|
||||
final Preference simStatusPreference = mPreferenceList.get(simSlotNumber);
|
||||
simStatusPreference.setTitle(getPreferenceTitle(simSlotNumber /* sim slot */));
|
||||
simStatusPreference.setSummary(getCarrierName(simSlotNumber /* sim slot */));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
final int simSlot = mPreferenceList.indexOf(preference);
|
||||
if (simSlot == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SimStatusDialogFragment.show(mFragment, simSlot, getPreferenceTitle(simSlot));
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getPreferenceTitle(int simSlot) {
|
||||
return mTelephonyManager.getPhoneCount() > 1 ? mContext.getString(
|
||||
R.string.sim_status_title_sim_slot, simSlot + 1) : mContext.getString(
|
||||
R.string.sim_status_title);
|
||||
}
|
||||
|
||||
private CharSequence getCarrierName(int simSlot) {
|
||||
final List<SubscriptionInfo> subscriptionInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
if (subscriptionInfoList != null) {
|
||||
for (SubscriptionInfo info : subscriptionInfoList) {
|
||||
if (info.getSimSlotIndex() == simSlot) {
|
||||
return info.getCarrierName();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mContext.getText(R.string.device_info_not_available);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Preference createNewPreference(Context context) {
|
||||
return new Preference(context);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user