Merge "Add the log for new supported accessibility button type 'Accessibility Floating Menu'" into sc-dev

This commit is contained in:
Jason Hsu
2021-06-18 02:10:28 +00:00
committed by Android (Google) Code Review
2 changed files with 57 additions and 39 deletions

View File

@@ -16,6 +16,7 @@
package com.android.internal.accessibility.util; package com.android.internal.accessibility.util;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL; import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN; import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW; import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
@@ -28,6 +29,7 @@ import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__UNKNOWN; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SERVICE_STATUS__UNKNOWN;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON_LONG_PRESS; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON_LONG_PRESS;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_FLOATING_MENU;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__TRIPLE_TAP; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__TRIPLE_TAP;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__UNKNOWN_TYPE; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__UNKNOWN_TYPE;
import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY; import static com.android.internal.util.FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY;
@@ -37,6 +39,8 @@ import static com.android.internal.util.FrameworkStatsLog.MAGNIFICATION_USAGE_RE
import static com.android.internal.util.FrameworkStatsLog.MAGNIFICATION_USAGE_REPORTED__ACTIVATED_MODE__MAGNIFICATION_WINDOW; import static com.android.internal.util.FrameworkStatsLog.MAGNIFICATION_USAGE_REPORTED__ACTIVATED_MODE__MAGNIFICATION_WINDOW;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.ShortcutType; import android.view.accessibility.AccessibilityManager.ShortcutType;
@@ -50,50 +54,54 @@ public final class AccessibilityStatsLogUtils {
private AccessibilityStatsLogUtils() {} private AccessibilityStatsLogUtils() {}
/** /**
* Logs accessibility feature name that is assigned to the shortcut also its shortcut type. * Logs accessibility feature name that is assigned to the given {@code shortcutType}.
* Calls this when clicking the shortcut {@link AccessibilityManager#ACCESSIBILITY_BUTTON} or * Calls this when clicking the shortcut {@link AccessibilityManager#ACCESSIBILITY_BUTTON} or
* {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} * {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY}.
* *
* @param context context used to retrieve the {@link Settings} provider
* @param componentName component name of the accessibility feature * @param componentName component name of the accessibility feature
* @param shortcutType accessibility shortcut type {@link ShortcutType} * @param shortcutType accessibility shortcut type
*/ */
public static void logAccessibilityShortcutActivated(ComponentName componentName, public static void logAccessibilityShortcutActivated(Context context,
@ShortcutType int shortcutType) { ComponentName componentName, @ShortcutType int shortcutType) {
logAccessibilityShortcutActivated(componentName, shortcutType, UNKNOWN_STATUS); logAccessibilityShortcutActivatedInternal(componentName,
convertToLoggingShortcutType(context, shortcutType), UNKNOWN_STATUS);
} }
/** /**
* Logs accessibility feature name that is assigned to the shortcut also its shortcut type and * Logs accessibility feature name that is assigned to the given {@code shortcutType} and the
* enabled status. Calls this when clicking the shortcut * {@code serviceEnabled} status.
* {@link AccessibilityManager#ACCESSIBILITY_BUTTON} * Calls this when clicking the shortcut {@link AccessibilityManager#ACCESSIBILITY_BUTTON}
* or {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} * or {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY}.
* *
* @param context context used to retrieve the {@link Settings} provider
* @param componentName component name of the accessibility feature * @param componentName component name of the accessibility feature
* @param shortcutType accessibility shortcut type * @param shortcutType accessibility shortcut type
* @param serviceEnabled {@code true} if the service is enabled * @param serviceEnabled {@code true} if the service is enabled
*/ */
public static void logAccessibilityShortcutActivated(ComponentName componentName, public static void logAccessibilityShortcutActivated(Context context,
@ShortcutType int shortcutType, boolean serviceEnabled) { ComponentName componentName, @ShortcutType int shortcutType, boolean serviceEnabled) {
logAccessibilityShortcutActivated(componentName, shortcutType, logAccessibilityShortcutActivatedInternal(componentName,
convertToLoggingShortcutType(context, shortcutType),
convertToLoggingServiceStatus(serviceEnabled)); convertToLoggingServiceStatus(serviceEnabled));
} }
/** /**
* Logs accessibility feature name that is assigned to the shortcut also its shortcut type and * Logs accessibility feature name that is assigned to the given {@code loggingShortcutType} and
* status code. Calls this when clicking the shortcut * {@code loggingServiceStatus} code.
* {@link AccessibilityManager#ACCESSIBILITY_BUTTON}
* or {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY}
* *
* @param componentName component name of the accessibility feature * @param componentName component name of the accessibility feature
* @param shortcutType accessibility shortcut type {@link ShortcutType} * @param loggingShortcutType accessibility shortcut type for logging. 0 denotes
* @param serviceStatus The service status code. 0 denotes unknown_status, 1 denotes enabled, 2 * unknown_type, 1 denotes accessibility button, 2 denotes volume
* denotes disabled. * key, 3 denotes triple tap on the screen, 4 denotes long press on
* accessibility button, 5 denotes accessibility floating menu.
* @param loggingServiceStatus The service status code for logging. 0 denotes unknown_status, 1
* denotes enabled, 2 denotes disabled.
*/ */
private static void logAccessibilityShortcutActivated(ComponentName componentName, private static void logAccessibilityShortcutActivatedInternal(ComponentName componentName,
@ShortcutType int shortcutType, int serviceStatus) { int loggingShortcutType, int loggingServiceStatus) {
FrameworkStatsLog.write(FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED, FrameworkStatsLog.write(FrameworkStatsLog.ACCESSIBILITY_SHORTCUT_REPORTED,
componentName.flattenToString(), convertToLoggingShortcutType(shortcutType), componentName.flattenToString(), loggingShortcutType, loggingServiceStatus);
serviceStatus);
} }
/** /**
@@ -144,10 +152,19 @@ public final class AccessibilityStatsLogUtils {
convertToLoggingMagnificationMode(mode)); convertToLoggingMagnificationMode(mode));
} }
private static int convertToLoggingShortcutType(@ShortcutType int shortcutType) { private static boolean isFloatingMenuEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, /* def= */ -1)
== ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
}
private static int convertToLoggingShortcutType(Context context,
@ShortcutType int shortcutType) {
switch (shortcutType) { switch (shortcutType) {
case ACCESSIBILITY_BUTTON: case ACCESSIBILITY_BUTTON:
return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON; return isFloatingMenuEnabled(context)
? ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_FLOATING_MENU
: ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__A11Y_BUTTON;
case ACCESSIBILITY_SHORTCUT_KEY: case ACCESSIBILITY_SHORTCUT_KEY:
return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY; return ACCESSIBILITY_SHORTCUT_REPORTED__SHORTCUT_TYPE__VOLUME_KEY;
} }

View File

@@ -2892,7 +2892,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
// In case user assigned magnification to the given shortcut. // In case user assigned magnification to the given shortcut.
if (targetName.equals(MAGNIFICATION_CONTROLLER_NAME)) { if (targetName.equals(MAGNIFICATION_CONTROLLER_NAME)) {
final boolean enabled = !getFullScreenMagnificationController().isMagnifying(displayId); final boolean enabled = !getFullScreenMagnificationController().isMagnifying(displayId);
logAccessibilityShortcutActivated(MAGNIFICATION_COMPONENT_NAME, shortcutType, enabled); logAccessibilityShortcutActivated(mContext, MAGNIFICATION_COMPONENT_NAME, shortcutType,
enabled);
sendAccessibilityButtonToInputFilter(displayId); sendAccessibilityButtonToInputFilter(displayId);
return; return;
} }
@@ -2907,7 +2908,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
} }
// In case user assigned an accessibility shortcut target to the given shortcut. // In case user assigned an accessibility shortcut target to the given shortcut.
if (performAccessibilityShortcutTargetActivity(displayId, targetComponentName)) { if (performAccessibilityShortcutTargetActivity(displayId, targetComponentName)) {
logAccessibilityShortcutActivated(targetComponentName, shortcutType); logAccessibilityShortcutActivated(mContext, targetComponentName, shortcutType);
return; return;
} }
// in case user assigned an accessibility service to the given shortcut. // in case user assigned an accessibility service to the given shortcut.
@@ -2930,12 +2931,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
featureInfo.getSettingKey(), mCurrentUserId); featureInfo.getSettingKey(), mCurrentUserId);
// Assuming that the default state will be to have the feature off // Assuming that the default state will be to have the feature off
if (!TextUtils.equals(featureInfo.getSettingOnValue(), setting.read())) { if (!TextUtils.equals(featureInfo.getSettingOnValue(), setting.read())) {
logAccessibilityShortcutActivated(assignedTarget, shortcutType, /* serviceEnabled= */ logAccessibilityShortcutActivated(mContext, assignedTarget, shortcutType,
true); /* serviceEnabled= */ true);
setting.write(featureInfo.getSettingOnValue()); setting.write(featureInfo.getSettingOnValue());
} else { } else {
logAccessibilityShortcutActivated(assignedTarget, shortcutType, /* serviceEnabled= */ logAccessibilityShortcutActivated(mContext, assignedTarget, shortcutType,
false); /* serviceEnabled= */ false);
setting.write(featureInfo.getSettingOffValue()); setting.write(featureInfo.getSettingOffValue());
} }
return true; return true;
@@ -2997,13 +2998,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
if ((targetSdk <= Build.VERSION_CODES.Q && shortcutType == ACCESSIBILITY_SHORTCUT_KEY) if ((targetSdk <= Build.VERSION_CODES.Q && shortcutType == ACCESSIBILITY_SHORTCUT_KEY)
|| (targetSdk > Build.VERSION_CODES.Q && !requestA11yButton)) { || (targetSdk > Build.VERSION_CODES.Q && !requestA11yButton)) {
if (serviceConnection == null) { if (serviceConnection == null) {
logAccessibilityShortcutActivated(assignedTarget, logAccessibilityShortcutActivated(mContext, assignedTarget, shortcutType,
shortcutType, /* serviceEnabled= */ true); /* serviceEnabled= */ true);
enableAccessibilityServiceLocked(assignedTarget, mCurrentUserId); enableAccessibilityServiceLocked(assignedTarget, mCurrentUserId);
} else { } else {
logAccessibilityShortcutActivated(assignedTarget, logAccessibilityShortcutActivated(mContext, assignedTarget, shortcutType,
shortcutType, /* serviceEnabled= */ false); /* serviceEnabled= */ false);
disableAccessibilityServiceLocked(assignedTarget, mCurrentUserId); disableAccessibilityServiceLocked(assignedTarget, mCurrentUserId);
} }
return true; return true;
@@ -3024,8 +3025,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
return false; return false;
} }
// ServiceConnection means service enabled. // ServiceConnection means service enabled.
logAccessibilityShortcutActivated(assignedTarget, shortcutType, /* serviceEnabled= */ logAccessibilityShortcutActivated(mContext, assignedTarget, shortcutType,
true); /* serviceEnabled= */ true);
serviceConnection.notifyAccessibilityButtonClickedLocked(displayId); serviceConnection.notifyAccessibilityButtonClickedLocked(displayId);
return true; return true;
} }