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

Commit 32483f4c authored by Jayachandran C's avatar Jayachandran C Committed by Android (Google) Code Review
Browse files

Merge "NTT-Docomo SMS to misscall notification feature support" into udc-dev

parents 5d63759b 39b7d6ad
Loading
Loading
Loading
Loading
+91 −63
Original line number Diff line number Diff line
@@ -23,12 +23,14 @@ import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.SmsMessage;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;

import java.time.Instant;
@@ -152,9 +154,6 @@ public class MissedIncomingCallSmsFilter {
     * @return {@code true} if the SMS message has been processed as a missed incoming call SMS.
     */
    private boolean processSms(@NonNull SmsMessage message) {
        long missedCallTime = 0;
        String callerId = null;

        String[] smsPatterns = mCarrierConfig.getStringArray(CarrierConfigManager
                .KEY_MISSED_INCOMING_CALL_SMS_PATTERN_STRING_ARRAY);
        if (smsPatterns == null || smsPatterns.length == 0) {
@@ -162,6 +161,12 @@ public class MissedIncomingCallSmsFilter {
            return false;
        }

        boolean result = false;
        String[] missedCallMsgs = splitCalls(message.getMessageBody());
        if (missedCallMsgs != null && missedCallMsgs.length > 0) {
            for (String parsedMsg : missedCallMsgs) {
                long missedCallTime = 0;
                String callerId = null;
                for (String smsPattern : smsPatterns) {
                    Pattern pattern;
                    try {
@@ -172,7 +177,7 @@ public class MissedIncomingCallSmsFilter {
                        continue;
                    }

            Matcher matcher = pattern.matcher(message.getMessageBody());
                    Matcher matcher = pattern.matcher(parsedMsg);
                    String year = null, month = null, day = null, hour = null, minute = null;
                    if (matcher.find()) {
                        try {
@@ -220,18 +225,27 @@ public class MissedIncomingCallSmsFilter {
                            Rlog.d(TAG, "Caller id is not provided or can't be parsed.");
                        }
                        createMissedIncomingCallEvent(missedCallTime, callerId);
                return true;
                        result = true;
                        break;
                    }
                }

            }
        }
        if (!result) {
            Rlog.d(TAG, "SMS did not match any missed incoming call SMS pattern.");
        return false;
        }
        return result;
    }

    // Create phone account. The logic is copied from PhoneUtils.makePstnPhoneAccountHandle.
    private static PhoneAccountHandle makePstnPhoneAccountHandle(Phone phone) {
        return new PhoneAccountHandle(PSTN_CONNECTION_SERVICE_COMPONENT,
                String.valueOf(phone.getFullIccSerialNumber()));
    private String[] splitCalls(String messageBody) {
        String[] messages = null;
        if (messageBody != null) {
            messages = messageBody.split("(\\n|\\s\\n)" + "(\\n|\\s\\n)");
            Rlog.d(TAG,
                    "splitTheMultipleCalls no of calls = " + ((messages != null) ? messages.length
                            : 0));
        }
        return messages;
    }

    /**
@@ -260,4 +274,18 @@ public class MissedIncomingCallSmsFilter {
            tm.addNewIncomingCall(makePstnPhoneAccountHandle(mPhone), bundle);
        }
    }

    // Create phone account. The logic is copied from PhoneUtils.makePstnPhoneAccountHandle.
    private PhoneAccountHandle makePstnPhoneAccountHandle(Phone phone) {
        SubscriptionManager subscriptionManager =
                (SubscriptionManager) phone.getContext().getSystemService(
                        Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        UserHandle userHandle = subscriptionManager.getSubscriptionUserHandle(phone.getSubId());
        if (userHandle != null) {
            return new PhoneAccountHandle(PSTN_CONNECTION_SERVICE_COMPONENT,
                    String.valueOf(phone.getSubId()), userHandle);
        }
        return new PhoneAccountHandle(PSTN_CONNECTION_SERVICE_COMPONENT,
                String.valueOf(phone.getSubId()));
    }
}
 No newline at end of file