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

Commit 8ca0adee authored by Hemant Gupta's avatar Hemant Gupta Committed by android-build-merger
Browse files

Merge "OPP: Trigger media scan after transferred file" am: 8e2a967b

am: 9e1846d4

Change-Id: I0590df8b754b185fb0bf932e45b384bb916b50d2
parents 44926a89 9e1846d4
Loading
Loading
Loading
Loading
+8 −18
Original line number Diff line number Diff line
@@ -652,9 +652,6 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                            }
                        }

                        if (shouldScanFile(arrayPos)) {
                            scanFile(arrayPos);
                        }
                        deleteShare(arrayPos); // this advances in the array
                    } else {
                        int id = cursor.getInt(idColumn);
@@ -678,14 +675,11 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                                    Log.v(TAG,
                                            "Array update: removing " + arrayId + " @ " + arrayPos);
                                }
                                if (shouldScanFile(arrayPos)) {
                                    scanFile(arrayPos);
                                }
                                deleteShare(arrayPos);
                            } else if (arrayId == id) {
                                // This cursor row already exists in the stored array.
                                updateShare(cursor, arrayPos);

                                scanFileIfNeeded(arrayPos);
                                ++arrayPos;
                                cursor.moveToNext();
                                isAfterLast = cursor.isAfterLast();
@@ -1051,8 +1045,14 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        }
    }

    private boolean scanFile(int arrayPos) {
    private void scanFileIfNeeded(int arrayPos) {
        BluetoothOppShareInfo info = mShares.get(arrayPos);
        boolean isFileReceived = BluetoothShare.isStatusSuccess(info.mStatus)
                && info.mDirection == BluetoothShare.DIRECTION_INBOUND && !info.mMediaScanned
                && info.mConfirm != BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;
        if (!isFileReceived) {
            return;
        }
        synchronized (BluetoothOppService.this) {
            if (D) {
                Log.d(TAG, "Scanning file " + info.mFilename);
@@ -1060,20 +1060,10 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
            if (!mMediaScanInProgress) {
                mMediaScanInProgress = true;
                new MediaScannerNotifier(this, info, mHandler);
                return true;
            } else {
                return false;
            }
        }
    }

    private boolean shouldScanFile(int arrayPos) {
        BluetoothOppShareInfo info = mShares.get(arrayPos);
        return BluetoothShare.isStatusSuccess(info.mStatus)
                && info.mDirection == BluetoothShare.DIRECTION_INBOUND && !info.mMediaScanned
                && info.mConfirm != BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED;
    }

    // Run in a background thread at boot.
    private static void trimDatabase(ContentResolver contentResolver) {
        // remove the invisible/unconfirmed inbound shares