16dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leepackage com.android.server.telecom;
26dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport com.android.server.telecom.components.ErrorDialogActivity;
478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
56dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.content.Context;
66dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.content.Intent;
76dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.net.Uri;
86dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.os.Bundle;
99b71ea8289cb3c6e14beb11f7707ae3ef4dfe83fYorke Leeimport android.os.Trace;
106dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.os.UserHandle;
112221405ca90746f585a7d345b615b6af5995f397Tony Makimport android.os.UserManager;
1224b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunnimport android.telecom.Connection;
132221405ca90746f585a7d345b615b6af5995f397Tony Makimport android.telecom.DefaultDialerManager;
146dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.telecom.PhoneAccount;
156dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.telecom.PhoneAccountHandle;
166dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.telecom.TelecomManager;
174550623ca162ccb3291ec3f020b7ad3346784ebdAndrew Leeimport android.telecom.VideoProfile;
186dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.telephony.DisconnectCause;
196dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Leeimport android.telephony.PhoneNumberUtils;
204550623ca162ccb3291ec3f020b7ad3346784ebdAndrew Leeimport android.widget.Toast;
216dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
226dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee/**
238d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * Single point of entry for all outgoing and incoming calls.
248d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * {@link com.android.server.telecom.components.UserCallIntentProcessor} serves as a trampoline that
258d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * captures call intents for individual users and forwards it to the {@link CallIntentProcessor}
268d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * which interacts with the rest of Telecom, both of which run only as the primary user.
276dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee */
2878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadpublic class CallIntentProcessor {
29ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu    public interface Adapter {
30ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        void processOutgoingCallIntent(Context context, CallsManager callsManager,
31ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu                Intent intent);
32ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        void processIncomingCallIntent(CallsManager callsManager, Intent intent);
33ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        void processUnknownCallIntent(CallsManager callsManager, Intent intent);
34ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu    }
35ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu
36ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu    public static class AdapterImpl implements Adapter {
37ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        @Override
38ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        public void processOutgoingCallIntent(Context context, CallsManager callsManager,
39ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu                Intent intent) {
40ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu            CallIntentProcessor.processOutgoingCallIntent(context, callsManager, intent);
41ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        }
42ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu
43ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        @Override
44ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        public void processIncomingCallIntent(CallsManager callsManager, Intent intent) {
45ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu            CallIntentProcessor.processIncomingCallIntent(callsManager, intent);
46ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        }
47ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu
48ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        @Override
49ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        public void processUnknownCallIntent(CallsManager callsManager, Intent intent) {
50ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu            CallIntentProcessor.processUnknownCallIntent(callsManager, intent);
51ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu        }
52ecda55454f4993003e71e09a63d20f94a216cc47Hall Liu    }
536dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
548d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad    public static final String KEY_IS_UNKNOWN_CALL = "is_unknown_call";
558d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad    public static final String KEY_IS_INCOMING_CALL = "is_incoming_call";
5681050722a5236234e5a127f30a139f0238d316edYorke Lee    /*
5781050722a5236234e5a127f30a139f0238d316edYorke Lee     *  Whether or not the dialer initiating this outgoing call is the default dialer, or system
5881050722a5236234e5a127f30a139f0238d316edYorke Lee     *  dialer and thus allowed to make emergency calls.
5981050722a5236234e5a127f30a139f0238d316edYorke Lee     */
6081050722a5236234e5a127f30a139f0238d316edYorke Lee    public static final String KEY_IS_PRIVILEGED_DIALER = "is_privileged_dialer";
6178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
62578a4e6661fc1be20d164458acb335356d742f72Tony Mak    /**
63578a4e6661fc1be20d164458acb335356d742f72Tony Mak     * The user initiating the outgoing call.
64578a4e6661fc1be20d164458acb335356d742f72Tony Mak     */
65578a4e6661fc1be20d164458acb335356d742f72Tony Mak    public static final String KEY_INITIATING_USER = "initiating_user";
66578a4e6661fc1be20d164458acb335356d742f72Tony Mak
67578a4e6661fc1be20d164458acb335356d742f72Tony Mak
6878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    private final Context mContext;
6978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    private final CallsManager mCallsManager;
7078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
7178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    public CallIntentProcessor(Context context, CallsManager callsManager) {
7278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        this.mContext = context;
7378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        this.mCallsManager = callsManager;
7478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    }
756dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
7678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    public void processIntent(Intent intent) {
779250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        final boolean isUnknownCall = intent.getBooleanExtra(KEY_IS_UNKNOWN_CALL, false);
78e732ef425aba8df0229d61b071d4c00553ead469Yorke Lee        Log.i(this, "onReceive - isUnknownCall: %s", isUnknownCall);
796dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
809b71ea8289cb3c6e14beb11f7707ae3ef4dfe83fYorke Lee        Trace.beginSection("processNewCallCallIntent");
819250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        if (isUnknownCall) {
8278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            processUnknownCallIntent(mCallsManager, intent);
836dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        } else {
8478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            processOutgoingCallIntent(mContext, mCallsManager, intent);
856dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
869b71ea8289cb3c6e14beb11f7707ae3ef4dfe83fYorke Lee        Trace.endSection();
876dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    }
886dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
8978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad
906dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    /**
916dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee     * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
926dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee     *
936dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee     * @param intent Call intent containing data about the handle to call.
946dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee     */
9578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    static void processOutgoingCallIntent(
9678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Context context,
9778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            CallsManager callsManager,
9878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Intent intent) {
994550623ca162ccb3291ec3f020b7ad3346784ebdAndrew Lee
1006dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        Uri handle = intent.getData();
1016dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        String scheme = handle.getScheme();
1026dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        String uriString = handle.getSchemeSpecificPart();
1036dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1046dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (!PhoneAccount.SCHEME_VOICEMAIL.equals(scheme)) {
1056dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            handle = Uri.fromParts(PhoneNumberUtils.isUriNumber(uriString) ?
1066dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                    PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL, uriString, null);
1076dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1086dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1096dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
1106dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
1116dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1126dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        Bundle clientExtras = null;
1136dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (intent.hasExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS)) {
1146dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            clientExtras = intent.getBundleExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS);
1156dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1166dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (clientExtras == null) {
117a49ede1c4fb4486c51c218384299ad686ba2650aYorke Lee            clientExtras = new Bundle();
1186dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1196dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
12024b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn        // Ensure call subject is passed on to the connection service.
12124b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn        if (intent.hasExtra(TelecomManager.EXTRA_CALL_SUBJECT)) {
12224b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn            String callsubject = intent.getStringExtra(TelecomManager.EXTRA_CALL_SUBJECT);
12324b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn            clientExtras.putString(TelecomManager.EXTRA_CALL_SUBJECT, callsubject);
12424b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn        }
12524b6d7743ea4c896afe51830b2600527f97916c9Tyler Gunn
126005612a0af1fc475f422a1b0a4fb51fc5416ac90Omkar Kolangade        final int videoState = intent.getIntExtra( TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE,
127005612a0af1fc475f422a1b0a4fb51fc5416ac90Omkar Kolangade                VideoProfile.STATE_AUDIO_ONLY);
128005612a0af1fc475f422a1b0a4fb51fc5416ac90Omkar Kolangade        clientExtras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState);
129005612a0af1fc475f422a1b0a4fb51fc5416ac90Omkar Kolangade
13081050722a5236234e5a127f30a139f0238d316edYorke Lee        final boolean isPrivilegedDialer = intent.getBooleanExtra(KEY_IS_PRIVILEGED_DIALER, false);
1316dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
132d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak        boolean fixedInitiatingUser = fixInitiatingUserIfNecessary(context, intent);
133d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak        // Show the toast to warn user that it is a personal call though initiated in work profile.
134d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak        if (fixedInitiatingUser) {
135d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak            Toast.makeText(context, R.string.toast_personal_call_msg, Toast.LENGTH_LONG).show();
136d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak        }
137d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak
138578a4e6661fc1be20d164458acb335356d742f72Tony Mak        UserHandle initiatingUser = intent.getParcelableExtra(KEY_INITIATING_USER);
139578a4e6661fc1be20d164458acb335356d742f72Tony Mak
1406dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        // Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns
141578a4e6661fc1be20d164458acb335356d742f72Tony Mak        Call call = callsManager
142578a4e6661fc1be20d164458acb335356d742f72Tony Mak                .startOutgoingCall(handle, phoneAccountHandle, clientExtras, initiatingUser);
1436dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1446dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (call != null) {
1456dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            // Asynchronous calls should not usually be made inside a BroadcastReceiver because once
1466dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            // onReceive is complete, the BroadcastReceiver's process runs the risk of getting
1476dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            // killed if memory is scarce. However, this is OK here because the entire Telecom
1486dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            // process will be running throughout the duration of the phone call and should never
1496dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            // be killed.
1506dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
1516e8f3d70ac7397afb4cb5ab276d1cd385c92dd21Brad Ebinger                    context, callsManager, call, intent, callsManager.getPhoneNumberUtilsAdapter(),
152220b419bb5d1b4d1df08415c8e52cb7f0decbf7cHall Liu                    isPrivilegedDialer);
1536dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            final int result = broadcaster.processIntent();
1546dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            final boolean success = result == DisconnectCause.NOT_DISCONNECTED;
1556dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1566dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            if (!success && call != null) {
1576dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                disconnectCallAndShowErrorDialog(context, call, result);
1586dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            }
1596dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1606dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    }
1616dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1622221405ca90746f585a7d345b615b6af5995f397Tony Mak    /**
1632221405ca90746f585a7d345b615b6af5995f397Tony Mak     * If the call is initiated from managed profile but there is no work dialer installed, treat
1642221405ca90746f585a7d345b615b6af5995f397Tony Mak     * the call is initiated from its parent user.
165d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak     *
166d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak     * @return whether the initiating user is fixed.
1672221405ca90746f585a7d345b615b6af5995f397Tony Mak     */
168d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak    static boolean fixInitiatingUserIfNecessary(Context context, Intent intent) {
1692221405ca90746f585a7d345b615b6af5995f397Tony Mak        final UserHandle initiatingUser = intent.getParcelableExtra(KEY_INITIATING_USER);
1702221405ca90746f585a7d345b615b6af5995f397Tony Mak        if (UserUtil.isManagedProfile(context, initiatingUser)) {
1712221405ca90746f585a7d345b615b6af5995f397Tony Mak            boolean noDialerInstalled = DefaultDialerManager.getInstalledDialerApplications(context,
1722221405ca90746f585a7d345b615b6af5995f397Tony Mak                    initiatingUser.getIdentifier()).size() == 0;
1732221405ca90746f585a7d345b615b6af5995f397Tony Mak            if (noDialerInstalled) {
1742221405ca90746f585a7d345b615b6af5995f397Tony Mak                final UserManager userManager = UserManager.get(context);
1752221405ca90746f585a7d345b615b6af5995f397Tony Mak                UserHandle parentUserHandle =
1762221405ca90746f585a7d345b615b6af5995f397Tony Mak                        userManager.getProfileParent(
1772221405ca90746f585a7d345b615b6af5995f397Tony Mak                                initiatingUser.getIdentifier()).getUserHandle();
1782221405ca90746f585a7d345b615b6af5995f397Tony Mak                intent.putExtra(KEY_INITIATING_USER, parentUserHandle);
179d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak                return true;
1802221405ca90746f585a7d345b615b6af5995f397Tony Mak            }
1812221405ca90746f585a7d345b615b6af5995f397Tony Mak        }
182d7aaa1c2c71dd08422fd13fe2e2be183a7dd8b0dTony Mak        return false;
1832221405ca90746f585a7d345b615b6af5995f397Tony Mak    }
1842221405ca90746f585a7d345b615b6af5995f397Tony Mak
18578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad    static void processIncomingCallIntent(CallsManager callsManager, Intent intent) {
1866dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
1876dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
1886dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
1896dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (phoneAccountHandle == null) {
19078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Log.w(CallIntentProcessor.class,
19178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad                    "Rejecting incoming call due to null phone account");
1926dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            return;
1936dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1946dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (phoneAccountHandle.getComponentName() == null) {
19578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Log.w(CallIntentProcessor.class,
19678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad                    "Rejecting incoming call due to null component name");
1976dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            return;
1986dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
1996dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
2006dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        Bundle clientExtras = null;
2016dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (intent.hasExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS)) {
2026dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            clientExtras = intent.getBundleExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS);
2036dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
2046dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (clientExtras == null) {
205a49ede1c4fb4486c51c218384299ad686ba2650aYorke Lee            clientExtras = new Bundle();
2066dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
2076dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
20878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        Log.d(CallIntentProcessor.class,
20978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad                "Processing incoming call from connection service [%s]",
2106dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                phoneAccountHandle.getComponentName());
21178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        callsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras);
2126dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    }
2136dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
2140785274982d454b4fa036cc7a7aa9dcf768ef074David Stevens    static void processUnknownCallIntent(CallsManager callsManager, Intent intent) {
2159250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
2169250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee                TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
2179250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee
2189250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        if (phoneAccountHandle == null) {
21978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Log.w(CallIntentProcessor.class, "Rejecting unknown call due to null phone account");
2209250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee            return;
2219250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        }
2229250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        if (phoneAccountHandle.getComponentName() == null) {
22378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad            Log.w(CallIntentProcessor.class, "Rejecting unknown call due to null component name");
2249250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee            return;
2259250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee        }
2269250e5fa9987c3ab80e11e1955657055f5866539Yorke Lee
22778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad        callsManager.addNewUnknownCall(phoneAccountHandle, intent.getExtras());
2286dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    }
2296dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee
23072d271c4fdb6e497cf374ac1bfd1e615393fc4b2Andrew Lee    private static void disconnectCallAndShowErrorDialog(
23172d271c4fdb6e497cf374ac1bfd1e615393fc4b2Andrew Lee            Context context, Call call, int errorCode) {
2326dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        call.disconnect();
2336dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        final Intent errorIntent = new Intent(context, ErrorDialogActivity.class);
2346dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        int errorMessageId = -1;
2356dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        switch (errorCode) {
2366dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            case DisconnectCause.INVALID_NUMBER:
2376dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            case DisconnectCause.NO_PHONE_NUMBER_SUPPLIED:
2386dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                errorMessageId = R.string.outgoing_call_error_no_phone_number_supplied;
2396dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee                break;
2406dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
2416dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        if (errorMessageId != -1) {
2426dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee            errorIntent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, errorMessageId);
24394c7ab24798bc56a41d2119cec0fe7eecc36546bYorke Lee            errorIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
24494c7ab24798bc56a41d2119cec0fe7eecc36546bYorke Lee            context.startActivityAsUser(errorIntent, UserHandle.CURRENT);
2456dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee        }
2466dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee    }
2476dc1c75ff9fbabce11540c2bbe3972159899b414Yorke Lee}
248