1 /* 2 * Copyright (C) 2021 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 package com.android.settings.location; 17 18 import android.content.Context; 19 import android.os.UserHandle; 20 21 import androidx.preference.Preference; 22 import androidx.preference.PreferenceScreen; 23 24 import com.android.settings.widget.RestrictedAppPreference; 25 26 import java.util.List; 27 import java.util.Map; 28 29 /** 30 * Preference controller for the injected Location Services. 31 */ 32 public class LocationInjectedServicesPreferenceController 33 extends LocationInjectedServiceBasePreferenceController { 34 35 private static final String TAG = "LocationPrefCtrl"; 36 LocationInjectedServicesPreferenceController(Context context, String key)37 public LocationInjectedServicesPreferenceController(Context context, String key) { 38 super(context, key); 39 } 40 41 @Override injectLocationServices(PreferenceScreen screen)42 protected void injectLocationServices(PreferenceScreen screen) { 43 final Map<Integer, List<Preference>> prefs = getLocationServices(); 44 for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) { 45 for (Preference pref : entry.getValue()) { 46 if (pref instanceof RestrictedAppPreference) { 47 ((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled(); 48 } 49 } 50 if (entry.getKey() == UserHandle.myUserId()) { 51 LocationSettings.addPreferencesSorted(entry.getValue(), screen); 52 } 53 } 54 } 55 } 56