1 /* 2 * Copyright (C) 2022 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 package com.android.settings.display; 17 18 import android.content.Context; 19 import android.text.TextUtils; 20 21 import com.android.settings.core.BasePreferenceController; 22 23 /** 24 * The top-level preference controller for device state based auto-rotation settings. 25 * 26 * It doesn't do anything on its own besides showing/hiding. The toggling of the settings will 27 * always be done in the details screen when device state based auto-rotation is enabled. 28 */ 29 public class DeviceStateAutoRotateOverviewController extends BasePreferenceController { 30 31 /** Preference key for when it is used in "accessibility_system_controls.xml". */ 32 private static final String ACCESSIBILITY_PREF_KEY = "device_state_auto_rotate_accessibility"; 33 DeviceStateAutoRotateOverviewController(Context context, String key)34 public DeviceStateAutoRotateOverviewController(Context context, String key) { 35 super(context, key); 36 } 37 38 @Override getAvailabilityStatus()39 public int getAvailabilityStatus() { 40 return isAvailableInternal() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 41 } 42 isAvailableInternal()43 private boolean isAvailableInternal() { 44 return isA11yPage() 45 ? DeviceStateAutoRotationHelper.isDeviceStateRotationEnabledForA11y(mContext) 46 : DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext); 47 } 48 isA11yPage()49 private boolean isA11yPage() { 50 return TextUtils.equals(getPreferenceKey(), ACCESSIBILITY_PREF_KEY); 51 } 52 } 53