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

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

Merge changes I3472a117,I95bc1c0a into main

* changes:
  Open activity directly from notification (incoming file confirm)
  Open activity directly from notification (inbound transfer)
parents 5cae59c5 a091a32a
Loading
Loading
Loading
Loading
+39 −16
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))
@@ -572,15 +582,31 @@ class BluetoothOppNotification {
                    PendingIntent.getBroadcast(mContext, 0,
                            new Intent(baseIntent).setAction(Constants.ACTION_ACCEPT),
                            PendingIntent.FLAG_IMMUTABLE)).build();

            PendingIntent contentIntent;
            if (Flags.oppStartActivityDirectlyFromNotification()) {
                Intent intent = new Intent(mContext, BluetoothOppIncomingFileConfirmActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setDataAndNormalize(contentUri);
                contentIntent =
                        PendingIntent.getActivity(
                                mContext, 0, intent, PendingIntent.FLAG_IMMUTABLE);
            } else {
                contentIntent =
                        PendingIntent.getBroadcast(
                                mContext,
                                0,
                                new Intent(baseIntent)
                                        .setAction(Constants.ACTION_INCOMING_FILE_CONFIRM),
                                PendingIntent.FLAG_IMMUTABLE);
            }

            Notification public_n =
                    new Notification.Builder(mContext, OPP_NOTIFICATION_CHANNEL).setOnlyAlertOnce(
                            true)
                            .setOngoing(true)
                            .setWhen(info.mTimeStamp)
                            .setContentIntent(PendingIntent.getBroadcast(mContext, 0,
                                    new Intent(baseIntent).setAction(
                                            Constants.ACTION_INCOMING_FILE_CONFIRM),
                                    PendingIntent.FLAG_IMMUTABLE))
                            .setContentIntent(contentIntent)
                            .setDeleteIntent(PendingIntent.getBroadcast(mContext, 0,
                                    new Intent(baseIntent).setAction(Constants.ACTION_HIDE),
                                    PendingIntent.FLAG_IMMUTABLE))
@@ -604,10 +630,7 @@ class BluetoothOppNotification {
                            true)
                            .setOngoing(true)
                            .setWhen(info.mTimeStamp)
                            .setContentIntent(PendingIntent.getBroadcast(mContext, 0,
                                    new Intent(baseIntent).setAction(
                                            Constants.ACTION_INCOMING_FILE_CONFIRM),
                                    PendingIntent.FLAG_IMMUTABLE))
                            .setContentIntent(contentIntent)
                            .setDeleteIntent(PendingIntent.getBroadcast(mContext, 0,
                                    new Intent(baseIntent).setAction(Constants.ACTION_HIDE),
                                    PendingIntent.FLAG_IMMUTABLE))
+29 −25
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.flags.Flags;

/**
 * Receives and handles: system broadcasts; Intents from other applications; Intents from
@@ -83,6 +84,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
            }
            Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
        } else if (action.equals(Constants.ACTION_INCOMING_FILE_CONFIRM)) {
            if (!Flags.oppStartActivityDirectlyFromNotification()) {
                if (V) {
                    Log.v(TAG, "Receiver ACTION_INCOMING_FILE_CONFIRM");
                }
@@ -92,7 +94,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                in.setDataAndNormalize(uri);
                context.startActivity(in);

            }
        } else if (action.equals(Constants.ACTION_DECLINE)) {
            if (V) {
                Log.v(TAG, "Receiver ACTION_DECLINE");
@@ -152,8 +154,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.");
                }
@@ -162,7 +163,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.");
                }
@@ -171,6 +174,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
@@ -42,6 +42,7 @@ import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.R;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.flags.Flags;

/**
 * View showing the user's finished bluetooth opp transfers that the user does not confirm.
@@ -79,8 +80,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,10 +51,12 @@ 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;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -119,7 +122,10 @@ 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"));
@@ -152,7 +158,10 @@ 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"));
@@ -165,7 +174,10 @@ 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"));
+11 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.flags.Flags;

import com.google.common.base.Objects;

@@ -142,7 +143,11 @@ public class BluetoothOppTransferHistoryTest {
                mTargetContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH));

        BluetoothOppTestUtils.setUpMockCursor(mCursor, mCursorMockDataList);
        if (Flags.oppStartActivityDirectlyFromNotification()) {
            mIntent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER);
        } else {
            mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND);
        }

        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
@@ -160,7 +165,11 @@ public class BluetoothOppTransferHistoryTest {
        mCursorMockDataList.set(1,
                new BluetoothOppTestUtils.CursorMockData(BluetoothShare.DIRECTION, 2,
                        BluetoothShare.DIRECTION_OUTBOUND));
        if (Flags.oppStartActivityDirectlyFromNotification()) {
            mIntent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
        } else {
            mIntent.putExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
        }

        ActivityScenario<BluetoothOppTransferHistory> scenario = ActivityScenario.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();