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

Commit 978ba2a5 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Bluetooth-OPP: Optimatize file transfer progress"

parents 5756d9cf 09ef1745
Loading
Loading
Loading
Loading
+13 −16
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {

    private final int MIN_FILE_LEN_FOR_TPUT_MEASUREMENT = 500000;

    private ContentResolverUpdateThread uiUpdateThread = null;

    public BluetoothOppObexClientSession(Context context, ObexTransport transport) {
        if (transport == null) {
            throw new NullPointerException("transport is null");
@@ -123,7 +125,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
    }

    private class ContentResolverUpdateThread extends Thread {
        private static final int sSleepTime = 500;
        private Uri contentUri;
        private Context mContext1;
        private long position;
@@ -135,28 +136,27 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
            position = pos;
        }

        public void updateProgress (long pos) {
            position = pos;
        }

        @Override
        public void run() {
            ContentValues updateValues;

            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            while (true) {
                updateValues = new ContentValues();
            synchronized (BluetoothOppObexClientSession.this) {
                if (uiUpdateThread != this) {
                    throw new IllegalStateException(
                        "multiple UpdateThreads in BluetoothOppObexClientSession");
                }
            }

                ContentValues updateValues = new ContentValues();
                updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                mContext1.getContentResolver().update(contentUri, updateValues,
                        null, null);
                synchronized (BluetoothOppObexClientSession.this) {
                    uiUpdateThread = null;


                try {
                    Thread.sleep(sSleepTime);
                } catch (InterruptedException e1) {
                    if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting");
                    return;
                }
            }
        }
    }
@@ -383,7 +383,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
            int status = BluetoothShare.STATUS_SUCCESS;
            Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId);
            ContentValues updateValues;
            ContentResolverUpdateThread uiUpdateThread = null;
            HeaderSet reply = new HeaderSet();
            HeaderSet request;
            request = new HeaderSet();
@@ -524,8 +523,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                                    uiUpdateThread = new ContentResolverUpdateThread (mContext1,
                                                                    contentUri, position);
                                    uiUpdateThread.start ( );
                                } else {
                                    uiUpdateThread.updateProgress (position);
                                }
                            }
                        }
+13 −19
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen

    boolean mTransferInProgress = false;

    private ContentResolverUpdateThread uiUpdateThread = null;

    public BluetoothOppObexServerSession(Context context, ObexTransport transport) {
        mContext = context;
        mTransport = transport;
@@ -169,7 +171,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen

    private class ContentResolverUpdateThread extends Thread {

        private static final int sSleepTime = 500;
        private Uri contentUri;
        private Context mContext1;
        private long position;
@@ -181,31 +182,27 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
            position = pos;
        }

        public void updateProgress (long pos) {
            position = pos;
        }

        @Override
        public void run() {
            ContentValues updateValues;

            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            synchronized (BluetoothOppObexServerSession.this) {
                if (uiUpdateThread != this) {
                    throw new IllegalStateException(
                        "multiple UpdateThreads in BluetoothOppObexServerSession");
                }
            }
            if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted());
            /*  Check if the Operation is interrupted before entering into loop */

            while ( !isInterrupted() ) {
                updateValues = new ContentValues();
                ContentValues  updateValues = new ContentValues();
                updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                mContext1.getContentResolver().update(contentUri, updateValues,
                        null, null);

                try {
                    Thread.sleep(sSleepTime);
                } catch (InterruptedException e1) {
                    if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1), exiting");
                    return;
                }
             synchronized (BluetoothOppObexServerSession.this) {
                uiUpdateThread = null;
             }

       }
    }
    /*
@@ -504,7 +501,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
        long beginTime = 0;
        int status = -1;
        BufferedOutputStream bos = null;
        ContentResolverUpdateThread uiUpdateThread = null;

        InputStream is = null;
        boolean error = false;
@@ -559,8 +555,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
                        uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri, position);
                        if (V) Log.v(TAG, "Worker for Updation : Created");
                        uiUpdateThread.start();
                    } else {
                        uiUpdateThread.updateProgress (position);
                    }
                }