public void onDestroy() {
super.onDestroy();
if (DBG) log("Destroying service.");
+ if(mAdapter != null)
+ mAdapter = null;
}
private void start() {
public void cleanup() {
cleanupNative();
+ if(mContext != null)
+ mContext = null;
+ if(mAdapter != null)
+ mAdapter = null;
}
private class Disconnected extends State {
}
public void cleanup() {
+ if(mAdapterProperties != null)
+ mAdapterProperties = null;
+ if(mAdapterService != null)
+ mAdapterService = null;
+ if(mContext != null)
+ mContext = null;
}
private class OffState extends State {
public void onDestroy() {
super.onDestroy();
if (DBG) log("Destroying service.");
+
+ //Cleanup other object references
+ if(mHealthChannels != null) {
+ mHealthChannels.clear();
+ mHealthChannels = null;
+ }
+ if(mHealthDevices != null) {
+ mHealthDevices.clear();
+ mHealthDevices = null;
+ }
+ if(mApps != null) {
+ mApps.clear();
+ mApps = null;
+ }
+ if(mAdapter != null)
+ mAdapter = null;
+
}
private void start() {
if (DBG) log("stop()");
//Cleanup looper
+ mHandler.removeCallbacksAndMessages(null);
Looper looper = mHandler.getLooper();
if (looper != null) {
looper.quit();
}
+ mHandler = null;
//Cleanup native
cleanupNative();
public void onDestroy() {
super.onDestroy();
if (DBG) log("Destroying service.");
+ if(mAdapter != null)
+ mAdapter = null;
+ if(mStateMachine != null)
+ {
+ mStateMachine.quit();
+ mStateMachine = null;
+ }
}
private void start() {
}
}
}
+ if(mContext != null)
+ mContext = null;
}
private class Disconnected extends State {
public void onDestroy() {
super.onDestroy();
if (DBG) log("Destroying service.");
+ if(mAdapter != null)
+ mAdapter = null;
+ if(mInputDevices != null) {
+ mInputDevices.clear();
+ mInputDevices = null;
+ }
}
private void start() {
if (mTcpServerSocket != null) {
try {
mTcpServerSocket.close();
+ mTcpServerSocket = null;
} catch (IOException e) {
Log.e(TAG, "Error close mTcpServerSocket");
}
if (mBtServerSocket != null) {
try {
mBtServerSocket.close();
+ mBtServerSocket = null;
} catch (IOException e) {
Log.e(TAG, "Error close mBtServerSocket");
}
getContentResolver().unregisterContentObserver(mObserver);
unregisterReceiver(mBluetoothReceiver);
mSocketListener.stop();
+ _cleanup();
+ }
+
+ /* Cleanup all local references. Called during onDestroy */
+ private void _cleanup() {
+ if(mBatchs != null) {
+ mBatchs.clear();
+ mBatchs = null;
+ }
+ if(mShares != null) {
+ mShares.clear();
+ mShares = null;
+ }
+ if(mObserver != null)
+ mObserver = null;
+ if(mNotifier != null)
+ mNotifier = null;
+ if(mHandler != null) {
+ mHandler.removeCallbacksAndMessages(null);
+ mHandler = null;
+ }
+ if(mSocketListener != null)
+ mSocketListener = null;
+ if(mPowerManager != null)
+ mPowerManager = null;
+ if(mPendingConnection != null)
+ mPendingConnection = null;
+ if(mTransfer != null) {
+ mTransfer.cleanup();
+ mTransfer = null;
+ }
+ if(mServerTransfer!= null) {
+ mServerTransfer.cleanup();
+ mServerTransfer = null;
+ }
+ if(mAdapter != null)
+ mAdapter = null;
}
/* suppose we auto accept an incoming OPUSH connection */
Log.e(TAG, "Unexpected error! batch id " + batch.mId
+ " doesn't match mTransfer id " + mTransfer.getBatchId());
}
+ mTransfer.cleanup();
mTransfer = null;
} else {
if (mServerTransfer == null) {
+ " doesn't match mServerTransfer id "
+ mServerTransfer.getBatchId());
}
+ mServerTransfer.cleanup();
mServerTransfer = null;
}
removeBatch(batch);
}
}
+ /**
+ * Object cleanup
+ */
+ public void cleanup() {
+ if(mContext != null)
+ mContext = null;
+ if(mAdapter != null)
+ mAdapter = null;
+ if(mBatch != null) {
+ mBatch = null;
+ }
+ if(mSession != null)
+ mSession = null;
+ if(mCurrentShare != null)
+ mCurrentShare = null;
+ if(mTransport != null)
+ mTransport = null;
+ if(mSessionHandler != null) {
+ mSessionHandler = null;
+ }
+ }
+
private void startObexSession() {
mBatch.mStatus = Constants.BATCH_STATUS_RUNNING;
public void onDestroy() {
super.onDestroy();
if (DBG) log("Stopping Bluetooth PanService");
+
+ //Cleanup referenced objects here
+ if(mAdapter != null)
+ mAdapter = null;
+ if(mPanDevices != null) {
+ mPanDevices.clear();
+ mPanDevices = null;
+ }
+ if(mBluetoothIfaceAddresses != null) {
+ mBluetoothIfaceAddresses.clear();
+ mBluetoothIfaceAddresses = null;
+ }
+ if(mPanIfName != null)
+ mPanIfName = null;
+ if(mHandler != null)
+ mHandler.removeCallbacksAndMessages(null);
}
private void start() {
mWakeLock = null;
}
closeService();
+ if(mAdapter != null)
+ mAdapter = null;
+ if(mSessionStatusHandler != null) {
+ mSessionStatusHandler.removeCallbacksAndMessages(null);
+ }
}
@Override