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

Commit 276ba1a7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "OPP: Check file size before send to prevent crash"

parents 684fc377 a71bac5d
Loading
Loading
Loading
Loading
+36 −17
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.util.Patterns;
import android.widget.Toast;

/**
 * This class is designed to act as the entry point of handling the share intent
@@ -109,11 +110,7 @@ public class BluetoothOppLauncherActivity extends Activity {
                    // session to DB.
                    Thread t = new Thread(new Runnable() {
                        public void run() {
                            BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
                                .saveSendingFileInfo(type,stream.toString(), false);
                            //Done getting file info..Launch device picker and finish this activity
                            launchDevicePicker();
                            finish();
                            sendFileInfo(type, stream.toString(), false);
                        }
                    });
                    t.start();
@@ -125,12 +122,7 @@ public class BluetoothOppLauncherActivity extends Activity {
                    if (fileUri != null) {
                        Thread t = new Thread(new Runnable() {
                            public void run() {
                                BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
                                    .saveSendingFileInfo(type,fileUri.toString(), false);
                                //Done getting file info..Launch device picker
                                //and finish this activity
                                launchDevicePicker();
                                finish();
                                sendFileInfo(type, fileUri.toString(), false);
                            }
                        });
                        t.start();
@@ -153,12 +145,17 @@ public class BluetoothOppLauncherActivity extends Activity {
                                + mimeType);
                    Thread t = new Thread(new Runnable() {
                        public void run() {
                            try {
                                BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
                                    .saveSendingFileInfo(mimeType, uris, false);
                                //Done getting file info..Launch device picker
                                //and finish this activity
                                launchDevicePicker();
                                finish();
                            } catch (IllegalArgumentException exception) {
                                showToast(exception.getMessage());
                                finish();
                            }
                        }
                    });
                    t.start();
@@ -377,4 +374,26 @@ public class BluetoothOppLauncherActivity extends Activity {
        }
        return text;
    }

    private void sendFileInfo(String mimeType, String uriString, boolean isHandover) {
        BluetoothOppManager manager = BluetoothOppManager.getInstance(getApplicationContext());
        try {
            manager.saveSendingFileInfo(mimeType, uriString, isHandover);
            launchDevicePicker();
            finish();
        } catch (IllegalArgumentException exception) {
            showToast(exception.getMessage());
            finish();
        }
    }

    private void showToast(final String msg) {
        BluetoothOppLauncherActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
            }
        });
    }

}
+4 −2
Original line number Diff line number Diff line
@@ -246,7 +246,8 @@ public class BluetoothOppManager {
        if (V) Log.v(TAG, "Application data stored to SharedPreference! ");
    }

    public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover) {
    public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover)
            throws IllegalArgumentException {
        synchronized (BluetoothOppManager.this) {
            mMultipleFlag = false;
            mMimeTypeOfSendingFile = mimeType;
@@ -259,7 +260,8 @@ public class BluetoothOppManager {
        }
    }

    public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover) {
    public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover)
            throws IllegalArgumentException {
        synchronized (BluetoothOppManager.this) {
            mMultipleFlag = true;
            mMimeTypeOfSendingFiles = mimeType;
+4 −0
Original line number Diff line number Diff line
@@ -212,6 +212,10 @@ public class BluetoothOppSendFileInfo {
        if (length == 0) {
            Log.e(TAG, "Could not determine size of file");
            return SEND_FILE_INFO_ERROR;
        } else if (length > 0xffffffffL) {
            String msg = "Files bigger than 4GB can't be transferred";
            Log.e(TAG, msg);
            throw new IllegalArgumentException(msg);
        }

        return new BluetoothOppSendFileInfo(fileName, contentType, length, is, 0);