Skip to content

Commit

Permalink
Add a button to execute Call redirection after user interaction
Browse files Browse the repository at this point in the history
We need to give user an option to place call without App's redirection,
 if the App wants to confirm this with users.

Bug: 130377723
Test: TestApp; Treehugger
Change-Id: If960a726122d1465025ea5bd307d080a67c937d8
Merged-In: If960a726122d1465025ea5bd307d080a67c937d8
(cherry picked from commit 2a7e65d)
  • Loading branch information
sqian committed Apr 15, 2019
1 parent d6900b1 commit 8502845
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 34 deletions.
8 changes: 7 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@
<string name="alert_outgoing_call">Placing this call will end your <xliff:g id="other_app">%1$s</xliff:g> call.</string>

<!-- Alert dialog content used to ask the user to confirm if they want to place a new outgoing call redirected by the app "other_app". -->
<string name="alert_redirect_outgoing_call">Allow <xliff:g id="other_app">%1$s</xliff:g> to place call using a different number or account.</string>
<string name="alert_redirect_outgoing_call">Allow <xliff:g id="other_app">%1$s</xliff:g> to place call using a different number?</string>

<!-- A button in the alert dialog "alert_redirect_outgoing_call" to place the call with the redirected number provided by App. -->
<string name="alert_place_redirect_outgoing_call">Call with <xliff:g id="other_app">%1$s</xliff:g></string>

<!-- A button in the alert dialog "alert_redirect_outgoing_call" to place the call without the redirected number provided by App. -->
<string name="alert_place_unredirect_outgoing_call">Call without <xliff:g id="other_app">%1$s</xliff:g></string>

