1 /* 2 * Copyright (C) 2018 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.autofill; 18 19 import android.content.ContentResolver; 20 import android.content.Context; 21 import android.database.ContentObserver; 22 import android.net.Uri; 23 import android.os.Handler; 24 import android.os.Looper; 25 import android.os.UserHandle; 26 import android.provider.Settings; 27 28 final class AutofillDeveloperSettingsObserver extends ContentObserver { 29 30 private final Runnable mChangeCallback; 31 private final ContentResolver mResolver; 32 AutofillDeveloperSettingsObserver(Context context, Runnable changeCallback)33 public AutofillDeveloperSettingsObserver(Context context, Runnable changeCallback) { 34 super(new Handler(Looper.getMainLooper())); 35 36 mResolver = context.getContentResolver(); 37 mChangeCallback = changeCallback; 38 } 39 register()40 public void register() { 41 mResolver.registerContentObserver(Settings.Global.getUriFor( 42 Settings.Global.AUTOFILL_LOGGING_LEVEL), false, this, 43 UserHandle.USER_ALL); 44 mResolver.registerContentObserver(Settings.Global.getUriFor( 45 Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE), false, this, 46 UserHandle.USER_ALL); 47 mResolver.registerContentObserver(Settings.Global.getUriFor( 48 Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS), false, this, 49 UserHandle.USER_ALL); 50 } 51 unregister()52 public void unregister() { 53 mResolver.unregisterContentObserver(this); 54 } 55 56 @Override onChange(boolean selfChange, Uri uri, int userId)57 public void onChange(boolean selfChange, Uri uri, int userId) { 58 mChangeCallback.run(); // Run Forrest, Run! 59 } 60 } 61