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

Commit 28a06f1c authored by Rohit Sekhar's avatar Rohit Sekhar
Browse files

Merge branch '1541devices-a15-switch_read' into 'a15'

FP6: parts: Read & apply switch state on boot && reorganize

See merge request e/devices/android_device_fairphone_FP6!18
parents 5673a96f 9d1f874c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
        android:label="SliderSwitchHandler">

        <activity
            android:name=".SwitchActivity"
            android:name=".switchcust.SwitchActivity"
            android:exported="true"
            android:label="@string/switch_settings_title"
            android:theme="@style/Theme.SubSettingsBase">
@@ -74,7 +74,7 @@
        </receiver>

	<receiver
            android:name=".SliderSwitchStateReceiver"
            android:name=".switchcust.SliderSwitchStateReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="lineageos.intent.action.PEN_INSERTED_STATE_CHANGED" />
@@ -82,13 +82,13 @@
        </receiver>

        <service
            android:name=".SliderSwitchHandlerService"
            android:name=".switchcust.SliderSwitchHandlerService"
            android:permission="android.permission.MANAGE_SENSOR_PRIVACY"
            android:exported="false"
            android:stopWithTask="false"/>

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

+36 −0
Original line number Diff line number Diff line
package org.lineageos.settings;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.preference.PreferenceManager;

public class AppPrefs {
    private static AppPrefs instance;
    private final SharedPreferences prefs;
    private final Context context;

    private static final String KEY_FIRST_BOOT = "first_boot";

    private AppPrefs(Context context) {
        this.context = context.getApplicationContext();
        prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
    }

    public static synchronized AppPrefs getInstance(Context context) {
        if (instance == null) {
            instance = new AppPrefs(context.getApplicationContext());
        }
        return instance;
    }

    public boolean getIsFirstBoot() {
        return prefs.getBoolean(KEY_FIRST_BOOT, true);
    }

    public void saveIsFirstBoot() {
        prefs.edit().putBoolean(KEY_FIRST_BOOT, false).apply();
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -5,15 +5,20 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.lineageos.settings.fpcameratoggle.FPCameraToggleUtils;
import org.lineageos.settings.switchcust.SliderSwitchHandlerService;

public class BootReceiver extends BroadcastReceiver {

    private static final String EXTRA_SLIDER_STATE = "state";

    @Override
    public void onReceive(final Context context, Intent intent) {
        if (!intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
            return;

        boolean switchState = SwitchStateUtils.getSwitchState();
        Intent sliderServiceIntent = new Intent(context, SliderSwitchHandlerService.class);
        sliderServiceIntent.putExtra(EXTRA_SLIDER_STATE, !switchState);
        context.startService(sliderServiceIntent);

        Intent countryServiceIntent = new Intent(context, CountryCodeService.class);
+23 −0
Original line number Diff line number Diff line
package org.lineageos.settings;

import android.util.Log;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class SwitchStateUtils {
    private static final String TAG = "SwitchStateUtils";
    private static final String SWITCH_STATE_PATH = "/sys/emkit/info/switch_state";

    public static boolean getSwitchState() {
        try (BufferedReader reader = new BufferedReader(new FileReader(SWITCH_STATE_PATH))) {
            String line = reader.readLine();
            if (line != null) {
                return "1".equals(line.trim());
            }
        } catch (IOException e) {
            Log.e(TAG, "Failed to read switch state from: " + SWITCH_STATE_PATH, e);
        }
        return false;
    }
}
Loading