Merge "Fix network can't handle simultaneously SS request for both subs" into main
This commit is contained in:
@@ -23,6 +23,14 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.sim.smartForwarding.EnableSmartForwardingTask.UpdateCommand;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class DisableSmartForwardingTask implements Runnable {
|
public class DisableSmartForwardingTask implements Runnable {
|
||||||
private final TelephonyManager tm;
|
private final TelephonyManager tm;
|
||||||
private final boolean[] callWaitingStatus;
|
private final boolean[] callWaitingStatus;
|
||||||
@@ -37,22 +45,123 @@ public class DisableSmartForwardingTask implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (int i = 0; i < tm.getActiveModemCount(); i++) {
|
FlowController controller = new FlowController();
|
||||||
int subId = getSubId(i);
|
if (controller.init()) {
|
||||||
if (callWaitingStatus != null
|
controller.startProcess();
|
||||||
&& subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
}
|
||||||
Log.d(TAG, "Restore call waiting to " + callWaitingStatus[i]);
|
|
||||||
tm.createForSubscriptionId(subId)
|
|
||||||
.setCallWaitingEnabled(callWaitingStatus[i], null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callForwardingInfo != null
|
class FlowController {
|
||||||
&& callForwardingInfo[i] != null
|
private final ArrayList<UpdateCommand> mSteps = new ArrayList<>();
|
||||||
&& subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
|
||||||
Log.d(TAG, "Restore call forwarding to " + callForwardingInfo[i]);
|
/* package */ boolean init() {
|
||||||
tm.createForSubscriptionId(subId)
|
if (tm == null) {
|
||||||
.setCallForwarding(callForwardingInfo[i], null, null);
|
Log.e(TAG, "TelephonyManager is null");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (callWaitingStatus == null || callForwardingInfo == null) {
|
||||||
|
Log.e(TAG, "CallWaitingStatus or CallForwardingInfo array is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int slotCount = tm.getActiveModemCount();
|
||||||
|
if (callWaitingStatus.length != slotCount || callForwardingInfo.length != slotCount) {
|
||||||
|
Log.e(TAG, "The length of CallWaitingStatus and CallForwardingInfo array"
|
||||||
|
+ " should be the same as phone count.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Executor executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
for (int i = 0; i < slotCount; i++) {
|
||||||
|
int subId = getSubId(i);
|
||||||
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSteps.add(new RestoreCallWaitingCommand(
|
||||||
|
tm, executor, callWaitingStatus[i], subId));
|
||||||
|
|
||||||
|
if (callForwardingInfo[i] != null) {
|
||||||
|
mSteps.add(new RestoreCallForwardingCommand(
|
||||||
|
tm, executor, callForwardingInfo[i], subId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* package */ void startProcess() {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
while (index < mSteps.size()) {
|
||||||
|
UpdateCommand currentStep = mSteps.get(index);
|
||||||
|
Log.d(TAG, "processing : " + currentStep);
|
||||||
|
|
||||||
|
try {
|
||||||
|
currentStep.process();
|
||||||
|
index++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Failed on : " + currentStep, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RestoreCallForwardingCommand extends UpdateCommand<Integer> {
|
||||||
|
private SettableFuture<Boolean> mResultFuture = SettableFuture.create();
|
||||||
|
private CallForwardingInfo mCallForwardingInfo;
|
||||||
|
|
||||||
|
/* package */ RestoreCallForwardingCommand(TelephonyManager tm, Executor executor,
|
||||||
|
CallForwardingInfo mCallForwardingInfo, int subId) {
|
||||||
|
super(tm, executor, subId);
|
||||||
|
this.mCallForwardingInfo = mCallForwardingInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process() throws Exception {
|
||||||
|
Log.d(TAG, "Restore call forwarding to " + mCallForwardingInfo);
|
||||||
|
tm.createForSubscriptionId(subId).setCallForwarding(mCallForwardingInfo, executor,
|
||||||
|
this::updateStatusCallBack);
|
||||||
|
return mResultFuture.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onRestore() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStatusCallBack(int result) {
|
||||||
|
Log.d(TAG, "updateStatusCallBack for CallForwarding: " + result);
|
||||||
|
mResultFuture.set(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RestoreCallWaitingCommand extends UpdateCommand<Integer> {
|
||||||
|
private SettableFuture<Boolean> mResultFuture = SettableFuture.create();
|
||||||
|
private boolean mCallWaitingStatus;
|
||||||
|
|
||||||
|
/* package */ RestoreCallWaitingCommand(TelephonyManager tm, Executor executor,
|
||||||
|
boolean mCallWaitingStatus, int subId) {
|
||||||
|
super(tm, executor, subId);
|
||||||
|
this.mCallWaitingStatus = mCallWaitingStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process() throws Exception {
|
||||||
|
Log.d(TAG, "Restore call waiting to " + mCallWaitingStatus);
|
||||||
|
tm.createForSubscriptionId(subId).setCallWaitingEnabled(mCallWaitingStatus, executor,
|
||||||
|
this::updateStatusCallBack);
|
||||||
|
return mResultFuture.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void onRestore() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStatusCallBack(int result) {
|
||||||
|
Log.d(TAG, "updateStatusCallBack for CallWaiting: " + result);
|
||||||
|
mResultFuture.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -85,12 +85,7 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
|
|||||||
|
|
||||||
public void enableSmartForwarding(String[] phoneNumber) {
|
public void enableSmartForwarding(String[] phoneNumber) {
|
||||||
// Pop-up ongoing dialog
|
// Pop-up ongoing dialog
|
||||||
ProgressDialog dialog = new ProgressDialog(this);
|
ProgressDialog dialog = showOngoingDialog();
|
||||||
dialog.setTitle(R.string.smart_forwarding_ongoing_title);
|
|
||||||
dialog.setIndeterminate(true);
|
|
||||||
dialog.setMessage(getText(R.string.smart_forwarding_ongoing_text));
|
|
||||||
dialog.setCancelable(false);
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
// Enable feature
|
// Enable feature
|
||||||
ListenableFuture<FeatureResult> enableTask =
|
ListenableFuture<FeatureResult> enableTask =
|
||||||
@@ -140,6 +135,9 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
|
|||||||
boolean[] callWaitingStatus = getAllSlotCallWaitingStatus(this, tm);
|
boolean[] callWaitingStatus = getAllSlotCallWaitingStatus(this, tm);
|
||||||
CallForwardingInfo[] callForwardingInfo = getAllSlotCallForwardingStatus(this, sm, tm);
|
CallForwardingInfo[] callForwardingInfo = getAllSlotCallForwardingStatus(this, sm, tm);
|
||||||
|
|
||||||
|
// Pop-up ongoing dialog
|
||||||
|
ProgressDialog dialog = showOngoingDialog();
|
||||||
|
|
||||||
// Disable feature
|
// Disable feature
|
||||||
ListenableFuture disableTask = service.submit(new DisableSmartForwardingTask(
|
ListenableFuture disableTask = service.submit(new DisableSmartForwardingTask(
|
||||||
tm, callWaitingStatus, callForwardingInfo));
|
tm, callWaitingStatus, callForwardingInfo));
|
||||||
@@ -147,11 +145,13 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result) {
|
public void onSuccess(Object result) {
|
||||||
clearAllBackupData(SmartForwardingActivity.this, sm, tm);
|
clearAllBackupData(SmartForwardingActivity.this, sm, tm);
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
Log.e(TAG, "Disable Feature exception" + t);
|
Log.e(TAG, "Disable Feature exception" + t);
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
}, ContextCompat.getMainExecutor(this));
|
}, ContextCompat.getMainExecutor(this));
|
||||||
}
|
}
|
||||||
@@ -174,4 +174,15 @@ public class SmartForwardingActivity extends SettingsBaseActivity {
|
|||||||
.create();
|
.create();
|
||||||
mDialog.show();
|
mDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProgressDialog showOngoingDialog() {
|
||||||
|
ProgressDialog dialog = new ProgressDialog(this);
|
||||||
|
dialog.setTitle(R.string.smart_forwarding_ongoing_title);
|
||||||
|
dialog.setIndeterminate(true);
|
||||||
|
dialog.setMessage(getText(R.string.smart_forwarding_ongoing_text));
|
||||||
|
dialog.setCancelable(false);
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user