blob: 7dc6e3d20cfec2b29fa537328c2155ae049f9010 [file] [log] [blame]
Doris Ling9ed29a22017-11-02 16:42:45 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14package com.android.settings.location;
15
16import android.content.Context;
17import android.os.UserManager;
18
Raff Tsai22295852019-11-22 11:35:40 +080019import com.android.settings.core.BasePreferenceController;
20import com.android.settings.dashboard.DashboardFragment;
Doris Ling9ed29a22017-11-02 16:42:45 -070021import com.android.settingslib.core.lifecycle.Lifecycle;
22
23/**
24 * A base controller for preferences that listens to location settings change and modifies location
25 * settings.
26 */
Raff Tsai22295852019-11-22 11:35:40 +080027public abstract class LocationBasePreferenceController extends BasePreferenceController
28 implements LocationEnabler.LocationModeChangeListener {
Doris Ling9ed29a22017-11-02 16:42:45 -070029
Raff Tsai22295852019-11-22 11:35:40 +080030 protected UserManager mUserManager;
31 protected LocationEnabler mLocationEnabler;
32 protected DashboardFragment mFragment;
33 protected Lifecycle mLifecycle;
Doris Ling9ed29a22017-11-02 16:42:45 -070034
Raff Tsai22295852019-11-22 11:35:40 +080035 /**
36 * Constructor of LocationBasePreferenceController. {@link BasePreferenceController} uses
37 * reflection to create controller, all controllers extends {@link BasePreferenceController}
38 * should have this function.
39 */
40 public LocationBasePreferenceController(Context context, String key) {
41 super(context, key);
Raff Tsaied1b8082019-11-28 10:13:11 +080042 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Raff Tsai22295852019-11-22 11:35:40 +080043 }
44
45 /**
46 * Initialize {@link LocationEnabler} in this controller
47 *
48 * @param fragment The {@link DashboardFragment} uses the controller.
49 */
50 public void init(DashboardFragment fragment) {
51 mFragment = fragment;
Raff Tsai22295852019-11-22 11:35:40 +080052 mLifecycle = mFragment.getSettingsLifecycle();
53 mLocationEnabler = new LocationEnabler(mContext, this /* listener */, mLifecycle);
Doris Ling9ed29a22017-11-02 16:42:45 -070054 }
55
56 @Override
Raff Tsai22295852019-11-22 11:35:40 +080057 public int getAvailabilityStatus() {
58 return AVAILABLE;
Doris Ling9ed29a22017-11-02 16:42:45 -070059 }
60
61}