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.settings.accessibility; 18 19 import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE; 20 import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE; 21 22 import android.accessibilityservice.AccessibilityServiceInfo; 23 import android.os.Bundle; 24 import android.view.View; 25 26 import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType; 27 import com.android.settings.R; 28 29 /** 30 * Fragment that only allowed hardware {@link UserShortcutType} for shortcut to open. 31 * 32 * <p>The child {@link ToggleAccessibilityServicePreferenceFragment} shows the actual UI for 33 * providing basic accessibility service setup. 34 * 35 * <p>For accessibility services that target SDK <= Q. 36 */ 37 public class VolumeShortcutToggleAccessibilityServicePreferenceFragment extends 38 ToggleAccessibilityServicePreferenceFragment { 39 40 @Override onViewCreated(View view, Bundle savedInstanceState)41 public void onViewCreated(View view, Bundle savedInstanceState) { 42 super.onViewCreated(view, savedInstanceState); 43 44 final CharSequence hardwareTitle = getPrefContext().getText( 45 R.string.accessibility_shortcut_edit_dialog_title_hardware); 46 mShortcutPreference.setSummary(hardwareTitle); 47 mShortcutPreference.setSettingsEditable(false); 48 49 setAllowedPreferredShortcutType(HARDWARE); 50 } 51 52 @Override getUserShortcutTypes()53 int getUserShortcutTypes() { 54 int shortcutTypes = super.getUserShortcutTypes(); 55 final boolean isServiceOn = 56 getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED); 57 final AccessibilityServiceInfo info = getAccessibilityServiceInfo(); 58 final boolean hasRequestAccessibilityButtonFlag = info != null 59 && (info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0; 60 if (hasRequestAccessibilityButtonFlag && isServiceOn) { 61 shortcutTypes |= SOFTWARE; 62 } else { 63 shortcutTypes &= (~SOFTWARE); 64 } 65 66 return shortcutTypes; 67 } 68 setAllowedPreferredShortcutType(int type)69 private void setAllowedPreferredShortcutType(int type) { 70 final String componentNameString = mComponentName.flattenToString(); 71 final PreferredShortcut shortcut = new PreferredShortcut(componentNameString, type); 72 73 PreferredShortcuts.saveUserShortcutType(getPrefContext(), shortcut); 74 } 75 } 76