Search in sources :

Example 41 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceControllerTest method onResume_oneNewAccount_shouldAddOneAccountPreference.

@Test
public void onResume_oneNewAccount_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isLinkedUser()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
    Account[] accountType1 = new Account[2];
    accountType1[0] = new Account("Acct11", "com.acct1");
    accountType1[1] = new Account("Acct12", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
    // add a new account
    accountType1 = new Account[3];
    accountType1[0] = new Account("Acct11", "com.acct1");
    accountType1[1] = new Account("Acct12", "com.acct1");
    accountType1[2] = new Account("Acct13", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    mController.onResume();
    // each account should be added only once
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct13")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 42 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceControllerTest method onResume_oneAccountRemoved_shouldRemoveOneAccountPreference.

@Test
public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isLinkedUser()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    Account[] accounts = { new Account("Acct1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
    Account[] accountType1 = new Account[2];
    accountType1[0] = new Account("Acct11", "com.acct1");
    accountType1[1] = new Account("Acct12", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
    // remove an account
    accountType1 = new Account[1];
    accountType1[0] = new Account("Acct11", "com.acct1");
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    mController.onResume();
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
    verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
    verify(preferenceGroup, times(1)).removePreference(argThat(titleMatches("Acct12")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(android.support.v7.preference.PreferenceManager) Test(org.junit.Test)

Example 43 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by omnirom.

the class SecuritySettingsTest method testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification.

@Test
public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() {
    final Preference preference = mock(Preference.class);
    final PreferenceGroup group = mock(PreferenceGroup.class);
    when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES)).thenReturn(preference);
    final LockScreenNotificationPreferenceController controller = mock(LockScreenNotificationPreferenceController.class);
    final SecuritySettings securitySettings = new SecuritySettings();
    ReflectionHelpers.setField(securitySettings, "mLockScreenNotificationPreferenceController", controller);
    when(controller.getSummaryResource()).thenReturn(1234);
    securitySettings.setLockscreenPreferencesSummary(group);
    verify(preference).setSummary(1234);
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) LockScreenNotificationPreferenceController(com.android.settings.notification.LockScreenNotificationPreferenceController) Test(org.junit.Test)

Example 44 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by crdroidandroid.

the class DevelopmentSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
    mWebViewUpdateService = WebViewFactory.getUpdateService();
    mOemLockManager = (OemLockManager) getSystemService(Context.OEM_LOCK_SERVICE);
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mUm = (UserManager) getSystemService(Context.USER_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mTelephonyMonitorController = new TelephonyMonitorPreferenceController(getActivity());
    mWebViewAppPrefController = new WebViewAppPreferenceController(getActivity());
    mVerifyAppsOverUsbController = new VerifyAppsOverUsbPreferenceController(getActivity());
    mCameraLaserSensorController = new CameraLaserSensorPreferenceController(getActivity());
    setIfOnlyAvailableForAdmins(true);
    if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
        // Block access to developer options if the user is not the owner, if user policy
        // restricts it, or if the device has not been provisioned
        mUnavailable = true;
        addPreferencesFromResource(R.xml.placeholder_prefs);
        return;
    }
    addPreferencesFromResource(R.xml.development_prefs);
    final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
    mEnableAdbController = new EnableAdbPreferenceController(getActivity());
    mAdbOverNetwork = findAndInitSwitchPref(ADB_TCPIP);
    mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
    if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
        if (debugDebuggingCategory != null) {
            debugDebuggingCategory.removePreference(mClearAdbKeys);
        }
    }
    mAllPrefs.add(mClearAdbKeys);
    mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
    if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
        debugDebuggingCategory.removePreference(mEnableTerminal);
        mEnableTerminal = null;
    }
    mTelephonyMonitorController.displayPreference(getPreferenceScreen());
    mWebViewAppPrefController.displayPreference(getPreferenceScreen());
    mEnableAdbController.displayPreference(getPreferenceScreen());
    mCameraLaserSensorController.displayPreference(getPreferenceScreen());
    mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
    mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
    mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
    if (!showEnableOemUnlockPreference(getActivity())) {
        removePreference(mEnableOemUnlock);
        mEnableOemUnlock = null;
    }
    mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
    mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY);
    mPassword = findPreference(LOCAL_BACKUP_PASSWORD);
    mAllPrefs.add(mPassword);
    if (!mUm.isAdminUser()) {
        disableForUser(mClearAdbKeys);
        disableForUser(mEnableTerminal);
        disableForUser(mPassword);
    }
    mDebugAppPref = findPreference(DEBUG_APP_KEY);
    mAllPrefs.add(mDebugAppPref);
    mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
    mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
    mAllPrefs.add(mMockLocationAppPref);
    mVerifyAppsOverUsbController.displayPreference(getPreferenceScreen());
    mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
    mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
    mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
    mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
    mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
    mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
    mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
    mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
    mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
    mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
    mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
    mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
    mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
    mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
    mDebugHwRenderer = addListPreference(DEBUG_HW_RENDERER_KEY);
    mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
    mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
    mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
    mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
    mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
    mTetheringHardwareOffload = findAndInitSwitchPref(TETHERING_HARDWARE_OFFLOAD);
    mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
    if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) {
        mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY);
    } else {
        mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY);
        if (mLogpersist != null) {
            mLogpersist.setEnabled(false);
            if (debugDebuggingCategory != null) {
                debugDebuggingCategory.removePreference(mLogpersist);
            }
        }
        mLogpersist = null;
    }
    mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
    mBluetoothShowDevicesWithoutNames = findAndInitSwitchPref(BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_KEY);
    mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
    mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY);
    if (!BluetoothHeadset.isInbandRingingSupported(getContext())) {
        removePreference(mBluetoothEnableInbandRinging);
        mBluetoothEnableInbandRinging = null;
    }
    mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY);
    mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY);
    mBluetoothSelectA2dpSampleRate = addListPreference(BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY);
    mBluetoothSelectA2dpBitsPerSample = addListPreference(BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY);
    mBluetoothSelectA2dpChannelMode = addListPreference(BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY);
    mBluetoothSelectA2dpLdacPlaybackQuality = addListPreference(BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY);
    initBluetoothConfigurationValues();
    mWindowAnimationScale = findAndInitAnimationScalePreference(WINDOW_ANIMATION_SCALE_KEY);
    mTransitionAnimationScale = findAndInitAnimationScalePreference(TRANSITION_ANIMATION_SCALE_KEY);
    mAnimatorDurationScale = findAndInitAnimationScalePreference(ANIMATOR_DURATION_SCALE_KEY);
    mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
    mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
    mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
    mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
    mImmediatelyDestroyActivities = (SwitchPreference) findPreference(IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
    mAllPrefs.add(mImmediatelyDestroyActivities);
    mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
    mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
    mShowAllANRs = (SwitchPreference) findPreference(SHOW_ALL_ANRS_KEY);
    mAllPrefs.add(mShowAllANRs);
    mResetSwitchPrefs.add(mShowAllANRs);
    mShowNotificationChannelWarnings = (SwitchPreference) findPreference(SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY);
    mAllPrefs.add(mShowNotificationChannelWarnings);
    mResetSwitchPrefs.add(mShowNotificationChannelWarnings);
    Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
    if (hdcpChecking != null) {
        mAllPrefs.add(hdcpChecking);
        removePreferenceForProduction(hdcpChecking);
    }
    Preference convertFbePreference = findPreference(KEY_CONVERT_FBE);
    try {
        IBinder service = ServiceManager.getService("mount");
        IStorageManager storageManager = IStorageManager.Stub.asInterface(service);
        if (!storageManager.isConvertibleToFBE()) {
            removePreference(KEY_CONVERT_FBE);
        } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) {
            convertFbePreference.setEnabled(false);
            convertFbePreference.setSummary(getResources().getString(R.string.convert_to_file_encryption_done));
        }
    } catch (RemoteException e) {
        removePreference(KEY_CONVERT_FBE);
    }
    mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
    if (!SystemProperties.getBoolean("ro.build.ab_update", false)) {
        removePreference(mOtaDisableAutomaticUpdate);
        mOtaDisableAutomaticUpdate = null;
    }
    mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE);
    mColorModePreference.updateCurrentAndSupported();
    if (mColorModePreference.getColorModeCount() < 2 || getContext().getResources().getConfiguration().isScreenWideColorGamut()) {
        removePreference(KEY_COLOR_MODE);
        mColorModePreference = null;
    }
    mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY);
    if (getResources().getBoolean(R.bool.config_enableColorTemperature)) {
        mAllPrefs.add(mColorTemperaturePreference);
        mResetSwitchPrefs.add(mColorTemperaturePreference);
    } else {
        removePreference(COLOR_TEMPERATURE_KEY);
        mColorTemperaturePreference = null;
    }
    mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
    mAllPrefs.add(mDevelopmentTools);
    mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
    mRootAccess.setOnPreferenceChangeListener(this);
    mRootAppops = (Preference) findPreference(ROOT_APPOPS_KEY);
    mRootAppops.setOnPreferenceClickListener(this);
    if (!removeRootOptionsIfRequired()) {
        if (FileUtils.fileExists("/system/xbin/su")) {
            mRootAccess.setEntries(R.array.root_access_entries);
            mRootAccess.setEntryValues(R.array.root_access_values);
        } else {
            mRootAccess.setEntries(R.array.root_access_entries_adb);
            mRootAccess.setEntryValues(R.array.root_access_values_adb);
        }
        mAllPrefs.add(mRootAccess);
        mAllPrefs.add(mRootAppops);
    }
    addDashboardCategoryPreferences();
}
Also used : WebViewAppPreferenceController(com.android.settings.webview.WebViewAppPreferenceController) IStorageManager(android.os.storage.IStorageManager) IBinder(android.os.IBinder) ListPreference(android.support.v7.preference.ListPreference) AnimationScalePreference(com.android.settings.AnimationScalePreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) AbstractEnableAdbPreferenceController(com.android.settingslib.development.AbstractEnableAdbPreferenceController) RemoteException(android.os.RemoteException)

