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

Commit 06f0519a authored by Eugene Susla's avatar Eugene Susla
Browse files

Make RemoteService propagate Context#bindService failure to PendingRequests

...and fix the attached bug which was caused by infinite wait due to lack
of said signal

Fixes: 129549258
Bug: 126266412
Test: - atest CtsContentCaptureServiceTestCases
- Ensure b/129549258#comment5 no longer reproduces
Change-Id: Id434ce268ca4ae6aa09140a3e17b6d8f476f3d9f
parent dd07ae57
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -252,6 +252,11 @@ public class RoleControllerManager {
                Log.e(LOG_TAG, "Error calling grantDefaultRoles()", e);
            }
        }

        @Override
        protected void onFailed() {
            mRemoteCallback.sendResult(null);
        }
    }

    /**
+14 −0
Original line number Diff line number Diff line
@@ -75,6 +75,20 @@ public abstract class AbstractMultiplePendingRequestsRemoteService<S
        }
    }

    @Override // from AbstractRemoteService
    final void handleBindFailure() {
        if (mPendingRequests != null) {
            final int size = mPendingRequests.size();
            if (mVerbose) Slog.v(mTag, "Sending failure to " + size + " pending requests");
            for (int i = 0; i < size; i++) {
                final BasePendingRequest<S, I> request = mPendingRequests.get(i);
                request.onFailed();
                request.finish();
            }
            mPendingRequests = null;
        }
    }

    @Override // from AbstractRemoteService
    public void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
        super.dump(prefix, pw);
+13 −0
Original line number Diff line number Diff line
@@ -397,6 +397,11 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
    abstract void handlePendingRequestWhileUnBound(
            @NonNull BasePendingRequest<S, I> pendingRequest);

    /**
     * Called if {@link Context#bindServiceAsUser} returns {@code false}.
     */
    abstract void handleBindFailure();

    private boolean handleIsBound() {
        return mService != null;
    }
@@ -418,6 +423,8 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
            mBinding = false;

            if (!mServiceDied) {
                // TODO(b/126266412): merge these 2 calls?
                handleBindFailure();
                handleBinderDied();
            }
        }
@@ -546,6 +553,12 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I

        void onFinished() { }

        /**
         * Called when request fails due to reasons internal to {@link AbstractRemoteService},
         * e.g. failure to bind to service.
         */
        protected void onFailed() { }

        /**
         * Checks whether this request was cancelled.
         */
+9 −0
Original line number Diff line number Diff line
@@ -66,6 +66,15 @@ public abstract class AbstractSinglePendingRequestRemoteService<S
        }
    }

    @Override // from AbstractRemoteService
    void handleBindFailure() {
        if (mPendingRequest != null) {
            if (mVerbose) Slog.v(mTag, "Sending failure to " + mPendingRequest);
            mPendingRequest.onFailed();
            mPendingRequest = null;
        }
    }

    @Override // from AbstractRemoteService
    public void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
        super.dump(prefix, pw);