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>
Thu, 18 Feb 2016 18:56:09 +0000 (10:56 -0800)
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 b923f46..2843249 100644 (file)
@@ -434,7 +434,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);
         }
@@ -458,6 +461,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 "
@@ -465,9 +469,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");