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.settings.accessibility; 18 19 import static com.android.settings.accessibility.TextReadingPreferenceFragment.BOLD_TEXT_KEY; 20 import static com.android.settings.accessibility.TextReadingPreferenceFragment.DISPLAY_SIZE_KEY; 21 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS; 22 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS; 23 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_ANYTHING_ELSE; 24 import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS; 25 import static com.android.settings.accessibility.TextReadingPreferenceFragment.FONT_SIZE_KEY; 26 import static com.android.settings.accessibility.TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY; 27 import static com.android.settings.accessibility.TextReadingPreferenceFragment.RESET_KEY; 28 29 import android.content.ComponentName; 30 31 import com.android.internal.util.FrameworkStatsLog; 32 import com.android.settings.core.instrumentation.SettingsStatsLog; 33 34 /** Methods for logging accessibility states. */ 35 public final class AccessibilityStatsLogUtils { 36 AccessibilityStatsLogUtils()37 private AccessibilityStatsLogUtils() {} 38 39 /** 40 * Logs accessibility service name and its enabled status. Calls this when the user trigger 41 * the accessibility service to be enabled/disabled. 42 * 43 * @param componentName component name of the service 44 * @param enabled {@code true} if the service is enabled 45 */ logAccessibilityServiceEnabled(ComponentName componentName, boolean enabled)46 static void logAccessibilityServiceEnabled(ComponentName componentName, boolean enabled) { 47 SettingsStatsLog.write(SettingsStatsLog.ACCESSIBILITY_SERVICE_REPORTED, 48 componentName.flattenToString(), convertToLoggingServiceEnabled(enabled)); 49 } 50 convertToLoggingServiceEnabled(boolean enabled)51 private static int convertToLoggingServiceEnabled(boolean enabled) { 52 return enabled ? SettingsStatsLog.ACCESSIBILITY_SERVICE_REPORTED__SERVICE_STATUS__ENABLED 53 : SettingsStatsLog.ACCESSIBILITY_SERVICE_REPORTED__SERVICE_STATUS__DISABLED; 54 } 55 56 /** 57 * Logs when the non-a11y category service is disabled. Calls this when the user disables the 58 * non-a11y category service for the first time. 59 * 60 * @param packageName package name of the service 61 * @param durationMills duration in milliseconds between starting the page and disabling the 62 * service 63 */ logDisableNonA11yCategoryService(String packageName, long durationMills)64 static void logDisableNonA11yCategoryService(String packageName, long durationMills) { 65 com.android.internal.accessibility.util.AccessibilityStatsLogUtils 66 .logNonA11yToolServiceWarningReported( 67 packageName, 68 com.android.internal.accessibility.util.AccessibilityStatsLogUtils 69 .ACCESSIBILITY_PRIVACY_WARNING_STATUS_SERVICE_DISABLED, 70 durationMills); 71 } 72 73 /** 74 * Converts to the key name for logging. 75 * 76 * @param prefKey the preference key 77 * @return the int value which maps to the key name 78 */ convertToItemKeyName(String prefKey)79 static int convertToItemKeyName(String prefKey) { 80 switch (prefKey) { 81 case FONT_SIZE_KEY: 82 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_FONT_SIZE; 83 case DISPLAY_SIZE_KEY: 84 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_DISPLAY_SIZE; 85 case BOLD_TEXT_KEY: 86 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_BOLD_TEXT; 87 case HIGH_TEXT_CONTRAST_KEY: 88 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_HIGH_CONTRAST_TEXT; 89 case RESET_KEY: 90 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_RESET; 91 default: 92 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_UNKNOWN_ITEM; 93 } 94 } 95 96 /** 97 * Converts to the entry point for logging. 98 * 99 * @param entryPoint the entry point 100 * @return the int value which maps to the entry point 101 */ convertToEntryPoint(int entryPoint)102 static int convertToEntryPoint(int entryPoint) { 103 switch (entryPoint) { 104 case SUW_VISION_SETTINGS: 105 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_VISION_SETTINGS; 106 case SUW_ANYTHING_ELSE: 107 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_ANYTHING_ELSE; 108 case DISPLAY_SETTINGS: 109 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_DISPLAY_SETTINGS; 110 case ACCESSIBILITY_SETTINGS: 111 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_ACCESSIBILITY_SETTINGS; 112 default: 113 return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_UNKNOWN_ENTRY; 114 } 115 } 116 117 /** 118 * Converts the entering page id where the hearing aid binding process starts for logging. 119 * 120 * @param pageId the entry page id where the hearing aid binding process starts 121 * @return the int value for logging mapped from some page ids defined in 122 * {@link SettingsStatsLog} 123 */ convertToHearingAidInfoBondEntry(int pageId)124 public static int convertToHearingAidInfoBondEntry(int pageId) { 125 switch (pageId) { 126 case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__SETTINGS_CONNECTED_DEVICE_CATEGORY: 127 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__CONNECTED_DEVICES; 128 case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__DIALOG_ACCESSIBILITY_HEARINGAID: 129 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__ACCESSIBILITY_HEARING_AIDS; 130 case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__DIALOG_ACCESSIBILITY_HEARING_AID_PAIR_ANOTHER: 131 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__ACCESSIBILITY_HEARING_AID_PAIR_ANOTHER; 132 case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__BLUETOOTH_FRAGMENT: 133 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__BLUETOOTH; 134 case SettingsStatsLog.SETTINGS_UICHANGED__PAGE_ID__ACCESSIBILITY_HEARING_AID_SETTINGS: 135 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__ACCESSIBILITY_HEARING_AID_SETTINGS; 136 default: 137 return FrameworkStatsLog.HEARING_AID_INFO_REPORTED__BOND_ENTRY__PAGE_UNKNOWN; 138 } 139 } 140 } 141