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

Commit b7682d40 authored by Tianjie Xu's avatar Tianjie Xu Committed by Gerrit Code Review
Browse files

Merge "Fixes how unbindService works"

parents 59e8bb9e cf7b9b9a
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -106,6 +106,8 @@ public class ResumeOnRebootServiceProvider {
        private final Context mContext;
        private final ComponentName mComponentName;
        private IResumeOnRebootService mBinder;
        @Nullable
        ServiceConnection mServiceConnection;

        private ResumeOnRebootServiceConnection(Context context,
                @NonNull ComponentName componentName) {
@@ -115,17 +117,9 @@ public class ResumeOnRebootServiceProvider {

        /** Unbind from the service */
        public void unbindService() {
            mContext.unbindService(new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    mBinder = null;

            if (mServiceConnection != null) {
                mContext.unbindService(mServiceConnection);
            }
            });
        }

        /** Bind to the service */
@@ -134,7 +128,7 @@ public class ResumeOnRebootServiceProvider {
                CountDownLatch connectionLatch = new CountDownLatch(1);
                Intent intent = new Intent();
                intent.setComponent(mComponentName);
                final boolean success = mContext.bindServiceAsUser(intent, new ServiceConnection() {
                mServiceConnection = new ServiceConnection() {
                    @Override
                    public void onServiceConnected(ComponentName name, IBinder service) {
                        mBinder = IResumeOnRebootService.Stub.asInterface(service);
@@ -143,8 +137,10 @@ public class ResumeOnRebootServiceProvider {

                    @Override
                    public void onServiceDisconnected(ComponentName name) {
                        mBinder = null;
                    }
                        },
                };
                final boolean success = mContext.bindServiceAsUser(intent, mServiceConnection,
                        Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
                        BackgroundThread.getHandler(), UserHandle.SYSTEM);