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
diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 63b9b66..813148f 100644
--- a/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -80,7 +80,7 @@
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 @@
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 @@
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 @@
.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))
diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
index ed93559..4aa104a 100644
--- a/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
+++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
@@ -31,6 +31,7 @@
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,25 +140,27 @@
}
} 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 (V) {
- Log.v(TAG, "Received ACTION_OPEN_OUTBOUND_TRANSFER.");
- }
+ if (!Flags.oppStartActivityDirectlyFromNotification()) {
+ if (V) {
+ Log.v(TAG, "Received ACTION_OPEN_OUTBOUND_TRANSFER.");
+ }
- Intent in = new Intent(context, BluetoothOppTransferHistory.class);
- in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
- context.startActivity(in);
+ Intent in = new Intent(context, BluetoothOppTransferHistory.class);
+ 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 (V) {
- Log.v(TAG, "Received ACTION_OPEN_INBOUND_TRANSFER.");
- }
+ if (!Flags.oppStartActivityDirectlyFromNotification()) {
+ if (V) {
+ Log.v(TAG, "Received ACTION_OPEN_INBOUND_TRANSFER.");
+ }
- Intent in = new Intent(context, BluetoothOppTransferHistory.class);
- in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- in.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);
- context.startActivity(in);
+ Intent in = new Intent(context, BluetoothOppTransferHistory.class);
+ 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());
diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferHistory.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferHistory.java
index fbc8d5c..5636df3 100644
--- a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferHistory.java
+++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransferHistory.java
@@ -38,6 +38,7 @@
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 @@
mListView.setEmptyView(findViewById(R.id.empty));
String direction;
- int dir = getIntent().getIntExtra(Constants.EXTRA_DIRECTION, 0);
- if (dir == BluetoothShare.DIRECTION_OUTBOUND) {
+
+ 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);
+ isOutbound = (dir == BluetoothShare.DIRECTION_OUTBOUND);
+ }
+
+ if (isOutbound) {
setTitle(getText(R.string.outbound_history_title));
direction = "(" + BluetoothShare.DIRECTION + " == " + BluetoothShare.DIRECTION_OUTBOUND
+ ")";
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
index 851acea..7faf6b7 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppReceiverTest.java
@@ -42,6 +42,7 @@
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 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 @@
}
@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 @@
}
@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"));