Search in sources :

Example 6 with SubscriptionManager

use of android.telephony.SubscriptionManager in project android_frameworks_base by ResurrectionRemix.

the class UserRestrictionsUtils method applyUserRestriction.

/**
     * Apply each user restriction.
     *
     * <p>See also {@link
     * com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser},
     * which should be in sync with this method.
     */
private static void applyUserRestriction(Context context, int userId, String key, boolean newValue) {
    if (UserManagerService.DBG) {
        Log.d(TAG, "Applying user restriction: userId=" + userId + " key=" + key + " value=" + newValue);
    }
    // When certain restrictions are cleared, we don't update the system settings,
    // because these settings are changeable on the Settings UI and we don't know the original
    // value -- for example LOCATION_MODE might have been off already when the restriction was
    // set, and in that case even if the restriction is lifted, changing it to ON would be
    // wrong.  So just don't do anything in such a case.  If the user hopes to enable location
    // later, they can do it on the Settings UI.
    // WARNING: Remember that Settings.Global and Settings.Secure are changeable via adb.
    // To prevent this from happening for a given user restriction, you have to add a check to
    // SettingsProvider.isGlobalOrSecureSettingRestrictedForUser.
    final ContentResolver cr = context.getContentResolver();
    final long id = Binder.clearCallingIdentity();
    try {
        switch(key) {
            case UserManager.DISALLOW_CONFIG_WIFI:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
                }
                break;
            case UserManager.DISALLOW_DATA_ROAMING:
                if (newValue) {
                    // DISALLOW_DATA_ROAMING user restriction is set.
                    // Multi sim device.
                    SubscriptionManager subscriptionManager = new SubscriptionManager(context);
                    final List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
                    if (subscriptionInfoList != null) {
                        for (SubscriptionInfo subInfo : subscriptionInfoList) {
                            android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING + subInfo.getSubscriptionId(), "0", userId);
                        }
                    }
                    // Single sim device.
                    android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING, "0", userId);
                }
                break;
            case UserManager.DISALLOW_SHARE_LOCATION:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF, userId);
                }
                break;
            case UserManager.DISALLOW_DEBUGGING_FEATURES:
                if (newValue) {
                    // TODO: should this be admin user?
                    if (userId == UserHandle.USER_SYSTEM) {
                        android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.ADB_ENABLED, "0", userId);
                    }
                }
                break;
            case UserManager.ENSURE_VERIFY_APPS:
                if (newValue) {
                    android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1", userId);
                    android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1", userId);
                }
                break;
            case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0, userId);
                }
                break;
            case UserManager.DISALLOW_RUN_IN_BACKGROUND:
                if (newValue) {
                    int currentUser = ActivityManager.getCurrentUser();
                    if (currentUser != userId && userId != UserHandle.USER_SYSTEM) {
                        try {
                            ActivityManagerNative.getDefault().stopUser(userId, false, null);
                        } catch (RemoteException e) {
                            throw e.rethrowAsRuntimeException();
                        }
                    }
                }
                break;
            case UserManager.DISALLOW_SAFE_BOOT:
                // Unlike with the other restrictions, we want to propagate the new value to
                // the system settings even if it is false. The other restrictions modify
                // settings which could be manually changed by the user from the Settings app
                // after the policies enforcing these restrictions have been revoked, so we
                // leave re-setting of those settings to the user.
                android.provider.Settings.Global.putInt(context.getContentResolver(), android.provider.Settings.Global.SAFE_BOOT_DISALLOWED, newValue ? 1 : 0);
                break;
            case UserManager.DISALLOW_FACTORY_RESET:
            case UserManager.DISALLOW_OEM_UNLOCK:
                if (newValue) {
                    PersistentDataBlockManager manager = (PersistentDataBlockManager) context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
                    if (manager != null && manager.getOemUnlockEnabled() && manager.getFlashLockState() != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
                        // Only disable OEM unlock if the bootloader is locked. If it's already
                        // unlocked, setting the OEM unlock enabled flag to false has no effect
                        // (the bootloader would remain unlocked).
                        manager.setOemUnlockEnabled(false);
                    }
                }
                break;
        }
    } finally {
        Binder.restoreCallingIdentity(id);
    }
}
Also used : PersistentDataBlockManager(android.service.persistentdata.PersistentDataBlockManager) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Example 7 with SubscriptionManager

