FrameworkFacade.java revision d9e0e830e4b4f3c8397460cf5e197345df62c802
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 17package com.android.server.wifi; 18 19import android.app.AppGlobals; 20import android.app.PendingIntent; 21import android.content.Context; 22import android.content.Intent; 23import android.net.TrafficStats; 24import android.net.ip.IpManager; 25import android.os.Handler; 26import android.os.IBinder; 27import android.os.RemoteException; 28import android.os.ServiceManager; 29import android.provider.Settings; 30import android.telephony.CarrierConfigManager; 31 32import com.android.server.wifi.util.WifiAsyncChannel; 33 34/** 35 * This class allows overriding objects with mocks to write unit tests 36 */ 37public class FrameworkFacade { 38 public static final String TAG = "FrameworkFacade"; 39 40 public boolean setIntegerSetting(Context context, String name, int def) { 41 return Settings.Global.putInt(context.getContentResolver(), name, def); 42 } 43 44 public int getIntegerSetting(Context context, String name, int def) { 45 return Settings.Global.getInt(context.getContentResolver(), name, def); 46 } 47 48 public long getLongSetting(Context context, String name, long def) { 49 return Settings.Global.getLong(context.getContentResolver(), name, def); 50 } 51 52 public boolean setStringSetting(Context context, String name, String def) { 53 return Settings.Global.putString(context.getContentResolver(), name, def); 54 } 55 56 public String getStringSetting(Context context, String name) { 57 return Settings.Global.getString(context.getContentResolver(), name); 58 } 59 60 public IBinder getService(String serviceName) { 61 return ServiceManager.getService(serviceName); 62 } 63 64 public PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags) { 65 return PendingIntent.getBroadcast(context, requestCode, intent, flags); 66 } 67 68 public SupplicantStateTracker makeSupplicantStateTracker(Context context, 69 WifiConfigManager configManager, Handler handler) { 70 return new SupplicantStateTracker(context, configManager, handler); 71 } 72 73 public boolean getConfigWiFiDisableInECBM(Context context) { 74 CarrierConfigManager configManager = (CarrierConfigManager) context 75 .getSystemService(Context.CARRIER_CONFIG_SERVICE); 76 if (configManager != null) { 77 return configManager.getConfig().getBoolean( 78 CarrierConfigManager.KEY_CONFIG_WIFI_DISABLE_IN_ECBM); 79 } 80 /* Default to TRUE */ 81 return true; 82 } 83 84 /** 85 * Create a new instance of WifiApConfigStore. 86 * @param context reference to a Context 87 * @param backupManagerProxy reference to a BackupManagerProxy 88 * @return an instance of WifiApConfigStore 89 */ 90 public WifiApConfigStore makeApConfigStore(Context context, 91 BackupManagerProxy backupManagerProxy) { 92 return new WifiApConfigStore(context, backupManagerProxy); 93 } 94 95 public long getTxPackets(String iface) { 96 return TrafficStats.getTxPackets(iface); 97 } 98 99 public long getRxPackets(String iface) { 100 return TrafficStats.getRxPackets(iface); 101 } 102 103 public IpManager makeIpManager( 104 Context context, String iface, IpManager.Callback callback) { 105 return new IpManager(context, iface, callback); 106 } 107 108 /** 109 * Checks whether the given uid has been granted the given permission. 110 * @param permName the permission to check 111 * @param uid The uid to check 112 * @return {@link PackageManager.PERMISSION_GRANTED} if the permission has been granted and 113 * {@link PackageManager.PERMISSION_DENIED} otherwise 114 */ 115 public int checkUidPermission(String permName, int uid) throws RemoteException { 116 return AppGlobals.getPackageManager().checkUidPermission(permName, uid); 117 } 118 119 /** 120 * Create a new instance of WifiAsyncChannel 121 * @param tag String corresponding to the service creating the channel 122 * @return WifiAsyncChannel object created 123 */ 124 public WifiAsyncChannel makeWifiAsyncChannel(String tag) { 125 return new WifiAsyncChannel(tag); 126 } 127} 128