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

Commit f2262376 authored by Juffin Alex Varghese's avatar Juffin Alex Varghese
Browse files

Bluetooth-OPP: Handle SQLException while OPP operation

Handle SQLException during updateActiveNotification of OPP
operation.

CRs-Fixed: 568920
Change-Id: I95116a21f0177fdbf3eb0c6c7beb90cd6c264724
parent 0afc3378
Loading
Loading
Loading
Loading
+33 −4
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.util.Log;
import android.os.Handler;
@@ -161,6 +162,7 @@ class BluetoothOppNotification {
            mUpdateCompleteNotification = true;
            updateCompletedNotification();
            updateIncomingFileConfirmNotification();
            mHandler.removeMessages(NOTIFY);
        }
    }

@@ -220,8 +222,16 @@ class BluetoothOppNotification {

    private void updateActiveNotification() {
        // Active transfers
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
        Cursor cursor;

        try {
            cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_RUNNING, null, BluetoothShare._ID);
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor == null) {
            return;
        }
@@ -378,8 +388,15 @@ class BluetoothOppNotification {
        }

        // Creating outbound notification
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
        Cursor cursor;
        try {
            cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_COMPLETED_OUTBOUND, null, BluetoothShare.TIMESTAMP + " DESC");
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor == null) {
            return;
        }
@@ -428,8 +445,14 @@ class BluetoothOppNotification {
        }

        // Creating inbound notification
        try {
            cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_COMPLETED_INBOUND, null, BluetoothShare.TIMESTAMP + " DESC");
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor == null) {
            return;
        }
@@ -476,8 +499,14 @@ class BluetoothOppNotification {
    }

    private void updateIncomingFileConfirmNotification() {
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
        Cursor cursor;
        try {
            cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_CONFIRM_PENDING, null, BluetoothShare._ID);
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor == null) {
            return;
+10 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Environment;
import android.os.StatFs;
@@ -95,9 +96,16 @@ public class BluetoothOppReceiveFileInfo {
        Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
        String filename = null, hint = null, mimeType = null;
        long length = 0;
        Cursor metadataCursor = contentResolver.query(contentUri, new String[] {
        Cursor metadataCursor;
        try {
            metadataCursor = contentResolver.query(contentUri, new String[] {
                BluetoothShare.FILENAME_HINT, BluetoothShare.TOTAL_BYTES, BluetoothShare.MIMETYPE
                }, null, null, null);
        } catch (SQLiteException e) {
            metadataCursor = null;
            Log.e(Constants.TAG, "SQLite exception: " + e);
        }

        if (metadataCursor != null) {
            try {
                if (metadataCursor.moveToFirst()) {
+9 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
@@ -199,8 +200,15 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
            context.startActivity(in);
        } else if (action.equals(Constants.ACTION_HIDE)) {
            if (V) Log.v(TAG, "Receiver hide for " + intent.getData());
            Cursor cursor = context.getContentResolver().query(intent.getData(), null, null, null,
            Cursor cursor;
            try {
                cursor = context.getContentResolver().query(intent.getData(), null, null, null,
                    null);
            } catch (SQLiteException e) {
                cursor = null;
                Log.e(TAG, "SQLite exception: " + e);
            }

            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    int statusColumn = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
+26 −7
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.IntentFilter;
import android.database.CharArrayBuffer;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
@@ -436,8 +437,14 @@ public class BluetoothOppService extends Service {
                    }
                    mPendingUpdate = false;
                }
                Cursor cursor = getContentResolver().query(BluetoothShare.CONTENT_URI, null, null,
                Cursor cursor;
                try {
                    cursor = getContentResolver().query(BluetoothShare.CONTENT_URI, null, null,
                        null, BluetoothShare._ID);
                } catch (SQLiteException e) {
                    cursor = null;
                    Log.e(TAG, "SQLite exception: " + e);
                }

                if (cursor == null) {
                    return;
@@ -935,9 +942,15 @@ public class BluetoothOppService extends Service {
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.STATUS + "="
                + BluetoothShare.STATUS_RUNNING;

        Cursor cursorToFile = contentResolver.query(BluetoothShare.CONTENT_URI,
        Cursor cursorToFile;
        try {
            cursorToFile = contentResolver.query(BluetoothShare.CONTENT_URI,
                new String[] { BluetoothShare._DATA },
                WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF, null, null);
        } catch (SQLiteException e) {
                cursorToFile = null;
                Log.e(TAG, "SQLite exception: " + e);
        }

        // remove the share and the respective file which was interrupted by battery
        // removal in the local device
@@ -967,9 +980,15 @@ public class BluetoothOppService extends Service {
        final String WHERE_INBOUND_SUCCESS = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.STATUS + "="
                + BluetoothShare.STATUS_SUCCESS + " AND " + INVISIBLE;
        Cursor cursor = contentResolver.query(BluetoothShare.CONTENT_URI, new String[] {
        Cursor cursor;
        try {
            cursor = contentResolver.query(BluetoothShare.CONTENT_URI, new String[] {
                BluetoothShare._ID
                }, WHERE_INBOUND_SUCCESS, null, BluetoothShare._ID); // sort by id
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor == null) {
            return;
+16 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.util.Log;

import java.io.File;
@@ -68,7 +69,14 @@ public class BluetoothOppUtility {
    public static BluetoothOppTransferInfo queryRecord(Context context, Uri uri) {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothOppTransferInfo info = new BluetoothOppTransferInfo();
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        Cursor cursor;
        try {
            cursor = context.getContentResolver().query(uri, null, null, null, null);
        } catch (SQLiteException e) {
            cursor = null;
            Log.e(TAG, "SQLite exception: " + e);
        }

        if (cursor != null) {
            if (cursor.moveToFirst()) {
                info.mID = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare._ID));
@@ -136,10 +144,16 @@ public class BluetoothOppUtility {
        ArrayList<String> uris = Lists.newArrayList();
        final String WHERE = BluetoothShare.TIMESTAMP + " == " + timeStamp;

        Cursor metadataCursor = context.getContentResolver().query(BluetoothShare.CONTENT_URI,
        Cursor metadataCursor;
        try {
            metadataCursor = context.getContentResolver().query(BluetoothShare.CONTENT_URI,
                new String[] {
                    BluetoothShare._DATA
                }, WHERE, null, BluetoothShare._ID);
        } catch (SQLiteException e) {
           metadataCursor = null;
           Log.e(TAG, "SQLite exception: " + e);
        }

        if (metadataCursor == null) {
            return null;