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

Commit 34a5cef6 authored by Jason Monk's avatar Jason Monk
Browse files

Let SysUI watch TileService's dialog lifecycle

That way it can better handle tokens and service binding.

Change-Id: I9b882181ecbe52a65e731a2c45f1d296315884b4
parent 20a0e405
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -32,4 +32,6 @@ interface IQSService {
    boolean isLocked();
    boolean isSecure();
    void startUnlockAndRun(in Tile tile);

    void onDialogHidden(in Tile tile);
}
+16 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.WindowManager;

/**
@@ -206,6 +208,20 @@ public class TileService extends Service {
    public final void showDialog(Dialog dialog) {
        dialog.getWindow().getAttributes().token = mToken;
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_QS_DIALOG);
        dialog.getWindow().getDecorView().addOnAttachStateChangeListener(
                new OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
            }

            @Override
            public void onViewDetachedFromWindow(View v) {
                try {
                    mService.onDialogHidden(getQsTile());
                } catch (RemoteException e) {
                }
            }
        });
        dialog.show();
        try {
            mService.onShowDialog(mTile);
+9 −0
Original line number Diff line number Diff line
@@ -100,6 +100,15 @@ public class CustomTile extends QSTile<QSTile.State> {
        mIsShowingDialog = true;
    }

    public void onDialogHidden() {
        mIsShowingDialog = false;
        try {
            if (DEBUG) Log.d(TAG, "Removing token");
            mWindowManager.removeWindowToken(mToken);
        } catch (RemoteException e) {
        }
    }

    @Override
    public void setListening(boolean listening) {
        if (mListening == listening) return;
+11 −3
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class TileServiceManager {
    private boolean mJustBound;
    private long mLastUpdate;
    private int mType;
    private boolean mShowingDialog;

    TileServiceManager(TileServices tileServices, Handler handler, ComponentName component) {
        this(tileServices, handler, new TileLifecycleManager(handler,
@@ -86,6 +87,10 @@ public class TileServiceManager {
        mServices.recalculateBindAllowance();
    }

    public void setShowingDialog(boolean dialog) {
        mShowingDialog = dialog;
    }

    public IQSTileService getTileService() {
        return mStateManager;
    }
@@ -153,10 +158,13 @@ public class TileServiceManager {
            // Pending click is the most important thing, need to put this service at the top of
            // the list to be bound.
            mPriority = Integer.MAX_VALUE;
        } else if (mShowingDialog) {
            // Hang on to services that are showing dialogs so they don't die.
            mPriority = Integer.MAX_VALUE - 1;
        } else if (mJustBound) {
            // If we just bound, lets not thrash on binding/unbinding too much, this is second most
            // important.
            mPriority = Integer.MAX_VALUE - 1;
            mPriority = Integer.MAX_VALUE - 2;
        } else if (!mBindRequested) {
            // Don't care about binding right now, put us last.
            mPriority = Integer.MIN_VALUE;
@@ -165,8 +173,8 @@ public class TileServiceManager {
            long timeSinceUpdate = currentTime - mLastUpdate;
            // Fit compare into integer space for simplicity. Make sure to leave MAX_VALUE and
            // MAX_VALUE - 1 for the more important states above.
            if (timeSinceUpdate > Integer.MAX_VALUE - 2) {
                mPriority = Integer.MAX_VALUE - 2;
            if (timeSinceUpdate > Integer.MAX_VALUE - 3) {
                mPriority = Integer.MAX_VALUE - 3;
            } else {
                mPriority = (int) timeSinceUpdate;
            }
+12 −0
Original line number Diff line number Diff line
@@ -197,6 +197,18 @@ public class TileServices extends IQSService.Stub {
        if (customTile != null) {
            customTile.onDialogShown();
            mHost.collapsePanels();
            mServices.get(customTile).setShowingDialog(true);
        }
    }

    @Override
    public void onDialogHidden(Tile tile) {
        ComponentName componentName = tile.getComponentName();
        verifyCaller(componentName.getPackageName());
        CustomTile customTile = getTileForComponent(componentName);
        if (customTile != null) {
            mServices.get(customTile).setShowingDialog(false);
            customTile.onDialogHidden();
        }
    }

Loading