1 /* 2 * Copyright (C) 2022 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.providers.media.metrics; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 22 import com.android.internal.logging.InstanceId; 23 import com.android.internal.logging.UiEventLogger; 24 import com.android.providers.media.MediaProviderStatsLog; 25 26 public class MPUiEventLoggerImpl implements UiEventLogger { 27 28 @Override log(@onNull UiEventEnum event)29 public void log(@NonNull UiEventEnum event) { 30 log(event, 0, null); 31 } 32 33 @Override log(@onNull UiEventEnum event, @Nullable InstanceId instance)34 public void log(@NonNull UiEventEnum event, @Nullable InstanceId instance) { 35 logWithInstanceId(event, 0, null, instance); 36 } 37 38 @Override log(@onNull UiEventEnum event, int uid, @Nullable String packageName)39 public void log(@NonNull UiEventEnum event, int uid, @Nullable String packageName) { 40 final int eventID = event.getId(); 41 if (eventID > 0) { 42 MediaProviderStatsLog.write(MediaProviderStatsLog.UI_EVENT_REPORTED, 43 /* event_id = 1 */ eventID, 44 /* uid = 2 */ uid, 45 /* package_name = 3 */ packageName, 46 /* instance_id = 4 */ 0); 47 } 48 } 49 50 @Override logWithInstanceId(@onNull UiEventEnum event, int uid, @Nullable String packageName, @Nullable InstanceId instance)51 public void logWithInstanceId(@NonNull UiEventEnum event, int uid, @Nullable String packageName, 52 @Nullable InstanceId instance) { 53 final int eventID = event.getId(); 54 if ((eventID > 0) && (instance != null)) { 55 MediaProviderStatsLog.write(MediaProviderStatsLog.UI_EVENT_REPORTED, 56 /* event_id = 1 */ eventID, 57 /* uid = 2 */ uid, 58 /* package_name = 3 */ packageName, 59 /* instance_id = 4 */ instance.getId()); 60 } else { 61 log(event, uid, packageName); 62 } 63 } 64 65 @Override logWithPosition(@onNull UiEventEnum event, int uid, @Nullable String packageName, int position)66 public void logWithPosition(@NonNull UiEventEnum event, int uid, @Nullable String packageName, 67 int position) { 68 final int eventID = event.getId(); 69 if (eventID > 0) { 70 MediaProviderStatsLog.write(MediaProviderStatsLog.RANKING_SELECTED, 71 /* event_id = 1 */ eventID, 72 /* package_name = 2 */ packageName, 73 /* instance_id = 3 */ 0, 74 /* position_picked = 4 */ position, 75 /* is_pinned = 5 */ false); 76 } 77 } 78 79 @Override logWithInstanceIdAndPosition(@onNull UiEventEnum event, int uid, @Nullable String packageName, @Nullable InstanceId instance, int position)80 public void logWithInstanceIdAndPosition(@NonNull UiEventEnum event, int uid, 81 @Nullable String packageName, @Nullable InstanceId instance, int position) { 82 final int eventID = event.getId(); 83 if ((eventID > 0) && (instance != null)) { 84 MediaProviderStatsLog.write(MediaProviderStatsLog.RANKING_SELECTED, 85 /* event_id = 1 */ eventID, 86 /* package_name = 2 */ packageName, 87 /* instance_id = 3 */ instance.getId(), 88 /* position_picked = 4 */ position, 89 /* is_pinned = 5 */ false); 90 } else { 91 logWithPosition(event, uid, packageName, position); 92 } 93 } 94 } 95