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 android.content.ContentResolver;
20 import android.database.ContentObserver;
21 import android.os.Handler;
22 import android.provider.Settings;
23 
24 import androidx.annotation.VisibleForTesting;
25 
26 /**
27  * Helper class to observe Graphics Driver settings global change.
28  */
29 public class GraphicsDriverContentObserver extends ContentObserver {
30 
31     interface OnGraphicsDriverContentChangedListener {
onGraphicsDriverContentChanged()32         void onGraphicsDriverContentChanged();
33     }
34 
35     @VisibleForTesting
36     OnGraphicsDriverContentChangedListener mListener;
37 
GraphicsDriverContentObserver(Handler handler, OnGraphicsDriverContentChangedListener listener)38     public GraphicsDriverContentObserver(Handler handler,
39             OnGraphicsDriverContentChangedListener listener) {
40         super(handler);
41         mListener = listener;
42     }
43 
44     @Override
onChange(boolean selfChange)45     public void onChange(boolean selfChange) {
46         super.onChange(selfChange);
47         mListener.onGraphicsDriverContentChanged();
48     }
49 
50     /**
51      * Register GraphicsDriverContentObserver to ContentResolver.
52      */
register(ContentResolver contentResolver)53     public void register(ContentResolver contentResolver) {
54         contentResolver.registerContentObserver(
55                 Settings.Global.getUriFor(Settings.Global.GAME_DRIVER_ALL_APPS), false, this);
56     }
57 
58     /**
59      * Unregister GraphicsDriverContentObserver.
60      */
unregister(ContentResolver contentResolver)61     public void unregister(ContentResolver contentResolver) {
62         contentResolver.unregisterContentObserver(this);
63     }
64 }
65