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

Commit dbc02c2e authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android (Google) Code Review
Browse files

Merge "Update notification in Transfer history manually when BT if off"

parents aded9a3c cfac4a02
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -99,10 +99,6 @@ class BluetoothOppNotification {

    private int mActiveNotificationId = 0;

    private Notification mOutNoti = null;

    private Notification mInNoti = null;

    /**
     * This inner class is used to describe some properties for one transfer.
     */
@@ -348,21 +344,20 @@ class BluetoothOppNotification {
        outboundNum = outboundSuccNumber + outboundFailNumber;
        // create the outbound notification
        if (outboundNum > 0) {
            mOutNoti = new Notification();
            mOutNoti.icon = android.R.drawable.stat_sys_upload_done;
            Notification outNoti = new Notification();
            outNoti.icon = android.R.drawable.stat_sys_upload_done;
            title = mContext.getString(R.string.outbound_noti_title);
            caption = mContext.getString(R.string.noti_caption, outboundSuccNumber,
                    outboundFailNumber);
            intent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
            mOutNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
            outNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                    mContext, 0, intent, 0));
            mOutNoti.when = timeStamp;
            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, mOutNoti);
            outNoti.when = timeStamp;
            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, outNoti);
        } else {
            if (mNotificationMgr != null && mOutNoti != null) {
            if (mNotificationMgr != null) {
                mNotificationMgr.cancel(NOTIFICATION_ID_OUTBOUND);
                mOutNoti = null;
                if (V) Log.v(TAG, "outbound notification was removed.");
            }
        }
@@ -393,21 +388,20 @@ class BluetoothOppNotification {
        inboundNum = inboundSuccNumber + inboundFailNumber;
        // create the inbound notification
        if (inboundNum > 0) {
            mInNoti = new Notification();
            mInNoti.icon = android.R.drawable.stat_sys_download_done;
            Notification inNoti = new Notification();
            inNoti.icon = android.R.drawable.stat_sys_download_done;
            title = mContext.getString(R.string.inbound_noti_title);
            caption = mContext.getString(R.string.noti_caption, inboundSuccNumber,
                    inboundFailNumber);
            intent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER);
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
            mInNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
            inNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                    mContext, 0, intent, 0));
            mInNoti.when = timeStamp;
            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, mInNoti);
            inNoti.when = timeStamp;
            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, inNoti);
        } else {
            if (mNotificationMgr != null && mInNoti != null) {
            if (mNotificationMgr != null) {
                mNotificationMgr.cancel(NOTIFICATION_ID_INBOUND);
                mInNoti = null;
                if (V) Log.v(TAG, "inbound notification was removed.");
            }
        }
+23 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.bluetooth.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
@@ -75,6 +76,9 @@ public class BluetoothOppTransferHistory extends Activity implements

    private int mContextMenuPosition;

    /** Class to handle Notification Manager updates */
    private BluetoothOppNotification mNotifier;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
@@ -117,6 +121,8 @@ public class BluetoothOppTransferHistory extends Activity implements
            mListView.setOnCreateContextMenuListener(this);
            mListView.setOnItemClickListener(this);
        }

        mNotifier = new BluetoothOppNotification(this);
    }

    @Override
@@ -151,12 +157,14 @@ public class BluetoothOppTransferHistory extends Activity implements
        switch (item.getItemId()) {
            case R.id.transfer_menu_open:
                openCompleteTransfer();
                updateNotificationWhenBtDisabled();
                return true;

            case R.id.transfer_menu_clear:
                int sessionId = mTransferCursor.getInt(mIdColumnId);
                Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + sessionId);
                BluetoothOppUtility.updateVisibilityToHidden(this, contentUri);
                updateNotificationWhenBtDisabled();
                return true;
        }
        return false;
@@ -224,6 +232,7 @@ public class BluetoothOppTransferHistory extends Activity implements

                mTransferCursor.moveToNext();
            }
            updateNotificationWhenBtDisabled();
        }
    }

@@ -237,6 +246,7 @@ public class BluetoothOppTransferHistory extends Activity implements
        // Open the selected item
        mTransferCursor.moveToPosition(position);
        openCompleteTransfer();
        updateNotificationWhenBtDisabled();
    }

    /**
@@ -265,4 +275,17 @@ public class BluetoothOppTransferHistory extends Activity implements
            this.startActivity(in);
        }
    }

    /**
     * When Bluetooth is disabled, notification can not be updated by
     * ContentObserver in OppService, so need update manually.
     */
    private void updateNotificationWhenBtDisabled() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (!adapter.isEnabled()) {
            if (V) Log.v(TAG, "Bluetooth is not enabled, update notification manually.");
            mNotifier.updateNotification();
            mNotifier.finishNotification();
        }
    }
}