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

Commit 8617a870 authored by Rohit Sekhar's avatar Rohit Sekhar
Browse files

Revert "FairphoneParts: Introduce CountryCodeService"

This reverts commit 0d2f2a5a.
parent a5f84489
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -133,7 +133,6 @@ BOARD_BOOTCONFIG += \
    androidboot.usbcontroller=a600000.dwc3 \
    androidboot.load_modules_parallel=true \
    androidboot.vendor.qspa=true
#BOARD_BOOTCONFIG += androidboot.selinux=permissive
BOARD_INCLUDE_DTB_IN_BOOTIMG := true
BOARD_INIT_BOOT_HEADER_VERSION := 4
BOARD_MKBOOTIMG_INIT_ARGS += --header_version $(BOARD_INIT_BOOT_HEADER_VERSION)
+1 −6
Original line number Diff line number Diff line
@@ -3,10 +3,9 @@
    package="org.lineageos.settings.device"
    android:sharedUserId="android.uid.system">

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.MANAGE_SENSOR_PRIVACY"/>
    <uses-permission android:name="android.permission.OBSERVE_SENSOR_PRIVACY"/>
    <uses-permission android:name="android.permission.REBOOT" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
@@ -36,10 +35,6 @@
            android:exported="false"
            android:stopWithTask="false"/>

        <service
            android:name=".CountryCodeService"
            android:exported="false"
            android:stopWithTask="false"/>
    </application>

</manifest>
+2 −5
Original line number Diff line number Diff line
@@ -12,10 +12,7 @@ public class BootReceiver extends BroadcastReceiver {
        if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
            return;

        Intent sliderServiceIntent = new Intent(context, SliderSwitchHandlerService.class);
        context.startService(sliderServiceIntent);

        Intent countryServiceIntent = new Intent(context, CountryCodeService.class);
        context.startService(countryServiceIntent);
	Intent serviceIntent = new Intent(context, SliderSwitchHandlerService.class);
        context.startService(serviceIntent);
    }
}
+0 −127
Original line number Diff line number Diff line
package org.lineageos.settings.device;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class CountryCodeService extends Service {
    private static final String TAG = "CountryCodeService";

    private static final int REBOOT_DELAY_MS = 5 * 1000;

    private static final String PROP_ODM_CCODE = "persist.odm.ccode";
    private static final String ACTION_COUNTRYCODE_UPDATED =
            "android.intent.action.NETWORK_COUNTRYCODE_UPDATED";
    private static final String EXTRA_COUNTRYCODE = "countrycode";

    private static final String ODM_FCC = "fcc";
    private static final String ODM_EU  = "eu";
    private static final String ODM_OTH = "other";

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

    private final Runnable rebootTask = new Runnable() {
        @Override
        public void run() {
            if (mPowerManager != null) {
                Log.i(TAG, "Rebooting to load Wi-Fi/radio configuration");
                mPowerManager.reboot(null);
            } else {
                Log.e(TAG, "PowerManager is null; cannot reboot");
            }
        }
    };

    private final BroadcastReceiver mReceiver =
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    final String action = intent.getAction();
                    if (ACTION_COUNTRYCODE_UPDATED.equals(action)) {
                        final String country = normalize(intent.getStringExtra(EXTRA_COUNTRYCODE));
                        applyCountryCode(country);
                    }
                }
            };

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "Service created");
        mPowerManager = getSystemService(PowerManager.class);

        final IntentFilter filter = new IntentFilter();
        filter.addAction(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED);
        filter.addAction(ACTION_COUNTRYCODE_UPDATED);
        registerReceiver(mReceiver, filter);
        Log.d(TAG, "Receiver registered");
    }

    @Override
    public void onDestroy() {
        try {
            unregisterReceiver(mReceiver);
        } catch (IllegalArgumentException ignored) {}
        mHandler.removeCallbacksAndMessages(null);
        Log.d(TAG, "Service destroyed");
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    private void applyCountryCode(String country) {
        Log.d(TAG, "Broadcast countrycode = " + country);
        final String current = SystemProperties.get(PROP_ODM_CCODE, ODM_OTH);
        Log.d(TAG, "Current " + PROP_ODM_CCODE + " = " + current);

        if ("US".equals(country)) {
            if (!ODM_FCC.equals(current)) {
                SystemProperties.set(PROP_ODM_CCODE, ODM_FCC);
                showRebootToast("US", REBOOT_DELAY_MS);
                scheduleReboot(REBOOT_DELAY_MS);
            }
        } else if ("EU".equals(country)) {
            if (!ODM_EU.equals(current)) {
                SystemProperties.set(PROP_ODM_CCODE, ODM_EU);
            }
            if (ODM_FCC.equals(current)) {
                showRebootToast("EU", REBOOT_DELAY_MS);
                scheduleReboot(REBOOT_DELAY_MS);
            }
        } else {
            Log.d(TAG, "Ignoring unsupported country broadcast: " + country);
        }
    }

    private void scheduleReboot(int delayMs) {
        // Debounce: ensure only one reboot is queued
        mHandler.removeCallbacks(rebootTask);
        mHandler.postDelayed(rebootTask, delayMs);
        Log.i(TAG, "Reboot scheduled in " + (delayMs / 1000) + "s");
    }

    private void showRebootToast(String regionLabel, int delayMs) {
        final int seconds = Math.max(1, delayMs / 1000);
        final String msg = "Region set to " + regionLabel
                + ". Rebooting in " + seconds + "s to load the corresponding configuration.";
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }

    private static String normalize(String v) {
        return v == null ? "" : v.trim().toUpperCase();
    }
}
+0 −17
Original line number Diff line number Diff line
type devicesettings_app, domain;

app_domain(devicesettings_app)

# Allow devicesettings_app to find *_service
allow devicesettings_app {
  activity_service
  content_capture_service
  netstats_service
  sensor_privacy_service
  thermal_service
  vibrator_manager_service
  wifi_service
}:service_manager find;

# Allow setting countrycode property
set_prop(devicesettings_app, system_fp_prop)
Loading