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.content.Context; 21 import android.provider.SearchIndexableResource; 22 import android.provider.Settings; 23 import android.service.vr.VrListenerService; 24 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.settings.R; 28 import com.android.settings.overlay.FeatureFactory; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settings.search.Indexable; 31 import com.android.settings.utils.ManagedServiceSettings; 32 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 33 import com.android.settingslib.search.SearchIndexable; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 @SearchIndexable 39 public class VrListenerSettings extends ManagedServiceSettings { 40 private static final String TAG = VrListenerSettings.class.getSimpleName(); 41 private static final Config CONFIG = new Config.Builder() 42 .setTag(TAG) 43 .setSetting(Settings.Secure.ENABLED_VR_LISTENERS) 44 .setIntentAction(VrListenerService.SERVICE_INTERFACE) 45 .setPermission(android.Manifest.permission.BIND_VR_LISTENER_SERVICE) 46 .setNoun("vr listener") 47 .setWarningDialogTitle(R.string.vr_listener_security_warning_title) 48 .setWarningDialogSummary(R.string.vr_listener_security_warning_summary) 49 .setEmptyText(R.string.no_vr_listeners) 50 .build(); 51 52 @Override getConfig()53 protected Config getConfig() { 54 return CONFIG; 55 } 56 57 @Override getMetricsCategory()58 public int getMetricsCategory() { 59 return SettingsEnums.VR_MANAGE_LISTENERS; 60 } 61 62 @Override setEnabled(ComponentName service, String title, boolean enable)63 protected boolean setEnabled(ComponentName service, String title, boolean enable) { 64 logSpecialPermissionChange(enable, service.getPackageName()); 65 return super.setEnabled(service, title, enable); 66 } 67 68 @Override getPreferenceScreenResId()69 protected int getPreferenceScreenResId() { 70 return R.xml.vr_listeners_settings; 71 } 72 73 @VisibleForTesting logSpecialPermissionChange(boolean enable, String packageName)74 void logSpecialPermissionChange(boolean enable, String packageName) { 75 int logCategory = enable ? SettingsEnums.APP_SPECIAL_PERMISSION_VRHELPER_ALLOW 76 : SettingsEnums.APP_SPECIAL_PERMISSION_VRHELPER_DENY; 77 final MetricsFeatureProvider metricsFeatureProvider = 78 FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider(); 79 metricsFeatureProvider.action( 80 metricsFeatureProvider.getAttribution(getActivity()), 81 logCategory, 82 getMetricsCategory(), 83 packageName, 84 0); 85 } 86 87 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 88 new BaseSearchIndexProvider() { 89 @Override 90 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 91 boolean enabled) { 92 final List<SearchIndexableResource> result = new ArrayList<>(); 93 94 final SearchIndexableResource sir = new SearchIndexableResource(context); 95 sir.xmlResId = R.xml.vr_listeners_settings; 96 result.add(sir); 97 return result; 98 } 99 }; 100 101 } 102