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

Commit e35a423c authored by Soonil Nagarkar's avatar Soonil Nagarkar Committed by Android (Google) Code Review
Browse files

Merge "Handle bind failure in ServiceWatcher"

parents 007a9ef1 99a08270
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class ServiceWatcher implements ServiceConnection {
    private static final String EXTRA_SERVICE_VERSION = "serviceVersion";
    private static final String EXTRA_SERVICE_IS_MULTIUSER = "serviceIsMultiuser";

    private static final long RETRY_DELAY_MS = 15 * 1000;

    /** Function to run on binder interface. */
    public interface BinderRunner {
        /** Called to run client code with the binder. */
@@ -110,6 +112,10 @@ public class ServiceWatcher implements ServiceConnection {
            this.userId = userId;
        }

        public @Nullable String getPackageName() {
            return component != null ? component.getPackageName() : null;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
@@ -318,9 +324,13 @@ public class ServiceWatcher implements ServiceConnection {
        }

        Intent bindIntent = new Intent(mIntent).setComponent(mServiceInfo.component);
        mContext.bindServiceAsUser(bindIntent, this,
        if (!mContext.bindServiceAsUser(bindIntent, this,
                BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE,
                mHandler, UserHandle.of(mServiceInfo.userId));
                mHandler, UserHandle.of(mServiceInfo.userId))) {
            mServiceInfo = ServiceInfo.NONE;
            Log.e(TAG, getLogPrefix() + " unexpected bind failure - retrying later");
            mHandler.postDelayed(() -> onBestServiceChanged(false), RETRY_DELAY_MS);
        }
    }

    @Override
@@ -386,9 +396,7 @@ public class ServiceWatcher implements ServiceConnection {

    void onPackageChanged(String packageName) {
        // force a rebind if the changed package was the currently connected package
        String currentPackageName =
                mServiceInfo.component != null ? mServiceInfo.component.getPackageName() : null;
        onBestServiceChanged(packageName.equals(currentPackageName));
        onBestServiceChanged(packageName.equals(mServiceInfo.getPackageName()));
    }

    /**