Loading android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +9 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,15 @@ public class BluetoothMethodProxy { return contentResolver.query(contentUri, projection, selection, selectionArgs, sortOrder); } /** * Proxies {@link ContentResolver#delete(Uri, String, String[])}. */ public int contentResolverDelete(ContentResolver contentResolver, final Uri url, final String where, final String[] selectionArgs) { return contentResolver.delete(url, where, selectionArgs); } /** * Proxies {@link HeaderSet#getHeader}. */ Loading android/app/src/com/android/bluetooth/opp/BluetoothOppBatch.java +5 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.util.Log; import com.android.bluetooth.BluetoothMethodProxy; import java.util.ArrayList; /** Loading Loading @@ -148,7 +150,9 @@ public class BluetoothOppBatch { if (info.mStatus < 200) { if (info.mDirection == BluetoothShare.DIRECTION_INBOUND && info.mUri != null) { mContext.getContentResolver().delete(info.mUri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete( mContext.getContentResolver(), info.mUri, null, null ); } if (V) { Log.v(TAG, "Cancel batch for info " + info.mId); Loading android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBatchTest.java +14 −28 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.bluetooth.opp; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import android.content.Context; Loading @@ -24,9 +27,12 @@ import androidx.test.filters.MediumTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @MediumTest @RunWith(AndroidJUnit4.class) Loading Loading @@ -85,37 +91,17 @@ public class BluetoothOppBatchTest { } @Test public void cancelBatch_throwUnknownUri() { // Array can be access and edit by the inner class final boolean[] batchCancelCalled = {false}; mBluetoothOppBatch.registerListener(new BluetoothOppBatch.BluetoothOppBatchListener() { @Override public void onShareAdded(int id) { } @Override public void onShareDeleted(int id) { } public void cancelBatch_cancelSuccessfully() { @Override public void onBatchCanceled() { batchCancelCalled[0] = true; } }); BluetoothMethodProxy proxy = spy(BluetoothMethodProxy.getInstance()); BluetoothMethodProxy.setInstanceForTesting(proxy); doReturn(0).when(proxy).contentResolverDelete(any(), any(), any(), any()); assertThat(mBluetoothOppBatch.getPendingShare()).isEqualTo(mInitShareInfo); try { mBluetoothOppBatch.cancelBatch(); assertThat(mBluetoothOppBatch.isEmpty()).isTrue(); assertThat(batchCancelCalled[0]).isTrue(); } catch (IllegalArgumentException e) { // the id for BluetoothOppShareInfo id is made up, so the link is invalid, // leading to IllegalArgumentException. In this case, cancelBatch() failed assertThat(e).hasMessageThat().isEqualTo( "Unknown URI content://com.android.bluetooth.opp/btopp/0"); assertThat(mBluetoothOppBatch.isEmpty()).isFalse(); assertThat(batchCancelCalled[0]).isFalse(); } BluetoothMethodProxy.setInstanceForTesting(null); } } Loading
android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +9 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,15 @@ public class BluetoothMethodProxy { return contentResolver.query(contentUri, projection, selection, selectionArgs, sortOrder); } /** * Proxies {@link ContentResolver#delete(Uri, String, String[])}. */ public int contentResolverDelete(ContentResolver contentResolver, final Uri url, final String where, final String[] selectionArgs) { return contentResolver.delete(url, where, selectionArgs); } /** * Proxies {@link HeaderSet#getHeader}. */ Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppBatch.java +5 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.util.Log; import com.android.bluetooth.BluetoothMethodProxy; import java.util.ArrayList; /** Loading Loading @@ -148,7 +150,9 @@ public class BluetoothOppBatch { if (info.mStatus < 200) { if (info.mDirection == BluetoothShare.DIRECTION_INBOUND && info.mUri != null) { mContext.getContentResolver().delete(info.mUri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete( mContext.getContentResolver(), info.mUri, null, null ); } if (V) { Log.v(TAG, "Cancel batch for info " + info.mId); Loading
android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppBatchTest.java +14 −28 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ package com.android.bluetooth.opp; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import android.content.Context; Loading @@ -24,9 +27,12 @@ import androidx.test.filters.MediumTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @MediumTest @RunWith(AndroidJUnit4.class) Loading Loading @@ -85,37 +91,17 @@ public class BluetoothOppBatchTest { } @Test public void cancelBatch_throwUnknownUri() { // Array can be access and edit by the inner class final boolean[] batchCancelCalled = {false}; mBluetoothOppBatch.registerListener(new BluetoothOppBatch.BluetoothOppBatchListener() { @Override public void onShareAdded(int id) { } @Override public void onShareDeleted(int id) { } public void cancelBatch_cancelSuccessfully() { @Override public void onBatchCanceled() { batchCancelCalled[0] = true; } }); BluetoothMethodProxy proxy = spy(BluetoothMethodProxy.getInstance()); BluetoothMethodProxy.setInstanceForTesting(proxy); doReturn(0).when(proxy).contentResolverDelete(any(), any(), any(), any()); assertThat(mBluetoothOppBatch.getPendingShare()).isEqualTo(mInitShareInfo); try { mBluetoothOppBatch.cancelBatch(); assertThat(mBluetoothOppBatch.isEmpty()).isTrue(); assertThat(batchCancelCalled[0]).isTrue(); } catch (IllegalArgumentException e) { // the id for BluetoothOppShareInfo id is made up, so the link is invalid, // leading to IllegalArgumentException. In this case, cancelBatch() failed assertThat(e).hasMessageThat().isEqualTo( "Unknown URI content://com.android.bluetooth.opp/btopp/0"); assertThat(mBluetoothOppBatch.isEmpty()).isFalse(); assertThat(batchCancelCalled[0]).isFalse(); } BluetoothMethodProxy.setInstanceForTesting(null); } }