Android Security PIN 相关代码

开发项目遇到一个问题,具体描述及复制步骤如下:

就是开启"Enhanced PIN privacy"(增强的PIN隐私)的时候输入秘密的时候还是会显示数字

如下图,应该是直接是"." 不应该出现PIN 密码

想要的效果如下图:

设置的步骤如下图:

其中涉及到的部分code如下:

/frameworks/base/core/java/com/android/internal/widget/LockPatternUtils.java

/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputViewController.java

/frameworks/base/packages/SystemUI/src/com/android/keyguard/PasswordTextView.java

/frameworks/base/services/core/java/com/android/server/locksettings/LockSettingsStorage.java

I.LockPatternUtils.java:

java 复制代码
/**
     * @return Whether enhanced pin privacy is enabled.
     */
    public boolean isPinEnhancedPrivacyEnabled(int userId) {
        return getBoolean(LOCK_PIN_ENHANCED_PRIVACY, false, userId);
    }

    /**
     * Set whether enhanced pin privacy is enabled.
     */
    public void setPinEnhancedPrivacyEnabled(boolean enabled, int userId) {
        setBoolean(LOCK_PIN_ENHANCED_PRIVACY, enabled, userId);
    }

private boolean getBoolean(String secureSettingKey, boolean defaultValue, int userId) {
        Log.i("TD","LockPatternUtils----->getBoolean: "+secureSettingKey);
        try {
            return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId);
        } catch (RemoteException re) {
            return defaultValue;
        }
    }

    private void setBoolean(String secureSettingKey, boolean enabled, int userId) {
        Log.i("TD","LockPatternUtils----->setsetBoolean: "+secureSettingKey);
        try {
            getLockSettings().setBoolean(secureSettingKey, enabled, userId);
        } catch (RemoteException re) {
            // What can we do?
            Log.e(TAG, "Couldn't write boolean " + secureSettingKey + re);
        }
    }

II.KeyguardPinBasedInputViewController.java

java 复制代码
protected void onViewAttached() {
        super.onViewAttached();

        Log.i("TD","KeyguardPinBasedInputViewController------------->onViewAttached");
        boolean showAnimations = !mLockPatternUtils
                .isPinEnhancedPrivacyEnabled(KeyguardUpdateMonitor.getCurrentUser());
        mPasswordEntry.setShowPassword(showAnimations);
        for (NumPadKey button : mView.getButtons()) {
            button.setOnTouchListener((v, event) -> {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    mFalsingCollector.avoidGesture();
                }
                return false;
            });
            button.setAnimationEnabled(showAnimations);
        }
        mPasswordEntry.setOnKeyListener(mOnKeyListener);
        mPasswordEntry.setUserActivityListener(this::onUserInput);

        View deleteButton = mView.findViewById(R.id.delete_button);
        deleteButton.setOnTouchListener(mActionButtonTouchListener);
        deleteButton.setOnClickListener(v -> {
            // check for time-based lockouts
            Log.i("TD","KeyguardPinBasedInputViewController------------->deleteButton");
            if (mPasswordEntry.isEnabled()) {
                mPasswordEntry.deleteLastChar();
            }
        });
        deleteButton.setOnLongClickListener(v -> {
            // check for time-based lockouts
            if (mPasswordEntry.isEnabled()) {
                mView.resetPasswordText(true /* animate */, true /* announce */);
            }
            Log.i("TD","KeyguardPinBasedInputViewController------------->deleteButton#longPress");
            mView.doHapticKeyClick();
            return true;
        });

        View okButton = mView.findViewById(R.id.key_enter);
        if (okButton != null) {
            okButton.setOnTouchListener(mActionButtonTouchListener);
            okButton.setOnClickListener(v -> {
                Log.i("TD","KeyguardPinBasedInputViewController------------->okButton");
                if (mPasswordEntry.isEnabled()) {
                    verifyPasswordAndUnlock();
                }
            });
            okButton.setOnHoverListener(mLiftToActivateListener);
        }
    }

III.LockSettingsStorage.java
Pattern 的加密也会走到这边

java 复制代码
public void setBoolean(String key, boolean value, int userId) {
        Log.i("TD","LockSettingsStorage*******>setBoolean-=-key is: "+key + "  **value: "+value);
        setString(key, value ? "1" : "0", userId);
    }
    
    public void setString(String key, String value, int userId) {
        Preconditions.checkArgument(userId != USER_FRP, "cannot store lock settings for FRP user");

        writeKeyValue(key, value, userId);
        if (ArrayUtils.contains(SETTINGS_TO_BACKUP, key)) {
            BackupManager.dataChanged("com.android.providers.settings");
        }
    }
    
 public void writeKeyValue(String key, String value, int userId) {
        writeKeyValue(mOpenHelper.getWritableDatabase(), key, value, userId);
    }

    @VisibleForTesting
    public void writeKeyValue(SQLiteDatabase db, String key, String value, int userId) {
        Log.i("TD","LockSettingsService---->writeKeyValue");
        Log.i("TD","LockSettingsService---->COLUMN_KEY: "+key);
        Log.i("TD","LockSettingsService---->COLUMN_USERID: "+userId);
        Log.i("TD","LockSettingsService---->COLUMN_VALUE: "+value);
        ContentValues cv = new ContentValues();
        cv.put(COLUMN_KEY, key);
        cv.put(COLUMN_USERID, userId);
        cv.put(COLUMN_VALUE, value);

        db.beginTransaction();
        try {
            db.delete(TABLE, COLUMN_KEY + "=? AND " + COLUMN_USERID + "=?",
                    new String[] {key, Integer.toString(userId)});
            db.insert(TABLE, null, cv);
            db.setTransactionSuccessful();
            mCache.putKeyValue(key, value, userId);
        } finally {
            db.endTransaction();
        }
        dispatchChange(this);
    }    

