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

Commit 8481905a authored by Hall Liu's avatar Hall Liu Committed by Automerger Merge Worker
Browse files

Merge "Broadcast outgoing emergency calls from Telecom" am: fc4647b8 am:...

Merge "Broadcast outgoing emergency calls from Telecom" am: fc4647b8 am: 0e220dcf am: 52989419

Original change: https://android-review.googlesource.com/c/platform/packages/services/Telecomm/+/1469716

Change-Id: Ia2de058e839f7d55d5da1f9e5c238977d56af2ce
parents a66fcd77 52989419
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -403,6 +403,7 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
            // When testing emergency calls, we want the calls to go through to the test connection
            // service, not the telephony ConnectionService.
            if (mCall.isTestEmergencyCall()) {
                Log.i(this, "Processing test emergency call -- special rules");
                allAccounts = mPhoneAccountRegistrar.filterRestrictedPhoneAccounts(allAccounts);
            }

@@ -411,7 +412,7 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
                    preferredPAH);
            // Next, add all SIM phone accounts which can place emergency calls.
            sortSimPhoneAccountsForEmergency(allAccounts, preferredPA);
            // and pick the fist one that can place emergency calls.
            // and pick the first one that can place emergency calls.
            for (PhoneAccount phoneAccount : allAccounts) {
                if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS)
                        && phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
+39 −0
Original line number Diff line number Diff line
@@ -17,8 +17,16 @@
package com.android.server.telecom;

import android.telecom.Log;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyRegistryManager;
import android.telephony.emergency.EmergencyNumber;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * Send a {@link TelephonyManager#ACTION_PHONE_STATE_CHANGED} broadcast when the call state
@@ -52,6 +60,10 @@ final class PhoneStateBroadcaster extends CallsManagerListenerBase {
            return;
        }
        updateStates(call);

        if (call.isEmergencyCall() && !call.isIncoming()) {
            sendOutgoingEmergencyCallEvent(call);
        }
    }

    @Override
@@ -113,4 +125,31 @@ final class PhoneStateBroadcaster extends CallsManagerListenerBase {
            Log.i(this, "Broadcasted state change: %s", mCurrentState);
        }
    }

    private void sendOutgoingEmergencyCallEvent(Call call) {
        TelephonyManager tm = mCallsManager.getContext().getSystemService(TelephonyManager.class);
        String strippedNumber =
                PhoneNumberUtils.stripSeparators(call.getHandle().getSchemeSpecificPart());
        Optional<EmergencyNumber> emergencyNumber = tm.getEmergencyNumberList().values().stream()
                .flatMap(List::stream)
                .filter(numberObj -> Objects.equals(numberObj.getNumber(), strippedNumber))
                .findFirst();

        int subscriptionId = tm.getSubscriptionId(call.getTargetPhoneAccount());
        SubscriptionManager subscriptionManager =
                mCallsManager.getContext().getSystemService(SubscriptionManager.class);
        int simSlotIndex = SubscriptionManager.DEFAULT_PHONE_INDEX;
        if (subscriptionManager != null) {
            SubscriptionInfo subInfo =
                    subscriptionManager.getActiveSubscriptionInfo(subscriptionId);
            if (subInfo != null) {
                simSlotIndex = subInfo.getSimSlotIndex();
            }
        }

        if (emergencyNumber.isPresent()) {
            mRegistry.notifyOutgoingEmergencyCall(
                    simSlotIndex, subscriptionId, emergencyNumber.get());
        }
    }
}