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 a given share activity 79 * @param event 80 * @param instanceId 81 */ log(UiEventLogger.UiEventEnum event, InstanceId instanceId)82 void log(UiEventLogger.UiEventEnum event, InstanceId instanceId); 83 84 /** 85 * 86 * @return 87 */ getInstanceId()88 InstanceId getInstanceId(); 89 90 /** 91 * The UiEvent enums that this class can log. 92 */ 93 enum SharesheetStartedEvent implements UiEventLogger.UiEventEnum { 94 @UiEvent(doc = "Basic system Sharesheet has started and is visible.") 95 SHARE_STARTED(228); 96 97 private final int mId; SharesheetStartedEvent(int id)98 SharesheetStartedEvent(int id) { 99 mId = id; 100 } 101 @Override getId()102 public int getId() { 103 return mId; 104 } 105 } 106 107 /** 108 * The UiEvent enums that this class can log. 109 */ 110 enum SharesheetTargetSelectedEvent implements UiEventLogger.UiEventEnum { 111 INVALID(0), 112 @UiEvent(doc = "User selected a service target.") 113 SHARESHEET_SERVICE_TARGET_SELECTED(232), 114 @UiEvent(doc = "User selected an app target.") 115 SHARESHEET_APP_TARGET_SELECTED(233), 116 @UiEvent(doc = "User selected a standard target.") 117 SHARESHEET_STANDARD_TARGET_SELECTED(234), 118 @UiEvent(doc = "User selected the copy target.") 119 SHARESHEET_COPY_TARGET_SELECTED(235); 120 121 private final int mId; SharesheetTargetSelectedEvent(int id)122 SharesheetTargetSelectedEvent(int id) { 123 mId = id; 124 } getId()125 @Override public int getId() { 126 return mId; 127 } 128 fromTargetType(int targetType)129 public static SharesheetTargetSelectedEvent fromTargetType(int targetType) { 130 switch(targetType) { 131 case ChooserActivity.SELECTION_TYPE_SERVICE: 132 return SHARESHEET_SERVICE_TARGET_SELECTED; 133 case ChooserActivity.SELECTION_TYPE_APP: 134 return SHARESHEET_APP_TARGET_SELECTED; 135 case ChooserActivity.SELECTION_TYPE_STANDARD: 136 return SHARESHEET_STANDARD_TARGET_SELECTED; 137 case ChooserActivity.SELECTION_TYPE_COPY: 138 return SHARESHEET_COPY_TARGET_SELECTED; 139 default: 140 return INVALID; 141 } 142 } 143 } 144 145 /** 146 * The UiEvent enums that this class can log. 147 */ 148 enum SharesheetStandardEvent implements UiEventLogger.UiEventEnum { 149 INVALID(0), 150 @UiEvent(doc = "User clicked share.") 151 SHARESHEET_TRIGGERED(227), 152 @UiEvent(doc = "User changed from work to personal profile or vice versa.") 153 SHARESHEET_PROFILE_CHANGED(229), 154 @UiEvent(doc = "User expanded target list.") 155 SHARESHEET_EXPANDED(230), 156 @UiEvent(doc = "User collapsed target list.") 157 SHARESHEET_COLLAPSED(231), 158 @UiEvent(doc = "Sharesheet app targets is fully populated.") 159 SHARESHEET_APP_LOAD_COMPLETE(322), 160 @UiEvent(doc = "Sharesheet direct targets is fully populated.") 161 SHARESHEET_DIRECT_LOAD_COMPLETE(323), 162 @UiEvent(doc = "Sharesheet direct targets timed out.") 163 SHARESHEET_DIRECT_LOAD_TIMEOUT(324); 164 165 private final int mId; SharesheetStandardEvent(int id)166 SharesheetStandardEvent(int id) { 167 mId = id; 168 } getId()169 @Override public int getId() { 170 return mId; 171 } 172 } 173 174 /** 175 * Returns the enum used in sharesheet started atom to indicate what preview type was used. 176 */ typeFromPreviewInt(int previewType)177 default int typeFromPreviewInt(int previewType) { 178 switch(previewType) { 179 case ChooserActivity.CONTENT_PREVIEW_IMAGE: 180 return FrameworkStatsLog.SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_IMAGE; 181 case ChooserActivity.CONTENT_PREVIEW_FILE: 182 return FrameworkStatsLog.SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_FILE; 183 case ChooserActivity.CONTENT_PREVIEW_TEXT: 184 default: 185 return FrameworkStatsLog 186 .SHARESHEET_STARTED__PREVIEW_TYPE__CONTENT_PREVIEW_TYPE_UNKNOWN; 187 } 188 } 189 190 /** 191 * Returns the enum used in sharesheet started atom to indicate what intent triggers the 192 * ChooserActivity. 193 */ typeFromIntentString(String intent)194 default int typeFromIntentString(String intent) { 195 if (intent == null) { 196 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_DEFAULT; 197 } 198 switch (intent) { 199 case Intent.ACTION_VIEW: 200 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_VIEW; 201 case Intent.ACTION_EDIT: 202 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_EDIT; 203 case Intent.ACTION_SEND: 204 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SEND; 205 case Intent.ACTION_SENDTO: 206 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SENDTO; 207 case Intent.ACTION_SEND_MULTIPLE: 208 return FrameworkStatsLog 209 .SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_SEND_MULTIPLE; 210 case MediaStore.ACTION_IMAGE_CAPTURE: 211 return FrameworkStatsLog 212 .SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_IMAGE_CAPTURE; 213 case Intent.ACTION_MAIN: 214 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_ACTION_MAIN; 215 default: 216 return FrameworkStatsLog.SHARESHEET_STARTED__INTENT_TYPE__INTENT_DEFAULT; 217 } 218 } 219 } 220