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 public boolean isPinned; 48 CallRecord(int atomId, UiEventLogger.UiEventEnum eventId, String packageName, InstanceId instanceId)49 CallRecord(int atomId, UiEventLogger.UiEventEnum eventId, 50 String packageName, InstanceId instanceId) { 51 this.atomId = atomId; 52 this.packageName = packageName; 53 this.instanceId = instanceId; 54 this.event = eventId; 55 } 56 CallRecord(int atomId, String packageName, InstanceId instanceId, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)57 CallRecord(int atomId, String packageName, InstanceId instanceId, String mimeType, 58 int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, 59 String intent) { 60 this.atomId = atomId; 61 this.packageName = packageName; 62 this.instanceId = instanceId; 63 this.mimeType = mimeType; 64 this.appProvidedDirect = appProvidedDirect; 65 this.appProvidedApp = appProvidedApp; 66 this.isWorkprofile = isWorkprofile; 67 this.previewType = previewType; 68 this.intent = intent; 69 } 70 CallRecord(int atomId, String packageName, InstanceId instanceId, int targetType, int positionPicked, boolean isPinned)71 CallRecord(int atomId, String packageName, InstanceId instanceId, int targetType, 72 int positionPicked, boolean isPinned) { 73 this.atomId = atomId; 74 this.packageName = packageName; 75 this.instanceId = instanceId; 76 this.targetType = targetType; 77 this.positionPicked = positionPicked; 78 this.isPinned = isPinned; 79 } 80 81 } 82 private List<CallRecord> mCalls = new ArrayList<>(); 83 numCalls()84 public int numCalls() { 85 return mCalls.size(); 86 } 87 getCalls()88 List<CallRecord> getCalls() { 89 return mCalls; 90 } 91 get(int index)92 CallRecord get(int index) { 93 return mCalls.get(index); 94 } 95 event(int index)96 UiEventLogger.UiEventEnum event(int index) { 97 return mCalls.get(index).event; 98 } 99 removeCallsForUiEventsOfType(int uiEventType)100 public void removeCallsForUiEventsOfType(int uiEventType) { 101 mCalls.removeIf( 102 call -> 103 (call.atomId == FrameworkStatsLog.UI_EVENT_REPORTED) 104 && (call.event.getId() == uiEventType)); 105 } 106 107 @Override logShareStarted(int eventId, String packageName, String mimeType, int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, String intent)108 public void logShareStarted(int eventId, String packageName, String mimeType, 109 int appProvidedDirect, int appProvidedApp, boolean isWorkprofile, int previewType, 110 String intent) { 111 mCalls.add(new CallRecord(FrameworkStatsLog.SHARESHEET_STARTED, packageName, 112 getInstanceId(), mimeType, appProvidedDirect, appProvidedApp, isWorkprofile, 113 previewType, intent)); 114 } 115 116 @Override logShareTargetSelected(int targetType, String packageName, int positionPicked, boolean isPinned)117 public void logShareTargetSelected(int targetType, String packageName, int positionPicked, 118 boolean isPinned) { 119 mCalls.add(new CallRecord(FrameworkStatsLog.RANKING_SELECTED, packageName, getInstanceId(), 120 SharesheetTargetSelectedEvent.fromTargetType(targetType).getId(), positionPicked, 121 isPinned)); 122 } 123 124 @Override log(UiEventLogger.UiEventEnum event, InstanceId instanceId)125 public void log(UiEventLogger.UiEventEnum event, InstanceId instanceId) { 126 mCalls.add(new CallRecord(FrameworkStatsLog.UI_EVENT_REPORTED, 127 event, "", instanceId)); 128 } 129 130 @Override getInstanceId()131 public InstanceId getInstanceId() { 132 return InstanceId.fakeInstanceId(-1); 133 } 134 } 135