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

Commit e9c1990b authored by Omair Kamil's avatar Omair Kamil Committed by Gerrit Code Review
Browse files

Merge "Remove flag opp_start_activity_directly_from_notification" into main

parents df61d096 5bac675c
Loading
Loading
Loading
Loading
+17 −43
Original line number Diff line number Diff line
@@ -500,18 +500,11 @@ class BluetoothOppNotification {
                    BluetoothOppUtility.formatResultText(
                            outboundSuccNumber, outboundFailNumber, mContext);

            PendingIntent pi;
            if (Flags.oppStartActivityDirectlyFromNotification()) {
            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);
                pi = PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            } else {
                Intent in =
                        new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER)
                                .setClassName(mContext, BluetoothOppReceiver.class.getName());
                pi = PendingIntent.getBroadcast(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);
            }
            PendingIntent pi =
                    PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);

            Intent deleteIntent = new Intent(mContext, BluetoothOppReceiver.class);
            deleteIntent.setAction(Constants.ACTION_HIDE_COMPLETED_OUTBOUND_TRANSFER);
@@ -583,18 +576,11 @@ class BluetoothOppNotification {
                    BluetoothOppUtility.formatResultText(
                            inboundSuccNumber, inboundFailNumber, mContext);

            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);
            }
            PendingIntent pi =
                    PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);

            Intent deleteIntent = new Intent(mContext, BluetoothOppReceiver.class);
            deleteIntent.setAction(Constants.ACTION_HIDE_COMPLETED_INBOUND_TRANSFER);
