Remove config_mobile_hotspot_provision_app from CarrierConfigFacade am: 3f825b33f4 am: 2e961a60f4
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/sl4a/+/11908404
Change-Id: I9fb4d6126dce9b75f462b35ce17e7738b0bdbef1
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/CarrierConfigFacade.java b/Common/src/com/googlecode/android_scripting/facade/telephony/CarrierConfigFacade.java
index 3a0b8b3..b62aea9 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/CarrierConfigFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/CarrierConfigFacade.java
@@ -16,23 +16,27 @@
package com.googlecode.android_scripting.facade.telephony;
-import android.app.Activity;
import android.app.Service;
import android.content.Context;
-import android.content.Intent;
+import android.net.TetheringManager;
+import android.net.TetheringManager.OnTetheringEntitlementResultListener;
import android.telephony.CarrierConfigManager;
+import com.googlecode.android_scripting.Log;
import com.googlecode.android_scripting.facade.AndroidFacade;
import com.googlecode.android_scripting.facade.FacadeManager;
import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
import com.googlecode.android_scripting.rpc.Rpc;
import com.googlecode.android_scripting.rpc.RpcParameter;
-import com.googlecode.android_scripting.Log;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
public class CarrierConfigFacade extends RpcReceiver {
private final Service mService;
private final AndroidFacade mAndroidFacade;
private final CarrierConfigManager mCarrierConfigManager;
+ private final TetheringManager mTetheringManager;
public CarrierConfigFacade(FacadeManager manager) {
super(manager);
@@ -40,68 +44,51 @@
mAndroidFacade = manager.getReceiver(AndroidFacade.class);
mCarrierConfigManager =
(CarrierConfigManager)mService.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ mTetheringManager = (TetheringManager) mService.getSystemService(Context.TETHERING_SERVICE);
+
+ }
+
+ private class EntitlementResultListener implements OnTetheringEntitlementResultListener {
+ private final CompletableFuture<Integer> mFuture = new CompletableFuture<>();
+
+ @Override
+ public void onTetheringEntitlementResult(int result) {
+ mFuture.complete(result);
+ }
+
+ public int get(int timeout, TimeUnit unit) throws Exception {
+ return mFuture.get(timeout, unit);
+ }
+
}
@Rpc(description = "Tethering Entitlement Check")
public boolean carrierConfigIsTetheringModeAllowed(
@RpcParameter(name="mode") String mode,
@RpcParameter(name="timeout") Integer timeout) {
- String[] mProvisionApp = mService.getResources().getStringArray(
- com.android.internal.R.array.config_mobile_hotspot_provision_app);
- /* following check defined in
- frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java
- isProvisioningNeeded
- */
- if ((mProvisionApp == null) || (mProvisionApp.length != 2)){
- Log.d("carrierConfigIsTetheringModeAllowed: no check is present.");
- return true;
- }
- Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 0 " + mProvisionApp[0]);
- Log.d("carrierConfigIsTetheringModeAllowed mProvisionApp 1 " + mProvisionApp[1]);
-
- /* defined in frameworks/base/packages/SettingsLib/src/com/android/settingslib/TetherUtil.java
- public static final int INVALID = -1;
- public static final int WIFI_TETHERING = 0;
- public static final int USB_TETHERING = 1;
- public static final int BLUETOOTH_TETHERING = 2;
- */
- // TODO: b/26273844 need to use android.settingslib.TetherUtil to
- // replace those private defines.
- final int INVALID = -1;
- final int WIFI_TETHERING = 0;
- final int USB_TETHERING = 1;
- final int BLUETOOTH_TETHERING = 2;
-
- /* defined in packages/apps/Settings/src/com/android/settings/TetherSettings.java
- private static final int PROVISION_REQUEST = 0;
- */
- final int PROVISION_REQUEST = 0;
-
- int mTetherChoice = INVALID;
+ final int tetheringType;
if (mode.equals("wifi")){
- mTetherChoice = WIFI_TETHERING;
+ tetheringType = TetheringManager.TETHERING_WIFI;
} else if (mode.equals("usb")) {
- mTetherChoice = USB_TETHERING;
+ tetheringType = TetheringManager.TETHERING_USB;
} else if (mode.equals("bluetooth")) {
- mTetherChoice = BLUETOOTH_TETHERING;
+ tetheringType = TetheringManager.TETHERING_BLUETOOTH;
+ } else {
+ tetheringType = TetheringManager.TETHERING_INVALID;
}
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setClassName(mProvisionApp[0], mProvisionApp[1]);
- intent.putExtra("TETHER_TYPE", mTetherChoice);
+
+ final EntitlementResultListener listener = new EntitlementResultListener();
+ mTetheringManager.requestLatestTetheringEntitlementResult(tetheringType, true,
+ c -> c.run(), listener);
int result;
try{
- result = mAndroidFacade.startActivityForResultCodeWithTimeout(
- intent, PROVISION_REQUEST, timeout);
+ result = listener.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Log.d("phoneTetherCheck exception" + e.toString());
return false;
}
- if (result == Activity.RESULT_OK) {
- return true;
- } else {
- return false;
- }
+ return result == TetheringManager.TETHER_ERROR_NO_ERROR;
}
@Override