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

Commit 946f1934 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "OPP: Only start the service from AdapterService"

parents fccf0eba 4fb4bf5c
Loading
Loading
Loading
Loading
+30 −83
Original line number Original line Diff line number Diff line
@@ -35,7 +35,6 @@ package com.android.bluetooth.opp;
import android.content.ContentProvider;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.UriMatcher;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.Cursor;
import android.database.SQLException;
import android.database.SQLException;
@@ -116,34 +115,18 @@ public final class BluetoothOppProvider extends ContentProvider {
            createTable(db);
            createTable(db);
        }
        }


        //TODO: use this function to check garbage transfer left in db, for example,
        // a crash incoming file
        /*
         * (not a javadoc comment) Checks data integrity when opening the
         * database.
         */
        /*
         * @Override public void onOpen(final SQLiteDatabase db) {
         * super.onOpen(db); }
         */

        /**
        /**
         * Updates the database format when a content provider is used with a
         * Updates the database format when a content provider is used with a
         * database that was created with a different format.
         * database that was created with a different format.
         */
         */
        // Note: technically, this could also be a downgrade, so if we want
        // to gracefully handle upgrades we should be careful about
        // what to do on downgrades.
        @Override
        @Override
        public void onUpgrade(final SQLiteDatabase db, int oldV, final int newV) {
        public void onUpgrade(final SQLiteDatabase db, int oldV, final int newV) {
            if (oldV == DB_VERSION_NOP_UPGRADE_FROM) {
            if (oldV == DB_VERSION_NOP_UPGRADE_FROM) {
                if (newV == DB_VERSION_NOP_UPGRADE_TO) { // that's a no-op
                if (newV == DB_VERSION_NOP_UPGRADE_TO) {
                    // upgrade.
                    return;
                    return;
                }
                }
                // NOP_FROM and NOP_TO are identical, just in different
                // NOP_FROM and NOP_TO are identical, just in different code lines.
                // codelines. Upgrading
                // Upgrading from NOP_FROM is the same as upgrading from NOP_TO.
                // from NOP_FROM is the same as upgrading from NOP_TO.
                oldV = DB_VERSION_NOP_UPGRADE_TO;
                oldV = DB_VERSION_NOP_UPGRADE_TO;
            }
            }
            Log.i(TAG, "Upgrading downloads database from version " + oldV + " to " + newV
            Log.i(TAG, "Upgrading downloads database from version " + oldV + " to " + newV
@@ -167,7 +150,7 @@ public final class BluetoothOppProvider extends ContentProvider {
                    + BluetoothShare.TIMESTAMP + " INTEGER," + Constants.MEDIA_SCANNED
                    + BluetoothShare.TIMESTAMP + " INTEGER," + Constants.MEDIA_SCANNED
                    + " INTEGER); ");
                    + " INTEGER); ");
        } catch (SQLException ex) {
        } catch (SQLException ex) {
            Log.e(TAG, "couldn't create table in downloads database");
            Log.e(TAG, "createTable: Failed.");
            throw ex;
            throw ex;
        }
        }
    }
    }
@@ -176,7 +159,7 @@ public final class BluetoothOppProvider extends ContentProvider {
        try {
        try {
            db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
            db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
        } catch (SQLException ex) {
        } catch (SQLException ex) {
            Log.e(TAG, "couldn't drop table in downloads database");
            Log.e(TAG, "dropTable: Failed.");
            throw ex;
            throw ex;
        }
        }
    }
    }
