Settings Non-English language password on android phone?

陌路散爱 提交于 2020-01-17 04:56:09

问题


With Reference to this question on android stack, i have a solution to do which allows android phone to provide support for setting non-english language password.

My phones SRC is based on stock-android which is not allowing me to set password which is non-ascii standards like Hebrew.

Based from AOSP source code that handles the password input for lock screen, ChooseLockPassword.java, inside validatePassword() (line 292), here is a snippet that will show the "illegal character" message (from line 311):

// allow non control Latin-1 characters only
if (c < 32 || c > 127) {
    return getString(R.string.lockpassword_illegal_character);
}

I have commented out this part but i don't think so this will work. [Waiting to be Flashed] There are no such question for this condition, i need help for cracking the possibility for doing this any "Work around" will also do.


回答1:


So after fighting few days i got a workaround by implementing my method for it.

private String validateHebrewPassword(String password)
        {
                if (password.length() < mPasswordMinLength) {
                        return getString(mIsAlphaMode ?
                                        R.string.lockpassword_password_too_short
                                        : R.string.lockpassword_pin_too_short, mPasswordMinLength);
                }
                if (password.length() > mPasswordMaxLength) {
                        return getString(mIsAlphaMode ?
                                        R.string.lockpassword_password_too_long
                                        : R.string.lockpassword_pin_too_long, mPasswordMaxLength + 1);
                }

            for (int i = 0; i < password.length(); i++)
            {
                char c = password.charAt(i);
                        System.out.println("Validate Hebrew Password Success "+ " Char "+c+" for password "+password+ " langauage "+locale);

            }
            return null;
        }

And modiying its validatePasswor() caller a bit specific to hebrew like:

    private void handleNext() {
                final String pin = mPasswordEntry.getText().toString();
                if (TextUtils.isEmpty(pin)) {
                    return;
                }
                String errorMsg = null;
                if (mUiStage == Stage.Introduction) 
                {
                    String locale = java.util.Locale.getDefault().getLanguage();
                    if(locale.equals("iw")) //Specific Hebrew check
                    { 
                        errorMsg = validateHebrewPassword(pin); //New Method
                    }
                    else
                    {
                        errorMsg = validatePassword(pin); //AOSP Method
                    }
                    if (errorMsg == null) 
                    {
                        mFirstPin = pin;
                        mPasswordEntry.setText("");
                        updateStage(Stage.NeedToConfirm);
                    }
                } else if (mUiStage == Stage.NeedToConfirm) {
                    if (mFirstPin.equals(pin)) {
                        final boolean isFallback = getActivity().getIntent().getBooleanExtra(
                                LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false);
                        mLockPatternUtils.clearLock(isFallback);
                        mLockPatternUtils.saveLockPassword(pin, mRequestedQuality, isFallback);
                        getActivity().setResult(RESULT_FINISHED);
                        getActivity().finish();
                    } else {
                        CharSequence tmp = mPasswordEntry.getText();
                        if (tmp != null) {
                            Selection.setSelection((Spannable) tmp, 0, tmp.length());
                        }
                        updateStage(Stage.ConfirmWrong);
                    }
                }
                if (errorMsg != null) {
                    showError(errorMsg, mUiStage);
                }
            }

private void updateUi() {
            String password = mPasswordEntry.getText().toString();
            final int length = password.length();
            if (mUiStage == Stage.Introduction && length > 0) {
                if (length < mPasswordMinLength) {
                    String msg = getString(mIsAlphaMode ? R.string.lockpassword_password_too_short
                            : R.string.lockpassword_pin_too_short, mPasswordMinLength);
                    mHeaderText.setText(msg);
                    mNextButton.setEnabled(false);
                } else 
                {
                    String locale = java.util.Locale.getDefault().getLanguage();
                    String error = null;
                    if(locale.equals("iw")) //Specific Hebrew check
                    { 
                        error = validateHebrewPassword(password); //New method
                    }
                    else
                    {
                        error = validatePassword(password); //AOSP Method
                    }
                    if (error != null) {
                        mHeaderText.setText(error);
                        mNextButton.setEnabled(false);
                    } else {
                        mHeaderText.setText(R.string.lockpassword_press_continue);
                        mNextButton.setEnabled(true);
                    }
                }
            } else {
                mHeaderText.setText(mIsAlphaMode ? mUiStage.alphaHint : mUiStage.numericHint);
                mNextButton.setEnabled(length > 0);
            }
            mNextButton.setText(mUiStage.buttonText);
        }


来源:https://stackoverflow.com/questions/27182362/settings-non-english-language-password-on-android-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!