/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.car.settings; import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.provider.Settings; import java.lang.ref.WeakReference; /** * A content observer for garage mode settings. * @hide */ public abstract class GarageModeSettingsObserver extends ContentObserver { public static final Uri GARAGE_MODE_ENABLED_URI = Settings.Global.getUriFor(CarSettings.Global.KEY_GARAGE_MODE_ENABLED); public static final Uri GARAGE_MODE_WAKE_UP_TIME_URI = Settings.Global.getUriFor(CarSettings.Global.KEY_GARAGE_MODE_WAKE_UP_TIME); public static final Uri GARAGE_MODE_MAINTENANCE_WINDOW_URI = Settings.Global.getUriFor(CarSettings.Global.KEY_GARAGE_MODE_MAINTENANCE_WINDOW); public static final Uri[] GARAGE_SETTING_URIS = {GARAGE_MODE_ENABLED_URI, GARAGE_MODE_WAKE_UP_TIME_URI, GARAGE_MODE_MAINTENANCE_WINDOW_URI}; private final WeakReference mContext; public GarageModeSettingsObserver(Context context, Handler handler) { super(handler); mContext = new WeakReference(context); } public void register() { if (mContext.get() == null) { return; } for (Uri uri : GARAGE_SETTING_URIS) { mContext.get().getContentResolver().registerContentObserver( uri, false, this); } } public void unregister() { if (mContext.get() == null) { return; } mContext.get().getContentResolver().unregisterContentObserver(this); } }