@@ -696,30 +682,18 @@ class BluetoothOppNotification {
                                            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);
            }
            Intent in = new Intent(mContext, BluetoothOppIncomingFileConfirmActivity.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            in.setDataAndNormalize(contentUri);
            PendingIntent pi =
                    PendingIntent.getActivity(mContext, 0, in, PendingIntent.FLAG_IMMUTABLE);

            Notification.Builder publicNotificationBuilder =
                    new Notification.Builder(mContext, OPP_NOTIFICATION_CHANNEL)
                            .setOnlyAlertOnce(true)
                            .setOngoing(true)
                            .setWhen(info.mTimeStamp)
                            .setContentIntent(contentIntent)
                            .setContentIntent(pi)
                            .setDeleteIntent(
                                    PendingIntent.getBroadcast(
                                            mContext,
@@ -754,7 +728,7 @@ class BluetoothOppNotification {
                            .setOnlyAlertOnce(true)
                            .setOngoing(true)
                            .setWhen(info.mTimeStamp)
                            .setContentIntent(contentIntent)
                            .setContentIntent(pi)
                            .setDeleteIntent(
                                    PendingIntent.getBroadcast(
                                            mContext,
+0 −25
Original line number Diff line number Diff line
@@ -100,15 +100,6 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                toastMsg = context.getString(R.string.bt_toast_4, deviceName);
            }
            Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
        } else if (action.equals(Constants.ACTION_INCOMING_FILE_CONFIRM)
                && !Flags.oppStartActivityDirectlyFromNotification()) {
            Log.v(TAG, "Receiver ACTION_INCOMING_FILE_CONFIRM");

            Uri uri = intent.getData();
            Intent in = new Intent(context, BluetoothOppIncomingFileConfirmActivity.class);
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            in.setDataAndNormalize(uri);
            context.startActivity(in);
        } else if (action.equals(Constants.ACTION_DECLINE)) {
            Log.v(TAG, "Receiver ACTION_DECLINE");

@@ -164,22 +155,6 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                context.startActivity(in);
            }

        } else if (action.equals(Constants.ACTION_OPEN_OUTBOUND_TRANSFER)
                && !Flags.oppStartActivityDirectlyFromNotification()) {
            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);
        } else if (action.equals(Constants.ACTION_OPEN_INBOUND_TRANSFER)
                && !Flags.oppStartActivityDirectlyFromNotification()) {
            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);
        } else if (action.equals(Constants.ACTION_HIDE)) {
            Log.v(TAG, "Receiver hide for " + intent.getData());
            Cursor cursor =
+3 −11
Original line number Diff line number Diff line
@@ -113,18 +113,10 @@ public class BluetoothOppTransferHistory extends Activity
        mListView = (ListView) findViewById(R.id.list);
        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);
            isOutbound = (dir == BluetoothShare.DIRECTION_OUTBOUND);
        }
        boolean isOutbound =
                Constants.ACTION_OPEN_OUTBOUND_TRANSFER.equals(getIntent().getAction());

        String direction;
        if (isOutbound) {
            setTitle(getText(R.string.outbound_history_title));
            direction =
+0 −65
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.platform.test.flag.junit.SetFlagsRule;
import android.sysprop.BluetoothProperties;

import androidx.test.espresso.intent.Intents;
@@ -51,7 +50,6 @@ 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;

@@ -71,8 +69,6 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppReceiverTest {

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    Context mContext;

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
@@ -131,24 +127,6 @@ public class BluetoothOppReceiverTest {
        }
    }

    @Test
    public void onReceive_withActionIncomingFileConfirm_startsIncomingFileConfirmActivity() {
        mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION);
        try {
            BluetoothOppTestUtils.enableActivity(
                    BluetoothOppIncomingFileConfirmActivity.class, true, mContext);

            Intent intent = new Intent();
            intent.setAction(Constants.ACTION_INCOMING_FILE_CONFIRM);
            intent.setData(Uri.parse("content:///not/important"));
            mReceiver.onReceive(mContext, intent);
            intended(hasComponent(BluetoothOppIncomingFileConfirmActivity.class.getName()));
        } finally {
            BluetoothOppTestUtils.enableActivity(
                    BluetoothOppIncomingFileConfirmActivity.class, false, mContext);
        }
    }

    @Test
    public void onReceive_withActionAccept_updatesContents() {
        Uri uri = Uri.parse("content:///important");
@@ -189,49 +167,6 @@ public class BluetoothOppReceiverTest {
                        any());
    }

    @Test
    public void onReceive_withActionOutboundTransfer_startsTransferHistoryActivity() {
        mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION);
        try {
            BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext);

            Intent intent = new Intent();
            intent.setAction(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
            intent.setData(Uri.parse("content:///not/important"));
            intending(anyIntent())
                    .respondWith(
                            new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent()));

            mReceiver.onReceive(mContext, intent);
            intended(hasComponent(BluetoothOppTransferHistory.class.getName()));
            intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_OUTBOUND));
        } finally {
            BluetoothOppTestUtils.enableActivity(
                    BluetoothOppTransferHistory.class, false, mContext);
        }
    }

    @Test
    public void onReceive_withActionInboundTransfer_startsTransferHistoryActivity() {
        mSetFlagsRule.disableFlags(Flags.FLAG_OPP_START_ACTIVITY_DIRECTLY_FROM_NOTIFICATION);
        try {
            BluetoothOppTestUtils.enableActivity(BluetoothOppTransferHistory.class, true, mContext);

            Intent intent = new Intent();
            intent.setAction(Constants.ACTION_OPEN_INBOUND_TRANSFER);
            intent.setData(Uri.parse("content:///not/important"));
            intending(anyIntent())
                    .respondWith(
                            new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent()));
            mReceiver.onReceive(mContext, intent);
            intended(hasComponent(BluetoothOppTransferHistory.class.getName()));
            intended(hasExtra(Constants.EXTRA_DIRECTION, BluetoothShare.DIRECTION_INBOUND));
        } finally {
            BluetoothOppTestUtils.enableActivity(
                    BluetoothOppTransferHistory.class, false, mContext);
        }
    }

    @Test
    public void onReceive_withActionHide_contentUpdate() {
        List<BluetoothOppTestUtils.CursorMockData> cursorMockDataList;
+2 −11
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ 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;

@@ -155,11 +154,7 @@ 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.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
@@ -178,11 +173,7 @@ public class BluetoothOppTransferHistoryTest {
                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.launch(mIntent);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
Loading