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

Commit 3ff32bbc authored by Hieu Dang's avatar Hieu Dang Committed by Automerger Merge Worker
Browse files

Merge "Fix BluetoothOppBatchTest doesn't work" am: 2297dd06

parents b3b48029 2297dd06
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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}.
     */
+5 −1
Original line number Diff line number Diff line
@@ -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;

/**
@@ -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);
+14 −28
Original line number Diff line number Diff line
@@ -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;

@@ -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)
@@ -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);
    }
}