1 /* 2 * Copyright 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.car.settings.applications.specialaccess; 18 19 import android.Manifest; 20 import android.app.AppOpsManager; 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 24 import com.android.car.settings.applications.specialaccess.AppStateAppOpsBridge.PermissionState; 25 import com.android.car.settings.common.FragmentController; 26 import com.android.internal.util.ArrayUtils; 27 import com.android.settingslib.applications.ApplicationsState; 28 import com.android.settingslib.applications.ApplicationsState.AppFilter; 29 import com.android.settingslib.applications.ApplicationsState.CompoundFilter; 30 31 /** 32 * Manages the list of apps requesting to control Wi-Fi settings. Apps that also request {@link 33 * Manifest.permission#NETWORK_SETTINGS} are excluded from the list as this permission overrules 34 * {@link Manifest.permission#CHANGE_WIFI_STATE}. 35 */ 36 public class WifiControlPreferenceController extends AppOpsPreferenceController { 37 38 private static final AppFilter FILTER_CHANGE_WIFI_STATE = new AppFilter() { 39 @Override 40 public void init() { 41 // No op. 42 } 43 44 @Override 45 public boolean filterApp(ApplicationsState.AppEntry info) { 46 return !ArrayUtils.contains( 47 ((PermissionState) info.extraInfo).getRequestedPermissions(), 48 Manifest.permission.NETWORK_SETTINGS); 49 } 50 }; 51 WifiControlPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)52 public WifiControlPreferenceController(Context context, String preferenceKey, 53 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 54 super(context, preferenceKey, fragmentController, uxRestrictions); 55 init(AppOpsManager.OP_CHANGE_WIFI_STATE, Manifest.permission.CHANGE_WIFI_STATE, 56 AppOpsManager.MODE_IGNORED); 57 } 58 59 @Override getAppFilter()60 protected AppFilter getAppFilter() { 61 AppFilter filter = super.getAppFilter(); 62 return new CompoundFilter(filter, FILTER_CHANGE_WIFI_STATE); 63 } 64 } 65