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

Commit 54ba08e0 authored by Hemant Gupta's avatar Hemant Gupta Committed by Andre Eisenbach
Browse files

OPP: Handle Stale Data Exception

Use case:
1. Share numerous files
2. Wait for complete
3. View completed transfers
4. Before opening the transfer history click on home button
5. Repeat above steps numerous times

Failure:
Crash in com.android.bluetooth
Msg: StaleDataException, Attempting to access a
     closed Cursor Window

Root cause:
Some rare cases after pausing activity also cursor
is trying to fetch values from OPP DB.

Fix:
Catch Cursor Exception to avoid crash in opp profile
and break loop If we get at least one finished transfer
from DB to avoid UN necessary iterations.

Test: Stale Data Exception not observed as per above usecase.
Fixes: 35013626
Change-Id: I9c76638c162e9433b0aa17b99711557ba8f9ef07
parent cf77de70
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.StaleDataException;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
@@ -158,8 +159,7 @@ public class BluetoothOppTransferHistory extends Activity
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        if (!mShowAllIncoming) {
            boolean showClear = getClearableCount() > 0;
            menu.findItem(R.id.transfer_menu_clear_all).setEnabled(showClear);
            menu.findItem(R.id.transfer_menu_clear_all).setEnabled(isTransferComplete());
        }
        return super.onPrepareOptionsMenu(menu);
    }
@@ -246,21 +246,24 @@ public class BluetoothOppTransferHistory extends Activity
    }

    /**
     * Get the number of finished transfers, including error and success.
     * Returns true if the device has finished transfers, including error and success.
     */
    private int getClearableCount() {
        int count = 0;
    private boolean isTransferComplete() {
        try {
            if (mTransferCursor.moveToFirst()) {
                while (!mTransferCursor.isAfterLast()) {
                int statusColumnId = mTransferCursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
                    int statusColumnId = mTransferCursor
                                             .getColumnIndexOrThrow(BluetoothShare.STATUS);
                    int status = mTransferCursor.getInt(statusColumnId);
                    if (BluetoothShare.isStatusCompleted(status)) {
                    count++;
                        return true;
                    }
                    mTransferCursor.moveToNext();
                }
            }
        return count;
        } catch (StaleDataException e) {
        }
        return false;
    }

    /**