1 /* 2 * Copyright (C) 2015 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 package com.android.settingslib; 17 18 import android.content.Context; 19 import android.os.SystemProperties; 20 import android.support.annotation.VisibleForTesting; 21 import android.telephony.CarrierConfigManager; 22 23 public class TetherUtil { 24 25 @VisibleForTesting isEntitlementCheckRequired(Context context)26 static boolean isEntitlementCheckRequired(Context context) { 27 final CarrierConfigManager configManager = (CarrierConfigManager) context 28 .getSystemService(Context.CARRIER_CONFIG_SERVICE); 29 if (configManager == null || configManager.getConfig() == null) { 30 // return service default 31 return true; 32 } 33 return configManager.getConfig().getBoolean(CarrierConfigManager 34 .KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL); 35 } 36 isProvisioningNeeded(Context context)37 public static boolean isProvisioningNeeded(Context context) { 38 // Keep in sync with other usage of config_mobile_hotspot_provision_app. 39 // ConnectivityManager#enforceTetherChangePermission 40 String[] provisionApp = context.getResources().getStringArray( 41 com.android.internal.R.array.config_mobile_hotspot_provision_app); 42 if (SystemProperties.getBoolean("net.tethering.noprovisioning", false) 43 || provisionApp == null) { 44 return false; 45 } 46 // Check carrier config for entitlement checks 47 if (isEntitlementCheckRequired(context) == false) { 48 return false; 49 } 50 return (provisionApp.length == 2); 51 } 52 } 53