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

Commit 30ac6955 authored by Hieu Dang's avatar Hieu Dang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "cherry-pick-aosp-12Dec-Hieu" into tm-qpr-dev

* changes:
  Fix BluetoothOppIncomingFileActivityTest
  Add BluetoothOppReceiveFileInfoTest
  Fix Opp Activities Bugs
  Add BluetoothOppHistoryTest
  Add BluetoothOppHandoverReceiverTest
  Fix BluetoothOppTransferActivityTest
  Add BluetoothOppIncomingFileConfirmActivityTest
  Fix BluetoothOppUtilityTest
  Fix BluetoothOppManagerTest
  Add BluetoothOppManagerTest
  Fix BluetoothOppObexSession timeout failing tests
  Add BluetoothOppLauncherActivityTest
  Add BluetoothOppBtEnablingActivityTest
  Add BluetoothOppBtEnableActivityTest
parents 18779d7d 50e5be09
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -41,13 +41,16 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.VisibleForTesting;

import com.android.bluetooth.R;

/**
 * This class is designed to show BT enable confirmation dialog;
 */
public class BluetoothOppBtEnableActivity extends AlertActivity {
    private BluetoothOppManager mOppManager;
    @VisibleForTesting
    BluetoothOppManager mOppManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
+8 −4
Original line number Diff line number Diff line
@@ -48,7 +48,9 @@ import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;

/**
 * This class is designed to show BT enabling progress.
@@ -62,7 +64,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {

    private static final int BT_ENABLING_TIMEOUT = 0;

    private static final int BT_ENABLING_TIMEOUT_VALUE = 20000;
    @VisibleForTesting
    static int sBtEnablingTimeoutMs = 20000;

    private boolean mRegistered = false;

@@ -73,7 +76,7 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
        // If BT is already enabled jus return.
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter.isEnabled()) {
        if (BluetoothMethodProxy.getInstance().bluetoothAdapterIsEnabled(adapter)) {
            finish();
            return;
        }
@@ -88,7 +91,7 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {

        // Add timeout for enabling progress
        mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(BT_ENABLING_TIMEOUT),
                BT_ENABLING_TIMEOUT_VALUE);
                sBtEnablingTimeoutMs);
    }

    private View createView() {
@@ -119,7 +122,8 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
        }
    }

    private final Handler mTimeoutHandler = new Handler() {
    @VisibleForTesting
    final Handler mTimeoutHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
+4 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;

import java.util.ArrayList;

public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
@@ -93,7 +95,8 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
                if (D) {
                    Log.d(TAG, "Stopping handover transfer with Uri " + contentUri);
                }
                context.getContentResolver().delete(contentUri, null, null);
                BluetoothMethodProxy.getInstance().contentResolverDelete(
                        context.getContentResolver(), contentUri, null, null);
            }
        } else {
            if (D) {
+5 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;

/**
@@ -154,7 +155,8 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
            mUpdateValues = new ContentValues();
            mUpdateValues.put(BluetoothShare.USER_CONFIRMATION,
                    BluetoothShare.USER_CONFIRMATION_CONFIRMED);
            this.getContentResolver().update(mUri, mUpdateValues, null, null);
            BluetoothMethodProxy.getInstance().contentResolverUpdate(this.getContentResolver(),
                    mUri, mUpdateValues, null, null);

            Toast.makeText(this, getString(R.string.bt_toast_1), Toast.LENGTH_SHORT).show();
        }
@@ -165,7 +167,8 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity {
        mUpdateValues = new ContentValues();
        mUpdateValues.put(BluetoothShare.USER_CONFIRMATION,
                BluetoothShare.USER_CONFIRMATION_DENIED);
        this.getContentResolver().update(mUri, mUpdateValues, null, null);
        BluetoothMethodProxy.getInstance().contentResolverUpdate(this.getContentResolver(),
                mUri, mUpdateValues, null, null);
    }

    @Override
+13 −6
Original line number Diff line number Diff line
@@ -46,7 +46,10 @@ import android.util.Log;
import android.util.Patterns;
import android.widget.Toast;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.internal.annotations.VisibleForTesting;

import java.io.File;
import java.io.FileNotFoundException;
@@ -133,7 +136,7 @@ public class BluetoothOppLauncherActivity extends Activity {
                                "Get ACTION_SEND intent with Extra_text = " + extraText.toString()
                                        + "; mimetype = " + type);
                    }
                    final Uri fileUri = creatFileForSharedContent(
                    final Uri fileUri = createFileForSharedContent(
                            this.createCredentialProtectedStorageContext(), extraText);
                    if (fileUri != null) {
                        Thread t = new Thread(new Runnable() {
@@ -193,23 +196,26 @@ public class BluetoothOppLauncherActivity extends Activity {
            if (V) {
                Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri);
            }

            Intent intent1 = new Intent(Constants.ACTION_OPEN);
            intent1.setClassName(this, BluetoothOppReceiver.class.getName());
            intent1.setDataAndNormalize(uri);
            this.sendBroadcast(intent1);
            BluetoothMethodProxy.getInstance().contextSendBroadcast(this, intent1);
            finish();
        } else {
            Log.w(TAG, "Unsupported action: " + action);
            // To prevent activity to finish immediately in testing mode
            if (!Utils.isInstrumentationTestMode()) {
                finish();
            }
        }
    }

    /**
     * Turns on Bluetooth if not already on, or launches device picker if Bluetooth is on
     * @return
     */
    private void launchDevicePicker() {
    @VisibleForTesting
    void launchDevicePicker() {
        // TODO: In the future, we may send intent to DevicePickerActivity
        // directly,
        // and let DevicePickerActivity to handle Bluetooth Enable.
@@ -274,7 +280,8 @@ public class BluetoothOppLauncherActivity extends Activity {
        return false;
    }

    private Uri creatFileForSharedContent(Context context, CharSequence shareContent) {
    @VisibleForTesting
    Uri createFileForSharedContent(Context context, CharSequence shareContent) {
        if (shareContent == null) {
            return null;
        }
Loading