1 /* 2 * Copyright (C) 2016 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * 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.ContentResolver; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.telephony.CarrierConfigManager; 25 26 import com.googlecode.android_scripting.facade.AndroidFacade; 27 import com.googlecode.android_scripting.facade.FacadeManager; 28 import com.googlecode.android_scripting.jsonrpc.RpcReceiver; 29 import com.googlecode.android_scripting.rpc.Rpc; 30 import com.googlecode.android_scripting.rpc.RpcDefault; 31 import com.googlecode.android_scripting.rpc.RpcParameter; 32 import com.googlecode.android_scripting.Log; 33 import com.googlecode.android_scripting.MainThread; 34 import com.googlecode.android_scripting.rpc.RpcOptional; 35 36 public class CarrierConfigFacade extends RpcReceiver { 37 private final Service mService; 38 private final AndroidFacade mAndroidFacade; 39 private final CarrierConfigManager mCarrierConfigManager; 40 CarrierConfigFacade(FacadeManager manager)41 public CarrierConfigFacade(FacadeManager manager) { 42 super(manager); 43 mService = manager.getService(); 44 mAndroidFacade = manager.getReceiver(AndroidFacade.class); 45 mCarrierConfigManager = 46 (CarrierConfigManager)mService.getSystemService(Context.CARRIER_CONFIG_SERVICE); 47 } 48 49 @Rpc(description = "Tethering Entitlement Check") carrierConfigIsTetheringModeAllowed( @pcParametername="mode") String mode, @RpcParameter(name="timeout") Integer timeout)50 public boolean carrierConfigIsTetheringModeAllowed( 51 @RpcParameter(name="mode") String mode, 52 @RpcParameter(name="timeout") Integer timeout) { 53 String[] mProvisionApp = mService.getResources().getStringArray( 54 com.android.internal.R.array.config_mobile_hotspot_provision_app); 55 /* following check defined in 56 frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java 57 isProvisioningNeeded 58 */ 59 if ((mProvisionApp == null) || (mProvisionApp.length != 2)){ 60 Log.d("carrierConfigIsTetheringModeAllowed: no check is present."); 61 return true; 62 } 63 Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 0 " + mProvisionApp[0]); 64 Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 1 " + mProvisionApp[1]); 65 66 /* defined in frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java 67 public static final int INVALID = -1; 68 public static final int WIFI_TETHERING = 0; 69 public static final int USB_TETHERING = 1; 70 public static final int BLUETOOTH_TETHERING = 2; 71 */ 72 // TODO: b/26273844 need to use android.settingslib.TetherUtil to 73 // replace those private defines. 74 final int INVALID = -1; 75 final int WIFI_TETHERING = 0; 76 final int USB_TETHERING = 1; 77 final int BLUETOOTH_TETHERING = 2; 78 79 /* defined in packages/apps/Settings/src/com/android/settings/TetherSettings.java 80 private static final int PROVISION_REQUEST = 0; 81 */ 82 final int PROVISION_REQUEST = 0; 83 84 int mTetherChoice = INVALID; 85 if (mode.equals("wifi")){ 86 mTetherChoice = WIFI_TETHERING; 87 } else if (mode.equals("usb")) { 88 mTetherChoice = USB_TETHERING; 89 } else if (mode.equals("bluetooth")) { 90 mTetherChoice = BLUETOOTH_TETHERING; 91 } 92 Intent intent = new Intent(Intent.ACTION_MAIN); 93 intent.setClassName(mProvisionApp[0], mProvisionApp[1]); 94 intent.putExtra("TETHER_TYPE", mTetherChoice); 95 int result; 96 try{ 97 result = mAndroidFacade.startActivityForResultCodeWithTimeout( 98 intent, PROVISION_REQUEST, timeout); 99 } catch (Exception e) { 100 Log.d("phoneTetherCheck exception" + e.toString()); 101 return false; 102 } 103 104 if (result == Activity.RESULT_OK) { 105 return true; 106 } else { 107 return false; 108 } 109 } 110 111 @Override shutdown()112 public void shutdown() { 113 114 } 115 } 116