Loading android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java +5 −25 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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(); Loading @@ -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() { Loading Loading @@ -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()) { Loading Loading @@ -446,9 +434,6 @@ public class BluetoothPbapSimVcardManager { buffer.writeVCard(vcard); } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.terminate(); } Loading @@ -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; Loading @@ -502,9 +485,6 @@ public class BluetoothPbapSimVcardManager { } buffer.writeVCard(vcard); } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.terminate(); } Loading android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BluetoothPbapSimVcardManagerTest { @After public void tearDown() { mManager.close(); BluetoothMethodProxy.setInstanceForTesting(null); } Loading Loading @@ -145,9 +146,9 @@ public class BluetoothPbapSimVcardManagerTest { } @Test public void testTerminate() { public void testClose() { Cursor cursor = initManager(); mManager.terminate(); mManager.close(); verify(cursor).close(); } Loading Loading
android/app/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManager.java +5 −25 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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(); Loading @@ -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() { Loading Loading @@ -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()) { Loading Loading @@ -446,9 +434,6 @@ public class BluetoothPbapSimVcardManager { buffer.writeVCard(vcard); } } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.terminate(); } Loading @@ -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; Loading @@ -502,9 +485,6 @@ public class BluetoothPbapSimVcardManager { } buffer.writeVCard(vcard); } finally { if (composer != null) { composer.terminate(); } if (buffer != null) { buffer.terminate(); } Loading
android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapSimVcardManagerTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BluetoothPbapSimVcardManagerTest { @After public void tearDown() { mManager.close(); BluetoothMethodProxy.setInstanceForTesting(null); } Loading Loading @@ -145,9 +146,9 @@ public class BluetoothPbapSimVcardManagerTest { } @Test public void testTerminate() { public void testClose() { Cursor cursor = initManager(); mManager.terminate(); mManager.close(); verify(cursor).close(); } Loading