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

Commit 1e84e28b authored by Juffin Alex Varghese's avatar Juffin Alex Varghese Committed by Arne Coucheron
Browse files

Bluetooth-OPP: Update interrupted outbound/inbound shares status after BT turned ON

Updated interrupted outbound or inbound unconfirmed shares status to
UNKNOWN_ERROR if outbound transfer is interrupted by hardware error,
BT turned off etc.

CRs-Fixed: 768298
Change-Id: I0b12add43812fab86cb83e3b2b8e63683f8603c5
parent dda47fc2
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -161,7 +161,6 @@ public class BluetoothOppService extends Service {
        mBatchId = 1;
        mNotifier = new BluetoothOppNotification(this);
        mNotifier.mNotificationMgr.cancelAll();
        mNotifier.updateNotification();

        final ContentResolver contentResolver = getContentResolver();
        new Thread("trimDatabase") {
@@ -1069,18 +1068,54 @@ public class BluetoothOppService extends Service {
                WHERE_INVISIBLE_COMPLETE_INBOUND_FAILED, null);
        if (V) Log.v(TAG, "Deleted complete inbound failed shares, number = " + delNum);

        // remove outbound share interrupted by battery removal
        ContentValues updateValues;
        // Update interrupted outbound share status
        final String WHERE_OUTBOUND_INTERRUPTED_ON_POWER_OFF = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_OUTBOUND + " AND " + BluetoothShare.STATUS + "="
                + BluetoothShare.STATUS_PENDING + " OR " + BluetoothShare.STATUS + "="
                + BluetoothShare.STATUS_RUNNING;

        try {
            delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                    WHERE_OUTBOUND_INTERRUPTED_ON_POWER_OFF, null);
            if (V) Log.v(TAG, "Delete interrupted outbound share, number = " + delNum);
        } catch (SQLiteException e) {
                Log.e(TAG, "trimDatabase: could not deleted interrupted outbound failed shares: " + e);
        Cursor cursorToUpdate = contentResolver.query(BluetoothShare.CONTENT_URI, null,
                    WHERE_OUTBOUND_INTERRUPTED_ON_POWER_OFF, null, null);
        if (cursorToUpdate != null) {
            for (cursorToUpdate.moveToFirst(); !cursorToUpdate.isAfterLast();
                    cursorToUpdate.moveToNext()) {
                updateValues = new ContentValues();
                updateValues.put(BluetoothShare.STATUS, BluetoothShare.STATUS_UNKNOWN_ERROR);
                int mId = cursorToUpdate.getInt(cursorToUpdate.getColumnIndexOrThrow(
                                    BluetoothShare._ID));
                Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mId);
                contentResolver.update(contentUri, updateValues, null, null);
            }
            if (V) Log.v(TAG, "Update interrupted outbound share status, number = "
                        + cursorToUpdate.getCount());
            cursorToUpdate.close();
            cursorToUpdate = null;
        }

        // Update unconfirmed interrupted inbound shares status
        final String WHERE_CONFIRMATION_PENDING_INBOUND = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.USER_CONFIRMATION
                + "=" + BluetoothShare.USER_CONFIRMATION_PENDING;

        cursorToUpdate = contentResolver.query(BluetoothShare.CONTENT_URI, null,
                    WHERE_CONFIRMATION_PENDING_INBOUND, null, null);

        if (cursorToUpdate != null) {
            if (cursorToUpdate.moveToFirst()) {
                updateValues = new ContentValues();
                updateValues.put(BluetoothShare.USER_CONFIRMATION,
                        BluetoothShare.USER_CONFIRMATION_DENIED);
                updateValues.put(BluetoothShare.STATUS, BluetoothShare.STATUS_UNKNOWN_ERROR);
                int mId = cursorToUpdate.getInt(cursorToUpdate.getColumnIndexOrThrow(
                                    BluetoothShare._ID));
                Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mId);
                contentResolver.update(contentUri, updateValues, null, null);
            }
            if (V) Log.v(TAG, "Update interrupted inbound share status, number = "
                        + cursorToUpdate.getCount());
            cursorToUpdate.close();
            cursorToUpdate = null;
        }

        final String WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF = BluetoothShare.DIRECTION + "="
@@ -1107,14 +1142,6 @@ public class BluetoothOppService extends Service {
            cursorToFile = null;
        }

        // on boot : remove unconfirmed inbound shares.
        final String WHERE_CONFIRMATION_PENDING_INBOUND = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.USER_CONFIRMATION
                + "=" + BluetoothShare.USER_CONFIRMATION_PENDING;
        delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                 WHERE_CONFIRMATION_PENDING_INBOUND, null);
        if (V) Log.v(TAG, "Deleted unconfirmed incoming shares, number = " + delNum);

        // Only keep the inbound and successful shares for LiverFolder use
        // Keep the latest 1000 to easy db query
        final String WHERE_INBOUND_SUCCESS = BluetoothShare.DIRECTION + "="