1 /*
2  * Copyright (C) 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.location;
18 
19 import android.content.Context;
20 import android.os.UserHandle;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settings.widget.RestrictedAppPreference;
25 
26 import java.util.List;
27 import java.util.Map;
28 
29 /**
30  * Retrieve the Location Services used in profile user.
31  */
32 public class LocationServiceForWorkPreferenceController extends
33         LocationServicePreferenceController {
34     private static final String TAG = "LocationWorkPrefCtrl";
35 
LocationServiceForWorkPreferenceController(Context context, String key)36     public LocationServiceForWorkPreferenceController(Context context, String key) {
37         super(context, key);
38     }
39 
40     @Override
updateState(Preference preference)41     public void updateState(Preference preference) {
42         mCategoryLocationServices.removeAll();
43         final Map<Integer, List<Preference>> prefs = getLocationServices();
44         boolean show = false;
45         for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
46             for (Preference pref : entry.getValue()) {
47                 if (pref instanceof RestrictedAppPreference) {
48                     ((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
49                 }
50             }
51             if (entry.getKey() != UserHandle.myUserId()) {
52                 LocationSettings.addPreferencesSorted(entry.getValue(),
53                         mCategoryLocationServices);
54                 show = true;
55             }
56         }
57         mCategoryLocationServices.setVisible(show);
58     }
59 }
60