@@ -185,18 +168,12 @@ public final class BluetoothOppProvider extends ContentProvider {
    public String getType(Uri uri) {
    public String getType(Uri uri) {
        int match = sURIMatcher.match(uri);
        int match = sURIMatcher.match(uri);
        switch (match) {
        switch (match) {
            case SHARES: {
            case SHARES:
                return SHARE_LIST_TYPE;
                return SHARE_LIST_TYPE;
            }
            case SHARES_ID:
            case SHARES_ID: {
                return SHARE_TYPE;
                return SHARE_TYPE;
            }
            default:
            default: {
                throw new IllegalArgumentException("Unknown URI in getType(): " + uri);
                if (D) {
                    Log.d(TAG, "calling getType on an unknown URI: " + uri);
                }
                throw new IllegalArgumentException("Unknown URI: " + uri);
            }
        }
        }
    }
    }


@@ -226,10 +203,7 @@ public final class BluetoothOppProvider extends ContentProvider {
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();


        if (sURIMatcher.match(uri) != SHARES) {
        if (sURIMatcher.match(uri) != SHARES) {
            if (D) {
            throw new IllegalArgumentException("insert: Unknown/Invalid URI " + uri);
                Log.d(TAG, "calling insert on an unknown/invalid URI: " + uri);
            }
            throw new IllegalArgumentException("Unknown/Invalid URI " + uri);
        }
        }


        ContentValues filteredValues = new ContentValues();
        ContentValues filteredValues = new ContentValues();
@@ -247,7 +221,7 @@ public final class BluetoothOppProvider extends ContentProvider {
        Integer dir = values.getAsInteger(BluetoothShare.DIRECTION);
        Integer dir = values.getAsInteger(BluetoothShare.DIRECTION);
        Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION);
        Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION);


        if (values.getAsInteger(BluetoothShare.DIRECTION) == null) {
        if (dir == null) {
            dir = BluetoothShare.DIRECTION_OUTBOUND;
            dir = BluetoothShare.DIRECTION_OUTBOUND;
        }
        }
        if (dir == BluetoothShare.DIRECTION_OUTBOUND && con == null) {
        if (dir == BluetoothShare.DIRECTION_OUTBOUND && con == null) {
@@ -269,23 +243,17 @@ public final class BluetoothOppProvider extends ContentProvider {
        filteredValues.put(BluetoothShare.TIMESTAMP, ts);
        filteredValues.put(BluetoothShare.TIMESTAMP, ts);


        Context context = getContext();
        Context context = getContext();
        context.startService(new Intent(context, BluetoothOppService.class));


        long rowID = db.insert(DB_TABLE, null, filteredValues);
        long rowID = db.insert(DB_TABLE, null, filteredValues);


        Uri ret = null;
        if (rowID == -1) {
            Log.w(TAG, "couldn't insert " + uri + "into btopp database");
            return null;
        }


        if (rowID != -1) {
            context.startService(new Intent(context, BluetoothOppService.class));
            ret = Uri.parse(BluetoothShare.CONTENT_URI + "/" + rowID);
        context.getContentResolver().notifyChange(uri, null);
        context.getContentResolver().notifyChange(uri, null);
        } else {
            if (D) {
                Log.d(TAG, "couldn't insert into btopp database");
            }
        }


        return ret;
        return Uri.parse(BluetoothShare.CONTENT_URI + "/" + rowID);
    }
    }


    @Override
    @Override
@@ -304,23 +272,17 @@ public final class BluetoothOppProvider extends ContentProvider {


        int match = sURIMatcher.match(uri);
        int match = sURIMatcher.match(uri);
        switch (match) {
        switch (match) {
            case SHARES: {
            case SHARES:
                qb.setTables(DB_TABLE);
                qb.setTables(DB_TABLE);
                break;
                break;
            }
            case SHARES_ID:
            case SHARES_ID: {
                qb.setTables(DB_TABLE);
                qb.setTables(DB_TABLE);
                qb.appendWhere(BluetoothShare._ID + "=");
                qb.appendWhere(BluetoothShare._ID + "=");
                qb.appendWhere(uri.getPathSegments().get(1));
                qb.appendWhere(uri.getPathSegments().get(1));
                break;
                break;
            }
            default:
            default: {
                if (D) {
                    Log.d(TAG, "querying unknown URI: " + uri);
                }
                throw new IllegalArgumentException("Unknown URI: " + uri);
                throw new IllegalArgumentException("Unknown URI: " + uri);
        }
        }
        }


        if (V) {
        if (V) {
            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            java.lang.StringBuilder sb = new java.lang.StringBuilder();
@@ -366,17 +328,12 @@ public final class BluetoothOppProvider extends ContentProvider {


        Cursor ret = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
        Cursor ret = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);


        if (ret != null) {
        if (ret == null) {
            ret.setNotificationUri(getContext().getContentResolver(), uri);
            Log.w(TAG, "query failed in downloads database");
            if (V) {
            return null;
                Log.v(TAG, "created cursor " + ret + " on behalf of ");
            }
        } else {
            if (D) {
                Log.d(TAG, "query failed in downloads database");
            }
        }
        }


        ret.setNotificationUri(getContext().getContentResolver(), uri);
        return ret;
        return ret;
    }
    }


@@ -384,8 +341,8 @@ public final class BluetoothOppProvider extends ContentProvider {
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();


        int count;
        int count = 0;
        long rowId = 0;
        long rowId;


        int match = sURIMatcher.match(uri);
        int match = sURIMatcher.match(uri);
        switch (match) {
        switch (match) {
@@ -409,17 +366,11 @@ public final class BluetoothOppProvider extends ContentProvider {


                if (values.size() > 0) {
                if (values.size() > 0) {
                    count = db.update(DB_TABLE, values, myWhere, selectionArgs);
                    count = db.update(DB_TABLE, values, myWhere, selectionArgs);
                } else {
                    count = 0;
                }
                }
                break;
                break;
            }
            }
            default: {
            default:
                if (D) {
                throw new UnsupportedOperationException("Cannot update unknown URI: " + uri);
                    Log.d(TAG, "updating unknown/invalid URI: " + uri);
                }
                throw new UnsupportedOperationException("Cannot update URI: " + uri);
            }
        }
        }
        getContext().getContentResolver().notifyChange(uri, null);
        getContext().getContentResolver().notifyChange(uri, null);


@@ -453,12 +404,8 @@ public final class BluetoothOppProvider extends ContentProvider {
                count = db.delete(DB_TABLE, myWhere, selectionArgs);
                count = db.delete(DB_TABLE, myWhere, selectionArgs);
                break;
                break;
            }
            }
            default: {
            default:
                if (D) {
                throw new UnsupportedOperationException("Cannot delete unknown URI: " + uri);
                    Log.d(TAG, "deleting unknown/invalid URI: " + uri);
                }
                throw new UnsupportedOperationException("Cannot delete URI: " + uri);
            }
        }
        }
        getContext().getContentResolver().notifyChange(uri, null);
        getContext().getContentResolver().notifyChange(uri, null);
        return count;
        return count;
