John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.volume; |
| 18 | |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 19 | import android.content.Context; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 20 | import android.media.AudioManager; |
| 21 | import android.media.AudioSystem; |
| 22 | import android.provider.Settings.Global; |
| 23 | import android.util.Log; |
| 24 | |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 25 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 26 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 27 | import com.android.systemui.volume.VolumeDialogController.State; |
| 28 | |
| 29 | import java.util.Arrays; |
| 30 | |
| 31 | /** |
| 32 | * Interesting events related to the volume. |
| 33 | */ |
| 34 | public class Events { |
| 35 | private static final String TAG = Util.logTag(Events.class); |
| 36 | |
| 37 | public static final int EVENT_SHOW_DIALOG = 0; // (reason|int) (keyguard|bool) |
| 38 | public static final int EVENT_DISMISS_DIALOG = 1; // (reason|int) |
| 39 | public static final int EVENT_ACTIVE_STREAM_CHANGED = 2; // (stream|int) |
| 40 | public static final int EVENT_EXPAND = 3; // (expand|bool) |
| 41 | public static final int EVENT_KEY = 4; |
| 42 | public static final int EVENT_COLLECTION_STARTED = 5; |
| 43 | public static final int EVENT_COLLECTION_STOPPED = 6; |
| 44 | public static final int EVENT_ICON_CLICK = 7; // (stream|int) (icon_state|int) |
| 45 | public static final int EVENT_SETTINGS_CLICK = 8; |
| 46 | public static final int EVENT_TOUCH_LEVEL_CHANGED = 9; // (stream|int) (level|int) |
| 47 | public static final int EVENT_LEVEL_CHANGED = 10; // (stream|int) (level|int) |
| 48 | public static final int EVENT_INTERNAL_RINGER_MODE_CHANGED = 11; // (mode|int) |
| 49 | public static final int EVENT_EXTERNAL_RINGER_MODE_CHANGED = 12; // (mode|int) |
| 50 | public static final int EVENT_ZEN_MODE_CHANGED = 13; // (mode|int) |
| 51 | public static final int EVENT_SUPPRESSOR_CHANGED = 14; // (component|string) (name|string) |
| 52 | public static final int EVENT_MUTE_CHANGED = 15; // (stream|int) (muted|bool) |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 53 | public static final int EVENT_TOUCH_LEVEL_DONE = 16; // (stream|int) (level|bool) |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 54 | |
| 55 | private static final String[] EVENT_TAGS = { |
| 56 | "show_dialog", |
| 57 | "dismiss_dialog", |
| 58 | "active_stream_changed", |
| 59 | "expand", |
| 60 | "key", |
| 61 | "collection_started", |
| 62 | "collection_stopped", |
| 63 | "icon_click", |
| 64 | "settings_click", |
| 65 | "touch_level_changed", |
| 66 | "level_changed", |
| 67 | "internal_ringer_mode_changed", |
| 68 | "external_ringer_mode_changed", |
| 69 | "zen_mode_changed", |
| 70 | "suppressor_changed", |
| 71 | "mute_changed", |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 72 | "touch_level_done", |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | public static final int DISMISS_REASON_UNKNOWN = 0; |
| 76 | public static final int DISMISS_REASON_TOUCH_OUTSIDE = 1; |
| 77 | public static final int DISMISS_REASON_VOLUME_CONTROLLER = 2; |
| 78 | public static final int DISMISS_REASON_TIMEOUT = 3; |
| 79 | public static final int DISMISS_REASON_SCREEN_OFF = 4; |
| 80 | public static final int DISMISS_REASON_SETTINGS_CLICKED = 5; |
| 81 | public static final int DISMISS_REASON_DONE_CLICKED = 6; |
| 82 | public static final String[] DISMISS_REASONS = { |
| 83 | "unknown", |
| 84 | "touch_outside", |
| 85 | "volume_controller", |
| 86 | "timeout", |
| 87 | "screen_off", |
| 88 | "settings_clicked", |
| 89 | "done_clicked", |
| 90 | }; |
| 91 | |
| 92 | public static final int SHOW_REASON_UNKNOWN = 0; |
| 93 | public static final int SHOW_REASON_VOLUME_CHANGED = 1; |
| 94 | public static final int SHOW_REASON_REMOTE_VOLUME_CHANGED = 2; |
| 95 | public static final String[] SHOW_REASONS = { |
| 96 | "unknown", |
| 97 | "volume_changed", |
| 98 | "remote_volume_changed" |
| 99 | }; |
| 100 | |
| 101 | public static final int ICON_STATE_UNKNOWN = 0; |
| 102 | public static final int ICON_STATE_UNMUTE = 1; |
| 103 | public static final int ICON_STATE_MUTE = 2; |
| 104 | public static final int ICON_STATE_VIBRATE = 3; |
| 105 | |
| 106 | public static Callback sCallback; |
| 107 | |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 108 | public static void writeEvent(Context context, int tag, Object... list) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 109 | final long time = System.currentTimeMillis(); |
| 110 | final StringBuilder sb = new StringBuilder("writeEvent ").append(EVENT_TAGS[tag]); |
| 111 | if (list != null && list.length > 0) { |
| 112 | sb.append(" "); |
| 113 | switch (tag) { |
| 114 | case EVENT_SHOW_DIALOG: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 115 | MetricsLogger.visible(context, MetricsEvent.VOLUME_DIALOG); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 116 | MetricsLogger.histogram(context, "volume_from_keyguard", |
| 117 | (Boolean) list[1] ? 1 : 0); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 118 | sb.append(SHOW_REASONS[(Integer) list[0]]).append(" keyguard=").append(list[1]); |
| 119 | break; |
| 120 | case EVENT_EXPAND: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 121 | MetricsLogger.visibility(context, MetricsEvent.VOLUME_DIALOG_DETAILS, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 122 | (Boolean) list[0]); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 123 | sb.append(list[0]); |
| 124 | break; |
| 125 | case EVENT_DISMISS_DIALOG: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 126 | MetricsLogger.hidden(context, MetricsEvent.VOLUME_DIALOG); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 127 | sb.append(DISMISS_REASONS[(Integer) list[0]]); |
| 128 | break; |
| 129 | case EVENT_ACTIVE_STREAM_CHANGED: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 130 | MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_STREAM, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 131 | (Integer) list[0]); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 132 | sb.append(AudioSystem.streamToString((Integer) list[0])); |
| 133 | break; |
| 134 | case EVENT_ICON_CLICK: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 135 | MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_ICON, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 136 | (Integer) list[1]); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 137 | sb.append(AudioSystem.streamToString((Integer) list[0])).append(' ') |
| 138 | .append(iconStateToString((Integer) list[1])); |
| 139 | break; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 140 | case EVENT_TOUCH_LEVEL_DONE: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 141 | MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_SLIDER, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 142 | (Integer) list[1]); |
| 143 | // fall through |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 144 | case EVENT_TOUCH_LEVEL_CHANGED: |
| 145 | case EVENT_LEVEL_CHANGED: |
| 146 | case EVENT_MUTE_CHANGED: |
| 147 | sb.append(AudioSystem.streamToString((Integer) list[0])).append(' ') |
| 148 | .append(list[1]); |
| 149 | break; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 150 | case EVENT_KEY: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 151 | MetricsLogger.action(context, MetricsEvent.ACTION_VOLUME_KEY, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 152 | (Integer) list[1]); |
| 153 | sb.append(AudioSystem.streamToString((Integer) list[0])).append(' ') |
| 154 | .append(list[1]); |
| 155 | break; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 156 | case EVENT_EXTERNAL_RINGER_MODE_CHANGED: |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 157 | MetricsLogger.action(context, MetricsEvent.ACTION_RINGER_MODE, |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 158 | (Integer) list[0]); |
| 159 | // fall through |
| 160 | case EVENT_INTERNAL_RINGER_MODE_CHANGED: |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 161 | sb.append(ringerModeToString((Integer) list[0])); |
| 162 | break; |
| 163 | case EVENT_ZEN_MODE_CHANGED: |
| 164 | sb.append(zenModeToString((Integer) list[0])); |
| 165 | break; |
| 166 | case EVENT_SUPPRESSOR_CHANGED: |
| 167 | sb.append(list[0]).append(' ').append(list[1]); |
| 168 | break; |
| 169 | default: |
| 170 | sb.append(Arrays.asList(list)); |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | Log.i(TAG, sb.toString()); |
| 175 | if (sCallback != null) { |
| 176 | sCallback.writeEvent(time, tag, list); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | public static void writeState(long time, State state) { |
| 181 | if (sCallback != null) { |
| 182 | sCallback.writeState(time, state); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | private static String iconStateToString(int iconState) { |
| 187 | switch (iconState) { |
| 188 | case ICON_STATE_UNMUTE: return "unmute"; |
| 189 | case ICON_STATE_MUTE: return "mute"; |
| 190 | case ICON_STATE_VIBRATE: return "vibrate"; |
| 191 | default: return "unknown_state_" + iconState; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | private static String ringerModeToString(int ringerMode) { |
| 196 | switch (ringerMode) { |
| 197 | case AudioManager.RINGER_MODE_SILENT: return "silent"; |
| 198 | case AudioManager.RINGER_MODE_VIBRATE: return "vibrate"; |
| 199 | case AudioManager.RINGER_MODE_NORMAL: return "normal"; |
| 200 | default: return "unknown"; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | private static String zenModeToString(int zenMode) { |
| 205 | switch (zenMode) { |
| 206 | case Global.ZEN_MODE_OFF: return "off"; |
| 207 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return "important_interruptions"; |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 208 | case Global.ZEN_MODE_ALARMS: return "alarms"; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 209 | case Global.ZEN_MODE_NO_INTERRUPTIONS: return "no_interruptions"; |
| 210 | default: return "unknown"; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | public interface Callback { |
| 215 | void writeEvent(long time, int tag, Object[] list); |
| 216 | void writeState(long time, State state); |
| 217 | } |
| 218 | } |