summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2015-12-16 10:45:47 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2015-12-16 10:45:47 -0800
commitcc8d2bfb9550964236c6666b3c27686b7faf6505 (patch)
treeb062b9e387e080bf6c637ce19bf53e728f4886b3
parent978ba2a566a638c11724e613075c132a9f563f34 (diff)
parent097d4de2653652769c5a304188e05875316af28c (diff)
downloadandroid_packages_apps_Bluetooth-cc8d2bfb9550964236c6666b3c27686b7faf6505.tar.gz
android_packages_apps_Bluetooth-cc8d2bfb9550964236c6666b3c27686b7faf6505.tar.bz2
android_packages_apps_Bluetooth-cc8d2bfb9550964236c6666b3c27686b7faf6505.zip
Merge "Bluetooth: Single Contentresolver thread will be started during transfer"
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java38
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java53
2 files changed, 50 insertions, 41 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
index 180ef70ee..37aeeb1f0 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
@@ -77,7 +77,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
private final int MIN_FILE_LEN_FOR_TPUT_MEASUREMENT = 500000;
- private ContentResolverUpdateThread uiUpdateThread = null;
+ private long position;
public BluetoothOppObexClientSession(Context context, ObexTransport transport) {
if (transport == null) {
@@ -125,38 +125,37 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
}
private class ContentResolverUpdateThread extends Thread {
+ 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;
}
@Override
public void run() {
- Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-
- synchronized (BluetoothOppObexClientSession.this) {
- if (uiUpdateThread != this) {
- throw new IllegalStateException(
- "multiple UpdateThreads in BluetoothOppObexClientSession");
- }
- }
+ ContentValues updateValues;
- ContentValues updateValues = new ContentValues();
+ Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+ 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);
- synchronized (BluetoothOppObexClientSession.this) {
- uiUpdateThread = null;
-
+ try {
+ Thread.sleep(sSleepTime);
+ } catch (InterruptedException e1) {
+ if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting");
+ return;
+ }
}
}
}
@@ -379,10 +378,11 @@ 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;
+ ContentResolverUpdateThread uiUpdateThread = null;
HeaderSet reply = new HeaderSet();
HeaderSet request;
request = new HeaderSet();
@@ -521,7 +521,8 @@ 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 ( );
}
}
@@ -530,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;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
index 0278d99b2..2f6a48440 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
@@ -109,7 +109,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
boolean mTransferInProgress = false;
- private ContentResolverUpdateThread uiUpdateThread = null;
+ private int position;
public BluetoothOppObexServerSession(Context context, ObexTransport transport) {
mContext = context;
@@ -171,39 +171,44 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
private class ContentResolverUpdateThread extends Thread {
+ 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;
}
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
- synchronized (BluetoothOppObexServerSession.this) {
- if (uiUpdateThread != this) {
- throw new IllegalStateException(
- "multiple UpdateThreads in BluetoothOppObexServerSession");
- }
- }
+ ContentValues updateValues;
if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted());
/* Check if the Operation is interrupted before entering into loop */
-
- ContentValues updateValues = new ContentValues();
- updateValues.put(BluetoothShare.CURRENT_BYTES, position);
- mContext1.getContentResolver().update(contentUri, updateValues,
- null, null);
- synchronized (BluetoothOppObexServerSession.this) {
- uiUpdateThread = null;
- }
-
- }
+ 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");
+ return ;
+ }
+ }
+ }
}
/*
* Called when a ABORT request is received.
@@ -501,6 +506,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
long beginTime = 0;
int status = -1;
BufferedOutputStream bos = null;
+ ContentResolverUpdateThread uiUpdateThread = null;
+
InputStream is = null;
boolean error = false;
@@ -520,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);
}
@@ -552,7 +559,7 @@ 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();
}