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

Commit 0c6967fb authored by My Name's avatar My Name
Browse files

Fix BluetoothOppObexSession timeout failing tests

Bug: 259422308
Test: atest BluetoothOppObexSession
Tag: #refactor
Change-Id: I867fc16f4d80d3ffa5f2df9989444c4f1650c443
parent 28657ddb
Loading
Loading
Loading
Loading
+4 −36
Original line number Diff line number Diff line
@@ -72,42 +72,10 @@
      "name" : "net_test_stack_btm"
    },
    {
      "name" : "BluetoothInstrumentationTests",
      "options" : [{
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_MSG_CONNECT_TIMEOUT"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_MSG_SHARE_INTERRUPTED_batchFailed"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_TRANSPORT_ERROR_connectThreadIsNull"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#onBatchCanceled_checkStatus"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppUtilityTest#openReceivedFile_fileNotExist"
      }]
    },
    {
      "name" : "GoogleBluetoothInstrumentationTests",
      "options" : [{
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_MSG_CONNECT_TIMEOUT"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_MSG_SHARE_INTERRUPTED_batchFailed"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#eventHandler_handleMessage_TRANSPORT_ERROR_connectThreadIsNull"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppTransferTest#onBatchCanceled_checkStatus"
      }, {
        // b/259422308
        "exclude-filter" : "com.android.bluetooth.opp.BluetoothOppUtilityTest#openReceivedFile_fileNotExist"
      }]
      "name" : "BluetoothInstrumentationTests"
    },
    {
      "name" : "GoogleBluetoothInstrumentationTests"
    },
    {
      "name" : "FrameworkBluetoothTests"
+8 −4
Original line number Diff line number Diff line
@@ -395,7 +395,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
        ContentValues updateValues = new ContentValues();
        updateValues.put(BluetoothShare.USER_CONFIRMATION,
                BluetoothShare.USER_CONFIRMATION_TIMEOUT);
        mContext.getContentResolver().update(contentUri, updateValues, null, null);
        BluetoothMethodProxy.getInstance().contentResolverUpdate(mContext.getContentResolver(),
                contentUri, updateValues, null, null);
    }

    private void markBatchFailed(int failReason) {
@@ -421,7 +422,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
            }
            if (mCurrentShare.mDirection == BluetoothShare.DIRECTION_INBOUND
                    && mCurrentShare.mUri != null) {
                mContext.getContentResolver().delete(mCurrentShare.mUri, null, null);
                BluetoothMethodProxy.getInstance().contentResolverDelete(
                        mContext.getContentResolver(), mCurrentShare.mUri, null, null);
            }
        }

@@ -448,7 +450,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
                    }
                } else {
                    if (info.mStatus < 200 && info.mUri != null) {
                        mContext.getContentResolver().delete(info.mUri, null, null);
                        BluetoothMethodProxy.getInstance().contentResolverDelete(
                                mContext.getContentResolver(), info.mUri, null, null);
                    }
                }
                BluetoothMethodProxy.getInstance().contentResolverUpdate(
@@ -873,7 +876,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
        Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + share.mId);
        ContentValues updateValues = new ContentValues();
        updateValues.put(BluetoothShare.DIRECTION, share.mDirection);
        mContext.getContentResolver().update(contentUri, updateValues, null, null);
        BluetoothMethodProxy.getInstance().contentResolverUpdate(mContext.getContentResolver(),
                contentUri, updateValues, null, null);
    }

    /*
+7 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.bluetooth.opp.BluetoothOppTransfer.TRANSPORT_ERROR;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@@ -28,9 +29,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.content.ContentValues;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Looper;
@@ -49,7 +50,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

@@ -84,8 +84,12 @@ public class BluetoothOppTransferTest {
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        BluetoothMethodProxy.setInstanceForTesting(mCallProxy);
        doReturn(0).when(mCallProxy).contentResolverDelete(any(), nullable(Uri.class),
                nullable(String.class), nullable(String[].class));
        doReturn(0).when(mCallProxy).contentResolverUpdate(any(), nullable(Uri.class),
                nullable(ContentValues.class), nullable(String.class), nullable(String[].class));

        mInitShareInfo = new BluetoothOppShareInfo(123, mUri, mHintString, mFilename, mMimetype,
        mInitShareInfo = new BluetoothOppShareInfo(8765, mUri, mHintString, mFilename, mMimetype,
                mDirection, mDestination, mVisibility, mConfirm, mStatus, mTotalBytes,
                mCurrentBytes,
                mTimestamp, mMediaScanned);
@@ -125,7 +129,6 @@ public class BluetoothOppTransferTest {

    @Test
    public void onBatchCanceled_checkStatus() {
        doReturn(0).when(mCallProxy).contentResolverDelete(any(), any(), any(), any());
        // This will trigger mTransfer.onBatchCanceled(),
        // which will then change the status of the batch accordingly
        mBluetoothOppBatch.cancelBatch();
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer;
@@ -147,6 +148,9 @@ public class BluetoothOppUtilityTest {
        doReturn(true).when(mCursor).moveToFirst();
        doReturn(fileUri.toString()).when(mCursor).getString(anyInt());

        doReturn(0).when(mCallProxy).contentResolverDelete(any(), any(), nullable(String.class),
                nullable(String[].class));

        BluetoothOppUtility.openReceivedFile(spiedContext, "randomFileName.txt",
                "text/plain", 0L, contentResolverUri);