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:

/**
     * @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

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 的加密也会走到这边

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

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;
        }
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.

 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);
    }

相关推荐

  1. 图论相关代码(matlab)

    2023-12-28 15:20:09       17 阅读
  2. 链表的相关代码-顺序表

    2023-12-28 15:20:09       38 阅读
  3. ArcGIS Pro字段编号相关代码

    2023-12-28 15:20:09       31 阅读
  4. markdown绘制流程图相关代码片段记录

    2023-12-28 15:20:09       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-28 15:20:09       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-28 15:20:09       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-28 15:20:09       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-28 15:20:09       18 阅读

热门阅读

  1. Vue.set 方法原理

    2023-12-28 15:20:09       33 阅读
  2. PHP文件上传以及数据写入

    2023-12-28 15:20:09       33 阅读
  3. Crow:Middlewares的使用

    2023-12-28 15:20:09       35 阅读
  4. dockerfile——镜像构建工具详解及案例

    2023-12-28 15:20:09       25 阅读
  5. docker命令

    2023-12-28 15:20:09       23 阅读
  6. Docker的基础使用

    2023-12-28 15:20:09       33 阅读
  7. 北航人机交互复习

    2023-12-28 15:20:09       25 阅读
  8. 编程笔记 html5&css&js 008 HTML图片

    2023-12-28 15:20:09       31 阅读
  9. 在react中引用echarts

    2023-12-28 15:20:09       34 阅读