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

Commit 42456ab7 authored by Hemant Gupta's avatar Hemant Gupta Committed by android-build-merger
Browse files

Merge "OPP: Clear all BT Notification while switching off BT" am: be668bf2 am: 9d1381cd

am: 44b7862d

Change-Id: I9f54028e29ad5644daa514845bdf307fca51875e
parents 84ca92e2 44b7862d
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