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

Commit 86bb6c3c authored by Smriti Gupta's avatar Smriti Gupta Committed by Linux Build Service Account
Browse files

Clean up file when file transfer is aborted by remote/local device

Delete File when the transfer is terminated due to
Remote's BT is turned off, remote being taken out of reach or
remote is turned off properly. Also delete the file on the next
reboot while the previous inbound transfer was interrupted by
local device power off.
CRs-Fixed: 506182

Change-Id: I96211e701610322881eda8345d04898ae3f18ab6
parent e09ab512
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -562,13 +562,16 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
                    }
                }
            } catch (IOException e1) {
                Log.e(TAG, "Error when receiving file");
                Log.e(TAG, "Error when receiving file: " + e1);
                /* OBEX Abort packet received from remote device */
                if ("Abort Received".equals(e1.getMessage())) {
                    status = BluetoothShare.STATUS_CANCELED;
                } else {
                    status = BluetoothShare.STATUS_OBEX_DATA_ERROR;
                }
                if (mFileInfo.mFileName != null) {
                    new File(mFileInfo.mFileName).delete();
                }
                error = true;
            } finally {
                if (uiUpdateThread != null) {
+31 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import java.io.File;
import android.util.Log;
import android.os.Process;

@@ -919,6 +920,36 @@ public class BluetoothOppService extends Service {
                WHERE_INVISIBLE_COMPLETE_INBOUND_FAILED, null);
        if (V) Log.v(TAG, "Deleted complete inbound failed shares, number = " + delNum);

        final String WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.STATUS + "="
                + BluetoothShare.STATUS_RUNNING;

        Cursor cursorToFile = contentResolver.query(BluetoothShare.CONTENT_URI,
                                  new String[] { BluetoothShare._DATA },
                                  WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF, null, null);

        // remove the share and the respective file which was interrupted by battery
        // removal in the local device
        if (cursorToFile != null) {
            if (cursorToFile.moveToFirst()) {
                String fileName = cursorToFile.getString(0);
                Log.v(TAG, "File to be deleted: " + fileName);
                File fileToDelete = new File(fileName);
                if (fileToDelete != null) fileToDelete.delete();
                delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                             WHERE_INBOUND_INTERRUPTED_ON_POWER_OFF, null);
                if (V) Log.v(TAG, "Delete aborted inbound share, number = " + delNum);
            }
        }

        // on boot : remove unconfirmed inbound shares.
        final String WHERE_CONFIRMATION_PENDING_INBOUND = BluetoothShare.DIRECTION + "="
                + BluetoothShare.DIRECTION_INBOUND + " AND " + BluetoothShare.USER_CONFIRMATION
                + "=" + BluetoothShare.USER_CONFIRMATION_PENDING;
        delNum = contentResolver.delete(BluetoothShare.CONTENT_URI,
                 WHERE_CONFIRMATION_PENDING_INBOUND, null);
        if (V) Log.v(TAG, "Deleted unconfirmed incoming shares, number = " + delNum);

        // Only keep the inbound and successful shares for LiverFolder use
        // Keep the latest 1000 to easy db query
        final String WHERE_INBOUND_SUCCESS = BluetoothShare.DIRECTION + "="