Loading services/core/java/com/android/server/locksettings/RebootEscrowManager.java +29 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ import android.annotation.UserIdInt; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.os.Handler; import android.os.SystemClock; import android.os.SystemProperties; Loading Loading @@ -126,6 +129,7 @@ class RebootEscrowManager { ERROR_UNLOCK_ALL_USERS, ERROR_PROVIDER_MISMATCH, ERROR_KEYSTORE_FAILURE, ERROR_NO_NETWORK, }) @Retention(RetentionPolicy.SOURCE) @interface RebootEscrowErrorCode { Loading @@ -139,6 +143,7 @@ class RebootEscrowManager { static final int ERROR_UNLOCK_ALL_USERS = 5; static final int ERROR_PROVIDER_MISMATCH = 6; static final int ERROR_KEYSTORE_FAILURE = 7; static final int ERROR_NO_NETWORK = 8; private @RebootEscrowErrorCode int mLoadEscrowDataErrorCode = ERROR_NONE; Loading Loading @@ -235,6 +240,23 @@ class RebootEscrowManager { "server_based_ror_enabled", false); } public boolean isNetworkConnected() { final ConnectivityManager connectivityManager = mContext.getSystemService(ConnectivityManager.class); if (connectivityManager == null) { return false; } Network activeNetwork = connectivityManager.getActiveNetwork(); NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork); return networkCapabilities != null && networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_INTERNET) && networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_VALIDATED); } public Context getContext() { return mContext; } Loading Loading @@ -363,7 +385,11 @@ class RebootEscrowManager { } Slog.w(TAG, "Failed to load reboot escrow data after " + attemptNumber + " attempts"); if (mInjector.serverBasedResumeOnReboot() && !mInjector.isNetworkConnected()) { mLoadEscrowDataErrorCode = ERROR_NO_NETWORK; } else { mLoadEscrowDataErrorCode = ERROR_RETRY_COUNT_EXHAUSTED; } onGetRebootEscrowKeyFailed(users, attemptNumber); } Loading Loading @@ -471,6 +497,8 @@ class RebootEscrowManager { mLoadEscrowDataErrorCode = ERROR_UNKNOWN; } Slog.i(TAG, "Reporting RoR recovery metrics, success: " + success + ", service type: " + serviceType + ", error code: " + mLoadEscrowDataErrorCode); // TODO(179105110) report the duration since boot complete. mInjector.reportMetric(success, mLoadEscrowDataErrorCode, serviceType, attemptCount, escrowDurationInSeconds, vbmetaDigestStatus, -1); Loading services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java +17 −2 Original line number Diff line number Diff line Loading @@ -165,7 +165,17 @@ public class RebootEscrowManagerTests { mRebootEscrow = null; mServerBased = true; RebootEscrowProviderServerBasedImpl.Injector injector = new RebootEscrowProviderServerBasedImpl.Injector(serviceConnection); new RebootEscrowProviderServerBasedImpl.Injector(serviceConnection) { @Override long getServiceTimeoutInSeconds() { return 30; } @Override long getServerBlobLifetimeInMillis() { return 600_000; } }; mDefaultRebootEscrowProvider = new RebootEscrowProviderServerBasedImpl( storage, injector); mUserManager = userManager; Loading @@ -188,6 +198,11 @@ public class RebootEscrowManagerTests { return mServerBased; } @Override public boolean isNetworkConnected() { return false; } @Override public RebootEscrowProviderInterface createRebootEscrowProviderIfNeeded() { mRebootEscrowProviderInUse = mDefaultRebootEscrowProvider; Loading Loading @@ -602,7 +617,7 @@ public class RebootEscrowManagerTests { // Sleep 5s for the retry to complete Thread.sleep(5 * 1000); assertFalse(metricsSuccessCaptor.getValue()); assertEquals(Integer.valueOf(RebootEscrowManager.ERROR_RETRY_COUNT_EXHAUSTED), assertEquals(Integer.valueOf(RebootEscrowManager.ERROR_NO_NETWORK), metricsErrorCodeCaptor.getValue()); } Loading Loading
services/core/java/com/android/server/locksettings/RebootEscrowManager.java +29 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,9 @@ import android.annotation.UserIdInt; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.os.Handler; import android.os.SystemClock; import android.os.SystemProperties; Loading Loading @@ -126,6 +129,7 @@ class RebootEscrowManager { ERROR_UNLOCK_ALL_USERS, ERROR_PROVIDER_MISMATCH, ERROR_KEYSTORE_FAILURE, ERROR_NO_NETWORK, }) @Retention(RetentionPolicy.SOURCE) @interface RebootEscrowErrorCode { Loading @@ -139,6 +143,7 @@ class RebootEscrowManager { static final int ERROR_UNLOCK_ALL_USERS = 5; static final int ERROR_PROVIDER_MISMATCH = 6; static final int ERROR_KEYSTORE_FAILURE = 7; static final int ERROR_NO_NETWORK = 8; private @RebootEscrowErrorCode int mLoadEscrowDataErrorCode = ERROR_NONE; Loading Loading @@ -235,6 +240,23 @@ class RebootEscrowManager { "server_based_ror_enabled", false); } public boolean isNetworkConnected() { final ConnectivityManager connectivityManager = mContext.getSystemService(ConnectivityManager.class); if (connectivityManager == null) { return false; } Network activeNetwork = connectivityManager.getActiveNetwork(); NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork); return networkCapabilities != null && networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_INTERNET) && networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_VALIDATED); } public Context getContext() { return mContext; } Loading Loading @@ -363,7 +385,11 @@ class RebootEscrowManager { } Slog.w(TAG, "Failed to load reboot escrow data after " + attemptNumber + " attempts"); if (mInjector.serverBasedResumeOnReboot() && !mInjector.isNetworkConnected()) { mLoadEscrowDataErrorCode = ERROR_NO_NETWORK; } else { mLoadEscrowDataErrorCode = ERROR_RETRY_COUNT_EXHAUSTED; } onGetRebootEscrowKeyFailed(users, attemptNumber); } Loading Loading @@ -471,6 +497,8 @@ class RebootEscrowManager { mLoadEscrowDataErrorCode = ERROR_UNKNOWN; } Slog.i(TAG, "Reporting RoR recovery metrics, success: " + success + ", service type: " + serviceType + ", error code: " + mLoadEscrowDataErrorCode); // TODO(179105110) report the duration since boot complete. mInjector.reportMetric(success, mLoadEscrowDataErrorCode, serviceType, attemptCount, escrowDurationInSeconds, vbmetaDigestStatus, -1); Loading
services/tests/servicestests/src/com/android/server/locksettings/RebootEscrowManagerTests.java +17 −2 Original line number Diff line number Diff line Loading @@ -165,7 +165,17 @@ public class RebootEscrowManagerTests { mRebootEscrow = null; mServerBased = true; RebootEscrowProviderServerBasedImpl.Injector injector = new RebootEscrowProviderServerBasedImpl.Injector(serviceConnection); new RebootEscrowProviderServerBasedImpl.Injector(serviceConnection) { @Override long getServiceTimeoutInSeconds() { return 30; } @Override long getServerBlobLifetimeInMillis() { return 600_000; } }; mDefaultRebootEscrowProvider = new RebootEscrowProviderServerBasedImpl( storage, injector); mUserManager = userManager; Loading @@ -188,6 +198,11 @@ public class RebootEscrowManagerTests { return mServerBased; } @Override public boolean isNetworkConnected() { return false; } @Override public RebootEscrowProviderInterface createRebootEscrowProviderIfNeeded() { mRebootEscrowProviderInUse = mDefaultRebootEscrowProvider; Loading Loading @@ -602,7 +617,7 @@ public class RebootEscrowManagerTests { // Sleep 5s for the retry to complete Thread.sleep(5 * 1000); assertFalse(metricsSuccessCaptor.getValue()); assertEquals(Integer.valueOf(RebootEscrowManager.ERROR_RETRY_COUNT_EXHAUSTED), assertEquals(Integer.valueOf(RebootEscrowManager.ERROR_NO_NETWORK), metricsErrorCodeCaptor.getValue()); } Loading