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

Commit 24484f8e authored by Utkarsh Nigam's avatar Utkarsh Nigam Committed by Android (Google) Code Review
Browse files

Merge "Remove timeout logic from AppFunctionManagerService." into main

parents eff4dad4 807d168a
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -204,9 +204,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
                                            serviceIntent,
                                            targetUser,
                                            safeExecuteAppFunctionCallback,
                                            /* bindFlags= */ Context.BIND_AUTO_CREATE,
                                            /* timeoutInMillis= */ mServiceConfig
                                                    .getExecuteAppFunctionTimeoutMillis());
                                            /* bindFlags= */ Context.BIND_AUTO_CREATE);
                                })
                        .exceptionally(
                                ex -> {
@@ -221,13 +219,11 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            @NonNull Intent serviceIntent,
            @NonNull UserHandle targetUser,
            @NonNull SafeOneTimeExecuteAppFunctionCallback safeExecuteAppFunctionCallback,
            int bindFlags,
            long timeoutInMillis) {
            int bindFlags) {
        boolean bindServiceResult =
                mRemoteServiceCaller.runServiceCall(
                        serviceIntent,
                        bindFlags,
                        timeoutInMillis,
                        targetUser,
                        new RunServiceCallCallback<IAppFunctionService>() {
                            @Override
@@ -268,16 +264,6 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
                                                "Failed to connect to AppFunctionService",
                                                /* extras= */ null));
                            }

                            @Override
                            public void onTimedOut() {
                                Slog.e(TAG, "Timed out");
                                safeExecuteAppFunctionCallback.onResult(
                                        ExecuteAppFunctionResponse.newFailure(
                                                ExecuteAppFunctionResponse.RESULT_TIMED_OUT,
                                                "Binding to AppFunctionService timed out.",
                                                /* extras= */ null));
                            }
                        });

        if (!bindServiceResult) {
+0 −8
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ public interface RemoteServiceCaller<T> {
     * @param intent An Intent object that describes the service that should be bound.
     * @param bindFlags Flags used to control the binding process See {@link
     *     android.content.Context#bindService}.
     * @param timeoutInMillis The maximum time in milliseconds to wait for the service connection.
     * @param userHandle The UserHandle of the user for which the service should be bound.
     * @param callback A callback to be invoked for various events. See {@link
     *     RunServiceCallCallback}.
@@ -51,7 +50,6 @@ public interface RemoteServiceCaller<T> {
    boolean runServiceCall(
            @NonNull Intent intent,
            int bindFlags,
            long timeoutInMillis,
            @NonNull UserHandle userHandle,
            @NonNull RunServiceCallCallback<T> callback);

@@ -75,11 +73,5 @@ public interface RemoteServiceCaller<T> {

        /** Called when the service connection was failed to establish. */
        void onFailedToConnect();

        /**
         * Called when the whole operation(i.e. binding and the service call) takes longer than
         * allowed.
         */
        void onTimedOut();
    }
}
+2 −17
Original line number Diff line number Diff line
@@ -62,12 +62,11 @@ public class RemoteServiceCallerImpl<T> implements RemoteServiceCaller<T> {
    public boolean runServiceCall(
            @NonNull Intent intent,
            int bindFlags,
            long timeoutInMillis,
            @NonNull UserHandle userHandle,
            @NonNull RunServiceCallCallback<T> callback) {
        OneOffServiceConnection serviceConnection =
                new OneOffServiceConnection(
                        intent, bindFlags, timeoutInMillis, userHandle, callback);
                        intent, bindFlags, userHandle, callback);

        return serviceConnection.bindAndRun();
    }
@@ -76,28 +75,17 @@ public class RemoteServiceCallerImpl<T> implements RemoteServiceCaller<T> {
            implements ServiceConnection, ServiceUsageCompleteListener {
        private final Intent mIntent;
        private final int mFlags;
        private final long mTimeoutMillis;
        private final UserHandle mUserHandle;
        private final RunServiceCallCallback<T> mCallback;
        private final Runnable mTimeoutCallback;

        OneOffServiceConnection(
                @NonNull Intent intent,
                int flags,
                long timeoutMillis,
                @NonNull UserHandle userHandle,
                @NonNull RunServiceCallCallback<T> callback) {
            mIntent = intent;
            mFlags = flags;
            mTimeoutMillis = timeoutMillis;
            mCallback = callback;
            mTimeoutCallback =
                    () ->
                            mExecutor.execute(
                                    () -> {
                                        safeUnbind();
                                        mCallback.onTimedOut();
                                    });
            mUserHandle = userHandle;
        }

@@ -105,9 +93,7 @@ public class RemoteServiceCallerImpl<T> implements RemoteServiceCaller<T> {
            boolean bindServiceResult =
                    mContext.bindServiceAsUser(mIntent, this, mFlags, mUserHandle);

            if (bindServiceResult) {
                mHandler.postDelayed(mTimeoutCallback, mTimeoutMillis);
            } else {
            if(!bindServiceResult) {
                safeUnbind();
            }

@@ -141,7 +127,6 @@ public class RemoteServiceCallerImpl<T> implements RemoteServiceCaller<T> {

        private void safeUnbind() {
            try {
                mHandler.removeCallbacks(mTimeoutCallback);
                mContext.unbindService(this);
            } catch (Exception ex) {
                Log.w(TAG, "Failed to unbind", ex);