IV.PasswordTextView.java

java 复制代码
private void startDotAppearAnimation(long delay) {
            cancelAnimator(dotAnimator);
            if (!mShowPassword) {
                // We perform an overshoot animation
                ValueAnimator overShootAnimator = ValueAnimator.ofFloat(currentDotSizeFactor,
                        DOT_OVERSHOOT_FACTOR);
                overShootAnimator.addUpdateListener(dotSizeUpdater);
                overShootAnimator.setInterpolator(mAppearInterpolator);
                long overShootDuration = (long) (DOT_APPEAR_DURATION_OVERSHOOT
                        * OVERSHOOT_TIME_POSITION);
                overShootAnimator.setDuration(overShootDuration);
                ValueAnimator settleBackAnimator = ValueAnimator.ofFloat(DOT_OVERSHOOT_FACTOR,
                        1.0f);
                settleBackAnimator.addUpdateListener(dotSizeUpdater);
                settleBackAnimator.setDuration(DOT_APPEAR_DURATION_OVERSHOOT - overShootDuration);
                settleBackAnimator.addListener(dotFinishListener);
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playSequentially(overShootAnimator, settleBackAnimator);
                animatorSet.setStartDelay(delay);
                animatorSet.start();
                dotAnimator = animatorSet;
            } else {
                ValueAnimator growAnimator = ValueAnimator.ofFloat(currentDotSizeFactor, 1.0f);
                growAnimator.addUpdateListener(dotSizeUpdater);
                growAnimator.setDuration((long) (APPEAR_DURATION * (1.0f - currentDotSizeFactor)));
                growAnimator.addListener(dotFinishListener);
                growAnimator.setStartDelay(delay);
                growAnimator.start();
                dotAnimator = growAnimator;
            }
            dotAnimationIsGrowing = true;
        }
java 复制代码
void startAppearAnimation() {
            boolean dotNeedsAnimation = !mShowPassword
                    && (dotAnimator == null || !dotAnimationIsGrowing);
            boolean textNeedsAnimation = mShowPassword
                    && (textAnimator == null || !textAnimationIsGrowing);
            boolean widthNeedsAnimation = (widthAnimator == null || !widthAnimationIsGrowing);
            if (dotNeedsAnimation) {
                startDotAppearAnimation(0);
            }
            if (textNeedsAnimation) {
                startTextAppearAnimation();
            }
            if (widthNeedsAnimation) {
                startWidthAppearAnimation();
            }
            if (mShowPassword) {
                postDotSwap(TEXT_VISIBILITY_DURATION);
            }
        }

出现问题的地方就是下面代码注释的部分,这个值为True.

java 复制代码
 public void append(char c) {
        if (ZTelephonyManagerCommon.IS_ZEBRA_WWAN
            && (mPasswordMaxSize != -1)
            && (mText.length() >= mPasswordMaxSize)) {
            return;
        }
        int visibleChars = mTextChars.size();
        CharSequence textbefore = getTransformedText();
        mText = mText + c;
        int newLength = mText.length();
        CharState charState;
        if (newLength > visibleChars) {
            charState = obtainCharState(c);
            mTextChars.add(charState);
        } else {
            charState = mTextChars.get(newLength - 1);
            charState.whichChar = c;
        }

//        if (XXX.orElse(false)) {
//            mShowPassword = Settings.System.getInt(mContext.getContentResolver(),
//                    Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;
//        }
        Log.i("TD","mShowPassword--------->"+Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.TEXT_SHOW_PASSWORD, 1));
        charState.startAppearAnimation();

        // ensure that the previous element is being swapped
        if (newLength > 1) {
            CharState previousState = mTextChars.get(newLength - 2);
            if (previousState.isDotSwapPending) {
                previousState.swapToDotWhenAppearFinished();
            }
        }
        userActivity();
        sendAccessibilityEventTypeViewTextChanged(textbefore, textbefore.length(), 0, 1);
    }
相关推荐
Yawesh_best1 小时前
MySQL(5)【数据类型 —— 字符串类型】
android·mysql·adb
曾经的三心草4 小时前
Mysql之约束与事件
android·数据库·mysql·事件·约束
guoruijun_2012_48 小时前
fastadmin多个表crud连表操作步骤
android·java·开发语言
Winston Wood8 小时前
一文了解Android中的AudioFlinger
android·音频
B.-10 小时前
Flutter 应用在真机上调试的流程
android·flutter·ios·xcode·android-studio
有趣的杰克10 小时前
Flutter【04】高性能表单架构设计
android·flutter·dart
大耳猫15 小时前
主动测量View的宽高
android·ui
帅次18 小时前
Android CoordinatorLayout:打造高效交互界面的利器
android·gradle·android studio·rxjava·android jetpack·androidx·appcompat
枯骨成佛18 小时前
Android中Crash Debug技巧
android
kim56591 天前
android studio 更改gradle版本方法(备忘)
android·ide·gradle·android studio