1 /*
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  */
14 package com.android.settings.location;
15 
16 import android.content.Context;
17 import android.os.UserManager;
18 
19 import com.android.settings.core.BasePreferenceController;
20 import com.android.settings.dashboard.DashboardFragment;
21 import 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  */
27 public abstract class LocationBasePreferenceController extends BasePreferenceController
28         implements LocationEnabler.LocationModeChangeListener {
29 
30     protected UserManager mUserManager;
31     protected LocationEnabler mLocationEnabler;
32     protected DashboardFragment mFragment;
33     protected Lifecycle mLifecycle;
34 
35     /**
36      * Constructor of LocationBasePreferenceController. {@link BasePreferenceController} uses
37      * reflection to create controller, all controllers extends {@link BasePreferenceController}
38      * should have this function.
39      */
LocationBasePreferenceController(Context context, String key)40     public LocationBasePreferenceController(Context context, String key) {
41         super(context, key);
42         mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
43     }
44 
45     /**
46      * Initialize {@link LocationEnabler} in this controller
47      *
48      * @param fragment The {@link DashboardFragment} uses the controller.
49      */
init(DashboardFragment fragment)50     public void init(DashboardFragment fragment) {
51         mFragment = fragment;
52         mLifecycle = mFragment.getSettingsLifecycle();
53         mLocationEnabler = new LocationEnabler(mContext, this /* listener */, mLifecycle);
54     }
55 
56     @Override
getAvailabilityStatus()57     public int getAvailabilityStatus() {
58         return AVAILABLE;
59     }
60 
61 }
62