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

Commit 67815e4f authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Fix unbind crash in AbstractRemoteService.

Crashes if there's an attempt to unbind when the service isn't already
bound. It's unclear which service is triggering this code path though.

Fix: 230543089
Change-Id: Ia108c709ed3c82ca18e581b464c963d52e108a3e
parent d88a6933
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
    private final int mBindingFlags;
    protected I mService;

    private boolean mBound;
    private boolean mConnecting;
    private boolean mDestroyed;
    private boolean mServiceDied;
@@ -255,8 +256,10 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
                .append(String.valueOf(mDestroyed)).println();
        pw.append(prefix).append(tab).append("numUnfinishedRequests=")
                .append(String.valueOf(mUnfinishedRequests.size())).println();
        final boolean bound = handleIsBound();
        pw.append(prefix).append(tab).append("bound=")
                .append(String.valueOf(mBound));
        final boolean bound = handleIsBound();
        pw.append(prefix).append(tab).append("connected=")
                .append(String.valueOf(bound));
        final long idleTimeout = getTimeoutIdleBindMillis();
        if (bound) {
@@ -430,6 +433,8 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
     */
    abstract void handleBindFailure();

    // This is actually checking isConnected. TODO: rename this and other related methods (or just
    // stop using this class..)
    private boolean handleIsBound() {
        return mService != null;
    }
@@ -445,6 +450,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I

        final boolean willBind = mContext.bindServiceAsUser(mIntent, mServiceConnection, flags,
                mHandler, new UserHandle(mUserId));
        mBound = true;

        if (!willBind) {
            Slog.w(mTag, "could not bind to " + mIntent + " using flags " + flags);
@@ -469,7 +475,10 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
            }
        }
        mNextUnbind = 0;
        if (mBound) {
            mContext.unbindService(mServiceConnection);
            mBound = false;
        }
    }

    private class RemoteServiceConnection implements ServiceConnection {