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 17 package com.android.server.wifi.util; 18 19 import android.app.ActivityManager; 20 import android.content.Context; 21 22 /** 23 * A wifi permissions dependency class to wrap around external 24 * calls to static methods that enable testing. 25 */ 26 public class WifiPermissionsWrapper { 27 private static final String TAG = "WifiPermissionsWrapper"; 28 private final Context mContext; 29 WifiPermissionsWrapper(Context context)30 public WifiPermissionsWrapper(Context context) { 31 mContext = context; 32 } 33 getCurrentUser()34 public int getCurrentUser() { 35 return ActivityManager.getCurrentUser(); 36 } 37 38 /** 39 * Determine if a UID has a permission. 40 * 41 * @param permissionType permission string 42 * @param uid to get permission for 43 * @param pid to get permission for 44 * @return Permissions setting 45 */ getUidPermission(String permissionType, int uid, int pid)46 public int getUidPermission(String permissionType, int uid, int pid) { 47 return mContext.checkPermission(permissionType, pid, uid); 48 } 49 50 /** 51 * Wrapper around {@link #getUidPermission(String, int, int)}. 52 * TODO (b/231480106): Remove this wrapper and always pass the pid 53 */ getUidPermission(String permissionType, int uid)54 public int getUidPermission(String permissionType, int uid) { 55 // We don't care about the pid, pass in -1 56 return getUidPermission(permissionType, uid, -1); 57 } 58 59 /** 60 * Determines if the caller has the override wifi config permission. 61 * 62 * @param uid to check the permission for 63 * @param pid to check the permission for 64 * @return int representation of success or denied 65 */ getOverrideWifiConfigPermission(int uid, int pid)66 public int getOverrideWifiConfigPermission(int uid, int pid) { 67 return getUidPermission(android.Manifest.permission.OVERRIDE_WIFI_CONFIG, uid, pid); 68 } 69 70 /** 71 * Wrapper around {@link #getOverrideWifiConfigPermission(int, int)} 72 * TODO (b/231480106): Remove this wrapper and always pass the pid 73 */ getOverrideWifiConfigPermission(int uid)74 public int getOverrideWifiConfigPermission(int uid) { 75 // We don't care about the pid, pass in -1 76 return getOverrideWifiConfigPermission(uid, -1); 77 } 78 } 79