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 com.android.internal.logging.InstanceId;
20 import com.android.internal.logging.InstanceIdSequence;
21 import com.android.internal.logging.UiEventLogger;
22 import com.android.internal.logging.UiEventLoggerImpl;
23 import com.android.internal.util.FrameworkStatsLog;
24 
25 /**
26  * Standard implementation of ChooserActivityLogger interface.
27  * @hide
28  */
29 public class ChooserActivityLoggerImpl implements ChooserActivityLogger {
30     private static final int SHARESHEET_INSTANCE_ID_MAX = (1 << 13);
31 
32     private UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
33     // A small per-notification ID, used for statsd logging.
34     private InstanceId mInstanceId;
35     private static InstanceIdSequence sInstanceIdSequence;
36 
37     @Override
logShareStarted(int eventId, String packageName, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)38     public void logShareStarted(int eventId, String packageName, String mimeType,
39             int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType,
40             String intent) {
41         FrameworkStatsLog.write(FrameworkStatsLog.SHARESHEET_STARTED,
42                 /* event_id = 1 */ SharesheetStartedEvent.SHARE_STARTED.getId(),
43                 /* package_name = 2 */ packageName,
44                 /* instance_id = 3 */ getInstanceId().getId(),
45                 /* mime_type = 4 */ mimeType,
46                 /* num_app_provided_direct_targets = 5 */ appProvidedDirect,
47                 /* num_app_provided_app_targets = 6 */ appProvidedApp,
48                 /* is_workprofile = 7 */ isWorkprofile,
49                 /* previewType = 8 */ typeFromPreviewInt(previewType),
50                 /* intentType = 9 */ typeFromIntentString(intent));
51     }
52 
53     @Override
logShareTargetSelected(int targetType, String packageName, int positionPicked)54     public void logShareTargetSelected(int targetType, String packageName, int positionPicked) {
55         FrameworkStatsLog.write(FrameworkStatsLog.RANKING_SELECTED,
56                 /* event_id = 1 */ SharesheetTargetSelectedEvent.fromTargetType(targetType).getId(),
57                 /* package_name = 2 */ packageName,
58                 /* instance_id = 3 */ getInstanceId().getId(),
59                 /* position_picked = 4 */ positionPicked);
60     }
61 
62     @Override
log(UiEventLogger.UiEventEnum event, InstanceId instanceId)63     public void log(UiEventLogger.UiEventEnum event, InstanceId instanceId) {
64         mUiEventLogger.logWithInstanceId(
65                 event,
66                 0,
67                 null,
68                 instanceId);
69     }
70 
71     @Override
getInstanceId()72     public InstanceId getInstanceId() {
73         if (mInstanceId == null) {
74             if (sInstanceIdSequence == null) {
75                 sInstanceIdSequence = new InstanceIdSequence(SHARESHEET_INSTANCE_ID_MAX);
76             }
77             mInstanceId = sInstanceIdSequence.newInstanceId();
78         }
79         return mInstanceId;
80     }
81 
82 }
83