use of android.telephony.SubscriptionInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsDumpService method dumpDataUsage.
private JSONObject dumpDataUsage() throws JSONException {
JSONObject obj = new JSONObject();
DataUsageController controller = new DataUsageController(this);
ConnectivityManager connectivityManager = getSystemService(ConnectivityManager.class);
SubscriptionManager manager = SubscriptionManager.from(this);
TelephonyManager telephonyManager = TelephonyManager.from(this);
if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) {
JSONArray array = new JSONArray();
for (SubscriptionInfo info : manager.getAllSubscriptionInfoList()) {
NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(telephonyManager.getSubscriberId(info.getSubscriptionId()));
final JSONObject usage = dumpDataUsage(mobileAll, controller);
usage.put("subId", info.getSubscriptionId());
array.put(usage);
}
obj.put("cell", array);
}
if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_WIFI)) {
obj.put("wifi", dumpDataUsage(NetworkTemplate.buildTemplateWifiWildcard(), controller));
}
if (connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_ETHERNET)) {
obj.put("ethernet", dumpDataUsage(NetworkTemplate.buildTemplateEthernet(), controller));
}
return obj;
}
use of android.telephony.SubscriptionInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DataUsageSummary method getDefaultSubscriptionId.
public static int getDefaultSubscriptionId(Context context) {
SubscriptionManager subManager = SubscriptionManager.from(context);
if (subManager == null) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
SubscriptionInfo subscriptionInfo = subManager.getDefaultDataSubscriptionInfo();
if (subscriptionInfo == null) {
List<SubscriptionInfo> list = subManager.getAllSubscriptionInfoList();
if (list.size() == 0) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
subscriptionInfo = list.get(0);
}
return subscriptionInfo.getSubscriptionId();
}
use of android.telephony.SubscriptionInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DataUsageSummary method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
boolean hasMobileData = hasMobileData(getContext());
mDataUsageController = new DataUsageController(getContext());
mDataInfoController = new DataUsageInfoController();
addPreferencesFromResource(R.xml.data_usage);
int defaultSubId = getDefaultSubscriptionId(getContext());
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
hasMobileData = false;
}
mDefaultTemplate = getDefaultTemplate(getContext(), defaultSubId);
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
if (!hasMobileData || !isAdmin()) {
removePreference(KEY_RESTRICT_BACKGROUND);
}
if (hasMobileData) {
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
List<SubscriptionInfo> subscriptions = services.mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptions == null || subscriptions.size() == 0) {
addMobileSection(defaultSubId);
}
for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
addMobileSection(subscriptions.get(i).getSubscriptionId());
}
mSummaryPreference.setSelectable(true);
} else {
removePreference(KEY_LIMIT_SUMMARY);
mSummaryPreference.setSelectable(false);
}
boolean hasWifiRadio = hasWifiRadio(getContext());
if (hasWifiRadio) {
addWifiSection();
}
if (hasEthernet(getContext())) {
addEthernetSection();
}
mDataUsageTemplate = hasMobileData ? R.string.cell_data_template : hasWifiRadio ? R.string.wifi_data_template : R.string.ethernet_data_template;
setHasOptionsMenu(true);
}
use of android.telephony.SubscriptionInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TemplatePreferenceCategory method pushTemplates.
public void pushTemplates(NetworkServices services) {
if (mTemplate == null) {
throw new RuntimeException("null mTemplate for " + getKey());
}
if (mSubId != 0) {
SubscriptionManager sm = SubscriptionManager.from(getContext());
SubscriptionInfo info = sm.getActiveSubscriptionInfo(mSubId);
CharSequence name = info != null ? info.getDisplayName() : null;
if (name != null) {
setTitle(name);
}
}
for (int i = 0; i < getPreferenceCount(); i++) {
((TemplatePreference) getPreference(i)).setTemplate(mTemplate, mSubId, services);
}
}
use of android.telephony.SubscriptionInfo in project android_frameworks_base by DirtyUnicorns.
the class NetworkControllerImpl method dispatchDemoCommand.
@Override
public void dispatchDemoCommand(String command, Bundle args) {
if (!mDemoMode && command.equals(COMMAND_ENTER)) {
if (DEBUG)
Log.d(TAG, "Entering demo mode");
unregisterListeners();
mDemoMode = true;
mDemoInetCondition = mInetCondition;
mDemoWifiState = mWifiSignalController.getState();
mDemoWifiState.ssid = "DemoMode";
} else if (mDemoMode && command.equals(COMMAND_EXIT)) {
if (DEBUG)
Log.d(TAG, "Exiting demo mode");
mDemoMode = false;
// Update what MobileSignalControllers, because they may change
// to set the number of sim slots.
updateMobileControllers();
for (MobileSignalController controller : mMobileSignalControllers.values()) {
controller.resetLastState();
}
mWifiSignalController.resetLastState();
mReceiverHandler.post(mRegisterListeners);
notifyAllListeners();
} else if (mDemoMode && command.equals(COMMAND_NETWORK)) {
String airplane = args.getString("airplane");
if (airplane != null) {
boolean show = airplane.equals("show");
mCallbackHandler.setIsAirplaneMode(new IconState(show, TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext));
}
String fully = args.getString("fully");
if (fully != null) {
mDemoInetCondition = Boolean.parseBoolean(fully);
BitSet connected = new BitSet();
if (mDemoInetCondition) {
connected.set(mWifiSignalController.mTransportType);
}
mWifiSignalController.updateConnectivity(connected, connected);
for (MobileSignalController controller : mMobileSignalControllers.values()) {
if (mDemoInetCondition) {
connected.set(controller.mTransportType);
}
controller.updateConnectivity(connected, connected);
}
}
String wifi = args.getString("wifi");
if (wifi != null) {
boolean show = wifi.equals("show");
String level = args.getString("level");
if (level != null) {
mDemoWifiState.level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), WifiIcons.WIFI_LEVEL_COUNT - 1);
mDemoWifiState.connected = mDemoWifiState.level >= 0;
}
String activity = args.getString("activity");
if (activity != null) {
switch(activity) {
case "inout":
mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_INOUT);
break;
case "in":
mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_IN);
break;
case "out":
mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_OUT);
break;
default:
mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
break;
}
} else {
mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
}
mDemoWifiState.enabled = show;
mWifiSignalController.notifyListeners();
}
String sims = args.getString("sims");
if (sims != null) {
int num = MathUtils.constrain(Integer.parseInt(sims), 1, 8);
List<SubscriptionInfo> subs = new ArrayList<>();
if (num != mMobileSignalControllers.size()) {
mMobileSignalControllers.clear();
int start = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
for (int i = start; /* get out of normal index range */
i < start + num; i++) {
subs.add(addSignalController(i, i));
}
mCallbackHandler.setSubs(subs);
}
}
String nosim = args.getString("nosim");
if (nosim != null) {
mHasNoSims = nosim.equals("show");
mCallbackHandler.setNoSims(mHasNoSims);
}
String mobile = args.getString("mobile");
if (mobile != null) {
boolean show = mobile.equals("show");
String datatype = args.getString("datatype");
String slotString = args.getString("slot");
int slot = TextUtils.isEmpty(slotString) ? 0 : Integer.parseInt(slotString);
slot = MathUtils.constrain(slot, 0, 8);
// Ensure we have enough sim slots
List<SubscriptionInfo> subs = new ArrayList<>();
while (mMobileSignalControllers.size() <= slot) {
int nextSlot = mMobileSignalControllers.size();
subs.add(addSignalController(nextSlot, nextSlot));
}
if (!subs.isEmpty()) {
mCallbackHandler.setSubs(subs);
}
// Hack to index linearly for easy use.
MobileSignalController controller = mMobileSignalControllers.values().toArray(new MobileSignalController[0])[slot];
controller.getState().dataSim = datatype != null;
if (datatype != null) {
controller.getState().iconGroup = datatype.equals("1x") ? TelephonyIcons.ONE_X : datatype.equals("3g") ? TelephonyIcons.THREE_G : datatype.equals("4g") ? TelephonyIcons.FOUR_G : datatype.equals("4g+") ? TelephonyIcons.FOUR_G_PLUS : datatype.equals("e") ? TelephonyIcons.E : datatype.equals("g") ? TelephonyIcons.G : datatype.equals("h") ? TelephonyIcons.H : datatype.equals("hp") ? TelephonyIcons.HP : datatype.equals("lte") ? TelephonyIcons.LTE : datatype.equals("lte+") ? TelephonyIcons.LTE_PLUS : TelephonyIcons.UNKNOWN;
}
if (args.containsKey("roam")) {
controller.getState().roaming = "show".equals(args.getString("roam"));
}
int[][] icons = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH;
String level = args.getString("level");
if (level != null) {
controller.getState().level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), icons[0].length - 1);
controller.getState().connected = controller.getState().level >= 0;
}
String activity = args.getString("activity");
if (activity != null) {
controller.getState().dataConnected = true;
switch(activity) {
case "inout":
controller.setActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
break;
case "in":
controller.setActivity(TelephonyManager.DATA_ACTIVITY_IN);
break;
case "out":
controller.setActivity(TelephonyManager.DATA_ACTIVITY_OUT);
break;
default:
controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
break;
}
} else {
controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
}
if (activity != null) {
controller.setActivity(Integer.parseInt(activity));
}
controller.getState().enabled = show;
controller.notifyListeners();
}
String carrierNetworkChange = args.getString("carriernetworkchange");
if (carrierNetworkChange != null) {
boolean show = carrierNetworkChange.equals("show");
for (MobileSignalController controller : mMobileSignalControllers.values()) {
controller.setCarrierNetworkChangeMode(show);
}
}
}
}
Aggregations