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

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

Merge "Bluetooth: Single Contentresolver thread will be started during transfer"

parents 21d3be9f 6db289ce
Loading
Loading
Loading
Loading
+12 −13
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 long position;

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

    private class ContentResolverUpdateThread extends Thread {
        private static final int sSleepTime = 500;
        private static final int sSleepTime = 1000;
        private Uri contentUri;
        private Context mContext1;
        private long position;

        public ContentResolverUpdateThread(Context context, Uri cntUri, long pos) {
        public ContentResolverUpdateThread(Context context, Uri cntUri) {
            super("BtOpp ContentResolverUpdateThread");
            mContext1 = context;
            contentUri = cntUri;
            position = pos;
        }

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

        @Override
        public void run() {

            ContentValues updateValues;

            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            while (true) {
            if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted());
            /*  Check if the Operation is interrupted before entering into loop */
            while (!isInterrupted()) {
                updateValues = new ContentValues();
                updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                mContext1.getContentResolver().update(contentUri, updateValues,
@@ -379,7 +378,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
        private int sendFile(BluetoothOppSendFileInfo fileInfo) {
            boolean error = false;
            int responseCode = -1;
            long position = 0;
            position = 0;
            int status = BluetoothShare.STATUS_SUCCESS;
            Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId);
            ContentValues updateValues;
@@ -522,10 +521,9 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {

                                if (uiUpdateThread == null) {
                                    uiUpdateThread = new ContentResolverUpdateThread (mContext1,
                                                                    contentUri, position);
                                                             contentUri);
                                    if (V) Log.v(TAG, "Worker for Updation : Created");
                                    uiUpdateThread.start ( );
                                } else {
                                    uiUpdateThread.updateProgress (position);
                                }
                            }
                        }
@@ -533,6 +531,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {

                    if (uiUpdateThread != null) {
                        try {
                            if (V) Log.v(TAG, "Worker for Updation : Destroying");
                            uiUpdateThread.interrupt ();
                            uiUpdateThread.join ();
                            uiUpdateThread = null;
+27 −26
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen

    boolean mTransferInProgress = false;

    private int position;

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

    private class ContentResolverUpdateThread extends Thread {

        private static final int sSleepTime = 500;
        private static final int sSleepTime = 1000;
        private Uri contentUri;
        private Context mContext1;
        private long position;

        public ContentResolverUpdateThread(Context context, Uri cntUri, long pos) {
        private volatile boolean interrupted = false;
        public ContentResolverUpdateThread(Context context, Uri cntUri) {
            super("BtOpp Server ContentResolverUpdateThread");
            mContext1 = context;
            contentUri = cntUri;
            position = pos;
        }

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

        @Override
        public void run() {
            ContentValues updateValues;

            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            ContentValues updateValues;
            if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted());
            /*  Check if the Operation is interrupted before entering into loop */

            while ( !isInterrupted() ) {
               updateValues = new ContentValues();
               updateValues.put(BluetoothShare.CURRENT_BYTES, position);
               mContext1.getContentResolver().update(contentUri, updateValues,
                   null, null);
               /* Check if the Operation is interrupted before entering sleep */
               if (isInterrupted()) {
                   if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted before sleep !,"+
                                     " exiting");
                   return ;
               }

               try {
                   Thread.sleep(sSleepTime);
               } catch (InterruptedException e1) {
                    if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1), exiting");
                   if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1),"+
                                     " exiting");
                   return ;
               }
            }
@@ -506,6 +508,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
        BufferedOutputStream bos = null;
        ContentResolverUpdateThread uiUpdateThread = null;


        InputStream is = null;
        boolean error = false;
        try {
@@ -524,7 +527,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
            mContext.getContentResolver().update(contentUri, updateValues, null, null);
        }

        long position = 0;
        position = 0;
        if (!error) {
            bos = new BufferedOutputStream(fileInfo.mOutputStream, 0x10000);
        }
@@ -556,11 +559,9 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
                    }

                    if (uiUpdateThread == null) {
                        uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri, position);
                        uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri);
                        if (V) Log.v(TAG, "Worker for Updation : Created");
                        uiUpdateThread.start();
                    } else {
                        uiUpdateThread.updateProgress (position);
                    }
                }