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

Commit 3701cae0 authored by Rambo Wang's avatar Rambo Wang
Browse files

CarrierServiceBindHelper: context mismatch in bindService vs unbindservice

Two issues are observed due to the context mismatch:
1. unbindservice throw IAE with msg "Service not registered"
2. Binding connection leaks in various scenarios

To fix the issue, the context is created in the constructor and
used ever since.

Bug: 197274279
Test: atest CarrierServiceBindHelperTest
Change-Id: I0b6ebf88c5de71a8602f22d324cea91141c3c97c
parent 9e30d795
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class CarrierServiceBindHelper {
    };

    public CarrierServiceBindHelper(Context context) {
        mContext = context;
        mContext = context.createContextAsUser(Process.myUserHandle(), 0);

        updateBindingsAndSimStates();

@@ -283,8 +283,8 @@ public class CarrierServiceBindHelper {

            String error;
            try {
                if (mContext.createContextAsUser(Process.myUserHandle(), 0)
                        .bindService(carrierService,
                if (mContext.bindService(
                        carrierService,
                        Context.BIND_AUTO_CREATE
                                | Context.BIND_FOREGROUND_SERVICE
                                | Context.BIND_INCLUDE_CAPABILITIES,
@@ -350,12 +350,7 @@ public class CarrierServiceBindHelper {
            if (mServiceBound) {
                logdWithLocalLog("Unbinding from carrier app");
                mServiceBound = false;
                try {
                mContext.unbindService(connection);
                } catch (IllegalArgumentException e) {
                    //TODO(b/151328766): Figure out why we unbind without binding
                    logeWithLocalLog("Tried to unbind without binding e=" + e);
                }
            } else {
                logdWithLocalLog("Not bound, skipping unbindService call");
            }