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

Commit d85a8aef authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Add carrier config for partial sms raw message expiration.

Everytime at boot-up, we check Sms raw table, and delete the rows
with any partial message that is too old. By default the expiration
age is 30 days, but we want to make it configurable.

Bug: 77910620
Test: sanity-test
Change-Id: I76a4bac3e986cd39e0d57f9d09d1be2be125184e
Merged-In: I76a4bac3e986cd39e0d57f9d09d1be2be125184e
parent 6fb6114a
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -23,9 +23,11 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.database.SQLException;
import android.os.UserHandle;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;

import com.android.internal.telephony.cdma.CdmaInboundSmsHandler;
import com.android.internal.telephony.gsm.GsmInboundSmsHandler;
@@ -45,7 +47,7 @@ public class SmsBroadcastUndelivered {
    private static final boolean DBG = InboundSmsHandler.DBG;

    /** Delete any partial message segments older than 30 days. */
    static final long PARTIAL_SEGMENT_EXPIRE_AGE = (long) (60 * 60 * 1000) * 24 * 30;
    static final long DEFAULT_PARTIAL_SEGMENT_EXPIRE_AGE = (long) (60 * 60 * 1000) * 24 * 30;

    /**
     * Query projection for dispatching pending messages at boot time.
@@ -97,7 +99,7 @@ public class SmsBroadcastUndelivered {

        @Override
        public void run() {
            scanRawTable();
            scanRawTable(context);
            InboundSmsHandler.cancelNewMessageNotification(context);
        }
    }
@@ -140,7 +142,7 @@ public class SmsBroadcastUndelivered {
    /**
     * Scan the raw table for complete SMS messages to broadcast, and old PDUs to delete.
     */
    private void scanRawTable() {
    private void scanRawTable(Context context) {
        if (DBG) Rlog.d(TAG, "scanning raw table for undelivered messages");
        long startTime = System.nanoTime();
        HashMap<SmsReferenceKey, Integer> multiPartReceivedCount =
@@ -176,8 +178,9 @@ public class SmsBroadcastUndelivered {
                    Integer receivedCount = multiPartReceivedCount.get(reference);
                    if (receivedCount == null) {
                        multiPartReceivedCount.put(reference, 1);    // first segment seen
                        long expirationTime = getUndeliveredSmsExpirationTime(context);
                        if (tracker.getTimestamp() <
                                (System.currentTimeMillis() - PARTIAL_SEGMENT_EXPIRE_AGE)) {
                                (System.currentTimeMillis() - expirationTime)) {
                            // older than 30 days; delete if we don't find all the segments
                            oldMultiPartMessages.add(reference);
                        }
@@ -236,6 +239,20 @@ public class SmsBroadcastUndelivered {
        }
    }

    private long getUndeliveredSmsExpirationTime(Context context) {
        int subId = SubscriptionManager.getDefaultSmsSubscriptionId();
        CarrierConfigManager configManager =
                (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        PersistableBundle bundle = configManager.getConfigForSubId(subId);

        if (bundle != null) {
            return bundle.getLong(CarrierConfigManager.KEY_UNDELIVERED_SMS_MESSAGE_EXPIRATION_TIME,
                    DEFAULT_PARTIAL_SEGMENT_EXPIRE_AGE);
        } else {
            return DEFAULT_PARTIAL_SEGMENT_EXPIRE_AGE;
        }
    }

    /**
     * Used as the HashMap key for matching concatenated message segments.
     */