• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.applications.specialaccess.vrlistener;
17 
18 import android.app.settings.SettingsEnums;
19 import android.content.ComponentName;
20 import android.provider.Settings;
21 import android.service.vr.VrListenerService;
22 
23 import androidx.annotation.VisibleForTesting;
24 
25 import com.android.settings.R;
26 import com.android.settings.overlay.FeatureFactory;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settings.utils.ManagedServiceSettings;
29 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
30 import com.android.settingslib.search.SearchIndexable;
31 
32 @SearchIndexable
33 public class VrListenerSettings extends ManagedServiceSettings {
34     private static final String TAG = VrListenerSettings.class.getSimpleName();
35     private static final Config CONFIG = new Config.Builder()
36             .setTag(TAG)
37             .setSetting(Settings.Secure.ENABLED_VR_LISTENERS)
38             .setIntentAction(VrListenerService.SERVICE_INTERFACE)
39             .setPermission(android.Manifest.permission.BIND_VR_LISTENER_SERVICE)
40             .setNoun("vr listener")
41             .setWarningDialogTitle(R.string.vr_listener_security_warning_title)
42             .setWarningDialogSummary(R.string.vr_listener_security_warning_summary)
43             .setEmptyText(R.string.no_vr_listeners)
44             .build();
45 
46     @Override
getConfig()47     protected Config getConfig() {
48         return CONFIG;
49     }
50 
51     @Override
getMetricsCategory()52     public int getMetricsCategory() {
53         return SettingsEnums.VR_MANAGE_LISTENERS;
54     }
55 
56     @Override
setEnabled(ComponentName service, String title, boolean enable)57     protected boolean setEnabled(ComponentName service, String title, boolean enable) {
58         logSpecialPermissionChange(enable, service.getPackageName());
59         return super.setEnabled(service, title, enable);
60     }
61 
62     @Override
getPreferenceScreenResId()63     protected int getPreferenceScreenResId() {
64         return R.xml.vr_listeners_settings;
65     }
66 
67     @VisibleForTesting
logSpecialPermissionChange(boolean enable, String packageName)68     void logSpecialPermissionChange(boolean enable, String packageName) {
69         int logCategory = enable ? SettingsEnums.APP_SPECIAL_PERMISSION_VRHELPER_ALLOW
70                 : SettingsEnums.APP_SPECIAL_PERMISSION_VRHELPER_DENY;
71         final MetricsFeatureProvider metricsFeatureProvider =
72                 FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
73         metricsFeatureProvider.action(
74                 metricsFeatureProvider.getAttribution(getActivity()),
75                 logCategory,
76                 getMetricsCategory(),
77                 packageName,
78                 0);
79     }
80 
81     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
82             new BaseSearchIndexProvider(R.xml.vr_listeners_settings);
83 
84 }
85