diff options
author | Justin Koh <justinkoh@google.com> | 2014-04-22 11:02:32 -0700 |
---|---|---|
committer | Justin Koh <justinkoh@google.com> | 2014-04-22 11:05:15 -0700 |
commit | be4c2c2b9902ae2d846c205a3ea3ba8b437a0775 (patch) | |
tree | bdbad6b2e17bbf76b10a7118770d8177a31ba983 /policy | |
parent | 0456e3aab1e0587512c805d7e240ad1461a69375 (diff) | |
parent | d90712d044d9505966c6b37c14507156dcc8353a (diff) | |
download | frameworks_base-be4c2c2b9902ae2d846c205a3ea3ba8b437a0775.zip frameworks_base-be4c2c2b9902ae2d846c205a3ea3ba8b437a0775.tar.gz frameworks_base-be4c2c2b9902ae2d846c205a3ea3ba8b437a0775.tar.bz2 |
resolved conflicts for merge of d90712d0 to master
Change-Id: Ia587476c001bce5f0969557b15d366aed6b322b1
Diffstat (limited to 'policy')
-rw-r--r-- | policy/src/com/android/internal/policy/impl/GlobalActions.java | 225 |
1 files changed, 139 insertions, 86 deletions
diff --git a/policy/src/com/android/internal/policy/impl/GlobalActions.java b/policy/src/com/android/internal/policy/impl/GlobalActions.java index c6972b1..fec9dda 100644 --- a/policy/src/com/android/internal/policy/impl/GlobalActions.java +++ b/policy/src/com/android/internal/policy/impl/GlobalActions.java @@ -51,6 +51,7 @@ import android.service.dreams.IDreamManager; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.telephony.TelephonyManager; +import android.util.ArraySet; import android.util.Log; import android.util.TypedValue; import android.view.InputDevice; @@ -83,6 +84,15 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac private static final boolean SHOW_SILENT_TOGGLE = true; + /* Valid settings for global actions keys. + * see config.xml config_globalActionList */ + private static final String GLOBAL_ACTION_KEY_POWER = "power"; + private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane"; + private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport"; + private static final String GLOBAL_ACTION_KEY_SILENT = "silent"; + private static final String GLOBAL_ACTION_KEY_USERS = "users"; + private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings"; + private final Context mContext; private final WindowManagerFuncs mWindowManagerFuncs; private final AudioManager mAudioManager; @@ -235,92 +245,36 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac onAirplaneModeChanged(); mItems = new ArrayList<Action>(); - - // first: power off - mItems.add( - new SinglePressAction( - com.android.internal.R.drawable.ic_lock_power_off, - R.string.global_action_power_off) { - - public void onPress() { - // shutdown by making sure radio and power are handled accordingly. - mWindowManagerFuncs.shutdown(true); - } - - public boolean onLongPress() { - mWindowManagerFuncs.rebootSafeMode(true); - return true; - } - - public boolean showDuringKeyguard() { - return true; - } - - public boolean showBeforeProvisioning() { - return true; - } - }); - - // next: airplane mode - mItems.add(mAirplaneModeOn); - - // next: bug report, if enabled - if (Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) { - mItems.add( - new SinglePressAction(com.android.internal.R.drawable.ic_lock_bugreport, - R.string.global_action_bug_report) { - - public void onPress() { - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); - builder.setTitle(com.android.internal.R.string.bugreport_title); - builder.setMessage(com.android.internal.R.string.bugreport_message); - builder.setNegativeButton(com.android.internal.R.string.cancel, null); - builder.setPositiveButton(com.android.internal.R.string.report, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // Add a little delay before executing, to give the - // dialog a chance to go away before it takes a - // screenshot. - mHandler.postDelayed(new Runnable() { - @Override public void run() { - try { - ActivityManagerNative.getDefault() - .requestBugReport(); - } catch (RemoteException e) { - } - } - }, 500); - } - }); - AlertDialog dialog = builder.create(); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); - dialog.show(); - } - - public boolean onLongPress() { - return false; - } - - public boolean showDuringKeyguard() { - return true; - } - - public boolean showBeforeProvisioning() { - return false; - } - }); - } - - // last: silent mode - if (mShowSilentToggle) { - mItems.add(mSilentModeAction); - } - - // one more thing: optionally add a list of users to switch to - if (SystemProperties.getBoolean("fw.power_user_switcher", false)) { - addUsersToMenu(mItems); + String[] defaultActions = mContext.getResources().getStringArray( + com.android.internal.R.array.config_globalActionsList); + + ArraySet<String> addedKeys = new ArraySet<String>(); + for (int i = 0; i < defaultActions.length; i++) { + String actionKey = defaultActions[i]; + if (addedKeys.contains(actionKey)) { + // If we already have added this, don't add it again. + continue; + } + if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) { + mItems.add(getPowerAction()); + } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) { + mItems.add(mAirplaneModeOn); + } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey) + && (Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner())) { + mItems.add(getBugReportAction()); + } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey) && mShowSilentToggle) { + mItems.add(mSilentModeAction); + } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey) + && SystemProperties.getBoolean("fw.power_user_switcher", false)) { + addUsersToMenu(mItems); + } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) { + mItems.add(getSettingsAction()); + } else { + Log.e(TAG, "Invalid global action key " + actionKey); + } + // Add here so we don't add more than one. + addedKeys.add(actionKey); } mAdapter = new MyAdapter(); @@ -350,6 +304,105 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac return dialog; } + private Action getPowerAction() { + return new SinglePressAction( + com.android.internal.R.drawable.ic_lock_power_off, + R.string.global_action_power_off) { + + public void onPress() { + // shutdown by making sure radio and power are handled accordingly. + mWindowManagerFuncs.shutdown(true); + } + + public boolean onLongPress() { + mWindowManagerFuncs.rebootSafeMode(true); + return true; + } + + public boolean showDuringKeyguard() { + return true; + } + + public boolean showBeforeProvisioning() { + return true; + } + }; + } + + private Action getBugReportAction() { + return new SinglePressAction(com.android.internal.R.drawable.stat_sys_adb, + R.string.global_action_bug_report) { + + public void onPress() { + AlertDialog.Builder builder = new AlertDialog.Builder(mContext); + builder.setTitle(com.android.internal.R.string.bugreport_title); + builder.setMessage(com.android.internal.R.string.bugreport_message); + builder.setNegativeButton(com.android.internal.R.string.cancel, null); + builder.setPositiveButton(com.android.internal.R.string.report, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Add a little delay before executing, to give the + // dialog a chance to go away before it takes a + // screenshot. + mHandler.postDelayed(new Runnable() { + @Override public void run() { + try { + ActivityManagerNative.getDefault() + .requestBugReport(); + } catch (RemoteException e) { + } + } + }, 500); + } + }); + AlertDialog dialog = builder.create(); + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); + dialog.show(); + } + + public boolean onLongPress() { + return false; + } + + public boolean showDuringKeyguard() { + return true; + } + + public boolean showBeforeProvisioning() { + return false; + } + }; + } + + private Action getSettingsAction() { + return new SinglePressAction(com.android.internal.R.drawable.ic_settings, + R.string.global_action_settings) { + + @Override + public void onPress() { + Intent intent = new Intent(Settings.ACTION_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + } + + @Override + public boolean onLongPress() { + return false; + } + + @Override + public boolean showDuringKeyguard() { + return true; + } + + @Override + public boolean showBeforeProvisioning() { + return false; + } + }; + } + private UserInfo getCurrentUser() { try { return ActivityManagerNative.getDefault().getCurrentUser(); |