use of android.telephony.SubscriptionManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Status method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mHandler = new MyHandler(this);
    mCM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    addPreferencesFromResource(R.xml.device_info_status);
    mBatteryLevel = findPreference(KEY_BATTERY_LEVEL);
    mBatteryStatus = findPreference(KEY_BATTERY_STATUS);
    mBtAddress = findPreference(KEY_BT_ADDRESS);
    mWifiMacAddress = findPreference(KEY_WIFI_MAC_ADDRESS);
    mWimaxMacAddress = findPreference(KEY_WIMAX_MAC_ADDRESS);
    mIpAddress = findPreference(KEY_IP_ADDRESS);
    mRes = getResources();
    mUnknown = mRes.getString(R.string.device_info_default);
    mUnavailable = mRes.getString(R.string.status_unavailable);
    // Note - missing in zaku build, be careful later...
    mUptime = findPreference("up_time");
    if (!hasBluetooth()) {
        getPreferenceScreen().removePreference(mBtAddress);
        mBtAddress = null;
    }
    if (!hasWimax()) {
        getPreferenceScreen().removePreference(mWimaxMacAddress);
        mWimaxMacAddress = null;
    }
    mConnectivityIntentFilter = new IntentFilter();
    for (String intent : CONNECTIVITY_INTENTS) {
        mConnectivityIntentFilter.addAction(intent);
    }
    updateConnectivity();
    String serial = getSerialNumber();
    if (serial != null && !serial.equals("")) {
        setSummaryText(KEY_SERIAL_NUMBER, serial);
    } else {
        removePreferenceFromScreen(KEY_SERIAL_NUMBER);
    }
    //TODO: the bug above will surface in split system user mode.
    if (!UserManager.get(getContext()).isAdminUser() || Utils.isWifiOnly(getContext())) {
        removePreferenceFromScreen(KEY_SIM_STATUS);
        removePreferenceFromScreen(KEY_IMEI_INFO);
    } else {
        int numPhones = TelephonyManager.getDefault().getPhoneCount();
        if (numPhones > 1) {
            PreferenceScreen prefSet = getPreferenceScreen();
            Preference singleSimPref = prefSet.findPreference(KEY_SIM_STATUS);
            SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
            for (int i = 0; i < numPhones; i++) {
                SubscriptionInfo sir = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(i);
                Preference pref = new Preference(getActivity());
                pref.setOrder(singleSimPref.getOrder());
                pref.setTitle(getString(R.string.sim_card_status_title, i + 1));
                if (sir != null) {
                    pref.setSummary(sir.getDisplayName());
                } else {
                    pref.setSummary(R.string.sim_card_summary_empty);
                }
                Intent intent = new Intent(getActivity(), Settings.SimStatusActivity.class);
                intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_TITLE, getString(R.string.sim_card_status_title, i + 1));
                intent.putExtra(Settings.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
                intent.putExtra(SimStatus.EXTRA_SLOT_ID, i);
                pref.setIntent(intent);
                prefSet.addPreference(pref);
            }
            prefSet.removePreference(singleSimPref);
        }
    }
    if (SystemProperties.getBoolean("ro.alarm_boot", false)) {
        removePreferenceFromScreen(KEY_IMEI_INFO);
    }
}
Also used : IntentFilter(android.content.IntentFilter) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent) SubscriptionManager(android.telephony.SubscriptionManager) Settings(com.android.settings.Settings)

Example 8 with SubscriptionManager

use of android.telephony.SubscriptionManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SimStatus method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Intent intent = getActivity().getIntent();
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    int slotId = intent.getIntExtra(EXTRA_SLOT_ID, 0);
    mSir = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(slotId);
    updatePhoneInfos();
}
Also used : Intent(android.content.Intent) SubscriptionManager(android.telephony.SubscriptionManager)

Example 9 with SubscriptionManager

use of android.telephony.SubscriptionManager 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();
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager)

Example 10 with SubscriptionManager

use of android.telephony.SubscriptionManager 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);
    }
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager)

Aggregations

SubscriptionManager (android.telephony.SubscriptionManager)32 TelephonyManager (android.telephony.TelephonyManager)20 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SubscriptionInfo (android.telephony.SubscriptionInfo)13 NetworkIdentity (android.net.NetworkIdentity)10 ContentResolver (android.content.ContentResolver)4 Intent (android.content.Intent)4 RemoteException (android.os.RemoteException)4 PersistentDataBlockManager (android.service.persistentdata.PersistentDataBlockManager)4 TargetApi (android.annotation.TargetApi)2 Preference (android.support.v7.preference.Preference)2 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkTemplate (android.net.NetworkTemplate)1