Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fbb55d9 authored by Shuo Qian's avatar Shuo Qian Committed by Gerrit Code Review
Browse files

Merge "Add a button to execute Call redirection after user interaction"

parents 069f2f67 2a7e65dd
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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>
+36 −24
Original line number Diff line number Diff line
@@ -255,7 +255,13 @@ public class CallsManager extends Call.ListenerBase
     * 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;
@@ -1765,7 +1771,7 @@ public class CallsManager extends Call.ListenerBase
            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() {
@@ -1776,6 +1782,16 @@ public class CallsManager extends Call.ListenerBase
                        }
                    });

            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",
                    call.getId(), callRedirectionApp);
@@ -1795,31 +1811,27 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    public void placeRedirectedOutgoingCallAfterUserInteraction(String callId) {
        Log.i(this, "placeRedirectedOutgoingCallAfterUserInteraction for Call ID %s", callId);
        if (mPendingRedirectedOutgoingCall != null && mPendingRedirectedOutgoingCall.getId()
                .equals(callId)) {
            mHandler.post(mPendingRedirectionOutgoingCallInfo.get(callId).prepare());
            mPendingRedirectedOutgoingCall = null;
            mPendingRedirectionOutgoingCallInfo.remove(callId);
        } else {
            Log.w(this, "placeRedirectedOutgoingCallAfterUserInteraction 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);
    public void processRedirectedOutgoingCallAfterUserInteraction(String callId, String action) {
        Log.i(this, "processRedirectedOutgoingCallAfterUserInteraction for Call ID %s", callId);
        if (mPendingRedirectedOutgoingCall != null && mPendingRedirectedOutgoingCall.getId()
                .equals(callId)) {
            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, "cancelRedirectedOutgoingCallAfterUserInteraction for non-matched Call"
                    + " ID ", callId);
            Log.w(this, "processRedirectedOutgoingCallAfterUserInteraction for non-matched Call ID"
                    + " %s with handle %s and phoneAccountHandle %s", callId);
        }
    }

+23 −6
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.Intent;
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;

@@ -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}.
@@ -174,19 +180,30 @@ public final class TelecomBroadcastIntentProcessor {
        } 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();
            }
+21 −3
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ public class CallRedirectionConfirmDialogActivity extends Activity {
                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(
@@ -67,7 +68,22 @@ public class CallRedirectionConfirmDialogActivity extends Activity {
                        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(
@@ -96,7 +112,9 @@ public class CallRedirectionConfirmDialogActivity extends Activity {
                    }
                })
                .create();

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