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

Commit 54c0a196 authored by William Escande's avatar William Escande
Browse files

ProfileService: remove adapter and set binder as final

mAdapter is not possible to be null when a service is starting
mBinder should never be set to null as it is not expected to be cleared

Bug: 291815510
Test: m com.android.btservices
Test: atest BluetoothInstrumentationTest
Flag: EXEMPT, no-op
Change-Id: Ibad098f5bc36fe5d1966842325afb039ea6721b7
parent 69574b75
Loading
Loading
Loading
Loading
+4 −16
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@ public abstract class ProfileService extends ContextWrapper {
        void cleanup();
    }

    private BluetoothAdapter mAdapter;
    private IProfileServiceBinder mBinder;
    private final IProfileServiceBinder mBinder;
    private final String mName;
    private AdapterService mAdapterService;
    private boolean mProfileStarted = false;
@@ -69,7 +68,7 @@ public abstract class ProfileService extends ContextWrapper {
    }

    /**
     * Called in {@link #onCreate()} to init binder interface for this profile service
     * Called in ProfileService constructor to init binder interface for this profile service
     *
     * @return initialized binder interface for this profile service
     */
@@ -107,13 +106,11 @@ public abstract class ProfileService extends ContextWrapper {
        if (DBG) {
            Log.d(mName, "Service created");
        }
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mBinder = initBinder();
        mBinder = requireNonNull(initBinder(), "Binder null is not allowed for " + mName);
    }

    /** return the binder of the profile */
    public IBinder getBinder() {
        requireNonNull(mBinder, "Binder is null. onCreate need to be called first");
        return mBinder;
    }

@@ -212,11 +209,6 @@ public abstract class ProfileService extends ContextWrapper {
    @VisibleForTesting
    public void doStart() {
        Log.v(mName, "doStart");
        if (mAdapter == null) {
            Log.w(mName, "Can't start profile service: device does not have BT");
            return;
        }

        mAdapterService = AdapterService.getAdapterService();
        if (mAdapterService == null) {
            Log.w(mName, "Could not add this profile because AdapterService is null.");
@@ -255,10 +247,6 @@ public abstract class ProfileService extends ContextWrapper {
            mAdapterService.removeProfile(this);
        }
        cleanup();
        if (mBinder != null) {
        mBinder.cleanup();
            mBinder = null;
        }
        mAdapter = null;
    }
}