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

Commit 807d168a authored by Utkarsh Nigam's avatar Utkarsh Nigam
Browse files

Remove timeout logic from AppFunctionManagerService.

https://docs.google.com/document/d/1d2KLWoymaaf-UXKmSgWJeuzMTct4k1G53ZQMhx_6_M8/edit?tab=t.0

Change-Id: Icc87315c1ec594030b3a8ce266fb2c0cd93f3064
Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: atest CtsAppFunctionTestCases -c
Bug: 360864791
parent 97344c76
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);