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

Commit c1d088d7 authored by Hemant Gupta's avatar Hemant Gupta Committed by Myles Watson
Browse files

OPP: Clear all BT Notification while switching off BT

Use Case:
1.From a remote, send a file to DUT.
2.The incoming file request is present in notifications menu.
3.Now turn off the BT on the receiver side.

Failure:
Incoming file request is still present even after turning off BT.

Fix:
All BT related notification will be cleared from notification bar while BT is
being turned OFF. Otherwise, incoming file notification will be displayed on
notification bar even though BT is OFF.

Test: Incoming file notifications are removed after BT is turned off.

Bug: 35985175
Change-Id: I03eb47dbba99d3862e79237e085051c641d487e0
parent d67fe5f6
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -593,4 +593,12 @@ class BluetoothOppNotification {
        }
        cursor.close();
    }

    void cancelNotifications() {
        if (V) {
            Log.v(TAG, "cancelNotifications ");
        }
        mHandler.removeCallbacksAndMessages(null);
        mNotificationMgr.cancelAll();
    }
}
+38 −34
Original line number Diff line number Diff line
@@ -144,6 +144,22 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti

    private int mOppSdpHandle = -1;

    private static final String INVISIBLE =
            BluetoothShare.VISIBILITY + "=" + BluetoothShare.VISIBILITY_HIDDEN;

    private static final String WHERE_INBOUND_SUCCESS =
            BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_INBOUND + " AND "
                    + BluetoothShare.STATUS + "=" + BluetoothShare.STATUS_SUCCESS + " AND "
                    + INVISIBLE;

    private static final String WHERE_CONFIRM_PENDING_INBOUND = BluetoothShare.DIRECTION + "="
            + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.USER_CONFIRMATION + "="
            + BluetoothShare.USER_CONFIRMATION_PENDING;

    private static final String WHERE_INVISIBLE_UNCONFIRMED = "(" + BluetoothShare.STATUS + ">="
            + BluetoothShare.STATUS_SUCCESS + " AND " + INVISIBLE + ") OR ("
            + WHERE_CONFIRM_PENDING_INBOUND + ")";

    /*
     * TODO No support for queue incoming from multiple devices.
     * Make an array list of server session to support receiving queue from
@@ -163,13 +179,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        }
        mShares = Lists.newArrayList();
        mBatchs = Lists.newArrayList();
        mObserver = new BluetoothShareContentObserver();
        getContentResolver().registerContentObserver(BluetoothShare.CONTENT_URI, true, mObserver);
        mBatchId = 1;
        mNotifier = new BluetoothOppNotification(this);
        mNotifier.mNotificationMgr.cancelAll();
        mNotifier.updateNotification();

        final ContentResolver contentResolver = getContentResolver();
        new Thread("trimDatabase") {
            @Override
@@ -189,7 +199,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        if (V) {
            BluetoothOppPreference.getInstance(this).dump();
        }
        updateFromProvider();
    }

    @Override
@@ -197,6 +206,11 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        if (V) {
            Log.v(TAG, "start()");
        }
        mObserver = new BluetoothShareContentObserver();
        getContentResolver().registerContentObserver(BluetoothShare.CONTENT_URI, true, mObserver);
        mNotifier = new BluetoothOppNotification(this);
        mNotifier.mNotificationMgr.cancelAll();
        mNotifier.updateNotification();
        updateFromProvider();
        return true;
    }
@@ -248,6 +262,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                        mTransfer.onBatchCanceled();
                        mTransfer = null;
                    }
                    unregisterReceivers();
                    synchronized (BluetoothOppService.this) {
                        if (mUpdateThread != null) {
                            try {
@@ -259,6 +274,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                            mUpdateThread = null;
                        }
                    }
                    mNotifier.cancelNotifications();
                    break;
                case START_LISTENER:
                    if (mAdapter.isEnabled()) {
@@ -387,8 +403,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        if (V) {
            Log.v(TAG, "onDestroy");
        }
        getContentResolver().unregisterContentObserver(mObserver);
        unregisterReceiver(mBluetoothReceiver);
        stopListeners();
        if (mBatchs != null) {
            mBatchs.clear();
@@ -402,6 +416,18 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        return true;
    }

    private void unregisterReceivers() {
        try {
            if (mObserver != null) {
                getContentResolver().unregisterContentObserver(mObserver);
                mObserver = null;
            }
            unregisterReceiver(mBluetoothReceiver);
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "unregisterReceivers " + e.toString());
        }
    }

    /* suppose we auto accept an incoming OPUSH connection */
    private void createServerSession(ObexTransport transport) {
        mServerSession = new BluetoothOppObexServerSession(this, transport, mServerSocket);
@@ -1031,35 +1057,13 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                && info.mConfirm != BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;
    }

    private static final String INVISIBLE =
            BluetoothShare.VISIBILITY + "=" + BluetoothShare.VISIBILITY_HIDDEN;
    private static final String WHERE_INVISIBLE_COMPLETE_OUTBOUND =
            BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_OUTBOUND + " AND "
                    + BluetoothShare.STATUS + ">=" + BluetoothShare.STATUS_SUCCESS + " AND "
                    + INVISIBLE;
    private static final String WHERE_INVISIBLE_COMPLETE_INBOUND_FAILED =
            BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_INBOUND + " AND "
                    + BluetoothShare.STATUS + ">" + BluetoothShare.STATUS_SUCCESS + " AND "
                    + INVISIBLE;
    private static final String WHERE_INBOUND_SUCCESS =
            BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_INBOUND + " AND "
                    + BluetoothShare.STATUS + "=" + BluetoothShare.STATUS_SUCCESS + " AND "
                    + INVISIBLE;

    // Run in a background thread at boot.
    private static void trimDatabase(ContentResolver contentResolver) {
        // remove the invisible/complete/outbound shares
        // remove the invisible/unconfirmed inbound shares
        int delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                WHERE_INVISIBLE_COMPLETE_OUTBOUND, null);
        if (V) {
            Log.v(TAG, "Deleted complete outbound shares, number =  " + delNum);
        }

        // remove the invisible/finished/inbound/failed shares
        delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                WHERE_INVISIBLE_COMPLETE_INBOUND_FAILED, null);
                WHERE_INVISIBLE_UNCONFIRMED, null);
        if (V) {
            Log.v(TAG, "Deleted complete inbound failed shares, number = " + delNum);
            Log.v(TAG, "Deleted shares, number = " + delNum);
        }

        // Only keep the inbound and successful shares for LiverFolder use