1 /* 2 * Copyright (C) 2020 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.internal.app; 18 19 import android.content.Intent; 20 import android.provider.MediaStore; 21 22 import com.android.internal.logging.InstanceId; 23 import com.android.internal.logging.UiEvent; 24 import com.android.internal.logging.UiEventLogger; 25 import com.android.internal.util.FrameworkStatsLog; 26 27 /** 28 * Interface for writing Sharesheet atoms to statsd log. 29 * @hide 30 */ 31 public interface ChooserActivityLogger { 32 /** Logs a UiEventReported event for the system sharesheet completing initial start-up. */ logShareStarted(int eventId, String packageName, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)33 void logShareStarted(int eventId, String packageName, String mimeType, int appProvidedDirect, 34 int appProvidedApp, boolean isWorkprofile, int previewType, String intent); 35 36 /** Logs a UiEventReported event for the system sharesheet when the user selects a target. */ logShareTargetSelected(int targetType, String packageName, int positionPicked)37 void logShareTargetSelected(int targetType, String packageName, int positionPicked); 38 39 /** Logs a UiEventReported event for the system sharesheet being triggered by the user. */ logSharesheetTriggered()40 default void logSharesheetTriggered() { 41 log(SharesheetStandardEvent.SHARESHEET_TRIGGERED, getInstanceId()); 42 } 43 44 /** Logs a UiEventReported event for the system sharesheet completing loading app targets. */ logSharesheetAppLoadComplete()45 default void logSharesheetAppLoadComplete() { 46 log(SharesheetStandardEvent.SHARESHEET_APP_LOAD_COMPLETE, getInstanceId()); 47 } 48 49 /** 50 * Logs a UiEventReported event for the system sharesheet completing loading service targets. 51 */ logSharesheetDirectLoadComplete()52 default void logSharesheetDirectLoadComplete() { 53 log(SharesheetStandardEvent.SHARESHEET_DIRECT_LOAD_COMPLETE, getInstanceId()); 54 } 55 56 /** 57 * Logs a UiEventReported event for the system sharesheet timing out loading service targets. 58 */ logSharesheetDirectLoadTimeout()59 default void logSharesheetDirectLoadTimeout() { 60 log(SharesheetStandardEvent.SHARESHEET_DIRECT_LOAD_TIMEOUT, getInstanceId()); 61 } 62 63 /** 64 * Logs a UiEventReported event for the system sharesheet switching 65 * between work and main profile. 66 */ logShareheetProfileChanged()67 default void logShareheetProfileChanged() { 68 log(SharesheetStandardEvent.SHARESHEET_PROFILE_CHANGED, getInstanceId()); 69 } 70 71 /** Logs a UiEventReported event for the system sharesheet getting expanded or collapsed. */ logSharesheetExpansionChanged(boolean isCollapsed)72 default void logSharesheetExpansionChanged(boolean isCollapsed) { 73 log(isCollapsed ? SharesheetStandardEvent.SHARESHEET_COLLAPSED : 74 SharesheetStandardEvent.SHARESHEET_EXPANDED, getInstanceId()); 75 } 76 77 /** 78 * Logs a UiEventReported event for the system sharesheet app share ranking timing out. 79 */ logSharesheetAppShareRankingTimeout()80 default void logSharesheetAppShareRankingTimeout() { 81 log(SharesheetStandardEvent.SHARESHEET_APP_SHARE_RANKING_TIMEOUT, getInstanceId()); 82 } 83 84 /** 85 * Logs a UiEventReported event for the system sharesheet when direct share row is empty. 86 */ logSharesheetEmptyDirectShareRow()87 default void logSharesheetEmptyDirectShareRow() { 88 log(SharesheetStandardEvent.SHARESHEET_EMPTY_DIRECT_SHARE_ROW, getInstanceId()); 89 } 90 91 /** 92 * Logs a UiEventReported event for a given share activity 93 * @param event 94 * @param instanceId 95 */ log(UiEventLogger.UiEventEnum event, InstanceId instanceId)96 void log(UiEventLogger.UiEventEnum event, InstanceId instanceId); 97 98 /** 99 * 100 * @return 101 */ getInstanceId()102 InstanceId getInstanceId(); 103 104 /** 105 * The UiEvent enums that this class can log. 106 */ 107 enum SharesheetStartedEvent implements UiEventLogger.UiEventEnum { 108 @UiEvent(doc = "Basic system Sharesheet has started and is visible.") 109 SHARE_STARTED(228); 110 111 private final int mId; SharesheetStartedEvent(int id)112 SharesheetStartedEvent(int id) { 113 mId = id; 114 } 115 @Override getId()116 public int getId() { 117 return mId; 118 } 119 } 120 121 /** 122 * The UiEvent enums that this class can log. 123 */ 124 enum SharesheetTargetSelectedEvent implements UiEventLogger.UiEventEnum { 125 INVALID(0), 126 @UiEvent(doc = "User selected a service target.") 127 SHARESHEET_SERVICE_TARGET_SELECTED(232), 128 @UiEvent(doc = "User selected an app target.") 129 SHARESHEET_APP_TARGET_SELECTED(233), 130 @UiEvent(doc = "User selected a standard target.") 131 SHARESHEET_STANDARD_TARGET_SELECTED(234), 132 @UiEvent(doc = "User selected the copy target.") 133 SHARESHEET_COPY_TARGET_SELECTED(235), 134 @UiEvent(doc = "User selected the nearby target.") 135 SHARESHEET_NEARBY_TARGET_SELECTED(626), 136 @UiEvent(doc = "User selected the edit target.") 137 SHARESHEET_EDIT_TARGET_SELECTED(669); 138 139 private final int mId; SharesheetTargetSelectedEvent(int id)140 SharesheetTargetSelectedEvent(int id) { 141 mId = id; 142 } getId()143 @Override public int getId() { 144 return mId; 145 } 146 fromTargetType(int targetType)147 public static SharesheetTargetSelectedEvent fromTargetType(int targetType) { 148 switch(targetType) { 149 case ChooserActivity.SELECTION_TYPE_SERVICE: 150 return SHARESHEET_SERVICE_TARGET_SELECTED; 151 case ChooserActivity.SELECTION_TYPE_APP: 152 return SHARESHEET_APP_TARGET_SELECTED; 153 case ChooserActivity.SELECTION_TYPE_STANDARD: 154 return SHARESHEET_STANDARD_TARGET_SELECTED; 155 case ChooserActivity.SELECTION_TYPE_COPY: 156 return SHARESHEET_COPY_TARGET_SELECTED; 157 case ChooserActivity.SELECTION_TYPE_NEARBY: 158 return SHARESHEET_NEARBY_TARGET_SELECTED; 159 case ChooserActivity.SELECTION_TYPE_EDIT: 160 return SHARESHEET_EDIT_TARGET_SELECTED; 161 default: 162 return INVALID; 163 } 164 } 165 } 166 167 /** 168 * The UiEvent enums that this class can log. 169 */ 170 enum SharesheetStandardEvent implements UiEventLogger.UiEventEnum { 171 INVALID(0), 172 @UiEvent(doc = "User clicked share.") 173 SHARESHEET_TRIGGERED(227), 174 @UiEvent(doc = "User changed from work to personal profile or vice versa.") 175 SHARESHEET_PROFILE_CHANGED(229), 176 @UiEvent(doc = "User expanded target list.") 177 SHARESHEET_EXPANDED(230), 178 @UiEvent(doc = "User collapsed target list.") 179 SHARESHEET_COLLAPSED(231), 180 @UiEvent(doc = "Sharesheet app targets is fully populated.") 181 SHARESHEET_APP_LOAD_COMPLETE(322), 182 @UiEvent(doc = "Sharesheet direct targets is fully populated.") 183 SHARESHEET_DIRECT_LOAD_COMPLETE(323), 184 @UiEvent(doc = "Sharesheet direct targets timed out.") 185 SHARESHEET_DIRECT_LOAD_TIMEOUT(324), 186 @UiEvent(doc = "Sharesheet app share ranking timed out.") 187 SHARESHEET_APP_SHARE_RANKING_TIMEOUT(831), 188 @UiEvent(doc = "Sharesheet empty direct share row.") 189 SHARESHEET_EMPTY_DIRECT_SHARE_ROW(828); 190 191 private final int mId; SharesheetStandardEvent(int id)192 SharesheetStandardEvent(int id) { 193 mId = id; 194 } getId()195 @Override public int getId() { 196 return mId; 197 } 198 } 199 200 /** 201 * Returns the enum used in sharesheet started atom to indicate what preview type was used. 202 */ typeFromPreviewInt(int previewType)203 default int typeFromPreviewInt(int previewType) { 204 switch(previewType) { 205 case ChooserActivity.CONTENT_PREVIEW_IMAGE: 206 return FrameworkStatsLog.SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_IMAGE; 207 case ChooserActivity.CONTENT_PREVIEW_FILE: 208 return FrameworkStatsLog.SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_FILE; 209 case ChooserActivity.CONTENT_PREVIEW_TEXT: 210 default: 211 return FrameworkStatsLog 212 .SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_TYPE_UNKNOWN; 213 } 214 } 215 216 /** 217 * Returns the enum used in sharesheet started atom to indicate what intent triggers the 218 * ChooserActivity. 219 */ typeFromIntentString(String intent)220 default int typeFromIntentString(String intent) { 221 if (intent == null) { 222 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_DEFAULT; 223 } 224 switch (intent) { 225 case Intent.ACTION_VIEW: 226 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_VIEW; 227 case Intent.ACTION_EDIT: 228 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_EDIT; 229 case Intent.ACTION_SEND: 230 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SEND; 231 case Intent.ACTION_SENDTO: 232 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SENDTO; 233 case Intent.ACTION_SEND_MULTIPLE: 234 return FrameworkStatsLog 235 .SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SEND_MULTIPLE; 236 case MediaStore.ACTION_IMAGE_CAPTURE: 237 return FrameworkStatsLog 238 .SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_IMAGE_CAPTURE; 239 case Intent.ACTION_MAIN: 240 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_MAIN; 241 default: 242 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_DEFAULT; 243 } 244 } 245 } 246