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

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

Merge "Remove BluetoothPbapSimVCardManager#finalize" into main

parents 15ab20f3 84f3b3a0
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ import java.util.List;

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

    @VisibleForTesting
@@ -90,7 +90,6 @@ public class BluetoothPbapSimVcardManager {
    private final Context mContext;
    private ContentResolver mContentResolver;
    private Cursor mCursor;
    private boolean mTerminateIsCalled;
    private String mErrorReason = NO_ERROR;

    public BluetoothPbapSimVcardManager(final Context context) {
@@ -194,7 +193,8 @@ public class BluetoothPbapSimVcardManager {
        return builder.toString();
    }

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

        mTerminateIsCalled = true;
    }

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

    public int getCount() {
@@ -411,10 +401,8 @@ public class BluetoothPbapSimVcardManager {
                    2);
            return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
        }
        BluetoothPbapSimVcardManager composer = null;
        HandlerForStringBuffer buffer = null;
        try {
            composer = new BluetoothPbapSimVcardManager(context);
        try (BluetoothPbapSimVcardManager composer = new BluetoothPbapSimVcardManager(context)) {
            buffer = new HandlerForStringBuffer(op, ownerVCard);

            if (!composer.init(SIM_URI, null, null, null) || !buffer.init()) {
@@ -446,9 +434,6 @@ public class BluetoothPbapSimVcardManager {
                buffer.writeVCard(vcard);
            }
        } finally {
            if (composer != null) {
                composer.terminate();
            }
            if (buffer != null) {
                buffer.terminate();
            }
@@ -473,10 +458,8 @@ public class BluetoothPbapSimVcardManager {
            return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
        }
        Log.v(TAG, "composeAndSendSIMPhonebookOneVcard orderByWhat " + orderByWhat);
        BluetoothPbapSimVcardManager composer = null;
        HandlerForStringBuffer buffer = null;
        try {
            composer = new BluetoothPbapSimVcardManager(context);
        try (BluetoothPbapSimVcardManager composer = new BluetoothPbapSimVcardManager(context)) {
            buffer = new HandlerForStringBuffer(op, ownerVCard);
            if (!composer.init(SIM_URI, null, null, null) || !buffer.init()) {
                return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
@@ -502,9 +485,6 @@ public class BluetoothPbapSimVcardManager {
            }
            buffer.writeVCard(vcard);
        } finally {
            if (composer != null) {
                composer.terminate();
            }
            if (buffer != null) {
                buffer.terminate();
            }
+3 −2
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class BluetoothPbapSimVcardManagerTest {

    @After
    public void tearDown() {
        mManager.close();
        BluetoothMethodProxy.setInstanceForTesting(null);
    }

@@ -145,9 +146,9 @@ public class BluetoothPbapSimVcardManagerTest {
    }

    @Test
    public void testTerminate() {
    public void testClose() {
        Cursor cursor = initManager();
        mManager.terminate();
        mManager.close();

        verify(cursor).close();
    }