diff options
| author | bigrushdog <randall.rushing@gmail.com> | 2017-08-11 18:19:50 -0700 |
|---|---|---|
| committer | qjohn <townex22@gmail.com> | 2017-08-15 01:28:54 +0700 |
| commit | 0570b8827300d7119ff00a12d82d4e8bac60843b (patch) | |
| tree | e063833495a2227404b2ed7e65096f192a0edb2a | |
| parent | 8bdcbdda773eecc692c31c0e28f92e9dcffcb0e9 (diff) | |
DUtils: Migrate from broadcasts to API for some action handling [2/2]n7.1
Change-Id: I8734e2ee6d9b6201bf37fd3967067ff58eec85b7
| -rw-r--r-- | src/com/android/internal/utils/du/ActionHandler.java | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/src/com/android/internal/utils/du/ActionHandler.java b/src/com/android/internal/utils/du/ActionHandler.java index 6d296e6..0501437 100644 --- a/src/com/android/internal/utils/du/ActionHandler.java +++ b/src/com/android/internal/utils/du/ActionHandler.java @@ -60,9 +60,11 @@ import android.service.wallpaper.WallpaperService; import android.text.TextUtils; import android.util.Log; import android.util.Slog; +import android.view.IWindowManager; import android.view.InputDevice; import android.view.KeyCharacterMap; import android.view.KeyEvent; +import android.view.WindowManagerGlobal; import android.view.WindowManagerPolicyControl; import android.view.inputmethod.InputMethodManager; import android.widget.Toast; @@ -138,7 +140,6 @@ public class ActionHandler { public static final String INTENT_TOGGLE_SCREENRECORD = "action_handler_toggle_screenrecord"; public static final String INTENT_SCREENSHOT = "action_handler_screenshot"; public static final String INTENT_REGION_SCREENSHOT = "action_handler_region_screenshot"; - public static final String INTENT_TOGGLE_FLASHLIGHT = "action_handler_toggle_flashlight"; static enum SystemAction { NoAction(SYSTEMUI_TASK_NO_ACTION, SYSTEMUI, "label_action_no_action", "ic_sysbar_no_action"), @@ -314,6 +315,15 @@ public class ActionHandler { } } + private static void toggleFlashlight() { + IStatusBarService service = getStatusBarService(); + try { + service.toggleFlashlight(); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + private static void toggleRecentsApps() { IStatusBarService service = getStatusBarService(); if (service != null) { @@ -463,13 +473,13 @@ public class ActionHandler { killProcess(context); return; } else if (action.equals(SYSTEMUI_TASK_SCREENSHOT)) { - takeScreenshot(context); + sendCommandToWindowManager(new Intent(INTENT_SCREENSHOT)); return; } else if (action.equals(SYSTEMUI_TASK_REGION_SCREENSHOT)) { - takeRegionScreenshot(context); + sendCommandToWindowManager(new Intent(INTENT_REGION_SCREENSHOT)); return; } else if (action.equals(SYSTEMUI_TASK_SCREENRECORD)) { - takeScreenrecord(context); + sendCommandToWindowManager(new Intent(INTENT_TOGGLE_SCREENRECORD)); return; // } else if (action.equals(SYSTEMUI_TASK_AUDIORECORD)) { // takeAudiorecord(); @@ -493,10 +503,10 @@ public class ActionHandler { StatusBarHelper.fireGoogleNowOnTap(); return; } else if (action.equals(SYSTEMUI_TASK_POWER_MENU)) { - showPowerMenu(context); + sendCommandToWindowManager(new Intent(INTENT_SHOW_POWER_MENU)); return; } else if (action.equals(SYSTEMUI_TASK_TORCH)) { - toggleTorch(context); + StatusBarHelper.toggleFlashlight(); return; } else if (action.equals(SYSTEMUI_TASK_CAMERA)) { launchCamera(context); @@ -860,24 +870,13 @@ public class ActionHandler { } } - private static void toggleTorch(Context context) { - context.sendBroadcastAsUser(new Intent(INTENT_TOGGLE_FLASHLIGHT), new UserHandle( - UserHandle.USER_ALL)); - } - - private static void takeScreenshot(Context context) { - context.sendBroadcastAsUser(new Intent(INTENT_SCREENSHOT), new UserHandle( - UserHandle.USER_ALL)); - } - - private static void takeRegionScreenshot(Context context) { - context.sendBroadcastAsUser(new Intent(INTENT_REGION_SCREENSHOT), new UserHandle( - UserHandle.USER_ALL)); - } - - private static void takeScreenrecord(Context context) { - context.sendBroadcastAsUser(new Intent(INTENT_TOGGLE_SCREENRECORD), new UserHandle( - UserHandle.USER_ALL)); + private static void sendCommandToWindowManager(Intent intent) { + IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); + try { + wm.sendCustomAction(intent); + } catch (RemoteException e) { + e.printStackTrace(); + } } private static void killProcess(Context context) { @@ -1049,11 +1048,6 @@ public class ActionHandler { return false; } - private static void showPowerMenu(Context context) { - context.sendBroadcastAsUser(new Intent(INTENT_SHOW_POWER_MENU), new UserHandle( - UserHandle.USER_ALL)); - } - public static void volumePanel(Context context) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.adjustVolume(AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI); |
