1 /* 2 * Copyright (C) 2017 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.googlecode.android_scripting.facade.telephony; 18 19 import android.app.Activity; 20 import android.app.Service; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.telephony.CarrierConfigManager; 24 25 import com.googlecode.android_scripting.facade.AndroidFacade; 26 import com.googlecode.android_scripting.facade.FacadeManager; 27 import com.googlecode.android_scripting.jsonrpc.RpcReceiver; 28 import com.googlecode.android_scripting.rpc.Rpc; 29 import com.googlecode.android_scripting.rpc.RpcParameter; 30 import com.googlecode.android_scripting.Log; 31 32 public class CarrierConfigFacade extends RpcReceiver { 33 private final Service mService; 34 private final AndroidFacade mAndroidFacade; 35 private final CarrierConfigManager mCarrierConfigManager; 36 CarrierConfigFacade(FacadeManager manager)37 public CarrierConfigFacade(FacadeManager manager) { 38 super(manager); 39 mService = manager.getService(); 40 mAndroidFacade = manager.getReceiver(AndroidFacade.class); 41 mCarrierConfigManager = 42 (CarrierConfigManager)mService.getSystemService(Context.CARRIER_CONFIG_SERVICE); 43 } 44 45 @Rpc(description = "Tethering Entitlement Check") carrierConfigIsTetheringModeAllowed( @pcParametername="mode") String mode, @RpcParameter(name="timeout") Integer timeout)46 public boolean carrierConfigIsTetheringModeAllowed( 47 @RpcParameter(name="mode") String mode, 48 @RpcParameter(name="timeout") Integer timeout) { 49 String[] mProvisionApp = mService.getResources().getStringArray( 50 com.android.internal.R.array.config_mobile_hotspot_provision_app); 51 /* following check defined in 52 frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java 53 isProvisioningNeeded 54 */ 55 if ((mProvisionApp == null) || (mProvisionApp.length != 2)){ 56 Log.d("carrierConfigIsTetheringModeAllowed: no check is present."); 57 return true; 58 } 59 Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 0 " + mProvisionApp[0]); 60 Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 1 " + mProvisionApp[1]); 61 62 /* defined in frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java 63 public static final int INVALID = -1; 64 public static final int WIFI_TETHERING = 0; 65 public static final int USB_TETHERING = 1; 66 public static final int BLUETOOTH_TETHERING = 2; 67 */ 68 // TODO: b/26273844 need to use android.settingslib.TetherUtil to 69 // replace those private defines. 70 final int INVALID = -1; 71 final int WIFI_TETHERING = 0; 72 final int USB_TETHERING = 1; 73 final int BLUETOOTH_TETHERING = 2; 74 75 /* defined in packages/apps/Settings/src/com/android/settings/TetherSettings.java 76 private static final int PROVISION_REQUEST = 0; 77 */ 78 final int PROVISION_REQUEST = 0; 79 80 int mTetherChoice = INVALID; 81 if (mode.equals("wifi")){ 82 mTetherChoice = WIFI_TETHERING; 83 } else if (mode.equals("usb")) { 84 mTetherChoice = USB_TETHERING; 85 } else if (mode.equals("bluetooth")) { 86 mTetherChoice = BLUETOOTH_TETHERING; 87 } 88 Intent intent = new Intent(Intent.ACTION_MAIN); 89 intent.setClassName(mProvisionApp[0], mProvisionApp[1]); 90 intent.putExtra("TETHER_TYPE", mTetherChoice); 91 int result; 92 try{ 93 result = mAndroidFacade.startActivityForResultCodeWithTimeout( 94 intent, PROVISION_REQUEST, timeout); 95 } catch (Exception e) { 96 Log.d("phoneTetherCheck exception" + e.toString()); 97 return false; 98 } 99 100 if (result == Activity.RESULT_OK) { 101 return true; 102 } else { 103 return false; 104 } 105 } 106 107 @Override shutdown()108 public void shutdown() { 109 110 } 111 } 112