Loading core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java +142 −26 Original line number Diff line number Diff line Loading @@ -19,6 +19,15 @@ import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTT import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY; import static android.view.accessibility.AccessibilityManager.ShortcutType; import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.COMPONENT_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.FRAGMENT_TYPE; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.ICON_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.LABEL_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.SETTINGS_KEY; import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.IntDef; import android.annotation.NonNull; Loading Loading @@ -63,10 +72,6 @@ import java.util.StringJoiner; * Activity used to display and persist a service or feature target for the Accessibility button. */ public class AccessibilityButtonChooserActivity extends Activity { private static final String MAGNIFICATION_COMPONENT_ID = "com.android.server.accessibility.MagnificationController"; private static final char SERVICES_SEPARATOR = ':'; private static final TextUtils.SimpleStringSplitter sStringColonSplitter = new TextUtils.SimpleStringSplitter(SERVICES_SEPARATOR); Loading @@ -76,7 +81,7 @@ public class AccessibilityButtonChooserActivity extends Activity { ACCESSIBILITY_SHORTCUT_KEY); private int mShortcutType; private List<AccessibilityButtonTarget> mTargets = new ArrayList<>(); private final List<AccessibilityButtonTarget> mTargets = new ArrayList<>(); private AlertDialog mAlertDialog; private TargetAdapter mTargetAdapter; Loading @@ -99,7 +104,7 @@ public class AccessibilityButtonChooserActivity extends Activity { UserShortcutType.TRIPLETAP, }) /** Denotes the user shortcut type. */ public @interface UserShortcutType { private @interface UserShortcutType { int DEFAULT = 0; int SOFTWARE = 1; // 1 << 0 int HARDWARE = 2; // 1 << 1 Loading @@ -122,7 +127,7 @@ public class AccessibilityButtonChooserActivity extends Activity { AccessibilityServiceFragmentType.INTUITIVE, AccessibilityServiceFragmentType.BOUNCE, }) public @interface AccessibilityServiceFragmentType { private @interface AccessibilityServiceFragmentType { int LEGACY = 0; int INVISIBLE = 1; int INTUITIVE = 2; Loading @@ -140,11 +145,61 @@ public class AccessibilityButtonChooserActivity extends Activity { ShortcutMenuMode.LAUNCH, ShortcutMenuMode.EDIT, }) public @interface ShortcutMenuMode { private @interface ShortcutMenuMode { int LAUNCH = 0; int EDIT = 1; } /** * Annotation for align the element index of white listing feature * {@code WHITE_LISTING_FEATURES}. * * {@code COMPONENT_ID} is to get the service component name. * {@code LABEL_ID} is to get the service label text. * {@code ICON_ID} is to get the service icon. * {@code FRAGMENT_TYPE} is to get the service fragment type. * {@code SETTINGS_KEY} is to get the service settings key. */ @Retention(RetentionPolicy.SOURCE) @IntDef({ WhiteListingFeatureElementIndex.COMPONENT_ID, WhiteListingFeatureElementIndex.LABEL_ID, WhiteListingFeatureElementIndex.ICON_ID, WhiteListingFeatureElementIndex.FRAGMENT_TYPE, WhiteListingFeatureElementIndex.SETTINGS_KEY, }) @interface WhiteListingFeatureElementIndex { int COMPONENT_ID = 0; int LABEL_ID = 1; int ICON_ID = 2; int FRAGMENT_TYPE = 3; int SETTINGS_KEY = 4; } private static final String[][] WHITE_LISTING_FEATURES = { { COLOR_INVERSION_COMPONENT_NAME.flattenToString(), String.valueOf(R.string.color_inversion_feature_name), String.valueOf(R.drawable.ic_accessibility_color_inversion), String.valueOf(AccessibilityServiceFragmentType.INTUITIVE), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, }, { DALTONIZER_COMPONENT_NAME.flattenToString(), String.valueOf(R.string.color_correction_feature_name), String.valueOf(R.drawable.ic_accessibility_color_correction), String.valueOf(AccessibilityServiceFragmentType.INTUITIVE), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, }, { MAGNIFICATION_CONTROLLER_NAME, String.valueOf(R.string.accessibility_magnification_chooser_text), String.valueOf(R.drawable.ic_accessibility_magnification), String.valueOf(AccessibilityServiceFragmentType.INVISIBLE), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, }, }; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Loading Loading @@ -199,6 +254,20 @@ public class AccessibilityButtonChooserActivity extends Activity { private static List<AccessibilityButtonTarget> getServiceTargets(@NonNull Context context, @ShortcutType int shortcutType) { final List<AccessibilityButtonTarget> targets = new ArrayList<>(); targets.addAll(getAccessibilityServiceTargets(context)); targets.addAll(getWhiteListingServiceTargets(context)); final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); final List<String> requiredTargets = ams.getAccessibilityShortcutTargets(shortcutType); targets.removeIf(target -> !requiredTargets.contains(target.getId())); return targets; } private static List<AccessibilityButtonTarget> getAccessibilityServiceTargets( @NonNull Context context) { final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); final List<AccessibilityServiceInfo> installedServices = Loading @@ -209,29 +278,73 @@ public class AccessibilityButtonChooserActivity extends Activity { final List<AccessibilityButtonTarget> targets = new ArrayList<>(installedServices.size()); for (AccessibilityServiceInfo info : installedServices) { if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { targets.add(new AccessibilityButtonTarget(context, info)); } return targets; } final List<String> requiredTargets = ams.getAccessibilityShortcutTargets(shortcutType); targets.removeIf(target -> !requiredTargets.contains(target.getId())); private static List<AccessibilityButtonTarget> getWhiteListingServiceTargets( @NonNull Context context) { final List<AccessibilityButtonTarget> targets = new ArrayList<>(); // TODO(b/146815874): Will replace it with white list services. if (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1) { final AccessibilityButtonTarget magnificationTarget = new AccessibilityButtonTarget( for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { final AccessibilityButtonTarget target = new AccessibilityButtonTarget( context, MAGNIFICATION_COMPONENT_ID, R.string.accessibility_magnification_chooser_text, R.drawable.ic_accessibility_magnification, AccessibilityServiceFragmentType.INTUITIVE); targets.add(magnificationTarget); WHITE_LISTING_FEATURES[i][COMPONENT_ID], Integer.parseInt(WHITE_LISTING_FEATURES[i][LABEL_ID]), Integer.parseInt(WHITE_LISTING_FEATURES[i][ICON_ID]), Integer.parseInt(WHITE_LISTING_FEATURES[i][FRAGMENT_TYPE])); targets.add(target); } return targets; } private static boolean isWhiteListingServiceEnabled(@NonNull Context context, AccessibilityButtonTarget target) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(target.getId())) { return Settings.Secure.getInt(context.getContentResolver(), WHITE_LISTING_FEATURES[i][SETTINGS_KEY], /* settingsValueOff */ 0) == /* settingsValueOn */ 1; } } return false; } private static boolean isWhiteListingService(String componentId) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(componentId)) { return true; } } return false; } private void disableWhiteListingService(String componentId) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(componentId)) { Settings.Secure.putInt(getContentResolver(), WHITE_LISTING_FEATURES[i][SETTINGS_KEY], /* settingsValueOn */ 1); return; } } } private void disableService(ComponentName componentName) { final String componentId = componentName.flattenToString(); if (isWhiteListingService(componentId)) { disableWhiteListingService(componentName.flattenToString()); } else { setAccessibilityServiceState(this, componentName, /* enabled= */ false); } } private static class ViewHolder { ImageView mIconView; TextView mLabelView; Loading Loading @@ -350,11 +463,14 @@ public class AccessibilityButtonChooserActivity extends Activity { private void updateIntuitiveActionItemVisibility(@NonNull Context context, @NonNull ViewHolder holder, AccessibilityButtonTarget target) { final boolean isEditMenuMode = (mShortcutMenuMode == ShortcutMenuMode.EDIT); final boolean isServiceEnabled = isWhiteListingService(target.getId()) ? isWhiteListingServiceEnabled(context, target) : isAccessibilityServiceEnabled(context, target); holder.mViewItem.setImageDrawable(context.getDrawable(R.drawable.ic_delete_item)); holder.mViewItem.setVisibility(isEditMenuMode ? View.VISIBLE : View.GONE); holder.mSwitchItem.setVisibility(isEditMenuMode ? View.GONE : View.VISIBLE); holder.mSwitchItem.setChecked(!isEditMenuMode && isServiceEnabled(context, target)); holder.mSwitchItem.setChecked(!isEditMenuMode && isServiceEnabled); holder.mItemContainer.setVisibility(View.VISIBLE); } Loading Loading @@ -411,7 +527,7 @@ public class AccessibilityButtonChooserActivity extends Activity { } } private static boolean isServiceEnabled(@NonNull Context context, private static boolean isAccessibilityServiceEnabled(@NonNull Context context, AccessibilityButtonTarget target) { final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); Loading Loading @@ -470,14 +586,14 @@ public class AccessibilityButtonChooserActivity extends Activity { if (!hasValueInSettings(this, ACCESSIBILITY_SHORTCUT_KEY_USER_TYPE, componentName)) { setAccessibilityServiceState(this, componentName, /* enabled= */ false); disableService(componentName); } } else if (mShortcutType == ACCESSIBILITY_SHORTCUT_KEY) { optOutValueFromSettings(this, ACCESSIBILITY_SHORTCUT_KEY_USER_TYPE, componentName); if (!hasValueInSettings(this, ACCESSIBILITY_BUTTON_USER_TYPE, componentName)) { setAccessibilityServiceState(this, componentName, /* enabled= */ false); disableService(componentName); } } else { throw new IllegalArgumentException("Unsupported shortcut type:" + mShortcutType); Loading core/res/res/drawable/ic_accessibility_color_correction.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="192" android:viewportWidth="192" android:width="24dp" xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#00BCD4" android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M13.58,69.14L87.15,12c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c3.36,2.68 5.27,6.67 5.41,10.82c0.15,-4.51 -1.79,-8.93 -5.41,-11.82l-73.81,-58.94C99.61,7.01 92.35,6.96 87.15,11L13.58,68.14c-3.71,2.88 -5.72,7.36 -5.56,11.94C8.17,75.85 10.14,71.81 13.58,69.14z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M183.35,84.63l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84c-6.31,0 -11.87,-4.17 -13.7,-10.26L8.61,82.77c-0.36,-1.22 -0.55,-2.46 -0.59,-3.69c-0.06,1.56 0.13,3.14 0.59,4.69l28.53,89.97c1.83,6.09 7.39,10.26 13.7,10.26h90.37c6.28,0 11.82,-4.13 13.67,-10.19l28.48,-88.18c0.48,-1.57 0.67,-3.17 0.61,-4.75C183.92,82.13 183.73,83.39 183.35,84.63z" android:strokeAlpha="0.2"/> <path android:pathData="M60.01,135L60.01,135H60l48.04,49h33.17c6.28,0 11.82,-4.13 13.67,-10.19l18.68,-57.84L129.51,72.2l-0.01,0c0.27,0.27 0.52,0.5 0.77,0.77l0.55,0.55c1.57,1.56 1.57,4.08 -0.04,5.68l-12.56,12.49l6.36,6.3l1.38,1.37l-5.67,5.64l-5.71,-5.68L79.15,135H60.42H60.01z"> <aapt:attr name="android:fillColor"> <gradient android:endX="155.9627" android:endY="165.1493" android:startX="98.4649" android:startY="107.6516" android:type="linear"> <item android:color="#19263238" android:offset="0"/> <item android:color="#00212121" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:fillColor="#0097A7" android:pathData="M68.55,120.35l32.173,-32.173l7.658,7.658l-32.173,32.173z"/> <path android:fillColor="#FFFFFF" android:pathData="M130.83,73.52l-9.42,-9.36c-1.57,-1.56 -4.1,-1.56 -5.67,0l-12.56,12.48L95.42,69l-5.67,5.64l5.71,5.68L60,116.97V135h19.15l35.42,-35.68l5.71,5.68l5.67,-5.64l-7.73,-7.68l12.56,-12.48C132.4,77.6 132.4,75.08 130.83,73.52zM74.98,126.77l-6.43,-6.43l32.17,-32.17l6.43,6.43L74.98,126.77z"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M120.28,105l-5.71,-5.68l-35.42,35.68l-19.15,0l1,1l19.15,0l35.42,-35.68l5.71,5.68l5.68,-5.64l-1,-1z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M90.75,75.64l-0.01,0l4.71,4.68l0.01,0z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M131.83,74.52l-0.97,-0.97c1.54,1.56 1.53,4.06 -0.07,5.65l-12.56,12.48l1,1l12.55,-12.48C133.4,78.6 133.4,76.08 131.83,74.52z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M101.72,89.17l6.67,6.66l0,0l-7.67,-7.66l-32.17,32.17l1,1z" android:strokeAlpha="0.1"/> <path android:pathData="M37.13,173.7L8.62,83.69c-1.7,-5.8 0.3,-12 5,-15.6l73.52,-57.1c5.2,-4 12.5,-4 17.6,0.1l73.82,58.9c4.6,3.7 6.5,9.9 4.8,15.6l-28.51,88.21c-1.8,6.1 -7.4,10.2 -13.7,10.2H50.83C44.53,184 38.93,179.8 37.13,173.7z"> <aapt:attr name="android:fillColor"> <gradient android:centerX="21.977" android:centerY="23.8809" android:gradientRadius="158.0384" android:type="radial"> <item android:color="#19FFFFFF" android:offset="0"/> <item android:color="#00FFFFFF" android:offset="1"/> </gradient> </aapt:attr> </path> </vector> core/res/res/drawable/ic_accessibility_color_inversion.xml 0 → 100644 +47 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="192" android:viewportWidth="192" android:width="24dp" xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#546E7A" android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M183.37,84.63l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84c-6.31,0 -11.87,-4.17 -13.7,-10.26L8.61,82.77c-0.36,-1.22 -0.55,-2.46 -0.59,-3.69c-0.06,1.56 0.13,3.14 0.59,4.69l28.53,89.97c1.83,6.09 7.39,10.26 13.7,10.26h90.38c6.28,0 11.82,-4.13 13.67,-10.19l28.48,-88.18c0.48,-1.57 0.67,-3.17 0.61,-4.75C183.94,82.13 183.74,83.39 183.37,84.63z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M13.58,69.14L87.15,12c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c3.36,2.68 5.27,6.67 5.41,10.82c0.15,-4.51 -1.79,-8.93 -5.41,-11.82l-73.81,-58.94C99.61,7.01 92.35,6.96 87.15,11L13.58,68.14c-3.71,2.88 -5.72,7.36 -5.56,11.94C8.17,75.85 10.14,71.81 13.58,69.14z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M53,130.05l5.03,-4.79L44.16,112c-0.05,0.78 -0.14,1.52 -0.15,2.34C43.62,136.61 61.27,154.56 84,156v-5.31C70.13,149.64 58.56,141.54 53,130.05z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M109,52v5.31c13.65,1.05 24.67,9.15 30.11,20.64l-4.92,4.79L147.81,96c0.09,-0.78 0.17,-1.53 0.19,-2.34C148.38,71.39 131.36,53.44 109,52z" android:strokeAlpha="0.2"/> <path android:pathData="M154.89,173.81l13.57,-42.02l-46.53,-46.56C125.75,90.5 128,96.98 128,104c0,17.7 -14.3,32 -32,32c-8.64,0 -16.47,-3.42 -22.22,-8.97l0.9,0.91L130.73,184h10.49C147.5,184 153.04,179.87 154.89,173.81z"> <aapt:attr name="android:fillColor"> <gradient android:endX="153.3523" android:endY="161.6371" android:startX="90.6075" android:startY="98.8923" android:type="linear"> <item android:color="#33263238" android:offset="0"/> <item android:color="#05263238" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:pathData="M96,129.6V78.4c-14.11,0 -25.6,11.49 -25.6,25.6S81.89,129.6 96,129.6z"> <aapt:attr name="android:fillColor"> <gradient android:endX="150.8492" android:endY="164.1401" android:startX="88.1044" android:startY="101.3954" android:type="linear"> <item android:color="#33263238" android:offset="0"/> <item android:color="#05263238" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M96,136c-17.53,0 -31.72,-14.04 -31.99,-31.5c0,0.17 -0.01,0.33 -0.01,0.5c0,17.7 14.3,32 32,32s32,-14.3 32,-32c0,-0.17 -0.01,-0.33 -0.01,-0.5C127.72,121.96 113.53,136 96,136z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M70.4,104c0,0.17 0.01,0.33 0.01,0.5C70.68,90.62 82.06,79.4 96,79.4v-1C81.89,78.4 70.4,89.88 70.4,104z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M96,72c-17.7,0 -32,14.3 -32,32s14.3,32 32,32s32,-14.3 32,-32S113.7,72 96,72zM70.4,104c0,-14.11 11.49,-25.6 25.6,-25.6v51.2C81.89,129.6 70.4,118.11 70.4,104z" android:strokeAlpha="0.2"/> <path android:fillColor="#FFFFFF" android:pathData="M96,72c-17.7,0 -32,14.3 -32,32s14.3,32 32,32s32,-14.3 32,-32S113.7,72 96,72zM70.4,104c0,-14.11 11.49,-25.6 25.6,-25.6v51.2C81.89,129.6 70.4,118.11 70.4,104z"/> <path android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"> <aapt:attr name="android:fillColor"> <gradient android:endX="156.2451" android:endY="171.4516" android:startX="37.0633" android:startY="52.269802" android:type="linear"> <item android:color="#19FFFFFF" android:offset="0"/> <item android:color="#00FFFFFF" android:offset="1"/> </gradient> </aapt:attr> </path> </vector> core/res/res/values/symbols.xml +2 −0 Original line number Diff line number Diff line Loading @@ -3214,6 +3214,8 @@ <java-symbol type="string" name="edit_accessibility_shortcut_menu_button" /> <java-symbol type="string" name="cancel_accessibility_shortcut_menu_button" /> <java-symbol type="drawable" name="ic_accessibility_color_inversion" /> <java-symbol type="drawable" name="ic_accessibility_color_correction" /> <java-symbol type="drawable" name="ic_accessibility_magnification" /> <java-symbol type="drawable" name="ic_delete_item" /> Loading Loading
core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java +142 −26 Original line number Diff line number Diff line Loading @@ -19,6 +19,15 @@ import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTT import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY; import static android.view.accessibility.AccessibilityManager.ShortcutType; import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.COMPONENT_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.FRAGMENT_TYPE; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.ICON_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.LABEL_ID; import static com.android.internal.app.AccessibilityButtonChooserActivity.WhiteListingFeatureElementIndex.SETTINGS_KEY; import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.IntDef; import android.annotation.NonNull; Loading Loading @@ -63,10 +72,6 @@ import java.util.StringJoiner; * Activity used to display and persist a service or feature target for the Accessibility button. */ public class AccessibilityButtonChooserActivity extends Activity { private static final String MAGNIFICATION_COMPONENT_ID = "com.android.server.accessibility.MagnificationController"; private static final char SERVICES_SEPARATOR = ':'; private static final TextUtils.SimpleStringSplitter sStringColonSplitter = new TextUtils.SimpleStringSplitter(SERVICES_SEPARATOR); Loading @@ -76,7 +81,7 @@ public class AccessibilityButtonChooserActivity extends Activity { ACCESSIBILITY_SHORTCUT_KEY); private int mShortcutType; private List<AccessibilityButtonTarget> mTargets = new ArrayList<>(); private final List<AccessibilityButtonTarget> mTargets = new ArrayList<>(); private AlertDialog mAlertDialog; private TargetAdapter mTargetAdapter; Loading @@ -99,7 +104,7 @@ public class AccessibilityButtonChooserActivity extends Activity { UserShortcutType.TRIPLETAP, }) /** Denotes the user shortcut type. */ public @interface UserShortcutType { private @interface UserShortcutType { int DEFAULT = 0; int SOFTWARE = 1; // 1 << 0 int HARDWARE = 2; // 1 << 1 Loading @@ -122,7 +127,7 @@ public class AccessibilityButtonChooserActivity extends Activity { AccessibilityServiceFragmentType.INTUITIVE, AccessibilityServiceFragmentType.BOUNCE, }) public @interface AccessibilityServiceFragmentType { private @interface AccessibilityServiceFragmentType { int LEGACY = 0; int INVISIBLE = 1; int INTUITIVE = 2; Loading @@ -140,11 +145,61 @@ public class AccessibilityButtonChooserActivity extends Activity { ShortcutMenuMode.LAUNCH, ShortcutMenuMode.EDIT, }) public @interface ShortcutMenuMode { private @interface ShortcutMenuMode { int LAUNCH = 0; int EDIT = 1; } /** * Annotation for align the element index of white listing feature * {@code WHITE_LISTING_FEATURES}. * * {@code COMPONENT_ID} is to get the service component name. * {@code LABEL_ID} is to get the service label text. * {@code ICON_ID} is to get the service icon. * {@code FRAGMENT_TYPE} is to get the service fragment type. * {@code SETTINGS_KEY} is to get the service settings key. */ @Retention(RetentionPolicy.SOURCE) @IntDef({ WhiteListingFeatureElementIndex.COMPONENT_ID, WhiteListingFeatureElementIndex.LABEL_ID, WhiteListingFeatureElementIndex.ICON_ID, WhiteListingFeatureElementIndex.FRAGMENT_TYPE, WhiteListingFeatureElementIndex.SETTINGS_KEY, }) @interface WhiteListingFeatureElementIndex { int COMPONENT_ID = 0; int LABEL_ID = 1; int ICON_ID = 2; int FRAGMENT_TYPE = 3; int SETTINGS_KEY = 4; } private static final String[][] WHITE_LISTING_FEATURES = { { COLOR_INVERSION_COMPONENT_NAME.flattenToString(), String.valueOf(R.string.color_inversion_feature_name), String.valueOf(R.drawable.ic_accessibility_color_inversion), String.valueOf(AccessibilityServiceFragmentType.INTUITIVE), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, }, { DALTONIZER_COMPONENT_NAME.flattenToString(), String.valueOf(R.string.color_correction_feature_name), String.valueOf(R.drawable.ic_accessibility_color_correction), String.valueOf(AccessibilityServiceFragmentType.INTUITIVE), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, }, { MAGNIFICATION_CONTROLLER_NAME, String.valueOf(R.string.accessibility_magnification_chooser_text), String.valueOf(R.drawable.ic_accessibility_magnification), String.valueOf(AccessibilityServiceFragmentType.INVISIBLE), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, }, }; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Loading Loading @@ -199,6 +254,20 @@ public class AccessibilityButtonChooserActivity extends Activity { private static List<AccessibilityButtonTarget> getServiceTargets(@NonNull Context context, @ShortcutType int shortcutType) { final List<AccessibilityButtonTarget> targets = new ArrayList<>(); targets.addAll(getAccessibilityServiceTargets(context)); targets.addAll(getWhiteListingServiceTargets(context)); final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); final List<String> requiredTargets = ams.getAccessibilityShortcutTargets(shortcutType); targets.removeIf(target -> !requiredTargets.contains(target.getId())); return targets; } private static List<AccessibilityButtonTarget> getAccessibilityServiceTargets( @NonNull Context context) { final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); final List<AccessibilityServiceInfo> installedServices = Loading @@ -209,29 +278,73 @@ public class AccessibilityButtonChooserActivity extends Activity { final List<AccessibilityButtonTarget> targets = new ArrayList<>(installedServices.size()); for (AccessibilityServiceInfo info : installedServices) { if ((info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0) { targets.add(new AccessibilityButtonTarget(context, info)); } return targets; } final List<String> requiredTargets = ams.getAccessibilityShortcutTargets(shortcutType); targets.removeIf(target -> !requiredTargets.contains(target.getId())); private static List<AccessibilityButtonTarget> getWhiteListingServiceTargets( @NonNull Context context) { final List<AccessibilityButtonTarget> targets = new ArrayList<>(); // TODO(b/146815874): Will replace it with white list services. if (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 1) { final AccessibilityButtonTarget magnificationTarget = new AccessibilityButtonTarget( for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { final AccessibilityButtonTarget target = new AccessibilityButtonTarget( context, MAGNIFICATION_COMPONENT_ID, R.string.accessibility_magnification_chooser_text, R.drawable.ic_accessibility_magnification, AccessibilityServiceFragmentType.INTUITIVE); targets.add(magnificationTarget); WHITE_LISTING_FEATURES[i][COMPONENT_ID], Integer.parseInt(WHITE_LISTING_FEATURES[i][LABEL_ID]), Integer.parseInt(WHITE_LISTING_FEATURES[i][ICON_ID]), Integer.parseInt(WHITE_LISTING_FEATURES[i][FRAGMENT_TYPE])); targets.add(target); } return targets; } private static boolean isWhiteListingServiceEnabled(@NonNull Context context, AccessibilityButtonTarget target) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(target.getId())) { return Settings.Secure.getInt(context.getContentResolver(), WHITE_LISTING_FEATURES[i][SETTINGS_KEY], /* settingsValueOff */ 0) == /* settingsValueOn */ 1; } } return false; } private static boolean isWhiteListingService(String componentId) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(componentId)) { return true; } } return false; } private void disableWhiteListingService(String componentId) { for (int i = 0; i < WHITE_LISTING_FEATURES.length; i++) { if (WHITE_LISTING_FEATURES[i][COMPONENT_ID].equals(componentId)) { Settings.Secure.putInt(getContentResolver(), WHITE_LISTING_FEATURES[i][SETTINGS_KEY], /* settingsValueOn */ 1); return; } } } private void disableService(ComponentName componentName) { final String componentId = componentName.flattenToString(); if (isWhiteListingService(componentId)) { disableWhiteListingService(componentName.flattenToString()); } else { setAccessibilityServiceState(this, componentName, /* enabled= */ false); } } private static class ViewHolder { ImageView mIconView; TextView mLabelView; Loading Loading @@ -350,11 +463,14 @@ public class AccessibilityButtonChooserActivity extends Activity { private void updateIntuitiveActionItemVisibility(@NonNull Context context, @NonNull ViewHolder holder, AccessibilityButtonTarget target) { final boolean isEditMenuMode = (mShortcutMenuMode == ShortcutMenuMode.EDIT); final boolean isServiceEnabled = isWhiteListingService(target.getId()) ? isWhiteListingServiceEnabled(context, target) : isAccessibilityServiceEnabled(context, target); holder.mViewItem.setImageDrawable(context.getDrawable(R.drawable.ic_delete_item)); holder.mViewItem.setVisibility(isEditMenuMode ? View.VISIBLE : View.GONE); holder.mSwitchItem.setVisibility(isEditMenuMode ? View.GONE : View.VISIBLE); holder.mSwitchItem.setChecked(!isEditMenuMode && isServiceEnabled(context, target)); holder.mSwitchItem.setChecked(!isEditMenuMode && isServiceEnabled); holder.mItemContainer.setVisibility(View.VISIBLE); } Loading Loading @@ -411,7 +527,7 @@ public class AccessibilityButtonChooserActivity extends Activity { } } private static boolean isServiceEnabled(@NonNull Context context, private static boolean isAccessibilityServiceEnabled(@NonNull Context context, AccessibilityButtonTarget target) { final AccessibilityManager ams = (AccessibilityManager) context.getSystemService( Context.ACCESSIBILITY_SERVICE); Loading Loading @@ -470,14 +586,14 @@ public class AccessibilityButtonChooserActivity extends Activity { if (!hasValueInSettings(this, ACCESSIBILITY_SHORTCUT_KEY_USER_TYPE, componentName)) { setAccessibilityServiceState(this, componentName, /* enabled= */ false); disableService(componentName); } } else if (mShortcutType == ACCESSIBILITY_SHORTCUT_KEY) { optOutValueFromSettings(this, ACCESSIBILITY_SHORTCUT_KEY_USER_TYPE, componentName); if (!hasValueInSettings(this, ACCESSIBILITY_BUTTON_USER_TYPE, componentName)) { setAccessibilityServiceState(this, componentName, /* enabled= */ false); disableService(componentName); } } else { throw new IllegalArgumentException("Unsupported shortcut type:" + mShortcutType); Loading
core/res/res/drawable/ic_accessibility_color_correction.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="192" android:viewportWidth="192" android:width="24dp" xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#00BCD4" android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M13.58,69.14L87.15,12c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c3.36,2.68 5.27,6.67 5.41,10.82c0.15,-4.51 -1.79,-8.93 -5.41,-11.82l-73.81,-58.94C99.61,7.01 92.35,6.96 87.15,11L13.58,68.14c-3.71,2.88 -5.72,7.36 -5.56,11.94C8.17,75.85 10.14,71.81 13.58,69.14z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M183.35,84.63l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84c-6.31,0 -11.87,-4.17 -13.7,-10.26L8.61,82.77c-0.36,-1.22 -0.55,-2.46 -0.59,-3.69c-0.06,1.56 0.13,3.14 0.59,4.69l28.53,89.97c1.83,6.09 7.39,10.26 13.7,10.26h90.37c6.28,0 11.82,-4.13 13.67,-10.19l28.48,-88.18c0.48,-1.57 0.67,-3.17 0.61,-4.75C183.92,82.13 183.73,83.39 183.35,84.63z" android:strokeAlpha="0.2"/> <path android:pathData="M60.01,135L60.01,135H60l48.04,49h33.17c6.28,0 11.82,-4.13 13.67,-10.19l18.68,-57.84L129.51,72.2l-0.01,0c0.27,0.27 0.52,0.5 0.77,0.77l0.55,0.55c1.57,1.56 1.57,4.08 -0.04,5.68l-12.56,12.49l6.36,6.3l1.38,1.37l-5.67,5.64l-5.71,-5.68L79.15,135H60.42H60.01z"> <aapt:attr name="android:fillColor"> <gradient android:endX="155.9627" android:endY="165.1493" android:startX="98.4649" android:startY="107.6516" android:type="linear"> <item android:color="#19263238" android:offset="0"/> <item android:color="#00212121" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:fillColor="#0097A7" android:pathData="M68.55,120.35l32.173,-32.173l7.658,7.658l-32.173,32.173z"/> <path android:fillColor="#FFFFFF" android:pathData="M130.83,73.52l-9.42,-9.36c-1.57,-1.56 -4.1,-1.56 -5.67,0l-12.56,12.48L95.42,69l-5.67,5.64l5.71,5.68L60,116.97V135h19.15l35.42,-35.68l5.71,5.68l5.67,-5.64l-7.73,-7.68l12.56,-12.48C132.4,77.6 132.4,75.08 130.83,73.52zM74.98,126.77l-6.43,-6.43l32.17,-32.17l6.43,6.43L74.98,126.77z"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M120.28,105l-5.71,-5.68l-35.42,35.68l-19.15,0l1,1l19.15,0l35.42,-35.68l5.71,5.68l5.68,-5.64l-1,-1z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M90.75,75.64l-0.01,0l4.71,4.68l0.01,0z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M131.83,74.52l-0.97,-0.97c1.54,1.56 1.53,4.06 -0.07,5.65l-12.56,12.48l1,1l12.55,-12.48C133.4,78.6 133.4,76.08 131.83,74.52z" android:strokeAlpha="0.1"/> <path android:fillAlpha="0.1" android:fillColor="#263238" android:pathData="M101.72,89.17l6.67,6.66l0,0l-7.67,-7.66l-32.17,32.17l1,1z" android:strokeAlpha="0.1"/> <path android:pathData="M37.13,173.7L8.62,83.69c-1.7,-5.8 0.3,-12 5,-15.6l73.52,-57.1c5.2,-4 12.5,-4 17.6,0.1l73.82,58.9c4.6,3.7 6.5,9.9 4.8,15.6l-28.51,88.21c-1.8,6.1 -7.4,10.2 -13.7,10.2H50.83C44.53,184 38.93,179.8 37.13,173.7z"> <aapt:attr name="android:fillColor"> <gradient android:centerX="21.977" android:centerY="23.8809" android:gradientRadius="158.0384" android:type="radial"> <item android:color="#19FFFFFF" android:offset="0"/> <item android:color="#00FFFFFF" android:offset="1"/> </gradient> </aapt:attr> </path> </vector>
core/res/res/drawable/ic_accessibility_color_inversion.xml 0 → 100644 +47 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="192" android:viewportWidth="192" android:width="24dp" xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#546E7A" android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M183.37,84.63l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84c-6.31,0 -11.87,-4.17 -13.7,-10.26L8.61,82.77c-0.36,-1.22 -0.55,-2.46 -0.59,-3.69c-0.06,1.56 0.13,3.14 0.59,4.69l28.53,89.97c1.83,6.09 7.39,10.26 13.7,10.26h90.38c6.28,0 11.82,-4.13 13.67,-10.19l28.48,-88.18c0.48,-1.57 0.67,-3.17 0.61,-4.75C183.94,82.13 183.74,83.39 183.37,84.63z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M13.58,69.14L87.15,12c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c3.36,2.68 5.27,6.67 5.41,10.82c0.15,-4.51 -1.79,-8.93 -5.41,-11.82l-73.81,-58.94C99.61,7.01 92.35,6.96 87.15,11L13.58,68.14c-3.71,2.88 -5.72,7.36 -5.56,11.94C8.17,75.85 10.14,71.81 13.58,69.14z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M53,130.05l5.03,-4.79L44.16,112c-0.05,0.78 -0.14,1.52 -0.15,2.34C43.62,136.61 61.27,154.56 84,156v-5.31C70.13,149.64 58.56,141.54 53,130.05z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M109,52v5.31c13.65,1.05 24.67,9.15 30.11,20.64l-4.92,4.79L147.81,96c0.09,-0.78 0.17,-1.53 0.19,-2.34C148.38,71.39 131.36,53.44 109,52z" android:strokeAlpha="0.2"/> <path android:pathData="M154.89,173.81l13.57,-42.02l-46.53,-46.56C125.75,90.5 128,96.98 128,104c0,17.7 -14.3,32 -32,32c-8.64,0 -16.47,-3.42 -22.22,-8.97l0.9,0.91L130.73,184h10.49C147.5,184 153.04,179.87 154.89,173.81z"> <aapt:attr name="android:fillColor"> <gradient android:endX="153.3523" android:endY="161.6371" android:startX="90.6075" android:startY="98.8923" android:type="linear"> <item android:color="#33263238" android:offset="0"/> <item android:color="#05263238" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:pathData="M96,129.6V78.4c-14.11,0 -25.6,11.49 -25.6,25.6S81.89,129.6 96,129.6z"> <aapt:attr name="android:fillColor"> <gradient android:endX="150.8492" android:endY="164.1401" android:startX="88.1044" android:startY="101.3954" android:type="linear"> <item android:color="#33263238" android:offset="0"/> <item android:color="#05263238" android:offset="1"/> </gradient> </aapt:attr> </path> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M96,136c-17.53,0 -31.72,-14.04 -31.99,-31.5c0,0.17 -0.01,0.33 -0.01,0.5c0,17.7 14.3,32 32,32s32,-14.3 32,-32c0,-0.17 -0.01,-0.33 -0.01,-0.5C127.72,121.96 113.53,136 96,136z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#263238" android:pathData="M70.4,104c0,0.17 0.01,0.33 0.01,0.5C70.68,90.62 82.06,79.4 96,79.4v-1C81.89,78.4 70.4,89.88 70.4,104z" android:strokeAlpha="0.2"/> <path android:fillAlpha="0.2" android:fillColor="#FFFFFF" android:pathData="M96,72c-17.7,0 -32,14.3 -32,32s14.3,32 32,32s32,-14.3 32,-32S113.7,72 96,72zM70.4,104c0,-14.11 11.49,-25.6 25.6,-25.6v51.2C81.89,129.6 70.4,118.11 70.4,104z" android:strokeAlpha="0.2"/> <path android:fillColor="#FFFFFF" android:pathData="M96,72c-17.7,0 -32,14.3 -32,32s14.3,32 32,32s32,-14.3 32,-32S113.7,72 96,72zM70.4,104c0,-14.11 11.49,-25.6 25.6,-25.6v51.2C81.89,129.6 70.4,118.11 70.4,104z"/> <path android:pathData="M37.14,173.74L8.61,83.77c-1.72,-5.75 0.26,-11.97 4.97,-15.63L87.15,11c5.2,-4.04 12.46,-3.99 17.61,0.12l73.81,58.94c4.63,3.7 6.53,9.88 4.8,15.57l-28.48,88.18c-1.85,6.06 -7.39,10.19 -13.67,10.19H50.84C44.53,184 38.97,179.83 37.14,173.74z"> <aapt:attr name="android:fillColor"> <gradient android:endX="156.2451" android:endY="171.4516" android:startX="37.0633" android:startY="52.269802" android:type="linear"> <item android:color="#19FFFFFF" android:offset="0"/> <item android:color="#00FFFFFF" android:offset="1"/> </gradient> </aapt:attr> </path> </vector>
core/res/res/values/symbols.xml +2 −0 Original line number Diff line number Diff line Loading @@ -3214,6 +3214,8 @@ <java-symbol type="string" name="edit_accessibility_shortcut_menu_button" /> <java-symbol type="string" name="cancel_accessibility_shortcut_menu_button" /> <java-symbol type="drawable" name="ic_accessibility_color_inversion" /> <java-symbol type="drawable" name="ic_accessibility_color_correction" /> <java-symbol type="drawable" name="ic_accessibility_magnification" /> <java-symbol type="drawable" name="ic_delete_item" /> Loading