Loading src/com/android/bluetooth/opp/BluetoothOppNotification.java +8 −2 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.database.sqlite.SQLiteException; import android.content.res.Resources.NotFoundException; import android.net.Uri; import android.util.Log; import android.os.PowerManager; import android.os.Handler; import android.os.Message; import android.os.Process; Loading Loading @@ -102,6 +103,8 @@ class BluetoothOppNotification { private NotificationUpdateThread mUpdateNotificationThread; private PowerManager mPowerManager; private static final int NOTIFICATION_ID_OUTBOUND = -1000005; private static final int NOTIFICATION_ID_INBOUND = -1000006; Loading Loading @@ -147,6 +150,7 @@ class BluetoothOppNotification { mNotificationMgr = (NotificationManager)mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotifications = new HashMap<String, NotificationItem>(); mPowerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); } /** Loading Loading @@ -195,14 +199,16 @@ class BluetoothOppNotification { updateIncomingFileConfirmNotification(); try { Thread.sleep(1000); if (mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { if (V) Log.v(TAG, "NotificationThread was interrupted (1), exiting"); return; } if (V) Log.v(TAG, "Running = " + mRunning); } while (mRunning > 0); } while ((mRunning > 0) && mPowerManager.isScreenOn()); synchronized (BluetoothOppNotification.this) { mUpdateNotificationThread = null; Loading src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +12 −8 Original line number Diff line number Diff line Loading @@ -85,6 +85,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { private Handler mCallback; private PowerManager pm; private long position; public BluetoothOppObexClientSession(Context context, ObexTransport transport) { Loading Loading @@ -133,7 +135,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } private class ContentResolverUpdateThread extends Thread { private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; private volatile boolean interrupted = false; Loading @@ -150,10 +151,12 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { ContentValues updateValues; while (true) { if (pm.isScreenOn()) { 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 (interrupted == true) { Loading @@ -162,7 +165,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } try { Thread.sleep(sSleepTime); Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } catch (InterruptedException e1) { if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting"); return; Loading Loading @@ -208,7 +211,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { waitingForShare = true; mWaitingForRemote = false; mNumShares = initialNumShares; PowerManager pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE); pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } Loading Loading @@ -666,6 +669,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { Log.i(TAG, "SendFile finished sending file " + fileInfo.mFileName + " length " + fileInfo.mLength + "Bytes in " + (endTime - beginTime) + "ms" ); status = BluetoothShare.STATUS_SUCCESS; outputStream.close(); } else { error = true; Loading src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +12 −9 Original line number Diff line number Diff line Loading @@ -110,20 +110,22 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private BluetoothOppReceiveFileInfo mFileInfo; private PowerManager pm; private WakeLock mWakeLock; private WakeLock mPartialWakeLock; private long position; boolean mTimeoutMsgSent = false; boolean mTransferInProgress = false; private int position; public BluetoothOppObexServerSession(Context context, ObexTransport transport) { mContext = context; mTransport = transport; PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG); mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); Loading Loading @@ -194,7 +196,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private class ContentResolverUpdateThread extends Thread { private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; private volatile boolean interrupted = false; Loading @@ -210,10 +211,12 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); ContentValues updateValues; while (true) { if (pm.isScreenOn()) { 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 (interrupted == true) { Loading @@ -222,7 +225,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen } try { Thread.sleep(sSleepTime); Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } catch (InterruptedException e1) { if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1), exiting"); return; Loading src/com/android/bluetooth/opp/BluetoothOppService.java +24 −17 Original line number Diff line number Diff line Loading @@ -96,8 +96,6 @@ public class BluetoothOppService extends Service { /** Class to handle Notification Manager updates */ private BluetoothOppNotification mNotifier; private boolean mPendingUpdate; private UpdateThread mUpdateThread; private ArrayList<BluetoothOppShareInfo> mShares; Loading Loading @@ -439,10 +437,10 @@ public class BluetoothOppService extends Service { private void updateFromProvider() { synchronized (BluetoothOppService.this) { mPendingUpdate = true; if ((mUpdateThread == null) && (mAdapter != null) && mAdapter.isEnabled()) { if (V) Log.v(TAG, "Starting a new thread"); mPowerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE); mUpdateThread = new UpdateThread(); mUpdateThread.start(); } Loading @@ -459,25 +457,14 @@ public class BluetoothOppService extends Service { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); boolean keepService = false; for (;;) { do { synchronized (BluetoothOppService.this) { if (mUpdateThread != this) { throw new IllegalStateException( "multiple UpdateThreads in BluetoothOppService"); } if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); if (!mPendingUpdate) { mUpdateThread = null; if (!keepService && !mListenStarted) { if (V) Log.v(TAG, "Need to stop self"); stopSelf(); break; } if (V) Log.v(TAG, "***returning from updatethread***"); return; } mPendingUpdate = false; if (V) Log.v(TAG, "keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); } Cursor cursor; try { Loading Loading @@ -612,6 +599,26 @@ public class BluetoothOppService extends Service { cursor.close(); cursor = null; try { if (mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { if (V) Log.v(TAG, "OppService UpdateThread was interrupted (1), exiting"); return; } if (V) Log.v(TAG, "Batch size= " + mBatchs.size()); } while ((mBatchs.size() > 0) && mPowerManager.isScreenOn()); synchronized (BluetoothOppService.this) { mUpdateThread = null; if (!keepService && !mListenStarted) { if (V) Log.v(TAG, "Need to stop self"); stopSelf(); } if (V) Log.v(TAG, "***returning from updatethread***"); } } Loading src/com/android/bluetooth/opp/BluetoothShare.java +5 −0 Original line number Diff line number Diff line Loading @@ -421,4 +421,9 @@ public final class BluetoothShare implements BaseColumns { */ public static final int STATUS_CONNECTION_ERROR = 497; /** * Ongoing transfer progress update interval to 1 second */ public static final int UI_UPDATE_INTERVAL = 1000; } Loading
src/com/android/bluetooth/opp/BluetoothOppNotification.java +8 −2 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.database.sqlite.SQLiteException; import android.content.res.Resources.NotFoundException; import android.net.Uri; import android.util.Log; import android.os.PowerManager; import android.os.Handler; import android.os.Message; import android.os.Process; Loading Loading @@ -102,6 +103,8 @@ class BluetoothOppNotification { private NotificationUpdateThread mUpdateNotificationThread; private PowerManager mPowerManager; private static final int NOTIFICATION_ID_OUTBOUND = -1000005; private static final int NOTIFICATION_ID_INBOUND = -1000006; Loading Loading @@ -147,6 +150,7 @@ class BluetoothOppNotification { mNotificationMgr = (NotificationManager)mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotifications = new HashMap<String, NotificationItem>(); mPowerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); } /** Loading Loading @@ -195,14 +199,16 @@ class BluetoothOppNotification { updateIncomingFileConfirmNotification(); try { Thread.sleep(1000); if (mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { if (V) Log.v(TAG, "NotificationThread was interrupted (1), exiting"); return; } if (V) Log.v(TAG, "Running = " + mRunning); } while (mRunning > 0); } while ((mRunning > 0) && mPowerManager.isScreenOn()); synchronized (BluetoothOppNotification.this) { mUpdateNotificationThread = null; Loading
src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +12 −8 Original line number Diff line number Diff line Loading @@ -85,6 +85,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { private Handler mCallback; private PowerManager pm; private long position; public BluetoothOppObexClientSession(Context context, ObexTransport transport) { Loading Loading @@ -133,7 +135,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } private class ContentResolverUpdateThread extends Thread { private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; private volatile boolean interrupted = false; Loading @@ -150,10 +151,12 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { ContentValues updateValues; while (true) { if (pm.isScreenOn()) { 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 (interrupted == true) { Loading @@ -162,7 +165,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } try { Thread.sleep(sSleepTime); Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } catch (InterruptedException e1) { if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting"); return; Loading Loading @@ -208,7 +211,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { waitingForShare = true; mWaitingForRemote = false; mNumShares = initialNumShares; PowerManager pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE); pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } Loading Loading @@ -666,6 +669,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { Log.i(TAG, "SendFile finished sending file " + fileInfo.mFileName + " length " + fileInfo.mLength + "Bytes in " + (endTime - beginTime) + "ms" ); status = BluetoothShare.STATUS_SUCCESS; outputStream.close(); } else { error = true; Loading
src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +12 −9 Original line number Diff line number Diff line Loading @@ -110,20 +110,22 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private BluetoothOppReceiveFileInfo mFileInfo; private PowerManager pm; private WakeLock mWakeLock; private WakeLock mPartialWakeLock; private long position; boolean mTimeoutMsgSent = false; boolean mTransferInProgress = false; private int position; public BluetoothOppObexServerSession(Context context, ObexTransport transport) { mContext = context; mTransport = transport; PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG); mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); Loading Loading @@ -194,7 +196,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private class ContentResolverUpdateThread extends Thread { private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; private volatile boolean interrupted = false; Loading @@ -210,10 +211,12 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); ContentValues updateValues; while (true) { if (pm.isScreenOn()) { 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 (interrupted == true) { Loading @@ -222,7 +225,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen } try { Thread.sleep(sSleepTime); Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } catch (InterruptedException e1) { if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1), exiting"); return; Loading
src/com/android/bluetooth/opp/BluetoothOppService.java +24 −17 Original line number Diff line number Diff line Loading @@ -96,8 +96,6 @@ public class BluetoothOppService extends Service { /** Class to handle Notification Manager updates */ private BluetoothOppNotification mNotifier; private boolean mPendingUpdate; private UpdateThread mUpdateThread; private ArrayList<BluetoothOppShareInfo> mShares; Loading Loading @@ -439,10 +437,10 @@ public class BluetoothOppService extends Service { private void updateFromProvider() { synchronized (BluetoothOppService.this) { mPendingUpdate = true; if ((mUpdateThread == null) && (mAdapter != null) && mAdapter.isEnabled()) { if (V) Log.v(TAG, "Starting a new thread"); mPowerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE); mUpdateThread = new UpdateThread(); mUpdateThread.start(); } Loading @@ -459,25 +457,14 @@ public class BluetoothOppService extends Service { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); boolean keepService = false; for (;;) { do { synchronized (BluetoothOppService.this) { if (mUpdateThread != this) { throw new IllegalStateException( "multiple UpdateThreads in BluetoothOppService"); } if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); if (!mPendingUpdate) { mUpdateThread = null; if (!keepService && !mListenStarted) { if (V) Log.v(TAG, "Need to stop self"); stopSelf(); break; } if (V) Log.v(TAG, "***returning from updatethread***"); return; } mPendingUpdate = false; if (V) Log.v(TAG, "keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); } Cursor cursor; try { Loading Loading @@ -612,6 +599,26 @@ public class BluetoothOppService extends Service { cursor.close(); cursor = null; try { if (mPowerManager.isScreenOn()) { Thread.sleep(BluetoothShare.UI_UPDATE_INTERVAL); } } catch (InterruptedException e) { if (V) Log.v(TAG, "OppService UpdateThread was interrupted (1), exiting"); return; } if (V) Log.v(TAG, "Batch size= " + mBatchs.size()); } while ((mBatchs.size() > 0) && mPowerManager.isScreenOn()); synchronized (BluetoothOppService.this) { mUpdateThread = null; if (!keepService && !mListenStarted) { if (V) Log.v(TAG, "Need to stop self"); stopSelf(); } if (V) Log.v(TAG, "***returning from updatethread***"); } } Loading
src/com/android/bluetooth/opp/BluetoothShare.java +5 −0 Original line number Diff line number Diff line Loading @@ -421,4 +421,9 @@ public final class BluetoothShare implements BaseColumns { */ public static final int STATUS_CONNECTION_ERROR = 497; /** * Ongoing transfer progress update interval to 1 second */ public static final int UI_UPDATE_INTERVAL = 1000; }