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

Commit fa77d101 authored by Junda Liu's avatar Junda Liu
Browse files

No unbind if carrier app is the same.

Previously unbind is called first within bind, this will briefly
disconnect carrier app even though the new one is the same. This change
checks current binding and keep it if package is the same.

Bug: b/27499289
Change-Id: Ie5887d385a50818722116691424fb87bb928efa4
parent 9e0a6420
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ public class CarrierServiceBindHelper {
                    for (AppBinding appBinding : mBindings) {
                        if (carrierPackageName.equals(appBinding.getPackage())) {
                          log(carrierPackageName + " changed and corresponds to a phone. Rebinding.");
                          appBinding.unbind();
                          appBinding.bind();
                        }
                    }
@@ -160,9 +161,6 @@ public class CarrierServiceBindHelper {
        }

        public boolean bind() {
            // Make sure there is no existing binding for this phone
            unbind();

            // Get the package name for the carrier app
            List<String> carrierPackageNames =
                TelephonyManager.from(mContext).getCarrierPackageNamesForIntentAndPhone(
@@ -175,6 +173,16 @@ public class CarrierServiceBindHelper {
            }

            log("Found carrier app: " + carrierPackageNames);
            // If we are binding to a different package, unbind from the current one.
            if (connection != null) {
                if (!carrierPackage.equals(carrierPackageNames.get(0))) {
                    // Make sure there is no existing binding for this phone
                    unbind();
                } else {
                    return true;
                }
            }

            carrierPackage = carrierPackageNames.get(0);

            // Log debug information
@@ -275,6 +283,15 @@ public class CarrierServiceBindHelper {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
            // If replace is true, only care ACTION_PACKAGE_REPLACED.
            // Reason is update app or uninstall app update will have all 3 intents,
            // in the order or removed, added, replaced, all with extra_replace set to true.
            // In this case processing added and removed isn't needed.

            if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action))
                return;

            log("Receive action: " + action);
            switch (action) {
                case Intent.ACTION_PACKAGE_ADDED: