コード例 #1
1
  private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    // Location Settings
    addPreferencesFromResource(R.xml.location_settings);

    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();

    // Location Settings
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    if (GoogleLocationSettingHelper.isAvailable(getActivity())) {
      // GSF present, Add setting for 'Use My Location'
      CheckBoxPreference useLocation = new CheckBoxPreference(getActivity());
      useLocation.setKey(KEY_USE_LOCATION);
      useLocation.setTitle(R.string.use_location_title);
      useLocation.setSummary(R.string.use_location_summary);
      useLocation.setChecked(
          GoogleLocationSettingHelper.getUseLocationForServices(getActivity())
              == GoogleLocationSettingHelper.USE_LOCATION_FOR_SERVICES_ON);
      useLocation.setPersistent(false);
      useLocation.setOnPreferenceChangeListener(this);
      getPreferenceScreen().addPreference(useLocation);
      mUseLocation = useLocation;
    }

    // Change the summary for wifi-only devices
    if (Utils.isWifiOnly(getActivity())) {
      mNetwork.setSummaryOn(R.string.location_neighborhood_level_wifi);
    }

    // Security Settings
    // Add options for lock/unlock screen
    int resid = 0;
    if (!mLockPatternUtils.isSecure()) {
      if (mLockPatternUtils.isLockScreenDisabled()) {
        resid = R.xml.security_settings_lockscreen;
      } else {
        resid = R.xml.security_settings_chooser;
      }
    } else if (mLockPatternUtils.usingBiometricWeak()
        && mLockPatternUtils.isBiometricWeakInstalled()) {
      resid = R.xml.security_settings_biometric_weak;
    } else {
      switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
        case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
          resid = R.xml.security_settings_pattern;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
          resid = R.xml.security_settings_pin;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
        case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
          resid = R.xml.security_settings_password;
          break;
      }
    }
    addPreferencesFromResource(resid);

    boolean isSystemEmmcDetect = false;
    try {
      Class c = Class.forName(SYSTEM_DETECT_HANDLER);
      ISystemInfoDetectHandler handler = (ISystemInfoDetectHandler) c.newInstance();
      isSystemEmmcDetect = handler.isFileSystemAutoDetect();
      Log.i("SecuritySettings", "isSystemEmmcDetect = " + isSystemEmmcDetect);
    } catch (Exception e) {
      Log.i("SecuritySettings", "exception " + e);
      isSystemEmmcDetect = false;
    }
    if ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 1)
        || ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 2) && isSystemEmmcDetect)) {
      // Add options for device encryption
      DevicePolicyManager dpm =
          (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

      switch (dpm.getStorageEncryptionStatus()) {
        case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
          // The device is currently encrypted.
          addPreferencesFromResource(R.xml.security_settings_encrypted);
          break;
        case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
          // This device supports encryption but isn't encrypted.
          addPreferencesFromResource(R.xml.security_settings_unencrypted);
          break;
      }
    }

    // lock after preference
    mLockAfter = (ListPreference) root.findPreference(KEY_LOCK_AFTER_TIMEOUT);
    if (mLockAfter != null) {
      setupLockAfterPreference();
      updateLockAfterPreferenceSummary();
    }

    // visible pattern
    mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN);

    // lock instantly on power key press
    mPowerButtonInstantlyLocks =
        (CheckBoxPreference) root.findPreference(KEY_POWER_INSTANTLY_LOCKS);

    // don't display visible pattern if biometric and backup is not
    // pattern
    if (resid == R.xml.security_settings_biometric_weak
        && mLockPatternUtils.getKeyguardStoredPasswordQuality()
            != DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mVisiblePattern != null) {
        securityCategory.removePreference(root.findPreference(KEY_VISIBLE_PATTERN));
      }
    }

    // tactile feedback. Should be common to all unlock preference
    // screens.
    mTactileFeedback = (CheckBoxPreference) root.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
    if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mTactileFeedback != null) {
        securityCategory.removePreference(mTactileFeedback);
      }
    }

    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);

    MSimTelephonyManager tm = MSimTelephonyManager.getDefault();
    int numPhones = TelephonyManager.getDefault().getPhoneCount();
    boolean disableLock = false;
    for (int i = 0; i < numPhones; i++) {
      // Disable SIM lock if sim card is missing or unknown
      // notice:cdma can also set sim lock
      if ((tm.getSimState(i) == TelephonyManager.SIM_STATE_ABSENT)
          || (tm.getSimState(i) == TelephonyManager.SIM_STATE_UNKNOWN)) {
        disableLock = true;
      } else {
        disableLock = false;
        break;
      }
    }
    if (disableLock) {
      root.findPreference(KEY_SIM_LOCK).setEnabled(false);
    }

    // Show password
    mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);

    // SIM/RUIM lock
    Preference iccLock = (Preference) root.findPreference(KEY_SIM_LOCK_SETTINGS);

    Intent intent = new Intent();
    if (tm.isMultiSimEnabled()) {
      intent.setClassName(
          "com.android.settings", "com.android.settings.multisimsettings.MultiSimSettingTab");
      intent.putExtra(SelectSubscription.PACKAGE, "com.android.settings");
      intent.putExtra(SelectSubscription.TARGET_CLASS, "com.android.settings.IccLockSettings");
    } else {
      intent.setClassName("com.android.settings", "com.android.settings.IccLockSettings");
    }
    iccLock.setIntent(intent);

    // Credential storage
    mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);

    mToggleAppInstallation = (CheckBoxPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());

    return root;
  }
コード例 #2
0
  public PasswordUnlockScreen(
      Context context,
      Configuration configuration,
      LockPatternUtils lockPatternUtils,
      KeyguardUpdateMonitor updateMonitor,
      KeyguardScreenCallback callback) {
    super(context);

    mCreationHardKeyboardHidden = configuration.hardKeyboardHidden;
    mCreationOrientation = configuration.orientation;
    mUpdateMonitor = updateMonitor;
    mCallback = callback;
    mLockPatternUtils = lockPatternUtils;

    LayoutInflater layoutInflater = LayoutInflater.from(context);
    if (mCreationOrientation != Configuration.ORIENTATION_LANDSCAPE) {
      layoutInflater.inflate(R.layout.keyguard_screen_password_portrait, this, true);
    } else {
      layoutInflater.inflate(R.layout.keyguard_screen_password_landscape, this, true);
    }
    LockScreen.setBackground(context, (ViewGroup) findViewById(R.id.root));
    mStatusViewManager =
        new KeyguardStatusViewManager(this, mUpdateMonitor, mLockPatternUtils, mCallback, true);

    final int quality = lockPatternUtils.getKeyguardStoredPasswordQuality();
    mIsAlpha =
        DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == quality
            || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == quality
            || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == quality;

    mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
    mPasswordEntry = (EditText) findViewById(R.id.passwordEntry);
    mPasswordEntry.setOnEditorActionListener(this);

    mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this, false);
    mKeyboardHelper.setEnableHaptics(mLockPatternUtils.isTactileFeedbackEnabled());
    boolean imeOrDeleteButtonVisible = false;
    if (mIsAlpha) {
      // We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
      mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
      mKeyboardView.setVisibility(View.GONE);
    } else {
      // Use lockscreen's numeric keyboard if the physical keyboard isn't showing
      mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
      mKeyboardView.setVisibility(
          mCreationHardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO
              ? View.INVISIBLE
              : View.VISIBLE);

      // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
      // not a separate view
      View pinDelete = findViewById(R.id.pinDel);
      if (pinDelete != null) {
        pinDelete.setVisibility(View.VISIBLE);
        imeOrDeleteButtonVisible = true;
        pinDelete.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                mKeyboardHelper.handleBackspace();
              }
            });
      }
    }

    mPasswordEntry.requestFocus();

    // This allows keyboards with overlapping qwerty/numeric keys to choose just numeric keys.
    if (mIsAlpha) {
      mPasswordEntry.setKeyListener(TextKeyListener.getInstance());
      mPasswordEntry.setInputType(
          InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      // mStatusViewManager.setHelpMessage(R.string.keyguard_password_enter_password_code,
      // KeyguardStatusViewManager.LOCK_ICON);
    } else {
      mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
      mPasswordEntry.setInputType(
          InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
      // mStatusViewManager.setHelpMessage(R.string.keyguard_password_enter_pin_code,
      // KeyguardStatusViewManager.LOCK_ICON);
    }

    // Poke the wakelock any time the text is selected or modified
    mPasswordEntry.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            mCallback.pokeWakelock();
          }
        });

    mQuickUnlock =
        (Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, 0)
            == 1);

    mPasswordEntry.addTextChangedListener(
        new TextWatcher() {
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void afterTextChanged(Editable s) {
            if (!mResuming) {
              mCallback.pokeWakelock();
            }
            if (mQuickUnlock) {
              String entry = mPasswordEntry.getText().toString();
              if (entry.length() > MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT
                  && mLockPatternUtils.checkPassword(entry)) {
                mCallback.keyguardDone(true);
                mCallback.reportSuccessfulUnlockAttempt();
                KeyStore.getInstance().password(entry);
              }
            }
          }
        });

    // If there's more than one IME, enable the IME switcher button
    View switchImeButton = findViewById(R.id.switch_ime_button);
    final InputMethodManager imm =
        (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (mIsAlpha && switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) {
      switchImeButton.setVisibility(View.VISIBLE);
      imeOrDeleteButtonVisible = true;
      switchImeButton.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              mCallback.pokeWakelock(); // Leave the screen on a bit longer
              imm.showInputMethodPicker();
            }
          });
    }

    // If no icon is visible, reset the left margin on the password field so the text is
    // still centered.
    if (!imeOrDeleteButtonVisible) {
      android.view.ViewGroup.LayoutParams params = mPasswordEntry.getLayoutParams();
      if (params instanceof MarginLayoutParams) {
        ((MarginLayoutParams) params).leftMargin = 0;
        mPasswordEntry.setLayoutParams(params);
      }
    }
  }