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

Commit f8f04984 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Gerrit Code Review
Browse files

Merge "Remove MAP_LIMIT_NOTIFICATION flag" into main

parents 01ec4a58 ea338f8f
Loading
Loading
Loading
Loading
+9 −25
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.Utils;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.map.BluetoothMapbMessageMime.MimePart;
import com.android.bluetooth.mapapi.BluetoothMapContract;
@@ -1558,19 +1557,12 @@ public class BluetoothMapContentObserver {
                                            > BluetoothMapUtils.MAP_EVENT_REPORT_V10) {
                                long timestamp = c.getLong(c.getColumnIndex(Sms.DATE));
                                String date = BluetoothMapUtils.getDateTimeString(timestamp);
                                if (Flags.mapLimitNotification()) {
                                if (BluetoothMapUtils.isDateTimeOlderThanDuration(
                                        timestamp, NEW_MESSAGE_DURATION_FOR_NOTIFICATION)) {
                                    msgListSms.remove(id);
                                    continue;
                                }
                                } else {
                                    if (BluetoothMapUtils.isDateTimeOlderThanOneYear(timestamp)) {
                                        // Skip sending message events older than one year
                                        msgListSms.remove(id);
                                        continue;
                                    }
                                }

                                String subject = c.getString(c.getColumnIndex(Sms.BODY));
                                if (subject == null) {
                                    subject = "";
@@ -1813,19 +1805,11 @@ public class BluetoothMapContentObserver {
                                        TimeUnit.SECONDS.toMillis(
                                                c.getLong(c.getColumnIndex(Mms.DATE)));
                                String date = BluetoothMapUtils.getDateTimeString(timestamp);
                                if (Flags.mapLimitNotification()) {
                                if (BluetoothMapUtils.isDateTimeOlderThanDuration(
                                        timestamp, NEW_MESSAGE_DURATION_FOR_NOTIFICATION)) {
                                    msgListMms.remove(id);
                                    continue;
                                }
                                } else {
                                    if (BluetoothMapUtils.isDateTimeOlderThanOneYear(timestamp)) {
                                        // Skip sending new message events older than one year
                                        msgListMms.remove(id);
                                        continue;
                                    }
                                }

                                String subject = c.getString(c.getColumnIndex(Mms.SUBJECT));
                                if (subject == null || subject.length() == 0) {
+0 −17
Original line number Diff line number Diff line
@@ -755,23 +755,6 @@ public class BluetoothMapUtils {
        return format.format(cal.getTime());
    }

    static boolean isDateTimeOlderThanOneYear(long timestamp) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(timestamp);
        Calendar oneYearAgo = Calendar.getInstance();
        oneYearAgo.add(Calendar.YEAR, -1);
        if (cal.before(oneYearAgo)) {
            Log.v(
                    TAG,
                    "isDateTimeOlderThanOneYear "
                            + cal.getTimeInMillis()
                            + " oneYearAgo: "
                            + oneYearAgo.getTimeInMillis());
            return true;
        }
        return false;
    }

    static boolean isDateTimeOlderThanDuration(long timestamp, Duration duration) {
        Instant nowMinusDuration = Instant.now().minus(duration);
        Instant dateTime = Instant.ofEpochMilli(timestamp);
+0 −101
Original line number Diff line number Diff line
@@ -1458,61 +1458,8 @@ public class BluetoothMapContentObserverTest {
                mObserver.getMsgListMms().get(TEST_HANDLE_ONE).flagRead, TEST_READ_FLAG_ONE);
    }

    @Test
    public void handleMsgListChangesMms_withNonExistingOldMessage_andVersion12() {
        mSetFlagsRule.disableFlags(Flags.FLAG_MAP_LIMIT_NOTIFICATION);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -1);
        cal.add(Calendar.DATE, -1);
        long timestampSec = TimeUnit.MILLISECONDS.toSeconds(cal.getTimeInMillis());

        MatrixCursor cursor =
                new MatrixCursor(
                        new String[] {
                            Mms._ID,
                            Mms.MESSAGE_BOX,
                            Mms.MESSAGE_TYPE,
                            Mms.THREAD_ID,
                            Mms.READ,
                            Mms.DATE,
                            Mms.SUBJECT,
                            Mms.PRIORITY,
                            Mms.Addr.ADDRESS
                        });
        cursor.addRow(
                new Object[] {
                    TEST_HANDLE_ONE,
                    TEST_MMS_TYPE_ALL,
                    TEST_MMS_MTYPE,
                    TEST_THREAD_ID,
                    TEST_READ_FLAG_ONE,
                    timestampSec,
                    TEST_SUBJECT,
                    PduHeaders.PRIORITY_HIGH,
                    null
                });
        doReturn(cursor)
                .when(mMapMethodProxy)
                .contentResolverQuery(any(), any(), any(), any(), any(), any());

        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        // Giving a different handle for msg below and cursor above makes handleMsgListChangesMms()
        // function for a non-existing message
        BluetoothMapContentObserver.Msg msg =
                new BluetoothMapContentObserver.Msg(
                        TEST_HANDLE_TWO, TEST_INBOX_FOLDER_ID, TEST_READ_FLAG_ONE);
        map.put(TEST_HANDLE_TWO, msg);
        mObserver.setMsgListMms(map, true);
        mObserver.mMapEventReportVersion = BluetoothMapUtils.MAP_EVENT_REPORT_V12;

        mObserver.handleMsgListChangesMms();

        Assert.assertEquals(null, mObserver.getMsgListMms().get(TEST_HANDLE_ONE));
    }

    @Test
    public void handleMsgListChangesMms_withNonExistingOldMessage_andVersion12_andOneWeekLimit() {
        mSetFlagsRule.enableFlags(Flags.FLAG_MAP_LIMIT_NOTIFICATION);
        Instant oldInstant =
                Instant.now()
                        .minus(BluetoothMapContentObserver.NEW_MESSAGE_DURATION_FOR_NOTIFICATION);
@@ -1860,56 +1807,8 @@ public class BluetoothMapContentObserverTest {
                mObserver.getMsgListSms().get(TEST_HANDLE_ONE).flagRead, TEST_READ_FLAG_ONE);
    }

    @Test
    public void handleMsgListChangesSms_withNonExistingOldMessage_andVersion12() {
        mSetFlagsRule.disableFlags(Flags.FLAG_MAP_LIMIT_NOTIFICATION);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.YEAR, -1);
        cal.add(Calendar.DATE, -1);

        MatrixCursor cursor =
                new MatrixCursor(
                        new String[] {
                            Sms._ID,
                            Sms.TYPE,
                            Sms.THREAD_ID,
                            Sms.READ,
                            Sms.DATE,
                            Sms.BODY,
                            Sms.ADDRESS
                        });
        cursor.addRow(
                new Object[] {
                    TEST_HANDLE_ONE,
                    TEST_SMS_TYPE_ALL,
                    TEST_THREAD_ID,
                    TEST_READ_FLAG_ONE,
                    cal.getTimeInMillis(),
                    "",
                    null
                });
        doReturn(cursor)
                .when(mMapMethodProxy)
                .contentResolverQuery(any(), any(), any(), any(), any(), any());

        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        // Giving a different handle for msg below and cursor above makes handleMsgListChangesMms()
        // function for a non-existing message
        BluetoothMapContentObserver.Msg msg =
                new BluetoothMapContentObserver.Msg(
                        TEST_HANDLE_TWO, TEST_SMS_TYPE_INBOX, TEST_READ_FLAG_ONE);
        map.put(TEST_HANDLE_TWO, msg);
        mObserver.setMsgListSms(map, true);
        mObserver.mMapEventReportVersion = BluetoothMapUtils.MAP_EVENT_REPORT_V12;

        mObserver.handleMsgListChangesSms();

        Assert.assertEquals(null, mObserver.getMsgListSms().get(TEST_HANDLE_ONE));
    }

    @Test
    public void handleMsgListChangesSms_withNonExistingOldMessage_andVersion12_andOneWeekLimit() {
        mSetFlagsRule.enableFlags(Flags.FLAG_MAP_LIMIT_NOTIFICATION);
        Instant oldInstant =
                Instant.now()
                        .minus(BluetoothMapContentObserver.NEW_MESSAGE_DURATION_FOR_NOTIFICATION);
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ aconfig_declarations {
        "l2cap.aconfig",
        "le_advertising.aconfig",
        "leaudio.aconfig",
        "map.aconfig",
        "mapclient.aconfig",
        "mcp.aconfig",
        "metric.aconfig",
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ aconfig("bluetooth_flags_c_lib") {
    "l2cap.aconfig",
    "le_advertising.aconfig",
    "leaudio.aconfig",
    "map.aconfig",
    "mapclient.aconfig",
    "mcp.aconfig",
    "metric.aconfig",
Loading