1 /* 2 * Copyright (C) 2018 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 android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.Vibrator; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settingslib.search.SearchIndexable; 31 32 /** 33 * Accessibility settings for the vibration. 34 */ 35 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 36 public class VibrationSettings extends DashboardFragment { 37 38 private static final String TAG = "VibrationSettings"; 39 40 @Override getPreferenceScreenBindingKey(@onNull Context context)41 public @Nullable String getPreferenceScreenBindingKey(@NonNull Context context) { 42 return VibrationScreen.KEY; 43 } 44 45 @Override getMetricsCategory()46 public int getMetricsCategory() { 47 return SettingsEnums.ACCESSIBILITY_VIBRATION; 48 } 49 50 @Override getHelpResource()51 public int getHelpResource() { 52 return R.string.help_uri_accessibility_vibration; 53 } 54 55 @Override getPreferenceScreenResId()56 protected int getPreferenceScreenResId() { 57 return R.xml.accessibility_vibration_settings; 58 } 59 60 @Override getLogTag()61 protected String getLogTag() { 62 return TAG; 63 } 64 65 @VisibleForTesting isPageSearchEnabled(Context context)66 static boolean isPageSearchEnabled(Context context) { 67 final int supportedIntensityLevels = context.getResources().getInteger( 68 R.integer.config_vibration_supported_intensity_levels); 69 final boolean hasVibrator = context.getSystemService(Vibrator.class).hasVibrator(); 70 return hasVibrator && supportedIntensityLevels == 1; 71 } 72 73 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 74 new BaseSearchIndexProvider(R.xml.accessibility_vibration_settings) { 75 @Override 76 protected boolean isPageSearchEnabled(Context context) { 77 return VibrationSettings.isPageSearchEnabled(context); 78 } 79 }; 80 } 81