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

Commit 2873f153 authored by Hemant Gupta's avatar Hemant Gupta Committed by Myles Watson
Browse files

OPP: Fix file sending error by calculating size of file properly.

Use case:
Send and receive vcard file through OBEX multiple times (above 30 times)

Result:
Sometimes DUT is unable to begin the vcard sharing and a message is displayed
saying "File unknown file could not be sent".

Root cause:
In Some race conditions InputStream.available() returns zero which causing error.
According to java documentation InputStream.available() method provides a weak
guarantee so it isn't guaranteed to return the total number of bytes in the stream.

Fix:
Read the InputStream by read() API to calculate the actual length of data.

Change-Id: I3448d6d3c410ae9dc8213c1c1d5f23dba4a56982
parent 9e5f2125
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -224,8 +224,10 @@ public class BluetoothOppSendFileInfo {
    private static long getStreamSize(FileInputStream is) throws IOException {
    private static long getStreamSize(FileInputStream is) throws IOException {
        long length = 0;
        long length = 0;
        byte unused[] = new byte[4096];
        byte unused[] = new byte[4096];
        while (is.available() > 0) {
        int bytesRead = is.read(unused, 0, 4096);
            length += is.read(unused, 0, 4096);
        while (bytesRead != -1) {
            length += bytesRead;
            bytesRead = is.read(unused, 0, 4096);
        }
        }
        return length;
        return length;
    }
    }