<!-- Alert dialog content used to tell the user the call is canceled because no response from the call redirection app "other_app". -->
<string name="alert_redirect_outgoing_call_timeout">Call can\'t be placed by <xliff:g id="other_app">%1$s</xliff:g>. Try using a different call redirecting app or contacting the developer for help.</string>
Expand Down
60 changes: 36 additions & 24 deletions src/com/android/server/telecom/CallsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ interface PendingAction {
* Cached latest pending redirected call information which require user-intervention in order
* to be placed. Used by {@link #onCallRedirectionComplete}.
*/
private final Map<String, Runnable> mPendingRedirectionOutgoingCallInfo =
private final Map<String, Runnable> mPendingRedirectedOutgoingCallInfo =
new ConcurrentHashMap<>();
/**
* Cached latest pending Unredirected call information which require user-intervention in order
* to be placed. Used by {@link #onCallRedirectionComplete}.
*/
private final Map<String, Runnable> mPendingUnredirectedOutgoingCallInfo =
new ConcurrentHashMap<>();

private CompletableFuture<Call> mPendingCallConfirm;
Expand Down Expand Up @@ -1711,7 +1717,7 @@ public void onCallRedirectionComplete(Call call, Uri handle,
int videoState, boolean shouldCancelCall,
String uiAction) {
Log.i(this, "onCallRedirectionComplete for Call %s with handle %s" +
" and phoneAccountHandle %s", call, handle, phoneAccountHandle);
" and phoneAccountHandle %s", call, handle, phoneAccountHandle);

boolean endEarly = false;
String disconnectReason = "";
Expand Down Expand Up @@ -1767,7 +1773,7 @@ public void onCallRedirectionComplete(Call call, Uri handle,
Log.addEvent(call, LogUtils.Events.REDIRECTION_USER_CONFIRMATION);
mPendingRedirectedOutgoingCall = call;

mPendingRedirectionOutgoingCallInfo.put(call.getId(),
mPendingRedirectedOutgoingCallInfo.put(call.getId(),
new Runnable("CM.oCRC", mLock) {
@Override
public void loggedRun() {
Expand All @@ -1778,8 +1784,18 @@ public void loggedRun() {
}
});

mPendingUnredirectedOutgoingCallInfo.put(call.getId(),
new Runnable("CM.oCRC", mLock) {
@Override
public void loggedRun() {
call.setTargetPhoneAccount(phoneAccountHandle);
placeOutgoingCall(call, handle, null, speakerphoneOn,
videoState);
}
});

Log.i(this, "onCallRedirectionComplete: UI_TYPE_USER_DEFINED_ASK_FOR_CONFIRM "
+ "callId=%s, callRedirectionAppName=%s",
+ "callId=%s, callRedirectionAppName=%s",
call.getId(), callRedirectionApp);

Intent confirmIntent = new Intent(mContext,
Expand All @@ -1797,34 +1813,30 @@ public void loggedRun() {
}
}

public void placeRedirectedOutgoingCallAfterUserInteraction(String callId) {
Log.i(this, "placeRedirectedOutgoingCallAfterUserInteraction for Call ID %s", callId);
public void processRedirectedOutgoingCallAfterUserInteraction(String callId, String action) {
Log.i(this, "processRedirectedOutgoingCallAfterUserInteraction for Call ID %s", callId);
if (mPendingRedirectedOutgoingCall != null && mPendingRedirectedOutgoingCall.getId()
.equals(callId)) {
mHandler.post(mPendingRedirectionOutgoingCallInfo.get(callId).prepare());
if (action.equals(TelecomBroadcastIntentProcessor.ACTION_PLACE_REDIRECTED_CALL)) {
mHandler.post(mPendingRedirectedOutgoingCallInfo.get(callId).prepare());
} else if (action.equals(
TelecomBroadcastIntentProcessor.ACTION_PLACE_UNREDIRECTED_CALL)) {
mHandler.post(mPendingUnredirectedOutgoingCallInfo.get(callId).prepare());
} else if (action.equals(
TelecomBroadcastIntentProcessor.ACTION_CANCEL_REDIRECTED_CALL)) {
Log.addEvent(mPendingRedirectedOutgoingCall,
LogUtils.Events.REDIRECTION_USER_CANCELLED);
mPendingRedirectedOutgoingCall.disconnect("User canceled the redirected call.");
}
mPendingRedirectedOutgoingCall = null;
mPendingRedirectionOutgoingCallInfo.remove(callId);
mPendingRedirectedOutgoingCallInfo.remove(callId);
mPendingUnredirectedOutgoingCallInfo.remove(callId);
} else {
Log.w(this, "placeRedirectedOutgoingCallAfterUserInteraction for non-matched Call ID "
Log.w(this, "processRedirectedOutgoingCallAfterUserInteraction for non-matched Call ID"
+ " %s with handle %s and phoneAccountHandle %s", callId);
}
}

public void cancelRedirectedOutgoingCallAfterUserInteraction(String callId) {
Log.i(this, "cancelRedirectedOutgoingCallAfterUserInteraction for Call ID %s", callId);
if (mPendingRedirectedOutgoingCall != null && mPendingRedirectedOutgoingCall.getId()
.equals(callId)) {
Log.addEvent(mPendingRedirectedOutgoingCall,
LogUtils.Events.REDIRECTION_USER_CANCELLED);
mPendingRedirectedOutgoingCall.disconnect("User canceled the redirected call.");
mPendingRedirectedOutgoingCall = null;
mPendingRedirectionOutgoingCallInfo.remove(callId);
} else {
Log.w(this, "cancelRedirectedOutgoingCallAfterUserInteraction for non-matched Call"
+ " ID ", callId);
}
}

/**
* Attempts to issue/connect the specified call.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.os.UserHandle;
import android.telecom.Log;

import android.telecom.VideoProfile;
import com.android.server.telecom.ui.CallRedirectionConfirmDialogActivity;
import com.android.server.telecom.ui.ConfirmCallDialogActivity;

Expand Down Expand Up @@ -73,6 +72,13 @@ public final class TelecomBroadcastIntentProcessor {
public static final String ACTION_PLACE_REDIRECTED_CALL =
"com.android.server.telecom.PROCEED_WITH_REDIRECTED_CALL";

/**
* The action used to confirm to proceed the call without redirection via
* {@link com.android.server.telecom.ui.CallRedirectionConfirmDialogActivity}.
*/
public static final String ACTION_PLACE_UNREDIRECTED_CALL =
"com.android.server.telecom.PROCEED_WITH_UNREDIRECTED_CALL";

/**
* The action used to cancel a redirected call being confirmed via
* {@link com.android.server.telecom.ui.CallRedirectionConfirmDialogActivity}.
Expand Down Expand Up @@ -174,19 +180,30 @@ public void processIntent(Intent intent) {
} else if (ACTION_PLACE_REDIRECTED_CALL.equals(action)) {
Log.startSession("TBIP.aPRC");
try {
mCallsManager.placeRedirectedOutgoingCallAfterUserInteraction(
mCallsManager.processRedirectedOutgoingCallAfterUserInteraction(
intent.getStringExtra(CallRedirectionConfirmDialogActivity
.EXTRA_REDIRECTION_OUTGOING_CALL_ID),
ACTION_PLACE_REDIRECTED_CALL);
} finally {
Log.endSession();
}
} else if (ACTION_PLACE_UNREDIRECTED_CALL.equals(action)) {
Log.startSession("TBIP.aPUC");
try {
mCallsManager.processRedirectedOutgoingCallAfterUserInteraction(
intent.getStringExtra(CallRedirectionConfirmDialogActivity
.EXTRA_REDIRECTION_OUTGOING_CALL_ID));
.EXTRA_REDIRECTION_OUTGOING_CALL_ID),
ACTION_PLACE_UNREDIRECTED_CALL);
} finally {
Log.endSession();
}
} else if (ACTION_CANCEL_REDIRECTED_CALL.equals(action)) {
Log.startSession("TBIP.aCRC");
try {
mCallsManager.cancelRedirectedOutgoingCallAfterUserInteraction(
mCallsManager.processRedirectedOutgoingCallAfterUserInteraction(
intent.getStringExtra(CallRedirectionConfirmDialogActivity
.EXTRA_REDIRECTION_OUTGOING_CALL_ID)
);
.EXTRA_REDIRECTION_OUTGOING_CALL_ID),
ACTION_CANCEL_REDIRECTED_CALL);
} finally {
Log.endSession();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private void showDialog(final CharSequence redirectionAppName) {
R.string.alert_redirect_outgoing_call, redirectionAppName);
final AlertDialog confirmDialog = new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("Call", new DialogInterface.OnClickListener() {
.setPositiveButton(getString(R.string.alert_place_redirect_outgoing_call,
redirectionAppName), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent proceedWithRedirectedCall = new Intent(
Expand All @@ -67,7 +68,22 @@ public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
.setNegativeButton(getString(R.string.alert_place_unredirect_outgoing_call,
redirectionAppName), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent proceedWithoutRedirectedCall = new Intent(
TelecomBroadcastIntentProcessor.ACTION_PLACE_UNREDIRECTED_CALL,
null, CallRedirectionConfirmDialogActivity.this,
TelecomBroadcastReceiver.class);
proceedWithoutRedirectedCall.putExtra(EXTRA_REDIRECTION_OUTGOING_CALL_ID,
getIntent().getStringExtra(EXTRA_REDIRECTION_OUTGOING_CALL_ID));
sendBroadcast(proceedWithoutRedirectedCall);
dialog.dismiss();
finish();
}
})
.setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent cancelRedirectedCall = new Intent(
Expand Down Expand Up @@ -96,7 +112,9 @@ public void onCancel(DialogInterface dialog) {
}
})
.create();

confirmDialog.show();
confirmDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setAllCaps(false);
confirmDialog.getButton(DialogInterface.BUTTON_POSITIVE).setAllCaps(false);
confirmDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setAllCaps(false);
}
}

0 comments on commit 8502845

Please sign in to comment.