diff options
-rw-r--r-- | res/values/cm_arrays.xml | 10 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 15 | ||||
-rw-r--r-- | res/xml/button_settings.xml | 5 | ||||
-rw-r--r-- | res/xml/power_menu_settings.xml | 72 | ||||
-rw-r--r-- | src/com/android/settings/ButtonSettings.java | 1 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/PowerMenuActions.java | 316 | ||||
-rw-r--r-- | src/com/android/settings/profiles/ProfilesSettings.java | 1 |
7 files changed, 419 insertions, 1 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml index e7ba195..2c4e19b 100644 --- a/res/values/cm_arrays.xml +++ b/res/values/cm_arrays.xml @@ -246,4 +246,14 @@ <item>7</item> <item>8</item> </string-array> + + <string-array name="power_menu_actions_array" translatable="false"> + <item>power</item> + <item>reboot</item> + <item>screenshot</item> + <item>profile</item> + <item>airplane</item> + <item>users</item> + <item>bugreport</item> + </string-array> </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 84c8f63..7f88d89 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -362,6 +362,21 @@ <string name="backlight_summary_enabled_with_timeout">Enabled for <xliff:g id="timeout">%s</xliff:g></string> <string name="backlight_summary_enabled">Enabled</string> + <!-- Power menu --> + <string name="power_menu_title">Power menu</string> + <string name="power_menu_power_title">Power off</string> + <string name="power_menu_reboot_title">Reboot menu</string> + <string name="power_menu_screenshot_title">Screenshot</string> + <string name="power_menu_profiles_title">Profile switcher</string> + <string name="power_menu_airplane_title">Airplane mode</string> + <string name="power_menu_users_title">User switcher</string> + <string name="power_menu_settings_title">Settings shortcut</string> + <string name="power_menu_lockdown_title">Device lockdown</string> + <string name="power_menu_bug_report_title">Bug report</string> + <string name="power_menu_sound_title">Sound panel</string> + <string name="power_menu_bug_report_disabled">Bug reporting is disabled in development settings</string> + <string name="power_menu_profiles_disabled">System profiles are disabled</string> + <!-- Buttons - Enable navbar --> <string name="disable_navkeys_title">Enable on-screen nav bar</string> <string name="disable_navkeys_summary">Enable on-screen navigation bar and disable hardware buttons</string> diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml index 1584e98..d32d7f1 100644 --- a/res/xml/button_settings.xml +++ b/res/xml/button_settings.xml @@ -45,6 +45,11 @@ android:key="power_key" android:title="@string/hardware_keys_power_key_title" > + <PreferenceScreen + android:key="power_menu" + android:title="@string/power_menu_title" + android:fragment="com.android.settings.cyanogenmod.PowerMenuActions" /> + <SwitchPreference android:key="power_end_call" android:title="@string/power_end_call_title" diff --git a/res/xml/power_menu_settings.xml b/res/xml/power_menu_settings.xml new file mode 100644 index 0000000..cffee1f --- /dev/null +++ b/res/xml/power_menu_settings.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2014-2015 The CyanogenMod 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. +--> +<PreferenceScreen + xmlns:android="http://schemas.android.com/apk/res/android" + android:title="@string/power_menu_title" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> + + <CheckBoxPreference + android:key="power" + android:title="@string/power_menu_power_title" + android:defaultValue="true" /> + + <CheckBoxPreference + android:key="reboot" + android:title="@string/power_menu_reboot_title" + android:defaultValue="true" /> + + <CheckBoxPreference + android:key="screenshot" + android:title="@string/power_menu_screenshot_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="profile" + android:title="@string/power_menu_profiles_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="airplane" + android:title="@string/power_menu_airplane_title" + android:defaultValue="true" /> + + <CheckBoxPreference + android:key="users" + android:title="@string/power_menu_users_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="settings" + android:title="@string/power_menu_settings_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="lockdown" + android:title="@string/power_menu_lockdown_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="bugreport" + android:title="@string/power_menu_bug_report_title" + android:defaultValue="false" /> + + <CheckBoxPreference + android:key="silent" + android:title="@string/power_menu_sound_title" + android:defaultValue="true" /> + +</PreferenceScreen> diff --git a/src/com/android/settings/ButtonSettings.java b/src/com/android/settings/ButtonSettings.java index f8f0562..5ddfab1 100644 --- a/src/com/android/settings/ButtonSettings.java +++ b/src/com/android/settings/ButtonSettings.java @@ -207,7 +207,6 @@ public class ButtonSettings extends SettingsPreferenceFragment implements if (!Utils.isVoiceCapable(getActivity())) { powerCategory.removePreference(mPowerEndCall); mPowerEndCall = null; - prefScreen.removePreference(powerCategory); } } else { prefScreen.removePreference(powerCategory); diff --git a/src/com/android/settings/cyanogenmod/PowerMenuActions.java b/src/com/android/settings/cyanogenmod/PowerMenuActions.java new file mode 100644 index 0000000..b43fdfa --- /dev/null +++ b/src/com/android/settings/cyanogenmod/PowerMenuActions.java @@ -0,0 +1,316 @@ +/* + * Copyright (C) 2014-2015 The CyanogenMod 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 com.android.settings.cyanogenmod; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.UserInfo; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.SystemProperties; +import android.os.UserHandle; +import android.os.UserManager; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.PreferenceScreen; +import android.preference.ListPreference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.provider.Settings; + +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; +import com.android.internal.util.cm.PowerMenuConstants; + +import static com.android.internal.util.cm.PowerMenuConstants.*; + +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; + +public class PowerMenuActions extends SettingsPreferenceFragment { + final static String TAG = "PowerMenuActions"; + + private CheckBoxPreference mPowerPref; + private CheckBoxPreference mRebootPref; + private CheckBoxPreference mScreenshotPref; + private CheckBoxPreference mProfilePref; + private CheckBoxPreference mAirplanePref; + private CheckBoxPreference mUsersPref; + private CheckBoxPreference mSettingsPref; + private CheckBoxPreference mLockdownPref; + private CheckBoxPreference mBugReportPref; + private CheckBoxPreference mSilentPref; + + Context mContext; + private ArrayList<String> mLocalUserConfig = new ArrayList<String>(); + private String[] mAvailableActions; + private String[] mAllActions; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.power_menu_settings); + mContext = getActivity().getApplicationContext(); + + mAvailableActions = getActivity().getResources().getStringArray( + R.array.power_menu_actions_array); + mAllActions = PowerMenuConstants.getAllActions(); + + for (String action : mAllActions) { + // Remove preferences not present in the overlay + if (!isActionAllowed(action)) { + getPreferenceScreen().removePreference(findPreference(action)); + continue; + } + + if (action.equals(GLOBAL_ACTION_KEY_POWER)) { + mPowerPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_POWER); + } else if (action.equals(GLOBAL_ACTION_KEY_REBOOT)) { + mRebootPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_REBOOT); + } else if (action.equals(GLOBAL_ACTION_KEY_SCREENSHOT)) { + mScreenshotPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SCREENSHOT); + } else if (action.equals(GLOBAL_ACTION_KEY_PROFILE)) { + mProfilePref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_PROFILE); + } else if (action.equals(GLOBAL_ACTION_KEY_AIRPLANE)) { + mAirplanePref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_AIRPLANE); + } else if (action.equals(GLOBAL_ACTION_KEY_USERS)) { + mUsersPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_USERS); + } else if (action.equals(GLOBAL_ACTION_KEY_SETTINGS)) { + mSettingsPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SETTINGS); + } else if (action.equals(GLOBAL_ACTION_KEY_LOCKDOWN)) { + mLockdownPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_LOCKDOWN); + } else if (action.equals(GLOBAL_ACTION_KEY_BUGREPORT)) { + mBugReportPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_BUGREPORT); + } else if (action.equals(GLOBAL_ACTION_KEY_SILENT)) { + mSilentPref = (CheckBoxPreference) findPreference(GLOBAL_ACTION_KEY_SILENT); + } + } + + getUserConfig(); + } + + @Override + public void onStart() { + super.onStart(); + + if (mPowerPref != null) { + mPowerPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_POWER)); + } + + if (mRebootPref != null) { + mRebootPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_REBOOT)); + } + + if (mScreenshotPref != null) { + mScreenshotPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SCREENSHOT)); + } + + if (mProfilePref != null) { + mProfilePref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_PROFILE)); + } + + if (mAirplanePref != null) { + mAirplanePref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_AIRPLANE)); + } + + if (mUsersPref != null) { + if (!UserHandle.MU_ENABLED || !UserManager.supportsMultipleUsers()) { + getPreferenceScreen().removePreference(findPreference(GLOBAL_ACTION_KEY_USERS)); + } else { + List<UserInfo> users = ((UserManager) mContext.getSystemService( + Context.USER_SERVICE)).getUsers(); + boolean enabled = (users.size() > 1); + mUsersPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_USERS) && enabled); + mUsersPref.setEnabled(enabled); + } + } + + if (mSettingsPref != null) { + mSettingsPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SETTINGS)); + } + + if (mLockdownPref != null) { + mLockdownPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_LOCKDOWN)); + } + + if (mBugReportPref != null) { + mBugReportPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_BUGREPORT)); + } + + if (mSilentPref != null) { + mSilentPref.setChecked(settingsArrayContains(GLOBAL_ACTION_KEY_SILENT)); + } + + updatePreferences(); + } + + @Override + public void onResume() { + super.onResume(); + updatePreferences(); + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + boolean value; + + if (preference == mPowerPref) { + value = mPowerPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_POWER); + + } else if (preference == mRebootPref) { + value = mRebootPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_REBOOT); + + } else if (preference == mScreenshotPref) { + value = mScreenshotPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_SCREENSHOT); + + } else if (preference == mProfilePref) { + value = mProfilePref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_PROFILE); + + } else if (preference == mAirplanePref) { + value = mAirplanePref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_AIRPLANE); + + } else if (preference == mUsersPref) { + value = mUsersPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_USERS); + + } else if (preference == mSettingsPref) { + value = mSettingsPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_SETTINGS); + + } else if (preference == mLockdownPref) { + value = mLockdownPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_LOCKDOWN); + + } else if (preference == mBugReportPref) { + value = mBugReportPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_BUGREPORT); + + } else if (preference == mSilentPref) { + value = mSilentPref.isChecked(); + updateUserConfig(value, GLOBAL_ACTION_KEY_SILENT); + + } else { + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + return true; + } + + private boolean settingsArrayContains(String preference) { + return mLocalUserConfig.contains(preference); + } + + private boolean isActionAllowed(String action) { + if (Arrays.asList(mAvailableActions).contains(action)) { + return true; + } + return false; + } + + private void updateUserConfig(boolean enabled, String action) { + if (enabled) { + if (!settingsArrayContains(action)) { + mLocalUserConfig.add(action); + } + } else { + if (settingsArrayContains(action)) { + mLocalUserConfig.remove(action); + } + } + saveUserConfig(); + } + + private void updatePreferences() { + boolean bugreport = Settings.Secure.getInt(getContentResolver(), + Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0; + boolean profiles = Settings.System.getInt(getContentResolver(), + Settings.System.SYSTEM_PROFILES_ENABLED, 1) != 0; + + if (mProfilePref != null) { + mProfilePref.setEnabled(profiles); + if (profiles) { + mProfilePref.setSummary(null); + } else { + mProfilePref.setSummary(R.string.power_menu_profiles_disabled); + } + } + + if (mBugReportPref != null) { + mBugReportPref.setEnabled(bugreport); + if (bugreport) { + mBugReportPref.setSummary(null); + } else { + mBugReportPref.setSummary(R.string.power_menu_bug_report_disabled); + } + } + } + + private void getUserConfig() { + mLocalUserConfig.clear(); + String[] defaultActions; + String savedActions = Settings.Global.getStringForUser(mContext.getContentResolver(), + Settings.Global.POWER_MENU_ACTIONS, UserHandle.USER_CURRENT); + + if (savedActions == null) { + defaultActions = mContext.getResources().getStringArray( + com.android.internal.R.array.config_globalActionsList); + for (String action : defaultActions) { + mLocalUserConfig.add(action); + } + } else { + for (String action : savedActions.split("\\|")) { + mLocalUserConfig.add(action); + } + } + } + + private void saveUserConfig() { + StringBuilder s = new StringBuilder(); + + // TODO: Use DragSortListView + ArrayList<String> setactions = new ArrayList<String>(); + for (String action : mAllActions) { + if (settingsArrayContains(action) && isActionAllowed(action)) { + setactions.add(action); + } else { + continue; + } + } + + for (int i = 0; i < setactions.size(); i++) { + s.append(setactions.get(i).toString()); + if (i != setactions.size() - 1) { + s.append("|"); + } + } + + Settings.Global.putStringForUser(getContentResolver(), + Settings.Global.POWER_MENU_ACTIONS, s.toString(), UserHandle.USER_CURRENT); + updatePowerMenuDialog(); + } + + private void updatePowerMenuDialog() { + Intent u = new Intent(); + u.setAction(Intent.UPDATE_POWER_MENU); + mContext.sendBroadcastAsUser(u, UserHandle.ALL); + } +} diff --git a/src/com/android/settings/profiles/ProfilesSettings.java b/src/com/android/settings/profiles/ProfilesSettings.java index ed12663..59078ae 100644 --- a/src/com/android/settings/profiles/ProfilesSettings.java +++ b/src/com/android/settings/profiles/ProfilesSettings.java @@ -27,6 +27,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import android.os.UserHandle; import android.provider.Settings; import android.support.v4.view.ViewPager; import android.support.v13.app.FragmentStatePagerAdapter; |