aboutsummaryrefslogtreecommitdiff
path: root/configpanel/src
diff options
context:
space:
mode:
Diffstat (limited to 'configpanel/src')
-rw-r--r--configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java31
-rw-r--r--configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java148
-rw-r--r--configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java113
-rw-r--r--configpanel/src/org/lineageos/settings/device/Constants.java81
-rw-r--r--configpanel/src/org/lineageos/settings/device/KeyHandler.java94
-rw-r--r--configpanel/src/org/lineageos/settings/device/Startup.java97
-rw-r--r--configpanel/src/org/lineageos/settings/device/Utils.java65
7 files changed, 629 insertions, 0 deletions
diff --git a/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java b/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java
new file mode 100644
index 0000000..737dbd5
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/ButtonSettingsActivity.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class ButtonSettingsActivity extends PreferenceActivity {
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction().replace(android.R.id.content,
+ new ButtonSettingsFragment()).commit();
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java b/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java
new file mode 100644
index 0000000..b951641
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/ButtonSettingsFragment.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.app.ActionBar;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.view.MenuItem;
+
+import org.lineageos.internal.util.FileUtils;
+import org.lineageos.internal.util.PackageManagerUtils;
+
+public class ButtonSettingsFragment extends PreferenceFragment
+ implements OnPreferenceChangeListener {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.button_panel);
+ final ActionBar actionBar = getActivity().getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updatePreferencesBasedOnDependencies();
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ String node = Constants.sBooleanNodePreferenceMap.get(preference.getKey());
+ if (!TextUtils.isEmpty(node) && FileUtils.isFileWritable(node)) {
+ Boolean value = (Boolean) newValue;
+ FileUtils.writeLine(node, value ? "1" : "0");
+ if (Constants.FP_WAKEUP_KEY.equals(preference.getKey())) {
+ value &= prefs.getBoolean(Constants.FP_POCKETMODE_KEY, false);
+ Utils.broadcastCustIntent(getContext(), value);
+ }
+ return true;
+ }
+ node = Constants.sStringNodePreferenceMap.get(preference.getKey());
+ if (!TextUtils.isEmpty(node) && FileUtils.isFileWritable(node)) {
+ FileUtils.writeLine(node, (String) newValue);
+ return true;
+ }
+
+ if (Constants.FP_POCKETMODE_KEY.equals(preference.getKey())) {
+ Utils.broadcastCustIntent(getContext(), (Boolean) newValue);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void addPreferencesFromResource(int preferencesResId) {
+ super.addPreferencesFromResource(preferencesResId);
+ // Initialize node preferences
+ for (String pref : Constants.sBooleanNodePreferenceMap.keySet()) {
+ SwitchPreference b = (SwitchPreference) findPreference(pref);
+ if (b == null) continue;
+ b.setOnPreferenceChangeListener(this);
+ String node = Constants.sBooleanNodePreferenceMap.get(pref);
+ if (FileUtils.isFileReadable(node)) {
+ String curNodeValue = FileUtils.readOneLine(node);
+ b.setChecked(curNodeValue.equals("1"));
+ } else {
+ b.setEnabled(false);
+ }
+ }
+ for (String pref : Constants.sStringNodePreferenceMap.keySet()) {
+ ListPreference l = (ListPreference) findPreference(pref);
+ if (l == null) continue;
+ l.setOnPreferenceChangeListener(this);
+ String node = Constants.sStringNodePreferenceMap.get(pref);
+ if (FileUtils.isFileReadable(node)) {
+ l.setValue(FileUtils.readOneLine(node));
+ } else {
+ l.setEnabled(false);
+ }
+ }
+
+ // Initialize other preferences whose keys are not associated with nodes
+ final PreferenceCategory fingerprintCategory =
+ (PreferenceCategory) getPreferenceScreen().findPreference(Constants.CATEGORY_FP);
+
+ SwitchPreference b = (SwitchPreference) findPreference(Constants.FP_POCKETMODE_KEY);
+ if (!PackageManagerUtils.isAppInstalled(getContext(), "org.lineageos.pocketmode")) {
+ fingerprintCategory.removePreference(b);
+ } else {
+ b.setOnPreferenceChangeListener(this);
+ }
+
+ // Hide fingerprint features if the device doesn't support them
+ if (!FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) &&
+ !FileUtils.fileExists(Constants.FP_WAKEUP_NODE)) {
+ getPreferenceScreen().removePreference(fingerprintCategory);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ getActivity().onBackPressed();
+ return true;
+ }
+ return false;
+ }
+
+ private void updatePreferencesBasedOnDependencies() {
+ for (String pref : Constants.sNodeDependencyMap.keySet()) {
+ SwitchPreference b = (SwitchPreference) findPreference(pref);
+ if (b == null) continue;
+ String dependencyNode = Constants.sNodeDependencyMap.get(pref)[0];
+ if (FileUtils.isFileReadable(dependencyNode)) {
+ String dependencyNodeValue = FileUtils.readOneLine(dependencyNode);
+ boolean shouldSetEnabled = dependencyNodeValue.equals(
+ Constants.sNodeDependencyMap.get(pref)[1]);
+ Utils.updateDependentPreference(getContext(), b, pref, shouldSetEnabled);
+ }
+ }
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java b/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java
new file mode 100644
index 0000000..c234791
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017-2018 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.provider.SearchIndexableResource;
+import android.provider.SearchIndexablesProvider;
+
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK;
+import static android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID;
+import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
+import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS;
+import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS;
+
+import org.lineageos.internal.util.FileUtils;
+import org.lineageos.internal.util.PackageManagerUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ConfigPanelSearchIndexablesProvider extends SearchIndexablesProvider {
+ private static final String TAG = "ConfigPanelSearchIndexablesProvider";
+
+ public static final int SEARCH_IDX_BUTTON_PANEL = 0;
+
+ private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[]{
+ new SearchIndexableResource(1, R.xml.button_panel,
+ ButtonSettingsActivity.class.getName(),
+ R.drawable.ic_settings_additional_buttons),
+ };
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor queryXmlResources(String[] projection) {
+ MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS);
+ if (Startup.hasButtonProcs() /* show button panel */) {
+ cursor.addRow(generateResourceRef(INDEXABLE_RES[SEARCH_IDX_BUTTON_PANEL]));
+ }
+ return cursor;
+ }
+
+ private static Object[] generateResourceRef(SearchIndexableResource sir) {
+ final Object[] ref = new Object[INDEXABLES_XML_RES_COLUMNS.length];
+ ref[COLUMN_INDEX_XML_RES_RANK] = sir.rank;
+ ref[COLUMN_INDEX_XML_RES_RESID] = sir.xmlResId;
+ ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null;
+ ref[COLUMN_INDEX_XML_RES_ICON_RESID] = sir.iconResId;
+ ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "com.android.settings.action.EXTRA_SETTINGS";
+ ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "org.lineageos.settings.device";
+ ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = sir.className;
+ return ref;
+ }
+
+ private List<String> getNonIndexableKeys(Context context) {
+ List<String> keys = new ArrayList<>();
+ if (!PackageManagerUtils.isAppInstalled(context, "org.lineageos.pocketmode")) {
+ keys.add(Constants.FP_POCKETMODE_KEY);
+ }
+ if (!FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) &&
+ !FileUtils.fileExists(Constants.FP_WAKEUP_NODE)) {
+ keys.add(Constants.FP_HOME_KEY);
+ keys.add(Constants.FP_WAKEUP_KEY);
+ }
+ return keys;
+ }
+
+ @Override
+ public Cursor queryRawData(String[] projection) {
+ MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
+ return cursor;
+ }
+
+ @Override
+ public Cursor queryNonIndexableKeys(String[] projection) {
+ MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
+ final Context context = getContext();
+
+ List<String> nonIndexableKeys = getNonIndexableKeys(context);
+ for (String nik : nonIndexableKeys) {
+ final Object[] ref = new Object[NON_INDEXABLES_KEYS_COLUMNS.length];
+ ref[COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE] = nik;
+ cursor.addRow(ref);
+ }
+ return cursor;
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/Constants.java b/configpanel/src/org/lineageos/settings/device/Constants.java
new file mode 100644
index 0000000..b673946
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/Constants.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017-2018 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import org.lineageos.internal.util.FileUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Constants {
+
+ // Category keys
+ public static final String CATEGORY_FP = "fp_key";
+
+ // Preference keys
+ public static final String BUTTON_SWAP_KEY = "button_swap";
+ public static final String FP_HOME_KEY = "fp_home";
+ public static final String FP_POCKETMODE_KEY = "fp_pocketmode";
+ public static final String FP_WAKEUP_KEY = "fp_wakeup";
+
+ // Nodes
+ public static final String CYTTSP_BUTTON_SWAP_NODE = "/proc/buttons/reversed_keys_enable";
+ public static final String FP_HOME_KEY_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_key_events";
+ public static final String FP_WAKEUP_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_wakeup";
+ public static final String TOUCHPANEL_BUTTON_SWAP_NODE = "/proc/touchpanel/reversed_keys_enable";
+ public static final String VIRTUAL_KEYS_NODE = "/proc/touchpanel/capacitive_keys_enable";
+
+ // Intents
+ public static final String CUST_INTENT = "org.lineageos.settings.device.CUST_UPDATE";
+ public static final String CUST_INTENT_EXTRA = "pocketmode_service";
+
+ // Holds <preference_key> -> <proc_node> mapping
+ public static final Map<String, String> sBooleanNodePreferenceMap = new HashMap<>();
+ public static final Map<String, String> sStringNodePreferenceMap = new HashMap<>();
+
+ // Holds <preference_key> -> <default_values> mapping
+ public static final Map<String, Object> sNodeDefaultMap = new HashMap<>();
+
+ // Holds <preference_key> -> <user_set_values> mapping
+ public static final Map<String, Object[]> sNodeUserSetValuesMap = new HashMap<>();
+
+ // Holds <preference_key> -> <dependency_check> mapping
+ public static final Map<String, String[]> sNodeDependencyMap = new HashMap<>();
+
+ public static final String[] sButtonPrefKeys = {
+ BUTTON_SWAP_KEY,
+ FP_HOME_KEY,
+ FP_WAKEUP_KEY
+ };
+
+ static {
+ if (FileUtils.fileExists(Constants.CYTTSP_BUTTON_SWAP_NODE)) {
+ sBooleanNodePreferenceMap.put(BUTTON_SWAP_KEY, CYTTSP_BUTTON_SWAP_NODE);
+ } else if (FileUtils.fileExists(Constants.TOUCHPANEL_BUTTON_SWAP_NODE)) {
+ sBooleanNodePreferenceMap.put(BUTTON_SWAP_KEY, TOUCHPANEL_BUTTON_SWAP_NODE);
+ }
+ sBooleanNodePreferenceMap.put(FP_HOME_KEY, FP_HOME_KEY_NODE);
+ sBooleanNodePreferenceMap.put(FP_WAKEUP_KEY, FP_WAKEUP_NODE);
+
+ sNodeDefaultMap.put(BUTTON_SWAP_KEY, false);
+ sNodeDefaultMap.put(FP_HOME_KEY, false);
+ sNodeDefaultMap.put(FP_WAKEUP_KEY, true);
+
+ sNodeDependencyMap.put(FP_HOME_KEY, new String[]{ VIRTUAL_KEYS_NODE, "1" });
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/KeyHandler.java b/configpanel/src/org/lineageos/settings/device/KeyHandler.java
new file mode 100644
index 0000000..247624b
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/KeyHandler.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017-2019 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.KeyEvent;
+
+import com.android.internal.os.DeviceKeyHandler;
+
+import lineageos.providers.LineageSettings;
+
+import org.lineageos.internal.util.FileUtils;
+
+public class KeyHandler implements DeviceKeyHandler {
+
+ private static final String TAG = KeyHandler.class.getSimpleName();
+
+ private static final String FP_HOME_NODE = "/sys/devices/soc/soc:fpc_fpc1020/enable_key_events";
+
+ private static boolean sScreenTurnedOn = true;
+ private static final boolean DEBUG = false;
+
+ private final Context mContext;
+
+ private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+ sScreenTurnedOn = false;
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ sScreenTurnedOn = true;
+ }
+ }
+ };
+
+ public KeyHandler(Context context) {
+ mContext = context;
+
+ IntentFilter screenStateFilter = new IntentFilter();
+ screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
+ screenStateFilter.addAction(Intent.ACTION_SCREEN_ON);
+ mContext.registerReceiver(mScreenStateReceiver, screenStateFilter);
+ }
+
+ public KeyEvent handleKeyEvent(KeyEvent event) {
+ boolean virtualKeysEnabled = LineageSettings.System.getIntForUser(
+ mContext.getContentResolver(),
+ LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0;
+ boolean fingerprintHomeButtonEnabled = FileUtils.isFileReadable(FP_HOME_NODE) &&
+ FileUtils.readOneLine(FP_HOME_NODE).equals("1");
+
+ if (!hasSetupCompleted()) {
+ return event;
+ }
+
+ if (event.getKeyCode() == KeyEvent.KEYCODE_HOME) {
+ if (event.getScanCode() == 96) {
+ if (DEBUG) Log.d(TAG, "Fingerprint home button tapped");
+ return virtualKeysEnabled ? null : event;
+ }
+ if (event.getScanCode() == 102) {
+ if (DEBUG) Log.d(TAG, "Mechanical home button pressed");
+ return sScreenTurnedOn &&
+ (virtualKeysEnabled || fingerprintHomeButtonEnabled) ? null : event;
+ }
+ }
+ return event;
+ }
+
+ private boolean hasSetupCompleted() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.USER_SETUP_COMPLETE, 0) != 0;
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/Startup.java b/configpanel/src/org/lineageos/settings/device/Startup.java
new file mode 100644
index 0000000..4311cb5
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/Startup.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017-2018 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.SharedPreferences;
+import android.support.v7.preference.PreferenceManager;
+import android.util.Log;
+
+import org.lineageos.internal.util.FileUtils;
+
+public class Startup extends BroadcastReceiver {
+
+ private static final String TAG = Startup.class.getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (lineageos.content.Intent.ACTION_INITIALIZE_LINEAGE_HARDWARE.equals(action)) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+
+ // Disable button settings if needed
+ if (!hasButtonProcs()) {
+ disableComponent(context, ButtonSettingsActivity.class.getName());
+ } else {
+ enableComponent(context, ButtonSettingsActivity.class.getName());
+
+ // Restore nodes to saved preference values
+ for (String pref : Constants.sButtonPrefKeys) {
+ String node, value;
+ if (Constants.sStringNodePreferenceMap.containsKey(pref)) {
+ node = Constants.sStringNodePreferenceMap.get(pref);
+ value = Utils.getPreferenceString(context, pref);
+ } else {
+ node = Constants.sBooleanNodePreferenceMap.get(pref);
+ value = Utils.isPreferenceEnabled(context, pref) ? "1" : "0";
+ }
+ if (!FileUtils.writeLine(node, value)) {
+ Log.w(TAG, "Write to node " + node +
+ " failed while restoring saved preference values");
+ }
+ }
+
+ // Send initial broadcasts
+ final boolean shouldEnablePocketMode =
+ prefs.getBoolean(Constants.FP_WAKEUP_KEY, false) &&
+ prefs.getBoolean(Constants.FP_POCKETMODE_KEY, false);
+ Utils.broadcastCustIntent(context, shouldEnablePocketMode);
+ }
+ }
+ }
+
+ static boolean hasButtonProcs() {
+ return (FileUtils.fileExists(Constants.CYTTSP_BUTTON_SWAP_NODE) ||
+ FileUtils.fileExists(Constants.FP_HOME_KEY_NODE) ||
+ FileUtils.fileExists(Constants.FP_WAKEUP_NODE) ||
+ FileUtils.fileExists(Constants.TOUCHPANEL_BUTTON_SWAP_NODE));
+ }
+
+ private void disableComponent(Context context, String component) {
+ ComponentName name = new ComponentName(context, component);
+ PackageManager pm = context.getPackageManager();
+ pm.setComponentEnabledSetting(name,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+
+ private void enableComponent(Context context, String component) {
+ ComponentName name = new ComponentName(context, component);
+ PackageManager pm = context.getPackageManager();
+ if (pm.getComponentEnabledSetting(name)
+ == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
+ pm.setComponentEnabledSetting(name,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+ }
+}
diff --git a/configpanel/src/org/lineageos/settings/device/Utils.java b/configpanel/src/org/lineageos/settings/device/Utils.java
new file mode 100644
index 0000000..9b3b2d7
--- /dev/null
+++ b/configpanel/src/org/lineageos/settings/device/Utils.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2016 The CyanogenMod Project
+ * (C) 2017 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.lineageos.settings.device;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.UserHandle;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceManager;
+
+public class Utils {
+
+ public static boolean isPreferenceEnabled(Context context, String key) {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ return preferences.getBoolean(key, (Boolean) Constants.sNodeDefaultMap.get(key));
+ }
+
+ public static String getPreferenceString(Context context, String key) {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ return preferences.getString(key, (String) Constants.sNodeDefaultMap.get(key));
+ }
+
+ public static void updateDependentPreference(Context context, SwitchPreference b,
+ String key, boolean shouldSetEnabled) {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean prefActualValue = preferences.getBoolean(key, false);
+
+ if (shouldSetEnabled) {
+ if (Constants.sNodeUserSetValuesMap.get(key) != null &&
+ (Boolean) Constants.sNodeUserSetValuesMap.get(key)[1] &&
+ (Boolean) Constants.sNodeUserSetValuesMap.get(key)[1] != prefActualValue) {
+ b.setChecked(true);
+ Constants.sNodeUserSetValuesMap.put(key, new Boolean[]{ prefActualValue, false });
+ }
+ } else {
+ if (b.isEnabled() && prefActualValue) {
+ Constants.sNodeUserSetValuesMap.put(key, new Boolean[]{ prefActualValue, true });
+ }
+ b.setEnabled(false);
+ b.setChecked(false);
+ }
+ }
+
+ public static void broadcastCustIntent(Context context, boolean value) {
+ final Intent intent = new Intent(Constants.CUST_INTENT);
+ intent.putExtra(Constants.CUST_INTENT_EXTRA, value);
+ context.sendBroadcastAsUser(intent, UserHandle.CURRENT);
+ }
+}