Loading src/com/android/bluetooth/btservice/AdapterService.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -327,9 +327,11 @@ public class AdapterService extends Service { public void addProfile(ProfileService profile) { public void addProfile(ProfileService profile) { synchronized (mProfiles) { synchronized (mProfiles) { if (!mProfiles.contains(profile)) { mProfiles.add(profile); mProfiles.add(profile); } } } } } public void removeProfile(ProfileService profile) { public void removeProfile(ProfileService profile) { synchronized (mProfiles) { synchronized (mProfiles) { Loading src/com/android/bluetooth/btservice/ProfileService.java +15 −13 Original line number Original line Diff line number Diff line Loading @@ -53,8 +53,6 @@ public abstract class ProfileService extends Service { protected boolean mStartError=false; protected boolean mStartError=false; private boolean mCleaningUp = false; private boolean mCleaningUp = false; private AdapterService mAdapterService; protected String getName() { protected String getName() { return getClass().getSimpleName(); return getClass().getSimpleName(); } } Loading Loading @@ -107,16 +105,17 @@ public abstract class ProfileService extends Service { super.onCreate(); super.onCreate(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mBinder = initBinder(); mBinder = initBinder(); mAdapterService = AdapterService.getAdapterService(); if (mAdapterService != null) { mAdapterService.addProfile(this); } else { Log.w(TAG, "onCreate, null mAdapterService"); } } } public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) { if (DBG) log("onStartCommand()"); if (DBG) log("onStartCommand()"); AdapterService adapterService = AdapterService.getAdapterService(); if (adapterService != null) { adapterService.addProfile(this); } else { Log.w(TAG, "Could not add this profile because AdapterService is null."); } if (mStartError || mAdapter == null) { if (mStartError || mAdapter == null) { Log.w(mName, "Stopping profile service: device does not have BT"); Log.w(mName, "Stopping profile service: device does not have BT"); doStop(intent); doStop(intent); Loading Loading @@ -176,7 +175,8 @@ public abstract class ProfileService extends Service { @Override @Override public void onDestroy() { public void onDestroy() { if (DBG) log("Destroying service."); if (DBG) log("Destroying service."); if (mAdapterService != null) mAdapterService.removeProfile(this); AdapterService adapterService = AdapterService.getAdapterService(); if (adapterService != null) adapterService.removeProfile(this); if (mCleaningUp) { if (mCleaningUp) { if (DBG) log("Cleanup already started... Skipping cleanup()..."); if (DBG) log("Cleanup already started... Skipping cleanup()..."); Loading Loading @@ -220,15 +220,17 @@ public abstract class ProfileService extends Service { protected void notifyProfileServiceStateChanged(int state) { protected void notifyProfileServiceStateChanged(int state) { //Notify adapter service //Notify adapter service if (mAdapterService != null) { AdapterService adapterService = AdapterService.getAdapterService(); mAdapterService.onProfileServiceStateChanged(getClass().getName(), state); if (adapterService != null) { adapterService.onProfileServiceStateChanged(getClass().getName(), state); } } } } public void notifyProfileConnectionStateChanged(BluetoothDevice device, public void notifyProfileConnectionStateChanged(BluetoothDevice device, int profileId, int newState, int prevState) { int profileId, int newState, int prevState) { if (mAdapterService != null) { AdapterService adapterService = AdapterService.getAdapterService(); mAdapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState); if (adapterService != null) { adapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState); } } } } Loading Loading
src/com/android/bluetooth/btservice/AdapterService.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -327,9 +327,11 @@ public class AdapterService extends Service { public void addProfile(ProfileService profile) { public void addProfile(ProfileService profile) { synchronized (mProfiles) { synchronized (mProfiles) { if (!mProfiles.contains(profile)) { mProfiles.add(profile); mProfiles.add(profile); } } } } } public void removeProfile(ProfileService profile) { public void removeProfile(ProfileService profile) { synchronized (mProfiles) { synchronized (mProfiles) { Loading
src/com/android/bluetooth/btservice/ProfileService.java +15 −13 Original line number Original line Diff line number Diff line Loading @@ -53,8 +53,6 @@ public abstract class ProfileService extends Service { protected boolean mStartError=false; protected boolean mStartError=false; private boolean mCleaningUp = false; private boolean mCleaningUp = false; private AdapterService mAdapterService; protected String getName() { protected String getName() { return getClass().getSimpleName(); return getClass().getSimpleName(); } } Loading Loading @@ -107,16 +105,17 @@ public abstract class ProfileService extends Service { super.onCreate(); super.onCreate(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapter = BluetoothAdapter.getDefaultAdapter(); mBinder = initBinder(); mBinder = initBinder(); mAdapterService = AdapterService.getAdapterService(); if (mAdapterService != null) { mAdapterService.addProfile(this); } else { Log.w(TAG, "onCreate, null mAdapterService"); } } } public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) { if (DBG) log("onStartCommand()"); if (DBG) log("onStartCommand()"); AdapterService adapterService = AdapterService.getAdapterService(); if (adapterService != null) { adapterService.addProfile(this); } else { Log.w(TAG, "Could not add this profile because AdapterService is null."); } if (mStartError || mAdapter == null) { if (mStartError || mAdapter == null) { Log.w(mName, "Stopping profile service: device does not have BT"); Log.w(mName, "Stopping profile service: device does not have BT"); doStop(intent); doStop(intent); Loading Loading @@ -176,7 +175,8 @@ public abstract class ProfileService extends Service { @Override @Override public void onDestroy() { public void onDestroy() { if (DBG) log("Destroying service."); if (DBG) log("Destroying service."); if (mAdapterService != null) mAdapterService.removeProfile(this); AdapterService adapterService = AdapterService.getAdapterService(); if (adapterService != null) adapterService.removeProfile(this); if (mCleaningUp) { if (mCleaningUp) { if (DBG) log("Cleanup already started... Skipping cleanup()..."); if (DBG) log("Cleanup already started... Skipping cleanup()..."); Loading Loading @@ -220,15 +220,17 @@ public abstract class ProfileService extends Service { protected void notifyProfileServiceStateChanged(int state) { protected void notifyProfileServiceStateChanged(int state) { //Notify adapter service //Notify adapter service if (mAdapterService != null) { AdapterService adapterService = AdapterService.getAdapterService(); mAdapterService.onProfileServiceStateChanged(getClass().getName(), state); if (adapterService != null) { adapterService.onProfileServiceStateChanged(getClass().getName(), state); } } } } public void notifyProfileConnectionStateChanged(BluetoothDevice device, public void notifyProfileConnectionStateChanged(BluetoothDevice device, int profileId, int newState, int prevState) { int profileId, int newState, int prevState) { if (mAdapterService != null) { AdapterService adapterService = AdapterService.getAdapterService(); mAdapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState); if (adapterService != null) { adapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState); } } } } Loading