diff options
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java | 18 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java | 14 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 6efac93de..521c46a5d 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -432,6 +432,10 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } } + final int onePercent = Math.max((int)(fileInfo.mLength / 100), 1); + int percentPosition = 0; + updateValues = new ContentValues(); + while (!mInterrupted && okToProceed && (position != fileInfo.mLength)) { { if (V) timestamp = System.currentTimeMillis(); @@ -448,15 +452,21 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { okToProceed = false; } else { position += readLength; + percentPosition += readLength; if (V) { Log.v(TAG, "Sending file position = " + position + " readLength " + readLength + " bytes took " + (System.currentTimeMillis() - timestamp) + " ms"); } - updateValues = new ContentValues(); - updateValues.put(BluetoothShare.CURRENT_BYTES, position); - mContext1.getContentResolver().update(contentUri, updateValues, - null, null); + + // Limit the number of update() calls to once per percent as it is + // expensive. + if (percentPosition >= onePercent) { + updateValues.put(BluetoothShare.CURRENT_BYTES, position); + mContext1.getContentResolver().update(contentUri, updateValues, + null, null); + percentPosition = percentPosition % onePercent; + } } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index cb292c1b1..2ed021933 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -444,6 +444,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen int readLength = 0; long timestamp = 0; try { + ContentValues updateValues = new ContentValues(); + final int onePercent = Math.max((int)(fileInfo.mLength / 100), 1); + int percentPosition = 0; + while ((!mInterrupted) && (position != fileInfo.mLength)) { if (V) timestamp = System.currentTimeMillis(); @@ -457,6 +461,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen bos.write(b, 0, readLength); position += readLength; + percentPosition += readLength; if (V) { Log.v(TAG, "Receive file position = " + position + " readLength " @@ -464,9 +469,12 @@ 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); + // Limit the number of update() calls to once per percent as it is expensive. + if (percentPosition >= onePercent) { + updateValues.put(BluetoothShare.CURRENT_BYTES, position); + mContext.getContentResolver().update(contentUri, updateValues, null, null); + percentPosition = percentPosition % onePercent; + } } } catch (IOException e1) { Log.e(TAG, "Error when receiving file"); |