Example 45 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by crdroidandroid.

the class ProgressiveDisclosureMixin method findPreference.

/**
 * Finds preference by key, either from screen or from collapsed list.
 */
public Preference findPreference(PreferenceScreen screen, CharSequence key) {
    Preference preference = screen.findPreference(key);
    if (preference != null) {
        return preference;
    }
    for (int i = 0; i < mCollapsedPrefs.size(); i++) {
        final Preference pref = mCollapsedPrefs.get(i);
        if (TextUtils.equals(key, pref.getKey())) {
            return pref;
        }
        if (pref instanceof PreferenceGroup) {
            final Preference returnedPreference = ((PreferenceGroup) pref).findPreference(key);
            if (returnedPreference != null) {
                return returnedPreference;
            }
        }
    }
    Log.d(TAG, "Cannot find preference with key " + key);
    return null;
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)140 Preference (android.support.v7.preference.Preference)114 Context (android.content.Context)67 Test (org.junit.Test)54 PreferenceManager (android.support.v7.preference.PreferenceManager)50 ArrayList (java.util.ArrayList)50 UserInfo (android.content.pm.UserInfo)48 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)42 Account (android.accounts.Account)36 AuthenticatorDescription (android.accounts.AuthenticatorDescription)36 UserHandle (android.os.UserHandle)36 Intent (android.content.Intent)27 SwitchPreference (android.support.v14.preference.SwitchPreference)21 PreferenceCategory (android.support.v7.preference.PreferenceCategory)20 PackageManager (android.content.pm.PackageManager)16 ResolveInfo (android.content.pm.ResolveInfo)16 TelephonyManager (android.telephony.TelephonyManager)16 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)15 Activity (android.app.Activity)14