Loading src/com/android/bluetooth/map/BluetoothMapAppObserver.java +35 −8 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ public class BluetoothMapAppObserver{ private PackageManager mPackageManager = null; BluetoothMapAccountLoader mLoader; BluetoothMapService mMapService = null; private boolean mRegisteredReceiver = false; public BluetoothMapAppObserver(final Context context, BluetoothMapService mapService) { mContext = context; Loading Loading @@ -91,8 +92,12 @@ public class BluetoothMapAppObserver{ ArrayList<BluetoothMapAccountItem> oldAccountList = mFullList.get(app); ArrayList<BluetoothMapAccountItem> addedAccountList = (ArrayList<BluetoothMapAccountItem>)newAccountList.clone(); ArrayList<BluetoothMapAccountItem> removedAccountList = mFullList.get(app); // Same as oldAccountList.clone ArrayList<BluetoothMapAccountItem> removedAccountList = mFullList.get(app); if (oldAccountList == null) oldAccountList = new ArrayList <BluetoothMapAccountItem>(); if (removedAccountList == null) removedAccountList = new ArrayList <BluetoothMapAccountItem>(); mFullList.put(app, newAccountList); for(BluetoothMapAccountItem newAcc: newAccountList){ Loading Loading @@ -279,12 +284,26 @@ public class BluetoothMapAppObserver{ } } }; if (!mRegisteredReceiver) { try { mContext.registerReceiver(mReceiver,intentFilter); mRegisteredReceiver = true; } catch (Exception e) { Log.e(TAG,"Unable to register MapAppObserver receiver", e); } } } private void removeReceiver(){ if(D)Log.d(TAG,"removeReceiver()\n"); if (mRegisteredReceiver) { try { mRegisteredReceiver = false; mContext.unregisterReceiver(mReceiver); } catch (Exception e) { Log.e(TAG,"Unable to unregister mapAppObserver receiver", e); } } } /** Loading @@ -296,12 +315,20 @@ public class BluetoothMapAppObserver{ if(D)Log.d(TAG,"getEnabledAccountItems()\n"); ArrayList<BluetoothMapAccountItem> list = new ArrayList<BluetoothMapAccountItem>(); for (BluetoothMapAccountItem app:mFullList.keySet()){ if (app != null) { ArrayList<BluetoothMapAccountItem> accountList = mFullList.get(app); if (accountList != null) { for (BluetoothMapAccountItem acc: accountList) { if (acc.mIsChecked) { list.add(acc); } } } else { Log.w(TAG,"getEnabledAccountItems() - No AccountList enabled\n"); } } else { Log.w(TAG,"getEnabledAccountItems() - No Account in App enabled\n"); } } return list; } Loading src/com/android/bluetooth/map/BluetoothMapService.java +36 −13 Original line number Diff line number Diff line Loading @@ -141,10 +141,12 @@ public class BluetoothMapService extends ProfileService { private boolean mIsWaitingAuthorization = false; private boolean mRemoveTimeoutMsg = false; private boolean mRegisteredMapReceiver = false; private int mPermission = BluetoothDevice.ACCESS_UNKNOWN; private boolean mAccountChanged = false; private boolean mSdpSearchInitiated = false; SdpMnsRecord mMnsRecord = null; private boolean mStartError = true; // package and class name to which we send intent to check phone book access permission private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings"; Loading Loading @@ -452,6 +454,9 @@ public class BluetoothMapService extends ProfileService { return mState; } protected boolean isMapStarted() { return !mStartError; } public BluetoothDevice getRemoteDevice() { return mRemoteDevice; } Loading Loading @@ -569,6 +574,10 @@ public class BluetoothMapService extends ProfileService { @Override protected boolean start() { if (DEBUG) Log.d(TAG, "start()"); if (isMapStarted()) { Log.w(TAG, "start received for already started, ignoring"); return false; } IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); Loading @@ -585,12 +594,14 @@ public class BluetoothMapService extends ProfileService { } catch (MalformedMimeTypeException e) { Log.e(TAG, "Wrong mime type!!!", e); } if (!mRegisteredMapReceiver) { try { registerReceiver(mMapReceiver, filter); registerReceiver(mMapReceiver, filterMessageSent); mRegisteredMapReceiver = true; } catch (Exception e) { Log.w(TAG,"Unable to register map receiver",e); Log.e(TAG,"Unable to register map receiver",e); } } mAdapter = BluetoothAdapter.getDefaultAdapter(); mAppObserver = new BluetoothMapAppObserver(this, this); Loading @@ -601,7 +612,8 @@ public class BluetoothMapService extends ProfileService { // start RFCOMM listener sendStartListenerMessage(-1); return true; mStartError = false; return !mStartError; } /** Loading Loading @@ -762,13 +774,24 @@ public class BluetoothMapService extends ProfileService { @Override protected boolean stop() { if (DEBUG) Log.d(TAG, "stop()"); if (mRegisteredMapReceiver) { try { mRegisteredMapReceiver = false; unregisterReceiver(mMapReceiver); mAppObserver.shutdown(); } catch (Exception e) { Log.w(TAG,"Unable to unregister map receiver",e); Log.e(TAG,"Unable to unregister map receiver",e); } } //Stop MapProfile if already started. //TODO: Check if the profile state can be retreived from ProfileService or AdapterService. if (!isMapStarted()) { if (DEBUG) Log.d(TAG, "Service Not Available to STOP, ignoring"); return true; } else { if (VERBOSE) Log.d(TAG, "Service Stoping()"); } mStartError = true; setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED); sendShutdownMessage(); return true; Loading Loading
src/com/android/bluetooth/map/BluetoothMapAppObserver.java +35 −8 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ public class BluetoothMapAppObserver{ private PackageManager mPackageManager = null; BluetoothMapAccountLoader mLoader; BluetoothMapService mMapService = null; private boolean mRegisteredReceiver = false; public BluetoothMapAppObserver(final Context context, BluetoothMapService mapService) { mContext = context; Loading Loading @@ -91,8 +92,12 @@ public class BluetoothMapAppObserver{ ArrayList<BluetoothMapAccountItem> oldAccountList = mFullList.get(app); ArrayList<BluetoothMapAccountItem> addedAccountList = (ArrayList<BluetoothMapAccountItem>)newAccountList.clone(); ArrayList<BluetoothMapAccountItem> removedAccountList = mFullList.get(app); // Same as oldAccountList.clone ArrayList<BluetoothMapAccountItem> removedAccountList = mFullList.get(app); if (oldAccountList == null) oldAccountList = new ArrayList <BluetoothMapAccountItem>(); if (removedAccountList == null) removedAccountList = new ArrayList <BluetoothMapAccountItem>(); mFullList.put(app, newAccountList); for(BluetoothMapAccountItem newAcc: newAccountList){ Loading Loading @@ -279,12 +284,26 @@ public class BluetoothMapAppObserver{ } } }; if (!mRegisteredReceiver) { try { mContext.registerReceiver(mReceiver,intentFilter); mRegisteredReceiver = true; } catch (Exception e) { Log.e(TAG,"Unable to register MapAppObserver receiver", e); } } } private void removeReceiver(){ if(D)Log.d(TAG,"removeReceiver()\n"); if (mRegisteredReceiver) { try { mRegisteredReceiver = false; mContext.unregisterReceiver(mReceiver); } catch (Exception e) { Log.e(TAG,"Unable to unregister mapAppObserver receiver", e); } } } /** Loading @@ -296,12 +315,20 @@ public class BluetoothMapAppObserver{ if(D)Log.d(TAG,"getEnabledAccountItems()\n"); ArrayList<BluetoothMapAccountItem> list = new ArrayList<BluetoothMapAccountItem>(); for (BluetoothMapAccountItem app:mFullList.keySet()){ if (app != null) { ArrayList<BluetoothMapAccountItem> accountList = mFullList.get(app); if (accountList != null) { for (BluetoothMapAccountItem acc: accountList) { if (acc.mIsChecked) { list.add(acc); } } } else { Log.w(TAG,"getEnabledAccountItems() - No AccountList enabled\n"); } } else { Log.w(TAG,"getEnabledAccountItems() - No Account in App enabled\n"); } } return list; } Loading
src/com/android/bluetooth/map/BluetoothMapService.java +36 −13 Original line number Diff line number Diff line Loading @@ -141,10 +141,12 @@ public class BluetoothMapService extends ProfileService { private boolean mIsWaitingAuthorization = false; private boolean mRemoveTimeoutMsg = false; private boolean mRegisteredMapReceiver = false; private int mPermission = BluetoothDevice.ACCESS_UNKNOWN; private boolean mAccountChanged = false; private boolean mSdpSearchInitiated = false; SdpMnsRecord mMnsRecord = null; private boolean mStartError = true; // package and class name to which we send intent to check phone book access permission private static final String ACCESS_AUTHORITY_PACKAGE = "com.android.settings"; Loading Loading @@ -452,6 +454,9 @@ public class BluetoothMapService extends ProfileService { return mState; } protected boolean isMapStarted() { return !mStartError; } public BluetoothDevice getRemoteDevice() { return mRemoteDevice; } Loading Loading @@ -569,6 +574,10 @@ public class BluetoothMapService extends ProfileService { @Override protected boolean start() { if (DEBUG) Log.d(TAG, "start()"); if (isMapStarted()) { Log.w(TAG, "start received for already started, ignoring"); return false; } IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); Loading @@ -585,12 +594,14 @@ public class BluetoothMapService extends ProfileService { } catch (MalformedMimeTypeException e) { Log.e(TAG, "Wrong mime type!!!", e); } if (!mRegisteredMapReceiver) { try { registerReceiver(mMapReceiver, filter); registerReceiver(mMapReceiver, filterMessageSent); mRegisteredMapReceiver = true; } catch (Exception e) { Log.w(TAG,"Unable to register map receiver",e); Log.e(TAG,"Unable to register map receiver",e); } } mAdapter = BluetoothAdapter.getDefaultAdapter(); mAppObserver = new BluetoothMapAppObserver(this, this); Loading @@ -601,7 +612,8 @@ public class BluetoothMapService extends ProfileService { // start RFCOMM listener sendStartListenerMessage(-1); return true; mStartError = false; return !mStartError; } /** Loading Loading @@ -762,13 +774,24 @@ public class BluetoothMapService extends ProfileService { @Override protected boolean stop() { if (DEBUG) Log.d(TAG, "stop()"); if (mRegisteredMapReceiver) { try { mRegisteredMapReceiver = false; unregisterReceiver(mMapReceiver); mAppObserver.shutdown(); } catch (Exception e) { Log.w(TAG,"Unable to unregister map receiver",e); Log.e(TAG,"Unable to unregister map receiver",e); } } //Stop MapProfile if already started. //TODO: Check if the profile state can be retreived from ProfileService or AdapterService. if (!isMapStarted()) { if (DEBUG) Log.d(TAG, "Service Not Available to STOP, ignoring"); return true; } else { if (VERBOSE) Log.d(TAG, "Service Stoping()"); } mStartError = true; setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED); sendShutdownMessage(); return true; Loading