+69 −113

File changed.

Preview size limit exceeded, changes collapsed.

+4 −8
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.os.PowerManager;
import android.os.Process;
import android.os.Process;
import android.util.Log;
import android.util.Log;


@@ -172,11 +171,9 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
        }
        }
    }
    }


    ;

    private OppConnectionReceiver mBluetoothReceiver;
    private OppConnectionReceiver mBluetoothReceiver;


    public BluetoothOppTransfer(Context context, PowerManager powerManager, BluetoothOppBatch batch,
    public BluetoothOppTransfer(Context context, BluetoothOppBatch batch,
            BluetoothOppObexSession session) {
            BluetoothOppObexSession session) {


        mContext = context;
        mContext = context;
@@ -188,9 +185,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch


    }
    }


    public BluetoothOppTransfer(Context context, PowerManager powerManager,
    public BluetoothOppTransfer(Context context, BluetoothOppBatch batch) {
            BluetoothOppBatch batch) {
        this(context, batch, null);
        this(context, powerManager, batch, null);
    }
    }


    public int getBatchId() {
    public int getBatchId() {
@@ -828,7 +824,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
                return;
                return;
            }
            }
        }
        }
    };
    }


    private void markConnectionFailed(BluetoothSocket s) {
    private void markConnectionFailed(BluetoothSocket s) {
        if (V) {
        if (V) {