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

Commit bb1c7b66 authored by Omair Kamil's avatar Omair Kamil Committed by Gerrit Code Review
Browse files

Merge "Remove BluetoothPbapCallLogComposer#finalize" into main

parents e3550e09 21b80641
Loading
Loading
Loading
Loading
+3 −14
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ import java.util.Calendar;

/** VCard composer especially for Call Log used in Bluetooth. */
// Next tag value for ContentProfileErrorReportUtils.report(): 3
public class BluetoothPbapCallLogComposer {
public class BluetoothPbapCallLogComposer implements AutoCloseable {
    private static final String TAG = "PbapCallLogComposer";

    @VisibleForTesting
@@ -92,8 +92,6 @@ public class BluetoothPbapCallLogComposer {
    private final Context mContext;
    private Cursor mCursor;

    private boolean mTerminateIsCalled;

    private String mErrorReason = NO_ERROR;

    private final String RFC_2455_FORMAT = "yyyyMMdd'T'HHmmss";
@@ -281,7 +279,8 @@ public class BluetoothPbapCallLogComposer {
                toRfc2455Format(dateAsLong));
    }

    public void terminate() {
    /** Closes the composer, releasing all of its resources. */
    public void close() {
        if (mCursor != null) {
            try {
                mCursor.close();
@@ -296,16 +295,6 @@ public class BluetoothPbapCallLogComposer {
            }
            mCursor = null;
        }

        mTerminateIsCalled = true;
    }

    @Override
    @SuppressWarnings("Finalize") // TODO: b/366307571 remove override
    public void finalize() {
        if (!mTerminateIsCalled) {
            terminate();
        }
    }

    public int getCount() {
+1 −6
Original line number Diff line number Diff line
@@ -1103,13 +1103,11 @@ public class BluetoothPbapVcardManager {
            boolean vCardSelct) {
        long timestamp = System.currentTimeMillis();

        BluetoothPbapCallLogComposer composer = null;
        HandlerForStringBuffer buffer = null;

        try {
        try (BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext)) {
            VCardFilter vcardfilter = new VCardFilter(ignorefilter ? null : filter);
            PropertySelector vcardselector = new PropertySelector(selector);
            composer = new BluetoothPbapCallLogComposer(mContext);
            buffer = new HandlerForStringBuffer(op, ownerVCard);
            if (!composer.init(CallLog.Calls.CONTENT_URI, selection, null, CALLLOG_SORT_ORDER)
                    || !buffer.init()) {
@@ -1182,9 +1180,6 @@ public class BluetoothPbapVcardManager {
                return pbSize;
            }
        } finally {
            if (composer != null) {
                composer.terminate();
            }
            if (buffer != null) {
                buffer.terminate();
            }
+3 −10
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class BluetoothPbapCallLogComposerTest {
    @After
    public void tearDown() throws Exception {
        BluetoothMethodProxy.setInstanceForTesting(null);
        mComposer.close();
    }

    @Test
@@ -165,18 +166,10 @@ public class BluetoothPbapCallLogComposerTest {
    }

    @Test
    public void testTerminate() {
    public void testClose() {
        mComposer.init(CALL_LOG_URI, SELECTION, SELECTION_ARGS, SORT_ORDER);

        mComposer.terminate();
        verify(mMockCursor).close();
    }

    @Test
    public void testFinalize() {
        mComposer.init(CALL_LOG_URI, SELECTION, SELECTION_ARGS, SORT_ORDER);

        mComposer.finalize();
        mComposer.close();
        verify(mMockCursor).close();
    }