}
protected boolean stop() {
- // TODO(BT) mStateMachine.quit();
+ mStateMachine.doQuit();
return true;
}
protected boolean cleanup() {
if (mStateMachine!= null) {
mStateMachine.cleanup();
- mStateMachine=null;
}
return true;
}
}
+ public void doQuit() {
+ quitNow();
+ }
+
public void cleanup() {
cleanupNative();
- if(mService != null)
- mService = null;
- if (mContext != null)
- mContext = null;
- if(mAdapter != null)
- mAdapter = null;
}
private class Disconnected extends State {
mCleaningUp = true;
if (mAdapterStateMachine != null) {
- // TODO(BT) mAdapterStateMachine.quit();
+ mAdapterStateMachine.doQuit();
mAdapterStateMachine.cleanup();
- mAdapterStateMachine = null;
}
if (mBondStateMachine != null) {
- // TODO(BT) mBondStateMachine.quit();
+ mBondStateMachine.doQuit();
mBondStateMachine.cleanup();
- mBondStateMachine = null;
}
if (mRemoteDevices != null) {
mRemoteDevices.cleanup();
- mRemoteDevices = null;
}
if (mNativeAvailable) {
if (mAdapterProperties != null) {
mAdapterProperties.cleanup();
- mAdapterProperties = null;
}
if (mJniCallbacks != null) {
mJniCallbacks.cleanup();
- mJniCallbacks = null;
}
if (mProfileServicesState != null) {
mProfileServicesState.clear();
- mProfileServicesState= null;
}
clearAdapterService();
if (mBinder != null) {
mBinder.cleanup();
- mBinder = null;
+ mBinder = null; //Do not remove. Otherwise Binder leak!
}
if (mCallbacks !=null) {
setInitialState(mOffState);
}
+
+ public void doQuit() {
+ quitNow();
+ }
+
public void cleanup() {
if(mAdapterProperties != null)
mAdapterProperties = null;
@Override
public boolean processMessage(Message msg) {
- /* TODO(BT) if (msg.what == SM_QUIT_CMD) {
- Log.d(TAG, "Received quit request...");
- return false;
- } */
switch(msg.what) {
case USER_TURN_ON:
@Override
public boolean processMessage(Message msg) {
+
switch(msg.what) {
case USER_TURN_OFF:
if (DBG) Log.d(TAG,"CURRENT_STATE=ON, MESSAGE = USER_TURN_OFF");
@Override
public boolean processMessage(Message msg) {
+
boolean isTurningOn= isTurningOn();
boolean isTurningOff = isTurningOff();
+
switch (msg.what) {
case USER_TURN_ON:
if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = USER_TURN_ON"
private void errorLog(String msg) {
Log.e(TAG, msg);
}
+
}
setInitialState(mStableState);
}
+ public void doQuit() {
+ quitNow();
+ }
+
public void cleanup() {
mAdapterService = null;
mRemoteDevices = null;
@Override
public boolean processMessage(Message msg) {
- // TODO(BT)
- // if (msg.what == SM_QUIT_CMD) {
- // Log.d(TAG, "Received quit request...");
- // return false;
- // }
-
BluetoothDevice dev = (BluetoothDevice)msg.obj;
@Override
public boolean processMessage(Message msg) {
- // TODO(BT)
- // if (msg.what == SM_QUIT_CMD) {
- // Log.d(TAG, "PendingCommandState(): Received quit request...");
- // return false;
- // }
BluetoothDevice dev = (BluetoothDevice)msg.obj;
boolean result = false;
private void errorLog(String msg) {
Log.e(TAG, msg);
}
+
}
void cleanup() {
- mSdpTracker.clear();
- mSdpTracker = null;
- mDevices.clear();
- mDevices = null;
- mAdapterService = null;
- mAdapter= null;
+ if (mSdpTracker !=null)
+ mSdpTracker.clear();
+
+ if (mDevices != null)
+ mDevices.clear();
}
public Object Clone() throws CloneNotSupportedException {
}
if(mHealthChannels != null) {
mHealthChannels.clear();
- mHealthChannels = null;
}
if(mHealthDevices != null) {
mHealthDevices.clear();
- mHealthDevices = null;
}
if(mApps != null) {
mApps.clear();
- mApps = null;
}
return true;
}
public void cleanup() {
mPhonebooks.clear();
- mContentResolver = null;
- mContext = null;
- mStateMachine = null;
}
/** Returns the last dialled number, or null if no numbers have been called */
}
int size = pbr.cursor.getCount();
atCommandResponse = "+CPBS: \"" + mCurrentPhonebook + "\"," + size + "," + getMaxPhoneBookSize(size);
+ pbr.cursor.close();
+ pbr.cursor = null;
atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
break;
case TYPE_TEST: // Test
}
size = pbr.cursor.getCount();
log("handleCpbrCommand - size = "+size);
+ pbr.cursor.close();
+ pbr.cursor = null;
}
if (size == 0) {
/* Sending "+CPBR: (1-0)" can confused some carkits, send "1-1" * instead */
break;
}
}
+ if(pbr != null && pbr.cursor != null) {
+ pbr.cursor.close();
+ pbr.cursor = null;
+ }
return atCommandResult;
}
} catch (Exception e) {
Log.w(TAG,"Unable to unregister headset receiver",e);
}
- // TODO(BT) mStateMachine.quit();
+ mStateMachine.doQuit();
return true;
}
protected boolean cleanup() {
if (mStateMachine != null) {
mStateMachine.cleanup();
- mStateMachine=null;
}
return true;
}
setInitialState(mDisconnected);
}
+
+ public void doQuit() {
+ quitNow();
+ }
+
public void cleanup() {
if (mPhoneProxy != null) {
if (DBG) Log.d(TAG,"Unbinding service...");
if (mPhoneState != null) {
mPhoneState.listenForPhoneState(false);
mPhoneState.cleanup();
- mPhoneState=null;
}
if (mPhonebook != null) {
mPhonebook.cleanup();
- mPhonebook = null;
}
if (mNativeAvailable) {
cleanupNative();
mNativeAvailable = false;
}
- mService = null;
- mAdapter = null;
}
private class Disconnected extends State {
if(mInputDevices != null) {
mInputDevices.clear();
- mInputDevices = null;
}
return true;
}
private static final boolean V = Constants.VERBOSE;
public static final int MSG_INCOMING_BTOPP_CONNECTION = 100;
- private static final int JOIN_TIMEOUT_MS=2000;
private volatile boolean mInterrupted;
- private volatile boolean mFinish;
private Thread mSocketAcceptThread;
Log.e(TAG, "Error create RfcommServerSocket " + e1);
serverOK = false;
}
+
if (!serverOK) {
synchronized (this) {
try {
- if (V) Log.v(TAG, "Wait 3 seconds");
- Thread.sleep(3000);
+ if (V) Log.v(TAG, "Wait 300 ms");
+ Thread.sleep(300);
} catch (InterruptedException e) {
Log.e(TAG, "socketAcceptThread thread was interrupted (3)");
mInterrupted = true;
}
} catch (IOException e) {
Log.e(TAG, "Error accept connection " + e);
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException ie) {}
}
}
Log.i(TAG, "BluetoothSocket listen thread finished");
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;
BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE);
}
mPanDevices.clear();
- mPanDevices = null;
}
if(mBluetoothIfaceAddresses != null) {
mBluetoothIfaceAddresses.clear();
- mBluetoothIfaceAddresses = null;
}
- if(mPanIfName != null)
- mPanIfName = null;
return true;
}
in.putExtra(BluetoothAdapter.EXTRA_STATE, state);
if (V) Log.v(TAG,"***********state = " + state);
if ((state == BluetoothAdapter.STATE_TURNING_ON)
- || (state == BluetoothAdapter.STATE_TURNING_OFF)) {
+ || (state == BluetoothAdapter.STATE_OFF)) {
+ //FIX: We turn on PBAP after BluetoothAdapter.STATE_ON,
+ //but we turn off PBAP right after BluetoothAdapter.STATE_TURNING_OFF
startService = false;
}
} else {
boolean removeTimeoutMsg = true;
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
- if (state == BluetoothAdapter.STATE_OFF) {
+ if (state == BluetoothAdapter.STATE_TURNING_OFF) {
// Send any pending timeout now, as this service will be destroyed.
if (mSessionStatusHandler.hasMessages(USER_TIMEOUT)) {
Intent timeoutIntent =
try {
// It is mandatory for PSE to support initiation of bonding and
// encryption.
- mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord(
- "OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid());
+ mServerSocket = mAdapter.listenUsingEncryptedRfcommWithServiceRecord("OBEX Phonebook Access Server", BluetoothUuid.PBAP_PSE.getUuid());
} catch (IOException e) {
Log.e(TAG, "Error create RfcommServerSocket " + e.toString());
if (!initSocketOK) {
synchronized (this) {
try {
- if (VERBOSE) Log.v(TAG, "wait 3 seconds");
- Thread.sleep(3000);
+ if (VERBOSE) Log.v(TAG, "wait 300 ms");
+ Thread.sleep(300);
} catch (InterruptedException e) {
Log.e(TAG, "socketAcceptThread thread was interrupted (3)");
mInterrupted = true;