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