Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 00a03e9

Browse files
erfanoabdifazilsheik96
authored andcommitted
ParanoidSettings: Implement Power menu actions
[Adopted to S by: erfanoabdi] [Updated to U by: ikeramat] ikeramat: taken and adapted from: LineageOS/android_packages_apps_LineageParts@18f2dec this also includes Power Menu Action buttons Change-Id: Id6284f14ac57a57e499920498976959a25d33104
1 parent 2b5e6d7 commit 00a03e9

5 files changed

Lines changed: 348 additions & 0 deletions

File tree

res/values/strings.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,29 @@
127127
<string name="power_menu_type_grid">Grid</string>
128128
<string name="power_menu_type_legacy">Legacy (A7)</string>
129129

130+
<!-- Button settings - Power menu -->
131+
<string name="power_menu_type_title">Power menu style</string>
132+
<string name="power_menu_type_lite">Lite (A12)</string>
133+
<string name="power_menu_type_full">Full (A11)</string>
134+
<string name="power_menu_type_classic">Classic (A8)</string>
135+
<string name="power_menu_type_grid">Grid</string>
136+
<string name="power_menu_type_legacy">Legacy (A7)</string>
137+
<string name="power_menu_title">Power menu</string>
138+
<string name="power_menu_items_title">Power menu items</string>
139+
<string name="power_menu_screenshot_title">Screenshot</string>
140+
<string name="power_menu_screenshot_summary">Long-press for partial screenshot</string>
141+
<string name="power_menu_airplane_title">Airplane mode</string>
142+
<string name="power_menu_users_title">User switcher</string>
143+
<string name="power_menu_bug_report_title">Bug report</string>
144+
<string name="power_menu_bug_report_devoptions_unavailable">Bug reporting is disabled as development settings aren\'t enabled</string>
145+
<string name="power_menu_bug_report_unavailable_for_user">Bug reporting is disabled for non-primary users.</string>
146+
<string name="power_menu_emergency_title">Emergency</string>
147+
<string name="power_menu_devicecontrols_title">Device controls</string>
148+
<string name="power_menu_advanced_restart_title">Advanced restart</string>
149+
<string name="power_menu_advanced_restart_summary">When unlocked, include options in the power menu for restarting into recovery or bootloader</string>
150+
<string name="power_menu_emergency_affordance_enabled">Emergency affordance is enabled</string>
151+
152+
<!-- Text shown for the title of the restart systemui option -->
153+
<string name="power_menu_restart_systemui_title">Restart SystemUI</string>
154+
130155
</resources>

res/xml/interface_settings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
android:entries="@array/power_menu_type_entries"
3636
android:entryValues="@array/power_menu_type_values"
3737
android:defaultValue="0" />
38+
39+
<Preference
40+
android:key="power_menu"
41+
android:title="@string/power_menu_title"
42+
android:fragment="org.somethingos.somethingsettings.fragments.ui.PowerMenuActions" />
3843
</PreferenceCategory>
3944

