sdm660-common: DeviceSettings: Switch to SecureSettingSwitchPreference

* SharedPreference cannot be used untill device is unlocked
* This causes crashing the app at boot

Thanks to java gawd StYlOg for help me fixing this

Signed-off-by: OdSazib <odsazib@gmail.com>
This commit is contained in:
OdSazib 2020-11-10 19:56:08 +06:00
parent f2b7354ef6
commit 870343eb33
No known key found for this signature in database
GPG key ID: 0954440B60470871
3 changed files with 7 additions and 19 deletions

View file

@ -86,12 +86,13 @@
android:targetClass="org.lineageos.settings.kcal.KCalSettingsActivity"
android:targetPackage="org.lineageos.settings.kcal" />
</Preference>
<SwitchPreference
<org.lineageos.settings.device.preferences.SecureSettingSwitchPreference
android:key="fps_info"
android:icon="@drawable/ic_fps_info"
android:title="@string/fps_info_title"
android:summary="@string/fps_info_summary"
android:persistent="true" />
android:persistent="true"
android:defaultValue="false" />
<Preference
android:key="device_jason"

View file

@ -20,10 +20,9 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import org.lineageos.settings.device.kcal.Utils;
import org.lineageos.settings.device.preferences.SecureSettingSwitchPreference;
import java.lang.Math.*;
@ -34,8 +33,6 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (Settings.Secure.getInt(context.getContentResolver(), PREF_ENABLED, 0) == 1) {
FileUtils.setValue(KCAL_ENABLE, Settings.Secure.getInt(context.getContentResolver(),
PREF_ENABLED, 0));
@ -79,7 +76,7 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
FileUtils.setProp(DeviceSettings.HALL_WAKEUP_PROP, Settings.Secure.getInt(
context.getContentResolver(), DeviceSettings.PREF_HALL_WAKEUP, 1) == 1);
boolean enabled = sharedPrefs.getBoolean(DeviceSettings.PREF_KEY_FPS_INFO, false);
boolean enabled = Settings.Secure.getInt(context.getContentResolver(), DeviceSettings.PREF_KEY_FPS_INFO, 0) == 1;
if (enabled) {
context.startService(new Intent(context, FPSInfoService.class));
}

View file

@ -22,10 +22,6 @@ import android.os.Bundle;
import androidx.preference.PreferenceFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreference;
import org.lineageos.settings.device.kcal.KCalSettingsActivity;
import org.lineageos.settings.device.preferences.SecureSettingListPreference;
@ -81,15 +77,10 @@ public class DeviceSettings extends PreferenceFragment implements
private SecureSettingListPreference mTHERMAL;
private static Context mContext;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences_xiaomi_parts, rootKey);
mContext = this.getContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
if (FileUtils.fileWritable(NOTIF_LED_PATH)) {
NotificationLedSeekBarPreference notifLedBrightness =
(NotificationLedSeekBarPreference) findPreference(PREF_NOTIF_LED);
@ -120,8 +111,7 @@ public class DeviceSettings extends PreferenceFragment implements
displayCategory.removePreference(findPreference(PREF_DEVICE_JASON));
}
SwitchPreference fpsInfo = (SwitchPreference) findPreference(PREF_KEY_FPS_INFO);
fpsInfo.setChecked(prefs.getBoolean(PREF_KEY_FPS_INFO, false));
SecureSettingSwitchPreference fpsInfo = (SecureSettingSwitchPreference) findPreference(PREF_KEY_FPS_INFO);
fpsInfo.setOnPreferenceChangeListener(this);
Preference kcal = findPreference(PREF_DEVICE_KCAL);
@ -179,7 +169,7 @@ public class DeviceSettings extends PreferenceFragment implements
break;
case PREF_KEY_FPS_INFO:
boolean enabled = (Boolean) value;
boolean enabled = (boolean) value;
Intent fpsinfo = new Intent(this.getContext(), FPSInfoService.class);
if (enabled) {
this.getContext().startService(fpsinfo);