PowerMenuActions: Add emergency option

This allows toggling Emergency button in GlobalAction(Power menu).

Signed-off-by: Gegham Zakaryan <zakaryan.2004@outlook.com>
Change-Id: I190048e213a08a969e10aef4081650875dab2587
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0aab4cb..a00d805 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -263,6 +263,7 @@
     <string name="power_menu_bug_report_unavailable_for_user">Bug reporting is disabled for non-primary users.</string>
     <string name="power_menu_lockdown_title">Lockdown</string>
     <string name="power_menu_lockdown_unavailable">Lockdown is disabled as keyguard isn\'t secure</string>
+    <string name="power_menu_emergency_title">Emergency</string>
 
     <string name="camera_double_tap_power_gesture_title">Press power button twice for camera</string>
 
diff --git a/res/xml/power_menu_settings.xml b/res/xml/power_menu_settings.xml
index e947f31..d8b2a32 100644
--- a/res/xml/power_menu_settings.xml
+++ b/res/xml/power_menu_settings.xml
@@ -44,4 +44,9 @@
         android:key="lockdown"
         android:title="@string/power_menu_lockdown_title"
         android:defaultValue="false" />
+
+    <CheckBoxPreference
+        android:key="emergency"
+        android:title="@string/power_menu_emergency_title"
+        android:defaultValue="false" />
 </PreferenceScreen>
diff --git a/src/org/lineageos/lineageparts/input/PowerMenuActions.java b/src/org/lineageos/lineageparts/input/PowerMenuActions.java
index 9809de4..4c78077 100644
--- a/src/org/lineageos/lineageparts/input/PowerMenuActions.java
+++ b/src/org/lineageos/lineageparts/input/PowerMenuActions.java
@@ -49,6 +49,7 @@
     private CheckBoxPreference mUsersPref;
     private CheckBoxPreference mBugReportPref;
     private CheckBoxPreference mLockDownPref;
+    private CheckBoxPreference mEmergencyPref;
 
     private LineageGlobalActions mLineageGlobalActions;
 
@@ -78,6 +79,8 @@
                 mBugReportPref = findPreference(GLOBAL_ACTION_KEY_BUGREPORT);
             } else if (action.equals(GLOBAL_ACTION_KEY_LOCKDOWN)) {
                 mLockDownPref = findPreference(GLOBAL_ACTION_KEY_LOCKDOWN);
+            } else if (action.equals(GLOBAL_ACTION_KEY_EMERGENCY)) {
+                mEmergencyPref = findPreference(GLOBAL_ACTION_KEY_EMERGENCY);
             }
         }
 
@@ -116,6 +119,11 @@
                     GLOBAL_ACTION_KEY_BUGREPORT));
         }
 
+        if (mEmergencyPref != null) {
+            mEmergencyPref.setChecked(mLineageGlobalActions.userConfigContains(
+                    GLOBAL_ACTION_KEY_EMERGENCY));
+        }
+
         updatePreferences();
     }
 
@@ -153,6 +161,10 @@
             Settings.Secure.putIntForUser(getContentResolver(),
                     Settings.Secure.LOCKDOWN_IN_POWER_MENU, value ? 1 : 0, UserHandle.USER_CURRENT);
 
+        } else if (preference == mEmergencyPref) {
+            value = mEmergencyPref.isChecked();
+            mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_EMERGENCY);
+
         } else {
             return super.onPreferenceTreeClick(preference);
         }