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

Commit dde78da9 authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor
Browse files

parts: CountryCodeService: Add boot cooldown

 * Add a 30s boot cooldown period; ignore country code changes
   received during this window to avoid reboots from stale or
   transient broadcasts right after startup.
parent 098afc44
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public class CountryCodeService extends Service {

    private PowerManager mPowerManager;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private long mServiceStartMs;

    private final Runnable rebootTask = new Runnable() {
        @Override
@@ -60,6 +61,7 @@ public class CountryCodeService extends Service {
        super.onCreate();
        Log.d(TAG, "Service created");
        mPowerManager = getSystemService(PowerManager.class);
        mServiceStartMs = System.currentTimeMillis();

        final IntentFilter filter = new IntentFilter();
        filter.addAction(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED);
@@ -84,6 +86,10 @@ public class CountryCodeService extends Service {
    }

    private void applyCountryCode(String country) {
        if (System.currentTimeMillis() - mServiceStartMs < 30_000) {
            Log.i(TAG, "In boot cooldown; ignoring country change " + country);
            return;
        }
        Log.d(TAG, "Broadcast countrycode = " + country);
        final String current = SystemProperties.get(PROP_ODM_CCODE, ODM_OTH);
        Log.d(TAG, "Current " + PROP_ODM_CCODE + " = " + current);