1 /*
2  * Copyright (C) 2018 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.content.Intent;
21 import android.text.TextUtils;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.settings.overlay.FeatureFactory;
26 import com.android.settings.widget.RestrictedAppPreference;
27 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
28 import com.android.settingslib.location.InjectedSetting;
29 import com.android.settingslib.location.SettingsInjector;
30 import com.android.settingslib.widget.AppPreference;
31 
32 /**
33  * Adds the preferences specified by the {@link InjectedSetting} objects to a preference group.
34  */
35 public class AppSettingsInjector extends SettingsInjector {
36 
37     private final MetricsFeatureProvider mMetricsFeatureProvider;
38     private final int mMetricsCategory;
39 
AppSettingsInjector(Context context, int metricsCategory)40     public AppSettingsInjector(Context context, int metricsCategory) {
41         super(context);
42         mMetricsCategory = metricsCategory;
43         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
44     }
45 
46     @Override
createPreference(Context prefContext, InjectedSetting setting)47     protected Preference createPreference(Context prefContext, InjectedSetting setting) {
48         return TextUtils.isEmpty(setting.userRestriction)
49                 ? new AppPreference(prefContext)
50                 : new RestrictedAppPreference(prefContext, setting.userRestriction);
51     }
52 
53     @Override
logPreferenceClick(Intent intent)54     protected void logPreferenceClick(Intent intent) {
55         mMetricsFeatureProvider.logStartedIntent(intent, mMetricsCategory);
56     }
57 }
58