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

Commit bd3ef70c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add guards around unbind" into sc-dev am: e2b3bf94 am: 0ac2e636

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15301093

Change-Id: I5eda309348a8542be3f7b55b01c638df5f547bae
parents 55c7740c 0ac2e636
Loading
Loading
Loading
Loading
+23 −3
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.annotation.VisibleForTesting;


import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.broadcast.BroadcastDispatcher;


import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -204,9 +205,14 @@ public class TileLifecycleManager extends BroadcastReceiver implements
            if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser);
            if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent + " " + mUser);
            // Give it another chance next time it needs to be bound, out of kindness.
            // Give it another chance next time it needs to be bound, out of kindness.
            mBindTryCount = 0;
            mBindTryCount = 0;
            mWrapper = null;
            freeWrapper();
            if (mIsBound) {
            if (mIsBound) {
                try {
                    mContext.unbindService(this);
                    mContext.unbindService(this);
                } catch (Exception e) {
                    Log.e(TAG, "Failed to unbind service "
                            + mIntent.getComponent().flattenToShortString(), e);
                }
                mIsBound = false;
                mIsBound = false;
            }
            }
        }
        }
@@ -290,7 +296,9 @@ public class TileLifecycleManager extends BroadcastReceiver implements


    private void handleDeath() {
    private void handleDeath() {
        if (mWrapper == null) return;
        if (mWrapper == null) return;
        mWrapper = null;
        freeWrapper();
        // Clearly not bound anymore
        mIsBound = false;
        if (!mBound) return;
        if (!mBound) return;
        if (DEBUG) Log.d(TAG, "handleDeath");
        if (DEBUG) Log.d(TAG, "handleDeath");
        if (checkComponentState()) {
        if (checkComponentState()) {
@@ -472,6 +480,18 @@ public class TileLifecycleManager extends BroadcastReceiver implements
        return mToken;
        return mToken;
    }
    }


    private void freeWrapper() {
        if (mWrapper != null) {
            try {
                mWrapper.asBinder().unlinkToDeath(this, 0);
            } catch (NoSuchElementException e) {
                Log.w(TAG, "Trying to unlink not linked recipient for component"
                        + mIntent.getComponent().flattenToShortString());
            }
            mWrapper = null;
        }
    }

    public interface TileChangeListener {
    public interface TileChangeListener {
        void onTileChanged(ComponentName tile);
        void onTileChanged(ComponentName tile);
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -77,10 +77,10 @@ public class TileLifecycleManagerTest extends SysuiTestCase {


        // Stub.asInterface will just return itself.
        // Stub.asInterface will just return itself.
        when(mMockTileService.queryLocalInterface(anyString())).thenReturn(mMockTileService);
        when(mMockTileService.queryLocalInterface(anyString())).thenReturn(mMockTileService);
        when(mMockTileService.asBinder()).thenReturn(mMockTileService);


        mContext.addMockService(mTileServiceComponentName, mMockTileService);
        mContext.addMockService(mTileServiceComponentName, mMockTileService);



        mTileServiceIntent = new Intent().setComponent(mTileServiceComponentName);
        mTileServiceIntent = new Intent().setComponent(mTileServiceComponentName);
        mUser = new UserHandle(UserHandle.myUserId());
        mUser = new UserHandle(UserHandle.myUserId());
        mThread = new HandlerThread("TestThread");
        mThread = new HandlerThread("TestThread");