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

Commit 13c5ef45 authored by Kris Alder's avatar Kris Alder Committed by Android (Google) Code Review
Browse files

Merge "revert 2G toggles to previous state when advanced protection mode is disabled" into main

parents 66a8035e f8163969
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);
            }
        }
    }
}