TelephonyExtUtils: Set timeout for (de)activating provision

* catch OEM RIL being unresponsive to UICC provisioning request

Change-Id: Ic28c01412bffaec4cadabd3d68434ddef75693ef
This commit is contained in:
nico
2019-01-04 15:55:19 +00:00
committed by Michael Bestas
parent 68a1d795d3
commit eef2974c7f

View File

@@ -20,8 +20,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.telephony.SubscriptionManager;
import android.util.Log;
@@ -31,6 +33,8 @@ import org.codeaurora.internal.IExtTelephony;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
public final class TelephonyExtUtils {
private static final boolean DEBUG = false;
@@ -41,6 +45,9 @@ public final class TelephonyExtUtils {
public static final String EXTRA_NEW_PROVISION_STATE = "newProvisionState";
private static final int ACTIVATE_TIME_OUT = 15000;
private static final String PROP_TIME_OUT = "sys.uicc.activate.timeout";
// This is the list of possible values that
// IExtTelephony.getCurrentUiccCardProvisioningStatus() can return
public static final int CARD_NOT_PRESENT = -2;
@@ -147,15 +154,7 @@ public final class TelephonyExtUtils {
* @return The result of the activation or -1
*/
public int activateUiccCard(int slotId) {
IExtTelephony service = getService();
if (service != null) {
try {
return mExtTelephony.activateUiccCard(slotId);
} catch (RemoteException ex) {
Log.e(TAG, "Activating sub failed for slotId: " + slotId);
}
}
return -1;
return setUiccCardProvisioningStatus(PROVISIONED, slotId);
}
/**
@@ -164,14 +163,53 @@ public final class TelephonyExtUtils {
* @return The result of the deactivation or -1
*/
public int deactivateUiccCard(int slotId) {
IExtTelephony service = getService();
if (service != null) {
try {
return mExtTelephony.deactivateUiccCard(slotId);
} catch (RemoteException ex) {
Log.e(TAG, "Deactivating sub failed for slotId: " + slotId);
}
return setUiccCardProvisioningStatus(NOT_PROVISIONED, slotId);
}
private int setUiccCardProvisioningStatus(int provStatus, int slotId) {
String actionStr;
switch (provStatus) {
case PROVISIONED:
actionStr = "Activating";
break;
case NOT_PROVISIONED:
actionStr = "Deactivating";
break;
default:
Log.e(TAG, "Invalid argument for setUiccCardProvisioningStatus " +
"(provStatus=" + provStatus + ", slotId=" + slotId + ")");
return -1;
}
IExtTelephony service = getService();
if (service == null) {
return -1;
}
AsyncTask<Integer, Void, Integer> task = new AsyncTask<Integer, Void, Integer>() {
@Override
protected Integer doInBackground(Integer... params) {
try {
return params[0] == PROVISIONED
? mExtTelephony.activateUiccCard(params[1])
: mExtTelephony.deactivateUiccCard(params[1]);
} catch (RemoteException ex) {
Log.e(TAG, actionStr + " sub failed for slotId: " + params[1]);
}
return -1;
}
};
try {
return task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, provStatus, slotId)
.get(ACTIVATE_TIME_OUT, TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
Log.e(TAG, actionStr + " sub timed out for slotId: " + slotId);
SystemProperties.set(PROP_TIME_OUT, Integer.toString(slotId + 1));
} catch (Exception ex) {
Log.e(TAG, actionStr + " sub task failed for slotId: " + slotId);
}
return -1;
}