1 /* 2 * Copyright (C) 2021 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.applications; 18 19 import android.content.Context; 20 import android.text.TextUtils; 21 22 import androidx.preference.Preference; 23 24 import com.android.internal.annotations.VisibleForTesting; 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settings.overlay.FeatureFactory; 27 28 /** Contains logic that deals with showing Game Settings in app settings. */ 29 public class GameSettingsPreferenceController extends BasePreferenceController { 30 31 @VisibleForTesting 32 final GameSettingsFeatureProvider mGameSettingsFeatureProvider; 33 GameSettingsPreferenceController(Context context, String key)34 public GameSettingsPreferenceController(Context context, String key) { 35 super(context, key); 36 mGameSettingsFeatureProvider = 37 FeatureFactory.getFactory(context).getGameSettingsFeatureProvider(); 38 } 39 GameSettingsPreferenceController(Context context, String key, GameSettingsFeatureProvider gameSettingsFeatureProvider)40 GameSettingsPreferenceController(Context context, String key, 41 GameSettingsFeatureProvider gameSettingsFeatureProvider) { 42 super(context, key); 43 mGameSettingsFeatureProvider = gameSettingsFeatureProvider; 44 } 45 46 @Override getAvailabilityStatus()47 public int getAvailabilityStatus() { 48 return mGameSettingsFeatureProvider.isSupported(mContext) 49 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 50 } 51 52 @Override handlePreferenceTreeClick(Preference preference)53 public boolean handlePreferenceTreeClick(Preference preference) { 54 if (TextUtils.equals(getPreferenceKey(), preference.getKey())) { 55 mGameSettingsFeatureProvider.launchGameSettings(mContext); 56 return true; 57 } 58 return super.handlePreferenceTreeClick(preference); 59 } 60 } 61