locksettings: reduce visibility where unnecessarily broad
Reduce the visibility of methods and classes when possible, or add @VisibleForTesting. This is not comprehensive; it's just some cases I found in a quick scan through the code. I also didn't bother with some cases, like changing public to package private in classes that are package private anyway. Test: atest com.android.server.locksettings Change-Id: I2fdef595d68316b4832948bbf85b70411e684703
This commit is contained in:
@@ -375,7 +375,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
* @param profileUserId profile user Id
|
||||
* @param profileUserPassword profile original password (when it has separated lock).
|
||||
*/
|
||||
public void tieProfileLockIfNecessary(int profileUserId,
|
||||
private void tieProfileLockIfNecessary(int profileUserId,
|
||||
LockscreenCredential profileUserPassword) {
|
||||
if (DEBUG) Slog.v(TAG, "Check child profile lock for user: " + profileUserId);
|
||||
// Only for profiles that shares credential with parent
|
||||
@@ -713,7 +713,8 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
userHandle);
|
||||
}
|
||||
|
||||
public void onCleanupUser(int userId) {
|
||||
@VisibleForTesting
|
||||
void onCleanupUser(int userId) {
|
||||
hideEncryptionNotification(new UserHandle(userId));
|
||||
// User is stopped with its CE key evicted. Restore strong auth requirement to the default
|
||||
// flags after boot since stopping and restarting a user later is equivalent to rebooting
|
||||
@@ -725,7 +726,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public void onStartUser(final int userId) {
|
||||
private void onStartUser(final int userId) {
|
||||
maybeShowEncryptionNotificationForUser(userId, "user started");
|
||||
}
|
||||
|
||||
@@ -779,7 +780,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public void onUnlockUser(final int userId) {
|
||||
private void onUnlockUser(final int userId) {
|
||||
// Perform tasks which require locks in LSS on a handler, as we are callbacks from
|
||||
// ActivityManager.unlockUser()
|
||||
mHandler.post(new Runnable() {
|
||||
@@ -1222,7 +1223,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
* {@link #CREDENTIAL_TYPE_PATTERN}, {@link #CREDENTIAL_TYPE_PIN} and
|
||||
* {@link #CREDENTIAL_TYPE_PASSWORD}
|
||||
*/
|
||||
public int getCredentialTypeInternal(int userId) {
|
||||
private int getCredentialTypeInternal(int userId) {
|
||||
if (userId == USER_FRP) {
|
||||
return getFrpCredentialType();
|
||||
}
|
||||
@@ -1802,6 +1803,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting /** Note: this method is overridden in unit tests */
|
||||
protected boolean isCredentialSharableWithParent(int userId) {
|
||||
return getUserManagerFromCache(userId).isCredentialSharableWithParent();
|
||||
}
|
||||
@@ -2560,7 +2562,7 @@ public class LockSettingsService extends ILockSettings.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized IGateKeeperService getGateKeeperService() {
|
||||
private synchronized IGateKeeperService getGateKeeperService() {
|
||||
if (mGateKeeperService != null) {
|
||||
return mGateKeeperService;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.android.internal.widget.LockPatternUtils.StrongAuthTracker;
|
||||
/**
|
||||
* Keeps track of requests for strong authentication.
|
||||
*/
|
||||
@VisibleForTesting // public visibility is needed for Mockito
|
||||
public class LockSettingsStrongAuth {
|
||||
|
||||
private static final String TAG = "LockSettings";
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.security.keystore.UserNotAuthenticatedException;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.widget.LockscreenCredential;
|
||||
|
||||
@@ -60,6 +61,7 @@ import javax.crypto.spec.GCMParameterSpec;
|
||||
* <p> The encrypted credential is stored in-memory only so the cache does not persist across
|
||||
* reboots.
|
||||
*/
|
||||
@VisibleForTesting // public visibility is needed for Mockito
|
||||
public class ManagedProfilePasswordCache {
|
||||
|
||||
private static final String TAG = "ManagedProfilePasswordCache";
|
||||
|
||||
@@ -43,7 +43,7 @@ import java.util.Set;
|
||||
* If a /metadata partition does not exist, GSIs are not supported, and PasswordSlotManager will
|
||||
* simply not persist the slot mapping.
|
||||
*/
|
||||
public class PasswordSlotManager {
|
||||
class PasswordSlotManager {
|
||||
private static final String TAG = "PasswordSlotManager";
|
||||
|
||||
private static final String GSI_RUNNING_PROP = "ro.gsid.image_running";
|
||||
|
||||
@@ -49,7 +49,7 @@ import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class SyntheticPasswordCrypto {
|
||||
class SyntheticPasswordCrypto {
|
||||
private static final String TAG = "SyntheticPasswordCrypto";
|
||||
private static final int AES_GCM_KEY_SIZE = 32; // AES-256-GCM
|
||||
private static final int AES_GCM_IV_SIZE = 12;
|
||||
|
||||
@@ -112,7 +112,7 @@ import java.util.Set;
|
||||
* WEAVER_SLOT: Contains the Weaver slot number used by this protector. Only exists if the
|
||||
* protector uses Weaver.
|
||||
*/
|
||||
public class SyntheticPasswordManager {
|
||||
class SyntheticPasswordManager {
|
||||
private static final String SP_BLOB_NAME = "spblob";
|
||||
private static final String SP_E0_NAME = "e0";
|
||||
private static final String SP_P1_NAME = "p1";
|
||||
@@ -394,7 +394,7 @@ public class SyntheticPasswordManager {
|
||||
}
|
||||
}
|
||||
|
||||
static class SyntheticPasswordBlob {
|
||||
private static class SyntheticPasswordBlob {
|
||||
byte mVersion;
|
||||
byte mProtectorType;
|
||||
byte[] mContent;
|
||||
@@ -431,7 +431,7 @@ public class SyntheticPasswordManager {
|
||||
static final int TOKEN_TYPE_STRONG = 0;
|
||||
static final int TOKEN_TYPE_WEAK = 1;
|
||||
|
||||
static class TokenData {
|
||||
private static class TokenData {
|
||||
byte[] secdiscardableOnDisk;
|
||||
byte[] weaverSecret;
|
||||
byte[] aggregatedSecret;
|
||||
@@ -1623,7 +1623,7 @@ public class SyntheticPasswordManager {
|
||||
SyntheticPasswordCrypto.destroyProtectorKey(keyAlias);
|
||||
}
|
||||
|
||||
public static long generateProtectorId() {
|
||||
private static long generateProtectorId() {
|
||||
SecureRandom rng = new SecureRandom();
|
||||
long result;
|
||||
do {
|
||||
@@ -1685,15 +1685,17 @@ public class SyntheticPasswordManager {
|
||||
return Arrays.copyOf(key, mWeaverConfig.keySize);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected long sidFromPasswordHandle(byte[] handle) {
|
||||
return nativeSidFromPasswordHandle(handle);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected byte[] scrypt(byte[] password, byte[] salt, int n, int r, int p, int outLen) {
|
||||
return new Scrypt().scrypt(password, salt, n, r, p, outLen);
|
||||
}
|
||||
|
||||
native long nativeSidFromPasswordHandle(byte[] handle);
|
||||
private native long nativeSidFromPasswordHandle(byte[] handle);
|
||||
|
||||
@VisibleForTesting
|
||||
static byte[] bytesToHex(byte[] bytes) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.nio.ByteBuffer;
|
||||
* A versioned and serializable wrapper around {@link PasswordMetrics},
|
||||
* for long-term persistence on disk.
|
||||
*/
|
||||
public class VersionedPasswordMetrics {
|
||||
class VersionedPasswordMetrics {
|
||||
private static final int VERSION_1 = 1;
|
||||
|
||||
private final PasswordMetrics mMetrics;
|
||||
|
||||
Reference in New Issue
Block a user