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

Commit cd203681 authored by Malcolm Chen's avatar Malcolm Chen Committed by android-build-merger
Browse files

Merge "Add carrier config for partial sms raw message expiration." into pi-dev

am: efeba18b

Change-Id: I8483aabab430c9f8632581a7cbb24ea6b8395c97
parents ae382ff7 efeba18b
Loading
Loading
Loading
Loading
+22 −5
Original line number Original line Diff line number Diff line
@@ -23,9 +23,11 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.database.Cursor;
import android.database.Cursor;
import android.database.SQLException;
import android.database.SQLException;
import android.os.UserHandle;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.os.UserManager;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;


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


    /** Delete any partial message segments older than 30 days. */
    /** 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.
     * Query projection for dispatching pending messages at boot time.
@@ -97,7 +99,7 @@ public class SmsBroadcastUndelivered {


        @Override
        @Override
        public void run() {
        public void run() {
            scanRawTable();
            scanRawTable(context);
            InboundSmsHandler.cancelNewMessageNotification(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.
     * 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");
        if (DBG) Rlog.d(TAG, "scanning raw table for undelivered messages");
        long startTime = System.nanoTime();
        long startTime = System.nanoTime();
        HashMap<SmsReferenceKey, Integer> multiPartReceivedCount =
        HashMap<SmsReferenceKey, Integer> multiPartReceivedCount =
@@ -176,8 +178,9 @@ public class SmsBroadcastUndelivered {
                    Integer receivedCount = multiPartReceivedCount.get(reference);
                    Integer receivedCount = multiPartReceivedCount.get(reference);
                    if (receivedCount == null) {
                    if (receivedCount == null) {
                        multiPartReceivedCount.put(reference, 1);    // first segment seen
                        multiPartReceivedCount.put(reference, 1);    // first segment seen
                        long expirationTime = getUndeliveredSmsExpirationTime(context);
                        if (tracker.getTimestamp() <
                        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
                            // older than 30 days; delete if we don't find all the segments
                            oldMultiPartMessages.add(reference);
                            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.
     * Used as the HashMap key for matching concatenated message segments.
     */
     */