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

Commit 2daa6268 authored by Sandeep Bandaru's avatar Sandeep Bandaru
Browse files

Stop calling binder.linkToDeath in ServiceConnector.

Since `binderDied()` callback is same signal as service crashing, and prior implementation ultimately either invokes `unbind()` due to `binderDied()` following a `onServiceDisconnected` or vice-versa.
It is more straightforward to call `unbind()` regardless, whenever `onServiceDisconnected` invoked, so this cleans up resources, allows rebinding upon receiving a client request.

This change removes impl for `onBindingDied` and `binderDied` since we expect to do same behavior in those cases and avoid duplicate calls of `unbind` by not implementing them.

Bug: 418214801
Bug: 424695730
Flag: EXEMPT bugfix
Change-Id: I6d006df08174e6309f5c1e6b1581f457a7e69493
parent 849ff146
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -62,21 +62,4 @@ public class RemoteOnDeviceIntelligenceService extends
                TimeUnit.SECONDS.toMillis(30),
                mContext.getUserId());
    }

    @Override
    public void onBindingDied(@NonNull ComponentName name) {
        // When the binding dies, unbind to allow the service to be re-bound.
        unbind();
    }

    @Override
    public void binderDied() {
        // When the binder dies, dispatch the event to the clients
        // and cancel pending jobs.
        getJobHandler().post(() -> {
            dispatchOnBinderDied();
            cancelTimeout();
            cancelPendingJobs(); // TODO:418214801 - Evaluate if this can be removed.
        });
    }
}
+0 −17
Original line number Diff line number Diff line
@@ -72,21 +72,4 @@ public class RemoteOnDeviceSandboxedInferenceService extends
                TimeUnit.SECONDS.toMillis(30),
                mContext.getUserId());
    }

    @Override
    public void onBindingDied(@NonNull ComponentName name) {
        // When the binding dies, unbind to allow the service to be re-bound.
        unbind();
    }

    @Override
    public void binderDied() {
        // When the binder dies, dispatch the event to the clients
        // and cancel pending jobs.
        getJobHandler().post(() -> {
            dispatchOnBinderDied();
            cancelTimeout();
            cancelPendingJobs(); // TODO:418214801 - Evaluate if this can be removed.
        });
    }
}
+1 −30
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ public interface ServiceConnector<I extends IInterface> {
     * @param <I> see {@link ServiceConnector}
     */
    class Impl<I extends IInterface> extends ArrayDeque<Job<I, ?>>
            implements ServiceConnector<I>, ServiceConnection, IBinder.DeathRecipient, Runnable {
            implements ServiceConnector<I>, ServiceConnection, Runnable {

        static final boolean DEBUG = false;
        final String LOG_TAG = this.getClass().getSimpleName();
@@ -580,7 +580,6 @@ public interface ServiceConnector<I extends IInterface> {
            }
            if (wasBound) {
                dispatchOnServiceConnectionStatusChanged(service, false);
                service.asBinder().unlinkToDeath(this, 0);
                mService = null;
            }
            mBinding = false;
@@ -624,11 +623,6 @@ public interface ServiceConnector<I extends IInterface> {
            I service = binderAsInterface(binder);
            mService = service;
            mBinding = false;
            try {
                binder.linkToDeath(ServiceConnector.Impl.this, 0);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, "onServiceConnected " + name + ": ", e);
            }
            dispatchOnServiceConnectionStatusChanged(service, true);
            processQueue();
        }
@@ -638,30 +632,7 @@ public interface ServiceConnector<I extends IInterface> {
            if (DEBUG) {
                logTrace();
            }
            mBinding = true;
            I service = mService;
            if (service != null) {
                dispatchOnServiceConnectionStatusChanged(service, false);
                mService = null;
            }
        }

        @Override
        public void onBindingDied(@NonNull ComponentName name) {
            if (DEBUG) {
                logTrace();
            }
            binderDied();
        }

        @Override
        public void binderDied() {
            if (DEBUG) {
                logTrace();
            }
            mService = null;
            unbind();
            dispatchOnBinderDied();
        }

        protected void dispatchOnBinderDied() {