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