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

Commit 29846f67 authored by Victor Hsieh's avatar Victor Hsieh
Browse files

Set SECURE_FRP_MODE for backward compatibility on deactivation

Let's try to keep the mode in sync as a best effort. We expect to
replace all existing SECURE_FRP_MODE check with the new API later.

Bug: 290312729
Test: manually deactivate and see the setting change via adb shell
Change-Id: I20c6210532b6c775bc43447114448ef29e87c839
parent 778cbd12
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -275,10 +275,7 @@ public class PersistentDataBlockService extends SystemService {
            if (mFrpEnforced) {
                automaticallyDeactivateFrpIfPossible();
                setOemUnlockEnabledProperty(doGetOemUnlockEnabled());
                // Set the SECURE_FRP_MODE flag, for backward compatibility with clients who use it.
                // They should switch to calling #isFrpActive().
                Settings.Global.putInt(mContext.getContentResolver(),
                        Settings.Global.SECURE_FRP_MODE, mFrpActive ? 1 : 0);
                setOldSettingForBackworkCompatibility(mFrpActive);
            } else {
                formatIfOemUnlockEnabled();
            }
@@ -292,6 +289,13 @@ public class PersistentDataBlockService extends SystemService {
        mInitDoneSignal.countDown();
    }

    private void setOldSettingForBackworkCompatibility(boolean isActive) {
        // Set the SECURE_FRP_MODE flag, for backward compatibility with clients who use it.
        // They should switch to calling #isFrpActive().
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.SECURE_FRP_MODE, isActive ? 1 : 0);
    }

    private void setOemUnlockEnabledProperty(boolean oemUnlockEnabled) {
        setProperty(OEM_UNLOCK_PROP, oemUnlockEnabled ? "1" : "0");
    }
@@ -628,6 +632,7 @@ public class PersistentDataBlockService extends SystemService {
                Slog.w(TAG, "Upgrading from Android 14 or lower, defaulting FRP secret");
                writeFrpMagicAndDefaultSecret();
                mFrpActive = false;
                setOldSettingForBackworkCompatibility(mFrpActive);
                return true;
            }

@@ -699,6 +704,7 @@ public class PersistentDataBlockService extends SystemService {
    void activateFrp() {
        synchronized (mLock) {
            mFrpActive = true;
            setOldSettingForBackworkCompatibility(mFrpActive);
        }
    }

@@ -740,6 +746,7 @@ public class PersistentDataBlockService extends SystemService {
        if (MessageDigest.isEqual(secret, partitionSecret)) {
            mFrpActive = false;
            Slog.i(TAG, "FRP secret matched, FRP deactivated.");
            setOldSettingForBackworkCompatibility(mFrpActive);
            return true;
        } else {
            Slog.e(TAG,
@@ -1315,6 +1322,7 @@ public class PersistentDataBlockService extends SystemService {
        public boolean deactivateFactoryResetProtectionWithoutSecret() {
            synchronized (mLock) {
                mFrpActive = false;
                setOldSettingForBackworkCompatibility(/* isActive */ mFrpActive);
            }
            return true;
        }