195f03c41705b46851140965702b5f06cc03627b6Jason Monk/* 295f03c41705b46851140965702b5f06cc03627b6Jason Monk * Copyright (C) 2015 The Android Open Source Project 395f03c41705b46851140965702b5f06cc03627b6Jason Monk * 495f03c41705b46851140965702b5f06cc03627b6Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); 595f03c41705b46851140965702b5f06cc03627b6Jason Monk * you may not use this file except in compliance with the License. 695f03c41705b46851140965702b5f06cc03627b6Jason Monk * You may obtain a copy of the License at 795f03c41705b46851140965702b5f06cc03627b6Jason Monk * 895f03c41705b46851140965702b5f06cc03627b6Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 995f03c41705b46851140965702b5f06cc03627b6Jason Monk * 1095f03c41705b46851140965702b5f06cc03627b6Jason Monk * Unless required by applicable law or agreed to in writing, software 1195f03c41705b46851140965702b5f06cc03627b6Jason Monk * distributed under the License is distributed on an "AS IS" BASIS, 1295f03c41705b46851140965702b5f06cc03627b6Jason Monk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1395f03c41705b46851140965702b5f06cc03627b6Jason Monk * See the License for the specific language governing permissions and 1495f03c41705b46851140965702b5f06cc03627b6Jason Monk * limitations under the License. 1595f03c41705b46851140965702b5f06cc03627b6Jason Monk */ 1695f03c41705b46851140965702b5f06cc03627b6Jason Monkpackage com.android.settingslib; 1795f03c41705b46851140965702b5f06cc03627b6Jason Monk 1895f03c41705b46851140965702b5f06cc03627b6Jason Monkimport android.content.Context; 1995f03c41705b46851140965702b5f06cc03627b6Jason Monkimport android.net.wifi.WifiManager; 2095f03c41705b46851140965702b5f06cc03627b6Jason Monkimport android.os.SystemProperties; 211ba0fa04ded1df73363a1c25064a3d6f5686478dChris Mantonimport android.telephony.CarrierConfigManager; 2295f03c41705b46851140965702b5f06cc03627b6Jason Monk 2395f03c41705b46851140965702b5f06cc03627b6Jason Monkpublic class TetherUtil { 2495f03c41705b46851140965702b5f06cc03627b6Jason Monk 2595f03c41705b46851140965702b5f06cc03627b6Jason Monk public static boolean setWifiTethering(boolean enable, Context context) { 2695f03c41705b46851140965702b5f06cc03627b6Jason Monk final WifiManager wifiManager = 2795f03c41705b46851140965702b5f06cc03627b6Jason Monk (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 288ba94ba2ab946e5fac35db2d3bccb6674d1989c6Mitchell Wills return wifiManager.setWifiApEnabled(null, enable); 2995f03c41705b46851140965702b5f06cc03627b6Jason Monk } 3095f03c41705b46851140965702b5f06cc03627b6Jason Monk 311ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton private static boolean isEntitlementCheckRequired(Context context) { 321ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton final CarrierConfigManager configManager = (CarrierConfigManager) context 331ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton .getSystemService(Context.CARRIER_CONFIG_SERVICE); 341ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton return configManager.getConfig().getBoolean(CarrierConfigManager 351ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton .KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL); 361ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton } 371ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton 3895f03c41705b46851140965702b5f06cc03627b6Jason Monk public static boolean isProvisioningNeeded(Context context) { 3995f03c41705b46851140965702b5f06cc03627b6Jason Monk // Keep in sync with other usage of config_mobile_hotspot_provision_app. 4095f03c41705b46851140965702b5f06cc03627b6Jason Monk // ConnectivityManager#enforceTetherChangePermission 4195f03c41705b46851140965702b5f06cc03627b6Jason Monk String[] provisionApp = context.getResources().getStringArray( 4295f03c41705b46851140965702b5f06cc03627b6Jason Monk com.android.internal.R.array.config_mobile_hotspot_provision_app); 4395f03c41705b46851140965702b5f06cc03627b6Jason Monk if (SystemProperties.getBoolean("net.tethering.noprovisioning", false) 4495f03c41705b46851140965702b5f06cc03627b6Jason Monk || provisionApp == null) { 4595f03c41705b46851140965702b5f06cc03627b6Jason Monk return false; 4695f03c41705b46851140965702b5f06cc03627b6Jason Monk } 471ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton // Check carrier config for entitlement checks 481ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton if (isEntitlementCheckRequired(context) == false) { 491ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton return false; 501ba0fa04ded1df73363a1c25064a3d6f5686478dChris Manton } 5195f03c41705b46851140965702b5f06cc03627b6Jason Monk return (provisionApp.length == 2); 5295f03c41705b46851140965702b5f06cc03627b6Jason Monk } 5395f03c41705b46851140965702b5f06cc03627b6Jason Monk} 54