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.accessibility.util; 18 19 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON; 20 import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY; 21 22 import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_COMPONENT_NAME; 23 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__DISABLED; 24 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__ENABLED; 25 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__UNKNOWN; 26 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON; 27 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON_LONG_PRESS; 28 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__TRIPLE_TAP; 29 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__UNKNOWN_TYPE; 30 import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY; 31 32 import android.content.ComponentName; 33 import android.view.accessibility.AccessibilityManager; 34 import android.view.accessibility.AccessibilityManager.ShortcutType; 35 36 import com.android.internal.util.FrameworkStatsLog; 37 38 /** Methods for logging accessibility states. */ 39 public final class AccessibilityStatsLogUtils { 40 private static final int UNKNOWN_STATUS = 41 ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__UNKNOWN; 42 AccessibilityStatsLogUtils()43 private AccessibilityStatsLogUtils() {} 44 45 /** 46 * Logs accessibility feature name that is assigned to the shortcut also its shortcut type. 47 * Calls this when clicking the shortcut {@link AccessibilityManager#ACCESSIBILITY_BUTTON} or 48 * {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} 49 * 50 * @param componentName component name of the accessibility feature 51 * @param shortcutType accessibility shortcut type {@link ShortcutType} 52 */ logAccessibilityShortcutActivated(ComponentName componentName, @ShortcutType int shortcutType)53 public static void logAccessibilityShortcutActivated(ComponentName componentName, 54 @ShortcutType int shortcutType) { 55 logAccessibilityShortcutActivated(componentName, shortcutType, UNKNOWN_STATUS); 56 } 57 58 /** 59 * Logs accessibility feature name that is assigned to the shortcut also its shortcut type and 60 * enabled status. Calls this when clicking the shortcut 61 * {@link AccessibilityManager#ACCESSIBILITY_BUTTON} 62 * or {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} 63 * 64 * @param componentName component name of the accessibility feature 65 * @param shortcutType accessibility shortcut type 66 * @param serviceEnabled {@code true} if the service is enabled 67 */ logAccessibilityShortcutActivated(ComponentName componentName, @ShortcutType int shortcutType, boolean serviceEnabled)68 public static void logAccessibilityShortcutActivated(ComponentName componentName, 69 @ShortcutType int shortcutType, boolean serviceEnabled) { 70 logAccessibilityShortcutActivated(componentName, shortcutType, 71 convertToLoggingServiceStatus(serviceEnabled)); 72 } 73 74 /** 75 * Logs accessibility feature name that is assigned to the shortcut also its shortcut type and 76 * status code. Calls this when clicking the shortcut 77 * {@link AccessibilityManager#ACCESSIBILITY_BUTTON} 78 * or {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} 79 * 80 * @param componentName component name of the accessibility feature 81 * @param shortcutType accessibility shortcut type {@link ShortcutType} 82 * @param serviceStatus The service status code. 0 denotes unknown_status, 1 denotes enabled, 2 83 * denotes disabled. 84 */ logAccessibilityShortcutActivated(ComponentName componentName, @ShortcutType int shortcutType, int serviceStatus)85 private static void logAccessibilityShortcutActivated(ComponentName componentName, 86 @ShortcutType int shortcutType, int serviceStatus) { 87 FrameworkStatsLog.write(FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED, 88 componentName.flattenToString(), convertToLoggingShortcutType(shortcutType), 89 serviceStatus); 90 } 91 92 /** 93 * Logs magnification that is assigned to the triple tap shortcut. Calls this when triggering 94 * the magnification triple tap shortcut. 95 */ logMagnificationTripleTap(boolean enabled)96 public static void logMagnificationTripleTap(boolean enabled) { 97 FrameworkStatsLog.write(FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED, 98 MAGNIFICATION_COMPONENT_NAME.flattenToString(), 99 ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__TRIPLE_TAP, 100 convertToLoggingServiceStatus(enabled)); 101 } 102 103 /** 104 * Logs accessibility feature name that is assigned to the long pressed accessibility button 105 * shortcut. Calls this when clicking the long pressed accessibility button shortcut. 106 * 107 * @param componentName The component name of the accessibility feature. 108 */ logAccessibilityButtonLongPressStatus(ComponentName componentName)109 public static void logAccessibilityButtonLongPressStatus(ComponentName componentName) { 110 FrameworkStatsLog.write(FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED, 111 componentName.flattenToString(), 112 ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON_LONG_PRESS, 113 UNKNOWN_STATUS); 114 } 115 convertToLoggingShortcutType(@hortcutType int shortcutType)116 private static int convertToLoggingShortcutType(@ShortcutType int shortcutType) { 117 switch (shortcutType) { 118 case ACCESSIBILITY_BUTTON: 119 return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON; 120 case ACCESSIBILITY_SHORTCUT_KEY: 121 return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY; 122 } 123 return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__UNKNOWN_TYPE; 124 } 125 convertToLoggingServiceStatus(boolean enabled)126 private static int convertToLoggingServiceStatus(boolean enabled) { 127 return enabled ? ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__ENABLED 128 : ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__DISABLED; 129 } 130 } 131