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