From: Rubin Xu Date: Mon, 16 Apr 2018 13:45:21 +0000 (+0100) Subject: Remove unnecessary disk access when loading synthetic password states X-Git-Tag: android-x86-9.0-r1~137^2~18^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=aa7b526f48323c16ad961f1a6e165b493588f17f;p=android-x86%2Fframeworks-base.git Remove unnecessary disk access when loading synthetic password states The on-demand creation of enclosing directory only needs to happen before writing synthetic password data, not during reads. Bug: 78027659 Test: runtest frameworks-services -p com.android.server.locksettings Change-Id: I2a95f919d0d440caacea8880e33663cc074b1567 --- diff --git a/services/core/java/com/android/server/locksettings/LockSettingsStorage.java b/services/core/java/com/android/server/locksettings/LockSettingsStorage.java index 8b3a1a6a09f9..98f1740aa986 100644 --- a/services/core/java/com/android/server/locksettings/LockSettingsStorage.java +++ b/services/core/java/com/android/server/locksettings/LockSettingsStorage.java @@ -484,6 +484,7 @@ class LockSettingsStorage { } public void writeSyntheticPasswordState(int userId, long handle, String name, byte[] data) { + ensureSyntheticPasswordDirectoryForUser(userId); writeFile(getSynthenticPasswordStateFilePathForUser(userId, handle, name), data); } @@ -541,14 +542,19 @@ class LockSettingsStorage { return new File(Environment.getDataSystemDeDirectory(userId) ,SYNTHETIC_PASSWORD_DIRECTORY); } - @VisibleForTesting - protected String getSynthenticPasswordStateFilePathForUser(int userId, long handle, - String name) { + /** Ensure per-user directory for synthetic password state exists */ + private void ensureSyntheticPasswordDirectoryForUser(int userId) { File baseDir = getSyntheticPasswordDirectoryForUser(userId); - String baseName = String.format("%016x.%s", handle, name); if (!baseDir.exists()) { baseDir.mkdir(); } + } + + @VisibleForTesting + protected String getSynthenticPasswordStateFilePathForUser(int userId, long handle, + String name) { + final File baseDir = getSyntheticPasswordDirectoryForUser(userId); + final String baseName = String.format("%016x.%s", handle, name); return new File(baseDir, baseName).getAbsolutePath(); }