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

Commit f3786288 authored by Hemant Gupta's avatar Hemant Gupta
Browse files

OPP: Trigger media scan after transferred file

Use case:
1. Receive an image via Bluetooth.
2. Launch Album/Google Photos app.
3. Check if received file can be displayed.

Error:
After step 2, received picture via Bluetooth from
remote phone is not displayed in Album/Google Photos.

Root cause:
The Update Thread didn't trigger the media scan after
media files received successfully

With commit Ied9a640b96d59e6c2e6b171b0ac3c08173f0ecd7
trigger function was removed leading to this issue.

Fix:
Add scan File function back whenever arrayPos increased,
so, the UI will be up to date.

Test: Able to view file successfully after above usecase.

Bug: 109787940
Change-Id: I6727347b466b8e7371f25502449d01557a645865
parent b98edaf0
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