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

Commit b0ced317 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Open activity directly from notification (inbound transfer)

When user clicks the OPP notification for inbound transfer,
this CL makes the activity start directly from the notification.

Previously the intent was sent to BluetoothOppReceiver first,
which added noticable delay before launching an activity.

Since inbound and outbound transfer used almost same intents whose
only difference is their intent extras, this CL makes the intent
action be different for better code readability.

Bug: 319050411
Bug: 318610752
Test: atest BluetoothOppReceiverTest
Test: manual, after receiving a file via Bluetooth, click the
      notification titled "Bluetooth Share: Received files".
      There should be no lag when opening the activity
      "Inbound Transfers".
Change-Id: Ia24f19bb7d854eca1f9ea1b107f06287003f5bfe
parent cae7c96d
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ class BluetoothOppNotification {
            WHERE_COMPLETED + " AND " + "(" + BluetoothShare.DIRECTION + " == "
                    + BluetoothShare.DIRECTION_INBOUND + ")";

    static final String WHERE_CONFIRM_PENDING =
    private static final String WHERE_CONFIRM_PENDING =
            BluetoothShare.USER_CONFIRMATION + " == '" + BluetoothShare.USER_CONFIRMATION_PENDING
                    + "'" + " AND " + VISIBLE;

@@ -433,9 +433,9 @@ class BluetoothOppNotification {

            PendingIntent pi;
            if (Flags.oppStartActivityDirectlyFromNotification()) {
                Intent in = new Intent(mContext, BluetoothOppTransferHistory.class);
                Intent in = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
                in.setClass(mContext, BluetoothOppTransferHistory.class);
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
                pi = PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            } else {
                Intent in =
@@ -505,8 +505,20 @@ class BluetoothOppNotification {
        if (inboundNum > 0) {
            String caption = BluetoothOppUtility.formatResultText(inboundSuccNumber,
                    inboundFailNumber, mContext);
            Intent contentIntent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER).setClassName(
                    mContext, BluetoothOppReceiver.class.getName());

            PendingIntent pi;
            if (Flags.oppStartActivityDirectlyFromNotification()) {
                Intent in = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER);
                in.setClass(mContext, BluetoothOppTransferHistory.class);
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                pi = PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            } else {
                Intent in =
                        new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER)
                                .setClassName(mContext, BluetoothOppReceiver.class.getName());
                pi = PendingIntent.getBroadcast(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            }

            Intent deleteIntent = new Intent(Constants.ACTION_COMPLETE_HIDE).setClassName(
                    mContext, BluetoothOppReceiver.class.getName());
            Notification inNoti =
@@ -521,9 +533,7 @@ class BluetoothOppNotification {
                                                    .system_notification_accent_color,
                                            mContext.getTheme()))

                            .setContentIntent(
                                    PendingIntent.getBroadcast(mContext, 0, contentIntent,
                                        PendingIntent.FLAG_IMMUTABLE))
                            .setContentIntent(pi)
                            .setDeleteIntent(
                                    PendingIntent.getBroadcast(mContext, 0, deleteIntent,
                                        PendingIntent.FLAG_IMMUTABLE))
+19 −16
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.widget.Toast;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.flags.Flags;

/**
 * Receives and handles: system broadcasts; Intents from other applications;
@@ -139,8 +140,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
            }

        } else if (action.equals(Constants.ACTION_OPEN_OUTBOUND_TRANSFER)) {
            // TODO(b/319050411): Remove this if statement branch when the flag
            //                    oppStartActivityDirectlyFromNotification is cleaned up.
            if (!Flags.oppStartActivityDirectlyFromNotification()) {
                if (V) {
                    Log.v(TAG, "Received ACTION_OPEN_OUTBOUND_TRANSFER.");
                }
@@ -149,7 +149,9 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
                context.startActivity(in);
            }
        } else if (action.equals(Constants.ACTION_OPEN_INBOUND_TRANSFER)) {
            if (!Flags.oppStartActivityDirectlyFromNotification()) {
                if (V) {
                    Log.v(TAG, "Received ACTION_OPEN_INBOUND_TRANSFER.");
                }
@@ -158,6 +160,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);
                context.startActivity(in);
            }
        } else if (action.equals(Constants.ACTION_HIDE)) {
            if (V) {
                Log.v(TAG, "Receiver hide for " + intent.getData());
+13 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.widget.ListView;

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

/**
 * View showing the user's finished bluetooth opp transfers that the user does
@@ -75,8 +76,18 @@ public class BluetoothOppTransferHistory extends Activity
        mListView.setEmptyView(findViewById(R.id.empty));

        String direction;

        boolean isOutbound = false;

        if (Flags.oppStartActivityDirectlyFromNotification()) {
            String action = getIntent().getAction();
            isOutbound = Constants.ACTION_OPEN_OUTBOUND_TRANSFER.equals(action);
        } else {
            int dir = getIntent().getIntExtra(Constants.EXTRA_DIRECTION, 0);
        if (dir == BluetoothShare.DIRECTION_OUTBOUND) {
            isOutbound = (dir == BluetoothShare.DIRECTION_OUTBOUND);
        }

        if (isOutbound) {
            setTitle(getText(R.string.outbound_history_title));
            direction = "(" + BluetoothShare.DIRECTION + " == " + BluetoothShare.DIRECTION_OUTBOUND
                    + ")";
+12 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.platform.test.annotations.RequiresFlagsDisabled;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.Intents;
@@ -50,6 +51,7 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.flags.Flags;

import com.google.common.base.Objects;

@@ -152,7 +154,12 @@ public class BluetoothOppReceiverTest {
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION)
    public void onReceive_withActionOutboundTransfer_startsTransferHistoryActivity() {
        if (Flags.oppStartActivityDirectlyFromNotification()) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
        intent.setData(Uri.parse("content:///not/important"));
@@ -165,7 +172,12 @@ public class BluetoothOppReceiverTest {
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION)
    public void onReceive_withActionInboundTransfer_startsTransferHistoryActivity() {
        if (Flags.oppStartActivityDirectlyFromNotification()) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER);
        intent.setData(Uri.parse("content:///not/important"));