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

Commit c8e74f92 authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "Opp: Fix 'Sent/Received files' notifications being swiped out together" into main

parents b4850a2f 9511e559
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -72,13 +72,23 @@ class BluetoothOppNotification {
            BluetoothShare.STATUS + " >= '200' AND " + VISIBLE + " AND " + NOT_THROUGH_HANDOVER;
    // Don't show handover-initiated transfers

    private static final String WHERE_COMPLETED_OUTBOUND =
            WHERE_COMPLETED + " AND " + "(" + BluetoothShare.DIRECTION + " == "
                    + BluetoothShare.DIRECTION_OUTBOUND + ")";

    private static final String WHERE_COMPLETED_INBOUND =
            WHERE_COMPLETED + " AND " + "(" + BluetoothShare.DIRECTION + " == "
                    + BluetoothShare.DIRECTION_INBOUND + ")";
    static final String WHERE_COMPLETED_OUTBOUND =
            WHERE_COMPLETED
                    + " AND "
                    + "("
                    + BluetoothShare.DIRECTION
                    + " == "
                    + BluetoothShare.DIRECTION_OUTBOUND
                    + ")";

    static final String WHERE_COMPLETED_INBOUND =
            WHERE_COMPLETED
                    + " AND "
                    + "("
                    + BluetoothShare.DIRECTION
                    + " == "
                    + BluetoothShare.DIRECTION_INBOUND
                    + ")";

    private static final String WHERE_CONFIRM_PENDING =
            BluetoothShare.USER_CONFIRMATION + " == '" + BluetoothShare.USER_CONFIRMATION_PENDING
@@ -454,8 +464,13 @@ class BluetoothOppNotification {
                pi = PendingIntent.getBroadcast(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            }

            Intent deleteIntent = new Intent(Constants.ACTION_COMPLETE_HIDE).setClassName(
                    mContext, BluetoothOppReceiver.class.getName());
            Intent deleteIntent = new Intent(mContext, BluetoothOppReceiver.class);
            if (Flags.oppFixMultipleNotificationsIssues()) {
                deleteIntent.setAction(Constants.ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER);
            } else {
                deleteIntent.setAction(Constants.ACTION_COMPLETE_HIDE);
            }

            Notification.Builder b =
                    new Notification.Builder(mContext, OPP_NOTIFICATION_CHANNEL).setOnlyAlertOnce(
                            true)
@@ -531,8 +546,13 @@ class BluetoothOppNotification {
                pi = PendingIntent.getBroadcast(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            }

            Intent deleteIntent = new Intent(Constants.ACTION_COMPLETE_HIDE).setClassName(
                    mContext, BluetoothOppReceiver.class.getName());
            Intent deleteIntent = new Intent(mContext, BluetoothOppReceiver.class);
            if (Flags.oppFixMultipleNotificationsIssues()) {
                deleteIntent.setAction(Constants.ACTION_HIDE_COMPLETED_INBOUND_TRANSFER);
            } else {
                deleteIntent.setAction(Constants.ACTION_COMPLETE_HIDE);
            }

            Notification.Builder b =
                    new Notification.Builder(mContext, OPP_NOTIFICATION_CHANNEL).setOnlyAlertOnce(
                            true)
+30 −1
Original line number Diff line number Diff line
@@ -199,7 +199,8 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                }
                cursor.close();
            }
        } else if (action.equals(Constants.ACTION_COMPLETE_HIDE)) {
        } else if (action.equals(Constants.ACTION_COMPLETE_HIDE)
                && !Flags.oppFixMultipleNotificationsIssues()) {
            if (V) {
                Log.v(TAG, "Receiver ACTION_COMPLETE_HIDE");
            }
@@ -208,6 +209,34 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
            BluetoothMethodProxy.getInstance().contentResolverUpdate(
                    context.getContentResolver(), BluetoothShare.CONTENT_URI, updateValues,
                    BluetoothOppNotification.WHERE_COMPLETED, null);
        } else if (action.equals(Constants.ACTION_HIDE_COMPLETED_INBOUND_TRANSFER)
                && Flags.oppFixMultipleNotificationsIssues()) {
            if (V) {
                Log.v(TAG, "Received ACTION_HIDE_COMPLETED_INBOUND_TRANSFER");
            }
            ContentValues updateValues = new ContentValues();
            updateValues.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
            BluetoothMethodProxy.getInstance()
                    .contentResolverUpdate(
                            context.getContentResolver(),
                            BluetoothShare.CONTENT_URI,
                            updateValues,
                            BluetoothOppNotification.WHERE_COMPLETED_INBOUND,
                            null);
        } else if (action.equals(Constants.ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER)
                && Flags.oppFixMultipleNotificationsIssues()) {
            if (V) {
                Log.v(TAG, "Received ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER");
            }
            ContentValues updateValues = new ContentValues();
            updateValues.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
            BluetoothMethodProxy.getInstance()
                    .contentResolverUpdate(
                            context.getContentResolver(),
                            BluetoothShare.CONTENT_URI,
                            updateValues,
                            BluetoothOppNotification.WHERE_COMPLETED_OUTBOUND,
                            null);
        } else if (action.equals(BluetoothShare.TRANSFER_COMPLETED_ACTION)) {
            if (V) {
                Log.v(TAG, "Receiver Transfer Complete Intent for " + intent.getData());
+12 −2
Original line number Diff line number Diff line
@@ -142,11 +142,21 @@ public class Constants {
    static final String ACTION_DECLINE = "android.btopp.intent.action.DECLINE";

    /**
     * the intent that gets sent when deleting the notifications of outbound and
     * inbound completed transfer
     * The intent that gets sent when deleting the notifications of outbound and inbound completed
     * transfer.
     */
    // TODO(b/323096132): Remove this variable when the flag
    //                    opp_fix_multiple_notifications_issues is ramped up.
    static final String ACTION_COMPLETE_HIDE = "android.btopp.intent.action.HIDE_COMPLETE";

    /** The intent that gets sent when deleting the notifications of completed inbound transfer. */
    static final String ACTION_HIDE_COMPLETED_INBOUND_TRANSFER =
            "android.btopp.intent.action.HIDE_COMPLETED_INBOUND_TRANSFER";

    /** The intent that gets sent when deleting the notifications of completed outbound transfer. */
    static final String ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER =
            "android.btopp.intent.action.HIDE_COMPLETED_OUTBOUND_TRANSFER";

    /** the intent that gets sent when clicking a incoming file confirm notification */
    static final String ACTION_INCOMING_FILE_CONFIRM = "android.btopp.intent.action.CONFIRM";

+48 −8
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.Intents;
@@ -56,9 +59,9 @@ import com.android.bluetooth.flags.Flags;
import com.google.common.base.Objects;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -69,6 +72,10 @@ import java.util.List;

@RunWith(AndroidJUnit4.class)
public class BluetoothOppReceiverTest {

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    Context mContext;

    @Mock
@@ -124,8 +131,6 @@ public class BluetoothOppReceiverTest {
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION)
    public void onReceive_withActionIncomingFileConfirm_startsIncomingFileConfirmActivity() {
        Assume.assumeFalse(Flags.oppStartActivityDirectlyFromNotification());

        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_INCOMING_FILE_CONFIRM);
        intent.setData(Uri.parse("content:///not/important"));
@@ -160,8 +165,6 @@ public class BluetoothOppReceiverTest {
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION)
    public void onReceive_withActionOutboundTransfer_startsTransferHistoryActivity() {
        Assume.assumeFalse(Flags.oppStartActivityDirectlyFromNotification());

        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
        intent.setData(Uri.parse("content:///not/important"));
@@ -176,8 +179,6 @@ public class BluetoothOppReceiverTest {
    @Test
    @RequiresFlagsDisabled(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION)
    public void onReceive_withActionInboundTransfer_startsTransferHistoryActivity() {
        Assume.assumeFalse(Flags.oppStartActivityDirectlyFromNotification());

        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER);
        intent.setData(Uri.parse("content:///not/important"));
@@ -215,7 +216,8 @@ public class BluetoothOppReceiverTest {
    }

    @Test
    public void onReceive_withActionCompleteHide_contentUpdate() {
    @RequiresFlagsDisabled(Flags.FLAG_OPP_FIX_MULTIPLE_NOTIFICATIONS_ISSUES)
    public void onReceive_withActionCompleteHide_makeAllVisibilityHidden() {
        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_COMPLETE_HIDE);
        mReceiver.onReceive(mContext, intent);
@@ -224,6 +226,44 @@ public class BluetoothOppReceiverTest {
                        arg.get(BluetoothShare.VISIBILITY))), any(), any());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_OPP_FIX_MULTIPLE_NOTIFICATIONS_ISSUES)
    public void onReceive_withActionHideCompletedInboundTransfer_makesInboundVisibilityHidden() {
        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_HIDE_COMPLETED_INBOUND_TRANSFER);
        mReceiver.onReceive(mContext, intent);
        verify(mBluetoothMethodProxy)
                .contentResolverUpdate(
                        any(),
                        eq(BluetoothShare.CONTENT_URI),
                        argThat(
                                arg ->
                                        Objects.equal(
                                                BluetoothShare.VISIBILITY_HIDDEN,
                                                arg.get(BluetoothShare.VISIBILITY))),
                        eq(BluetoothOppNotification.WHERE_COMPLETED_INBOUND),
                        any());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_OPP_FIX_MULTIPLE_NOTIFICATIONS_ISSUES)
    public void onReceive_withActionHideCompletedOutboundTransfer_makesOutboundVisibilityHidden() {
        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER);
        mReceiver.onReceive(mContext, intent);
        verify(mBluetoothMethodProxy)
                .contentResolverUpdate(
                        any(),
                        eq(BluetoothShare.CONTENT_URI),
                        argThat(
                                arg ->
                                        Objects.equal(
                                                BluetoothShare.VISIBILITY_HIDDEN,
                                                arg.get(BluetoothShare.VISIBILITY))),
                        eq(BluetoothOppNotification.WHERE_COMPLETED_OUTBOUND),
                        any());
    }

    @Test
    public void onReceive_withActionTransferCompletedAndHandoverInitiated_contextSendBroadcast() {
        List<BluetoothOppTestUtils.CursorMockData> cursorMockDataList;