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

Commit f8163969 authored by Kris Alder's avatar Kris Alder
Browse files

revert 2G toggles to previous state when advanced protection mode is disabled

Bug: 383332123
Test: atest DisallowCellular2GTest
Flag: android.security.aapm_feature_disable_cellular_2g
Change-Id: I215b6a81993dc08cfbfe5e9f7de0cb3e6f442ca4
parent be97dd89
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public final class DisallowCellular2GAdvancedProtectionHook extends AdvancedProt
        mTelephonyManager = context.getSystemService(TelephonyManager.class);
        mSubscriptionManager = context.getSystemService(SubscriptionManager.class);

        setPolicy(enabled);
        onAdvancedProtectionChanged(enabled);
    }

    @NonNull
@@ -94,7 +94,8 @@ public final class DisallowCellular2GAdvancedProtectionHook extends AdvancedProt
        return false;
    }

    private void setPolicy(boolean enabled) {
    @Override
    public void onAdvancedProtectionChanged(boolean enabled) {
        if (enabled) {
            Slog.d(TAG, "Setting DISALLOW_CELLULAR_2G_GLOBALLY restriction");
            mDevicePolicyManager.addUserRestrictionGlobally(
@@ -105,21 +106,4 @@ public final class DisallowCellular2GAdvancedProtectionHook extends AdvancedProt
                    ADVANCED_PROTECTION_SYSTEM_ENTITY, UserManager.DISALLOW_CELLULAR_2G);
        }
    }

    @Override
    public void onAdvancedProtectionChanged(boolean enabled) {
        setPolicy(enabled);

        // Leave 2G disabled even if APM is disabled.
        if (!enabled) {
            for (TelephonyManager telephonyManager : getActiveTelephonyManagers()) {
                long oldAllowedTypes =
                        telephonyManager.getAllowedNetworkTypesForReason(
                                TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
                long newAllowedTypes = oldAllowedTypes & ~TelephonyManager.NETWORK_CLASS_BITMASK_2G;
                telephonyManager.setAllowedNetworkTypesForReason(
                        TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, newAllowedTypes);
            }
        }
    }
}