4045
<PreferenceCategory
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
SPDX-FileCopyrightText: 2014-2015 The CyanogenMod Project
4+
SPDX-FileCopyrightText: 2017-2018,2020-2022 The LineageOS Project
5+
SPDX-License-Identifier: Apache-2.0
6+
-->
7+
8+
<PreferenceScreen
9+
xmlns:android="http://schemas.android.com/apk/res/android"
10+
xmlns:settings="http://schemas.android.com/apk/res-auto">
11+
12+
<PreferenceCategory
13+
android:key="power_menu_items"
14+
android:title="@string/power_menu_items_title">
15+
16+
<CheckBoxPreference
17+
android:key="screenshot"
18+
android:title="@string/power_menu_screenshot_title"
19+
android:summary="@string/power_menu_screenshot_summary"
20+
android:defaultValue="false" />
21+
22+
<CheckBoxPreference
23+
android:key="airplane"
24+
android:title="@string/power_menu_airplane_title"
25+
android:defaultValue="false" />
26+
27+
<CheckBoxPreference
28+
android:key="users"
29+
android:title="@string/power_menu_users_title"
30+
android:defaultValue="false" />
31+
32+
<CheckBoxPreference
33+
android:key="bugreport"
34+
android:title="@string/power_menu_bug_report_title"
35+
android:defaultValue="false" />
36+
37+
<CheckBoxPreference
38+
android:key="emergency"
39+
android:title="@string/power_menu_emergency_title"
40+
android:defaultValue="false" />
41+
42+
<CheckBoxPreference
43+
android:key="devicecontrols"
44+
android:title="@string/power_menu_devicecontrols_title"
45+
android:defaultValue="false"
46+
android:enabled="false" />
47+
48+
<CheckBoxPreference
49+
android:key="restart_systemui"
50+
android:title="@string/power_menu_restart_systemui_title"
51+
android:defaultValue="false" />
52+
</PreferenceCategory>
53+
</PreferenceScreen>
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2014-2015 The CyanogenMod Project
3+
* SPDX-FileCopyrightText: 2017-2023 The LineageOS Project
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package org.somethingos.somethingsettings.fragments.ui;
8+
9+
import android.Manifest;
10+
import android.content.Context;
11+
import android.content.pm.UserInfo;
12+
import android.os.Bundle;
13+
import android.os.UserHandle;
14+
import android.os.UserManager;
15+
import android.provider.Settings;
16+
import android.service.controls.ControlsProviderService;
17+
18+
import androidx.preference.CheckBoxPreference;
19+
import androidx.preference.Preference;
20+
import androidx.preference.PreferenceCategory;
21+
22+
import org.somethingos.somethingsettings.utils.TelephonyUtils;
23+
24+
import com.android.internal.util.EmergencyAffordanceManager;
25+
import com.android.settingslib.applications.ServiceListing;
26+
27+
import com.android.internal.util.aospa.PowerMenuConstants;
28+
import com.android.internal.util.aospa.PowerMenuUtils;
29+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
30+
import com.android.settings.R;
31+
import com.android.settings.SettingsPreferenceFragment;
32+
import com.android.internal.lineage.app.LineageGlobalActions;
33+
34+
import java.util.List;
35+
36+
import static com.android.internal.util.aospa.PowerMenuConstants.*;
37+
38+
public class PowerMenuActions extends SettingsPreferenceFragment {
39+
final static String TAG = "PowerMenuActions";
40+
41+
private static final String CATEGORY_POWER_MENU_ITEMS = "power_menu_items";
42+
43+
private PreferenceCategory mPowerMenuItemsCategory;
44+
45+
private CheckBoxPreference mScreenshotPref;
46+
private CheckBoxPreference mAirplanePref;
47+
private CheckBoxPreference mUsersPref;
48+
private CheckBoxPreference mBugReportPref;
49+
private CheckBoxPreference mEmergencyPref;
50+
private CheckBoxPreference mDeviceControlsPref;
51+
private CheckBoxPreference mRestartSystemUIPref;
52+
53+
private LineageGlobalActions mLineageGlobalActions;
54+
55+
private EmergencyAffordanceManager mEmergencyAffordanceManager;
56+
private boolean mForceEmergCheck = false;
57+
58+
Context mContext;
59+
private UserManager mUserManager;
60+
61+
@Override
62+
public void onCreate(Bundle savedInstanceState) {
63+
super.onCreate(savedInstanceState);
64+
65+
addPreferencesFromResource(R.xml.power_menu_actions_settings);
66+
requireActivity().setTitle(R.string.power_menu_title);
67+
mContext = requireActivity().getApplicationContext();
68+
mUserManager = UserManager.get(mContext);
69+
mLineageGlobalActions = mContext.getSystemService(LineageGlobalActions.class);
70+
mEmergencyAffordanceManager = new EmergencyAffordanceManager(mContext);
71+
72+
mPowerMenuItemsCategory = findPreference(CATEGORY_POWER_MENU_ITEMS);
73+
74+
for (String action : PowerMenuConstants.getAllActions()) {
75+
if (action.equals(GLOBAL_ACTION_KEY_SCREENSHOT)) {
76+
mScreenshotPref = findPreference(GLOBAL_ACTION_KEY_SCREENSHOT);
77+
} else if (action.equals(GLOBAL_ACTION_KEY_AIRPLANE)) {
78+
mAirplanePref = findPreference(GLOBAL_ACTION_KEY_AIRPLANE);
79+
} else if (action.equals(GLOBAL_ACTION_KEY_USERS)) {
80+
mUsersPref = findPreference(GLOBAL_ACTION_KEY_USERS);
81+
} else if (action.equals(GLOBAL_ACTION_KEY_BUGREPORT)) {
82+
mBugReportPref = findPreference(GLOBAL_ACTION_KEY_BUGREPORT);
83+
} else if (action.equals(GLOBAL_ACTION_KEY_EMERGENCY)) {
84+
mEmergencyPref = findPreference(GLOBAL_ACTION_KEY_EMERGENCY);
85+
} else if (action.equals(GLOBAL_ACTION_KEY_DEVICECONTROLS)) {
86+
mDeviceControlsPref = findPreference(GLOBAL_ACTION_KEY_DEVICECONTROLS);
87+
} else if (action.equals(GLOBAL_ACTION_KEY_RESTART_SYSTEMUI)) {
88+
mRestartSystemUIPref = findPreference(GLOBAL_ACTION_KEY_RESTART_SYSTEMUI);
89+
}
90+
}
91+
92+
if (!TelephonyUtils.isVoiceCapable(requireActivity())) {
93+
mPowerMenuItemsCategory.removePreference(mEmergencyPref);
94+
mEmergencyPref = null;
95+
}
96+
}
97+
98+
@Override
99+
public void onStart() {
100+
super.onStart();
101+
102+
if (mScreenshotPref != null) {
103+
mScreenshotPref.setChecked(mLineageGlobalActions.userConfigContains(
104+
GLOBAL_ACTION_KEY_SCREENSHOT));
105+
}
106+
107+
if (mAirplanePref != null) {
108+
mAirplanePref.setChecked(mLineageGlobalActions.userConfigContains(
109+
GLOBAL_ACTION_KEY_AIRPLANE));
110+
}
111+
112+
if (mUsersPref != null) {
113+
if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers()) {
114+
mPowerMenuItemsCategory.removePreference(mUsersPref);
115+
mUsersPref = null;
116+
} else {
117+
List<UserInfo> users = mUserManager.getUsers();
118+
boolean enabled = (users.size() > 1);
119+
mUsersPref.setChecked(mLineageGlobalActions.userConfigContains(
120+
GLOBAL_ACTION_KEY_USERS) && enabled);
121+
mUsersPref.setEnabled(enabled);
122+
}
123+
}
124+
125+
if (mBugReportPref != null) {
126+
mBugReportPref.setChecked(mLineageGlobalActions.userConfigContains(
127+
GLOBAL_ACTION_KEY_BUGREPORT));
128+
}
129+
130+
if (mEmergencyPref != null) {
131+
mForceEmergCheck = mEmergencyAffordanceManager.needsEmergencyAffordance();
132+
mEmergencyPref.setChecked(mLineageGlobalActions.userConfigContains(
133+
GLOBAL_ACTION_KEY_EMERGENCY) || mForceEmergCheck);
134+
mEmergencyPref.setEnabled(!mForceEmergCheck);
135+
}
136+
137+
if (mDeviceControlsPref != null) {
138+
mDeviceControlsPref.setChecked(mLineageGlobalActions.userConfigContains(
139+
GLOBAL_ACTION_KEY_DEVICECONTROLS));
140+
141+
// Enable preference if any device control app is installed
142+
ServiceListing serviceListing = new ServiceListing.Builder(mContext)
143+
.setIntentAction(ControlsProviderService.SERVICE_CONTROLS)
144+
.setPermission(Manifest.permission.BIND_CONTROLS)
145+
.setNoun("Controls Provider")
146+
.setSetting("controls_providers")
147+
.setTag("controls_providers")
148+
.build();
149+
serviceListing.addCallback(
150+
services -> mDeviceControlsPref.setEnabled(!services.isEmpty()));
151+
serviceListing.reload();
152+
}
153+
154+
if (mRestartSystemUIPref != null) {
155+
mRestartSystemUIPref.setChecked(mLineageGlobalActions.userConfigContains(
156+
GLOBAL_ACTION_KEY_RESTART_SYSTEMUI));
157+
}
158+
159+
updatePreferences();
160+
}
161+
162+
@Override
163+
public void onResume() {
164+
super.onResume();
165+
updatePreferences();
166+
}
167+
168+
@Override
169+
public boolean onPreferenceTreeClick(Preference preference) {
170+
boolean value;
171+
172+
if (preference == mScreenshotPref) {
173+
value = mScreenshotPref.isChecked();
174+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_SCREENSHOT);
175+
176+
} else if (preference == mAirplanePref) {
177+
value = mAirplanePref.isChecked();
178+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_AIRPLANE);
179+
180+
} else if (preference == mUsersPref) {
181+
value = mUsersPref.isChecked();
182+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_USERS);
183+
184+
} else if (preference == mBugReportPref) {
185+
value = mBugReportPref.isChecked();
186+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_BUGREPORT);
187+
Settings.Global.putInt(getContentResolver(),
188+
Settings.Global.BUGREPORT_IN_POWER_MENU, value ? 1 : 0);
189+
190+
} else if (preference == mEmergencyPref) {
191+
value = mEmergencyPref.isChecked();
192+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_EMERGENCY);
193+
194+
} else if (preference == mDeviceControlsPref) {
195+
value = mDeviceControlsPref.isChecked();
196+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_DEVICECONTROLS);
197+
198+
} else if (preference == mRestartSystemUIPref) {
199+
value = mRestartSystemUIPref.isChecked();
200+
mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_RESTART_SYSTEMUI);
201+
202+
} else {
203+
return super.onPreferenceTreeClick(preference);
204+
}
205+
return true;
206+
}
207+
208+
private void updatePreferences() {
209+
UserInfo currentUser = mUserManager.getUserInfo(UserHandle.myUserId());
210+
boolean developmentSettings = Settings.Global.getInt(
211+
getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1;
212+
boolean bugReport = Settings.Global.getInt(
213+
getContentResolver(), Settings.Global.BUGREPORT_IN_POWER_MENU, 0) == 1;
214+
boolean isPrimaryUser = currentUser == null || currentUser.isPrimary();
215+
if (mBugReportPref != null) {
216+
mBugReportPref.setEnabled(developmentSettings && isPrimaryUser);
217+
if (!developmentSettings) {
218+
mBugReportPref.setChecked(false);
219+
mBugReportPref.setSummary(R.string.power_menu_bug_report_devoptions_unavailable);
220+
} else if (!isPrimaryUser) {
221+
mBugReportPref.setChecked(false);
222+
mBugReportPref.setSummary(R.string.power_menu_bug_report_unavailable_for_user);
223+
} else {
224+
mBugReportPref.setChecked(bugReport);
225+
mBugReportPref.setSummary(null);
226+
}
227+
}
228+
if (mEmergencyPref != null) {
229+
if (mForceEmergCheck) {
230+
mEmergencyPref.setSummary(R.string.power_menu_emergency_affordance_enabled);
231+
} else {
232+
mEmergencyPref.setSummary(null);
233+
}
234+
}
235+
}
236+
237+
@Override
238+
public int getMetricsCategory() {
239+
return -1;
240+
}
241+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2016 The CyanogenMod Project
3+
* SPDX-FileCopyrightText: 2023 The LineageOS Project
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
package org.somethingos.somethingsettings.utils;
7+
8+
import android.content.Context;
9+
import android.telephony.TelephonyManager;
10+
11+
import androidx.annotation.NonNull;
12+
13+
public class TelephonyUtils {
14+
15+
private static final String TAG = TelephonyUtils.class.getSimpleName();
16+
17+
/**
18+
* Returns whether the device is voice-capable (meaning, it is also a phone).
19+
*/
20+
public static boolean isVoiceCapable(@NonNull Context context) {
21+
TelephonyManager telephony = context.getSystemService(TelephonyManager.class);
22+
return telephony != null && telephony.isVoiceCapable();
23+
}
24+
}

0 commit comments

Comments
 (0)