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

Commit 9c9f000a authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Open activity directly from notification (outbound transfer)

When user clicks the OPP notification for outbound 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.

Bug: 319050411
Bug: 318610752
Test: m -j;
Test: manual, after sending a file via Bluetooth, click the notification
      titled "Bluetooth Share: Sent files". There should be no lag
      when opening the activity "Outbound Transfers".
Change-Id: I3be36ba6236c95a6c6d97f3bd123254ce27ba15b
parent af686c85
Loading
Loading
Loading
Loading
+26 −31
Original line number Diff line number Diff line
/*
 * Copyright (c) 2008-2009, Motorola, Inc.
 * Copyright (C) 2024 The Android Open Source Project
 *
 * All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * - Neither the name of the Motorola, Inc. nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.opp;
@@ -51,6 +35,7 @@ import android.util.Log;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.flags.Flags;

import com.google.common.annotations.VisibleForTesting;

@@ -445,8 +430,20 @@ class BluetoothOppNotification {
        if (outboundNum > 0) {
            String caption = BluetoothOppUtility.formatResultText(outboundSuccNumber,
                    outboundFailNumber, mContext);
            Intent contentIntent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER).setClassName(
                    mContext, BluetoothOppReceiver.class.getName());

            PendingIntent pi;
            if (Flags.oppStartActivityDirectlyFromNotification()) {
                Intent in = new Intent(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 =
                        new Intent(Constants.ACTION_OPEN_OUTBOUND_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 outNoti =
@@ -460,9 +457,7 @@ class BluetoothOppNotification {
                                            android.R.color
                                                    .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))
+2 −0
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ 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 (V) {
                Log.v(TAG, "Received ACTION_OPEN_OUTBOUND_TRANSFER.");
            }