Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa535537 authored by Tianjie Xu's avatar Tianjie Xu Committed by Automerger Merge Worker
Browse files

Merge "Add an error code for RoR failure due to no network" am: 6890be92

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1716971

Change-Id: I70fbb3844af94d4f15ba734f5d52d4bb59cfbded
parents 2d170271 6890be92
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -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;
@@ -126,6 +129,7 @@ class RebootEscrowManager {
            ERROR_UNLOCK_ALL_USERS,
            ERROR_PROVIDER_MISMATCH,
            ERROR_KEYSTORE_FAILURE,
            ERROR_NO_NETWORK,
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface RebootEscrowErrorCode {
@@ -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;

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

@@ -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);
+17 −2
Original line number Diff line number Diff line
@@ -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;
@@ -188,6 +198,11 @@ public class RebootEscrowManagerTests {
            return mServerBased;
        }

        @Override
        public boolean isNetworkConnected() {
            return false;
        }

        @Override
        public RebootEscrowProviderInterface createRebootEscrowProviderIfNeeded() {
            mRebootEscrowProviderInUse = mDefaultRebootEscrowProvider;
@@ -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());
    }