1 /* 2 * Copyright (C) 2024 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.datetime; 17 18 import android.content.Context; 19 20 import androidx.annotation.NonNull; 21 22 import com.android.settings.core.BasePreferenceController; 23 import com.android.settingslib.core.AbstractPreferenceController; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Objects; 28 29 /** 30 * A controller for the Settings category for "time feedback". 31 */ 32 public class TimeFeedbackPreferenceCategoryController extends BasePreferenceController { 33 34 private final List<AbstractPreferenceController> mChildControllers = new ArrayList<>(); 35 TimeFeedbackPreferenceCategoryController( Context context, String preferenceKey)36 public TimeFeedbackPreferenceCategoryController( 37 Context context, String preferenceKey) { 38 super(context, preferenceKey); 39 } 40 41 /** 42 * Adds a controller whose own availability can determine the category's availability status. 43 */ addChildController(@onNull AbstractPreferenceController childController)44 void addChildController(@NonNull AbstractPreferenceController childController) { 45 mChildControllers.add(Objects.requireNonNull(childController)); 46 } 47 48 @Override getAvailabilityStatus()49 public int getAvailabilityStatus() { 50 // Firstly, hide the category if it is not enabled by flags. 51 if (!isTimeFeedbackFeatureEnabled()) { 52 return UNSUPPORTED_ON_DEVICE; 53 } 54 55 // Secondly, only show the category if there's one or more controllers available within it. 56 for (AbstractPreferenceController childController : mChildControllers) { 57 if (childController.isAvailable()) { 58 return AVAILABLE; 59 } 60 } 61 return UNSUPPORTED_ON_DEVICE; 62 } 63 isTimeFeedbackFeatureEnabled()64 protected boolean isTimeFeedbackFeatureEnabled() { 65 return TimeFeedbackLaunchUtils.isFeedbackFeatureSupported(); 66 } 67 } 68