android.os.StrictMode#noteSlowCall ( )源码实例Demo

下面列出了android.os.StrictMode#noteSlowCall ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: armadillo   文件: ArmadilloBcryptKeyStretcher.java
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(byte[] salt, char[] password, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    Bytes passwordBytes = Bytes.empty();
    try {
        passwordBytes = Bytes.from(password);
        return BCrypt.with(BCrypt.Version.VERSION_2A).hashRaw(logRounds,
                HKDF.fromHmacSha256().expand(salt, "bcrypt-salt".getBytes(), 16),
            HKDF.fromHmacSha256().expand(passwordBytes.array(), "bcrypt-pw".getBytes(), 71)).rawHash;
    } finally {
        passwordBytes.mutable().secureWipe();
    }
}
 
源代码2 项目: armadillo   文件: SecureSharedPreferences.java
@Override
public boolean isValidPassword() {
    StrictMode.noteSlowCall("checking password should only be done in a background thread");
    if (!supportVerifyPassword) {
        throw new UnsupportedOperationException("support verify password is not enabled");
    }
    try {
        String storedValue = getString(PASSWORD_VALIDATION_KEY, null);
        return storedValue != null && Bytes.parseBase64(storedValue).equalsConstantTime(preferencesSalt);
    } catch (SecureSharedPreferenceCryptoException e) {
        return false;
    }
}
 
源代码3 项目: armadillo   文件: SecureSharedPreferences.java
@SuppressLint("ApplySharedPref")
@Override
public void changePassword(@Nullable char[] newPassword, @Nullable KeyStretchingFunction newKsFunction) {
    StrictMode.noteSlowCall("changing password should only be done in a background thread");

    newPassword = newPassword == null || newPassword.length == 0 ? null : newPassword;

    SharedPreferences.Editor editor = this.edit();
    KeyStretchingFunction currentFunction = encryptionProtocol.getKeyStretchingFunction();

    for (String keyHash : getAll().keySet()) {
        encryptionProtocol.setKeyStretchingFunction(currentFunction);
        if (!reencryptStringType(newPassword, (Editor) editor, keyHash, newKsFunction)) {
            reencryptStringSetType(newPassword, (Editor) editor, keyHash, newKsFunction);
        }
    }
    editor.commit();

    if (newKsFunction != null) {
        encryptionProtocol.setKeyStretchingFunction(newKsFunction);
    }

    if (password != null) {
        password.wipe();
    }
    password = encryptionProtocol.obfuscatePassword(newPassword);
}
 
源代码4 项目: android_9.0.0_r45   文件: WebView.java
/**
 * Finds all instances of find on the page and highlights them.
 * Notifies any registered {@link FindListener}.
 *
 * @param find the string to find
 * @return the number of occurrences of the String "find" that were found
 * @deprecated {@link #findAllAsync} is preferred.
 * @see #setFindListener
 */
@Deprecated
public int findAll(String find) {
    checkThread();
    StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
    return mProvider.findAll(find);
}
 
源代码5 项目: armadillo   文件: PBKDF2KeyStretcher.java
/**
 * Computes the PBKDF2 hash of a password.
 *
 * @param password   the password to hash.
 * @param salt       the salt
 * @param iterations the iteration count (slowness factor)
 * @param outBytes   the length of the hash to compute in bytes
 * @return the PBDKF2 hash of the password
 */
private static byte[] pbkdf2(Provider provider, char[] password, byte[] salt, int iterations, int outBytes) throws NoSuchAlgorithmException, InvalidKeySpecException {
    StrictMode.noteSlowCall("pbkdf2 is a very expensive call and should not be done on the main thread");
    PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, outBytes * 8);
    SecretKeyFactory skf = provider != null ? SecretKeyFactory.getInstance(PBKDF2_ALGORITHM, provider) : SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);
    return skf.generateSecret(spec).getEncoded();
}
 
源代码6 项目: armadillo   文件: BrokenBcryptKeyStretcher.java
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(char[] password, byte[] salt, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    return BCrypt.with(CUSTOM_LEGACY_VERSION, new SecureRandom(), rawPassword -> Bytes.wrapNullSafe(rawPassword).copy().array()).hash(logRounds,
        createLegacySalt(salt),
        createLegacyPassword(password, salt));
}
 
源代码7 项目: armadillo   文件: BrokenBcryptKeyStretcherTest.java
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(char[] password, byte[] salt, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    return Bytes.from(BCrypt.hashpw(String.valueOf(password) + Bytes.wrap(salt).encodeHex(), generateSalt(salt, logRounds))).array();
}