• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.UiEventLogger;
21 import com.android.internal.util.FrameworkStatsLog;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 public class ChooserActivityLoggerFake implements ChooserActivityLogger {
27     static class CallRecord {
28         // shared fields between all logs
29         public int atomId;
30         public String packageName;
31         public InstanceId instanceId;
32 
33         // generic log field
34         public UiEventLogger.UiEventEnum event;
35 
36         // share started fields
37         public String mimeType;
38         public int appProvidedDirect;
39         public int appProvidedApp;
40         public boolean isWorkprofile;
41         public int previewType;
42         public String intent;
43 
44         // share completed fields
45         public int targetType;
46         public int positionPicked;
47 
CallRecord(int atomId, UiEventLogger.UiEventEnum eventId, String packageName, InstanceId instanceId)48         CallRecord(int atomId, UiEventLogger.UiEventEnum eventId,
49                 String packageName, InstanceId instanceId) {
50             this.atomId = atomId;
51             this.packageName = packageName;
52             this.instanceId = instanceId;
53             this.event = eventId;
54         }
55 
CallRecord(int atomId, String packageName, InstanceId instanceId, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)56         CallRecord(int atomId, String packageName, InstanceId instanceId, String mimeType,
57                 int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType,
58                 String intent) {
59             this.atomId = atomId;
60             this.packageName = packageName;
61             this.instanceId = instanceId;
62             this.mimeType = mimeType;
63             this.appProvidedDirect = appProvidedDirect;
64             this.appProvidedApp = appProvidedApp;
65             this.isWorkprofile = isWorkprofile;
66             this.previewType = previewType;
67             this.intent = intent;
68         }
69 
CallRecord(int atomId, String packageName, InstanceId instanceId, int targetType, int positionPicked)70         CallRecord(int atomId, String packageName, InstanceId instanceId, int targetType,
71                 int positionPicked) {
72             this.atomId = atomId;
73             this.packageName = packageName;
74             this.instanceId = instanceId;
75             this.targetType = targetType;
76             this.positionPicked = positionPicked;
77         }
78 
79     }
80     private List<CallRecord> mCalls = new ArrayList<>();
81 
numCalls()82     public int numCalls() {
83         return mCalls.size();
84     }
85 
getCalls()86     List<CallRecord> getCalls() {
87         return mCalls;
88     }
89 
get(int index)90     CallRecord get(int index) {
91         return mCalls.get(index);
92     }
93 
event(int index)94     UiEventLogger.UiEventEnum event(int index) {
95         return mCalls.get(index).event;
96     }
97 
98     @Override
logShareStarted(int eventId, String packageName, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)99     public void logShareStarted(int eventId, String packageName, String mimeType,
100             int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType,
101             String intent) {
102         mCalls.add(new CallRecord(FrameworkStatsLog.SHARESHEET_STARTED, packageName,
103                 getInstanceId(), mimeType, appProvidedDirect, appProvidedApp, isWorkprofile,
104                 previewType, intent));
105     }
106 
107     @Override
logShareTargetSelected(int targetType, String packageName, int positionPicked)108     public void logShareTargetSelected(int targetType, String packageName, int positionPicked) {
109         mCalls.add(new CallRecord(FrameworkStatsLog.RANKING_SELECTED, packageName, getInstanceId(),
110                 SharesheetTargetSelectedEvent.fromTargetType(targetType).getId(), positionPicked));
111     }
112 
113     @Override
log(UiEventLogger.UiEventEnum event, InstanceId instanceId)114     public void log(UiEventLogger.UiEventEnum event, InstanceId instanceId) {
115         mCalls.add(new CallRecord(FrameworkStatsLog.UI_EVENT_REPORTED,
116                     event, "", instanceId));
117     }
118 
119     @Override
getInstanceId()120     public InstanceId getInstanceId() {
121         return InstanceId.fakeInstanceId(-1);
122     }
123 }
124