OSDN Git Service

Improve BT OPP throughput
authorDeepak A Metri <deepak.a.metri@intel.com>
Fri, 9 Oct 2015 10:42:21 +0000 (12:42 +0200)
committerAndre Eisenbach <eisenbach@google.com>
Wed, 17 Feb 2016 18:19:38 +0000 (18:19 +0000)
Progress Bar updation during OPP takes around 40ms for each update.
This causes a significant delay in OPP file transfer, which eventually
will decrease the throughput.
To improve the throughput, invoke the progressBar updation only if there
is a change in the percentage.

Change-Id: I64a0b47093698959026d2b97f296c709a7d92703
Signed-off-by: Deepak A Metri <deepak.a.metri@intel.com>
Signed-off-by: Cedric Bondier <cedric.bondier@intel.com>
Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java

index 1a8ac6c..7590632 100644 (file)
@@ -337,7 +337,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
         private int sendFile(BluetoothOppSendFileInfo fileInfo) {
             boolean error = false;
             int responseCode = -1;
-            int position = 0;
+            long position = 0;
             int status = BluetoothShare.STATUS_SUCCESS;
             Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId);
             ContentValues updateValues;
@@ -393,6 +393,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
 
                 if (!error) {
                     int readLength = 0;
+                    long percent = 0;
+                    long prevPercent = 0;
                     boolean okToProceed = false;
                     long timestamp = 0;
                     int outputBufferSize = putOperation.getMaxPacketSize();
@@ -465,10 +467,15 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                                             + " readLength " + readLength + " bytes took "
                                             + (System.currentTimeMillis() - timestamp) + " ms");
                                 }
-                                updateValues = new ContentValues();
-                                updateValues.put(BluetoothShare.CURRENT_BYTES, position);
-                                mContext1.getContentResolver().update(contentUri, updateValues,
-                                        null, null);
+                                // Update the Progress Bar only if there is change in percentage
+                                percent = position * 100 / fileInfo.mLength;
+                                if (percent > prevPercent) {
+                                    updateValues = new ContentValues();
+                                    updateValues.put(BluetoothShare.CURRENT_BYTES, position);
+                                    mContext1.getContentResolver().update(contentUri, updateValues,
+                                            null, null);
+                                    prevPercent = percent;
+                                }
                             }
                         }
                     }
index ffb00e9..ee46646 100644 (file)
@@ -454,7 +454,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
             mContext.getContentResolver().update(contentUri, updateValues, null, null);
         }
 
-        int position = 0;
+        long position = 0;
+        long percent = 0;
+        long prevPercent = 0;
+
         if (!error) {
             bos = new BufferedOutputStream(fileInfo.mOutputStream, 0x10000);
         }
@@ -478,6 +481,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
 
                     bos.write(b, 0, readLength);
                     position += readLength;
+                    percent = position * 100 / fileInfo.mLength;
 
                     if (V) {
                         Log.v(TAG, "Receive file position = " + position + " readLength "
@@ -485,9 +489,13 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
                                 + (System.currentTimeMillis() - timestamp) + " ms");
                     }
 
-                    ContentValues updateValues = new ContentValues();
-                    updateValues.put(BluetoothShare.CURRENT_BYTES, position);
-                    mContext.getContentResolver().update(contentUri, updateValues, null, null);
+                    // Update the Progress Bar only if there is change in percentage
+                    if (percent > prevPercent) {
+                        ContentValues updateValues = new ContentValues();
+                        updateValues.put(BluetoothShare.CURRENT_BYTES, position);
+                        mContext.getContentResolver().update(contentUri, updateValues, null, null);
+                        prevPercent = percent;
+                    }
                 }
             } catch (IOException e1) {
                 Log.e(TAG, "Error when receiving file");