• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.development.graphicsdriver;
18 
19 import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
20 import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
21 
22 import android.content.ContentResolver;
23 import android.content.Context;
24 import android.os.Handler;
25 import android.os.Looper;
26 import android.provider.Settings;
27 
28 import androidx.annotation.VisibleForTesting;
29 import androidx.preference.Preference;
30 import androidx.preference.PreferenceScreen;
31 
32 import com.android.settings.core.BasePreferenceController;
33 import com.android.settingslib.core.lifecycle.LifecycleObserver;
34 import com.android.settingslib.core.lifecycle.events.OnStart;
35 import com.android.settingslib.core.lifecycle.events.OnStop;
36 import com.android.settingslib.widget.FooterPreference;
37 
38 /**
39  * Controller of footer preference for Graphics Driver Preferences dashboard.
40  */
41 public class GraphicsDriverFooterPreferenceController extends BasePreferenceController
42         implements GraphicsDriverContentObserver.OnGraphicsDriverContentChangedListener,
43         LifecycleObserver, OnStart, OnStop {
44 
45     private final ContentResolver mContentResolver;
46     @VisibleForTesting
47     GraphicsDriverContentObserver mGraphicsDriverContentObserver;
48 
49     private FooterPreference mPreference;
50 
GraphicsDriverFooterPreferenceController(Context context, String key)51     public GraphicsDriverFooterPreferenceController(Context context, String key) {
52         super(context, key);
53         mContentResolver = context.getContentResolver();
54         mGraphicsDriverContentObserver =
55                 new GraphicsDriverContentObserver(new Handler(Looper.getMainLooper()), this);
56     }
57 
58     @Override
getAvailabilityStatus()59     public int getAvailabilityStatus() {
60         return Settings.Global.getInt(
61                 mContentResolver, Settings.Global.GAME_DRIVER_ALL_APPS, GAME_DRIVER_DEFAULT)
62                 == GAME_DRIVER_OFF
63                 ? AVAILABLE_UNSEARCHABLE
64                 : CONDITIONALLY_UNAVAILABLE;
65     }
66 
67     @Override
displayPreference(PreferenceScreen screen)68     public void displayPreference(PreferenceScreen screen) {
69         super.displayPreference(screen);
70         mPreference = screen.findPreference(getPreferenceKey());
71     }
72 
73     @Override
onStart()74     public void onStart() {
75         mGraphicsDriverContentObserver.register(mContentResolver);
76     }
77 
78     @Override
onStop()79     public void onStop() {
80         mGraphicsDriverContentObserver.unregister(mContentResolver);
81     }
82 
83     @Override
updateState(Preference preference)84     public void updateState(Preference preference) {
85         final FooterPreference footerPref = (FooterPreference) preference;
86         footerPref.setVisible(isAvailable());
87     }
88 
89     @Override
onGraphicsDriverContentChanged()90     public void onGraphicsDriverContentChanged() {
91         updateState(mPreference);
92     }
93 }
94