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

Commit 4a0b008a authored by Hiroki Yamamoto's avatar Hiroki Yamamoto Committed by android-build-merger
Browse files

Merge "OPP: Notify NFC of that the transfer still alive per a certain period"...

Merge "OPP: Notify NFC of that the transfer still alive per a certain period" am: eb9f0455 am: 179f108e
am: 1d27776c

Change-Id: Ie916a13f57150736d108abc2cada6bafa82c57a5
parents f8990614 1d27776c
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Process;
import android.os.SystemClock;
import android.util.Log;

import java.io.BufferedInputStream;
@@ -440,6 +441,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                    long prevPercent = 0;
                    boolean okToProceed = false;
                    long timestamp = 0;
                    long currentTime = 0;
                    long prevTimestamp = SystemClock.elapsedRealtime();
                    int outputBufferSize = putOperation.getMaxPacketSize();
                    byte[] buffer = new byte[outputBufferSize];
                    BufferedInputStream a = new BufferedInputStream(fileInfo.mInputStream, 0x4000);
@@ -491,7 +494,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {

                    while (!mInterrupted && okToProceed && (position < fileInfo.mLength)) {
                        if (V) {
                            timestamp = System.currentTimeMillis();
                            timestamp = SystemClock.elapsedRealtime();
                        }

                        readLength = a.read(buffer, 0, outputBufferSize);
@@ -508,19 +511,23 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                            okToProceed = false;
                        } else {
                            position += readLength;
                            currentTime = SystemClock.elapsedRealtime();
                            if (V) {
                                Log.v(TAG, "Sending file position = " + position + " readLength "
                                        + readLength + " bytes took " + (System.currentTimeMillis()
                                        - timestamp) + " ms");
                                Log.v(TAG, "Sending file position = " + position
                                        + " readLength " + readLength + " bytes took "
                                        + (currentTime - timestamp) + " ms");
                            }
                            // Update the Progress Bar only if there is change in percentage
                            // or once per a period to notify NFC of this transfer is still alive
                            percent = position * 100 / fileInfo.mLength;
                            if (percent > prevPercent) {
                            if (percent > prevPercent
                                    || currentTime - prevTimestamp > Constants.NFC_ALIVE_CHECK_MS) {
                                updateValues = new ContentValues();
                                updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                                mContext1.getContentResolver()
                                        .update(contentUri, updateValues, null, null);
                                prevPercent = percent;
                                prevTimestamp = currentTime;
                            }
                        }
                    }
+10 −4
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.util.Log;
import android.webkit.MimeTypeMap;

@@ -491,11 +492,13 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler
            byte[] b = new byte[outputBufferSize];
            int readLength = 0;
            long timestamp = 0;
            long currentTime = 0;
            long prevTimestamp = SystemClock.elapsedRealtime();
            try {
                while ((!mInterrupted) && (position != fileInfo.mLength)) {

                    if (V) {
                        timestamp = System.currentTimeMillis();
                        timestamp = SystemClock.elapsedRealtime();
                    }

                    readLength = is.read(b);
@@ -510,20 +513,23 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler
                    bos.write(b, 0, readLength);
                    position += readLength;
                    percent = position * 100 / fileInfo.mLength;
                    currentTime = SystemClock.elapsedRealtime();

                    if (V) {
                        Log.v(TAG,
                                "Receive file position = " + position + " readLength " + readLength
                                        + " bytes took " + (System.currentTimeMillis() - timestamp)
                                        + " ms");
                                        + " bytes took " + (currentTime - timestamp) + " ms");
                    }

                    // Update the Progress Bar only if there is change in percentage
                    if (percent > prevPercent) {
                    // or once per a period to notify NFC of this transfer is still alive
                    if (percent > prevPercent
                            || currentTime - prevTimestamp > Constants.NFC_ALIVE_CHECK_MS) {
                        ContentValues updateValues = new ContentValues();
                        updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                        mContext.getContentResolver().update(contentUri, updateValues, null, null);
                        prevPercent = percent;
                        prevTimestamp = currentTime;
                    }
                }
            } catch (IOException e1) {
+7 −0
Original line number Diff line number Diff line
@@ -231,6 +231,13 @@ public class Constants {
    /** Where we store Bluetooth received files on the external storage */
    public static final String DEFAULT_STORE_SUBDIR = "/bluetooth";

    /**
     * Notify NFC of the transfer progress per this period
     * to NFC Handover still consider this transfer to be "alive"
     * This value is taken into account the timeout value 20sec in NFC and delaying broadcast
     */
    public static final int NFC_ALIVE_CHECK_MS = 10000;

    /**
     * Debug level logging
     */