Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d3d71c1 authored by Calvin On's avatar Calvin On Committed by android-build-merger
Browse files

Merge \"Use the live AdapterService in ProfileService.\" into nyc-mr1-dev

am: ae20236e

Change-Id: I295257c0afd078410881f2d709dcf68c5ab03947
parents 553e11b4 ae20236e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -327,9 +327,11 @@ public class AdapterService extends Service {

    public void addProfile(ProfileService profile) {
        synchronized (mProfiles) {
            if (!mProfiles.contains(profile)) {
                mProfiles.add(profile);
            }
        }
    }

    public void removeProfile(ProfileService profile) {
        synchronized (mProfiles) {
+15 −13
Original line number Diff line number Diff line
@@ -53,8 +53,6 @@ public abstract class ProfileService extends Service {
    protected boolean mStartError=false;
    private boolean mCleaningUp = false;

    private AdapterService mAdapterService;

    protected String getName() {
        return getClass().getSimpleName();
    }
@@ -107,16 +105,17 @@ public abstract class ProfileService extends Service {
        super.onCreate();
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        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) {
        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) {
            Log.w(mName, "Stopping profile service: device does not have BT");
            doStop(intent);
@@ -176,7 +175,8 @@ public abstract class ProfileService extends Service {
    @Override
    public void onDestroy() {
        if (DBG) log("Destroying service.");
        if (mAdapterService != null) mAdapterService.removeProfile(this);
        AdapterService adapterService = AdapterService.getAdapterService();
        if (adapterService != null) adapterService.removeProfile(this);

        if (mCleaningUp) {
            if (DBG) log("Cleanup already started... Skipping cleanup()...");
@@ -220,15 +220,17 @@ public abstract class ProfileService extends Service {

    protected void notifyProfileServiceStateChanged(int state) {
        //Notify adapter service
        if (mAdapterService != null) {
            mAdapterService.onProfileServiceStateChanged(getClass().getName(), state);
        AdapterService adapterService = AdapterService.getAdapterService();
        if (adapterService != null) {
            adapterService.onProfileServiceStateChanged(getClass().getName(), state);
        }
    }

    public void notifyProfileConnectionStateChanged(BluetoothDevice device,
            int profileId, int newState, int prevState) {
        if (mAdapterService != null) {
            mAdapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState);
        AdapterService adapterService = AdapterService.getAdapterService();
        if (adapterService != null) {
            adapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState);
        }
    }