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

Commit 4fdc9181 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding support for listening to end callbacks when launching an intent from Launcher

Also moving various state handling to these end callbacks enstead of relying on resume

Bug: 265134143
Test: Verified that the end callback is received
Change-Id: I326a99c80154d244c0e49f678717c476602b6240
parent 7bc6cdee
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static android.window.SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED;

import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
@@ -43,6 +44,7 @@ import android.content.Intent;
import android.content.pm.ActivityInfo.Config;
import android.content.pm.LauncherApps;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
@@ -95,10 +97,13 @@ import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemClickHandler.ItemClickProxy;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SplitConfigurationOptions.SplitSelectSource;
import com.android.launcher3.util.TraceHelper;
@@ -567,6 +572,22 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        }
    }

    @Override
    public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
        RunnableList callbacks = new RunnableList();
        ActivityOptions options = ActivityOptions.makeCustomAnimation(
                this, 0, 0, Color.TRANSPARENT,
                Executors.MAIN_EXECUTOR.getHandler(), null,
                elapsedRealTime -> callbacks.executeAllAndDestroy());
        options.setSplashScreenStyle(splashScreenStyle);
        return new ActivityOptionsWrapper(options, callbacks);
    }

    @Override
    public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
        return makeDefaultActivityOptions(SPLASH_SCREEN_STYLE_UNDEFINED);
    }

    /**
     * Sets a new data-source for this taskbar instance
     */
+19 −9
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.SensorManager;
@@ -143,6 +144,7 @@ import com.android.launcher3.uioverrides.touchcontrollers.TwoButtonNavbarTouchCo
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.ObjectWrapper;
@@ -343,14 +345,16 @@ public class QuickstepLauncher extends Launcher {
    }

    @Override
    public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
    public RunnableList startActivitySafely(View v, Intent intent, ItemInfo item) {
        // Only pause is taskbar controller is not present
        mHotseatPredictionController.setPauseUIUpdate(getTaskbarUIController() == null);
        boolean started = super.startActivitySafely(v, intent, item);
        if (getTaskbarUIController() == null && !started) {
        RunnableList result = super.startActivitySafely(v, intent, item);
        if (getTaskbarUIController() == null && result == null) {
            mHotseatPredictionController.setPauseUIUpdate(false);
        } else {
            result.add(() -> mHotseatPredictionController.setPauseUIUpdate(false));
        }
        return started;
        return result;
    }

    @Override
@@ -370,11 +374,6 @@ public class QuickstepLauncher extends Launcher {
                | ACTIVITY_STATE_USER_ACTIVE | ACTIVITY_STATE_TRANSITION_ACTIVE)) != 0) {
            onStateOrResumeChanging((getActivityFlags() & ACTIVITY_STATE_TRANSITION_ACTIVE) == 0);
        }

        if (((changeBits & ACTIVITY_STATE_STARTED) != 0
                || (changeBits & getActivityFlags() & ACTIVITY_STATE_DEFERRED_RESUMED) != 0)) {
            mHotseatPredictionController.setPauseUIUpdate(false);
        }
    }

    @Override
@@ -1101,6 +1100,17 @@ public class QuickstepLauncher extends Launcher {
        return activityOptions;
    }

    @Override
    public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
        RunnableList callbacks = new RunnableList();
        ActivityOptions options = ActivityOptions.makeCustomAnimation(
                this, 0, 0, Color.TRANSPARENT,
                Executors.MAIN_EXECUTOR.getHandler(), null,
                elapsedRealTime -> callbacks.executeAllAndDestroy());
        options.setSplashScreenStyle(splashScreenStyle);
        return new ActivityOptionsWrapper(options, callbacks);
    }

    @Override
    @BinderThread
    public void enterStageSplitFromRunningApp(boolean leftOrTop) {
+7 −0
Original line number Diff line number Diff line
@@ -155,6 +155,13 @@ public abstract class BaseDraggingActivity extends BaseActivity
        return wrapper;
    }

    @Override
    public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) {
        ActivityOptionsWrapper wrapper = super.makeDefaultActivityOptions(splashScreenStyle);
        addOnResumeCallback(wrapper.onEndCallback::executeAllAndDestroy);
        return wrapper;
    }

    @Override
    protected void onStart() {
        super.onStart();
+15 −7
Original line number Diff line number Diff line
@@ -2154,30 +2154,38 @@ public class Launcher extends StatefulActivity<LauncherState>
    }

    @Override
    public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
    public RunnableList startActivitySafely(View v, Intent intent, ItemInfo item) {
        if (!hasBeenResumed()) {
            RunnableList result = new RunnableList();
            // Workaround an issue where the WM launch animation is clobbered when finishing the
            // recents animation into launcher. Defer launching the activity until Launcher is
            // next resumed.
            addOnResumeCallback(() -> startActivitySafely(v, intent, item));
            addOnResumeCallback(() -> {
                RunnableList actualResult = startActivitySafely(v, intent, item);
                if (actualResult != null) {
                    actualResult.add(result::executeAllAndDestroy);
                } else {
                    result.executeAllAndDestroy();
                }
            });
            if (mOnDeferredActivityLaunchCallback != null) {
                mOnDeferredActivityLaunchCallback.run();
                mOnDeferredActivityLaunchCallback = null;
            }
            return true;
            return result;
        }

        boolean success = super.startActivitySafely(v, intent, item);
        if (success && v instanceof BubbleTextView) {
        RunnableList result = super.startActivitySafely(v, intent, item);
        if (result != null && v instanceof BubbleTextView) {
            // This is set to the view that launched the activity that navigated the user away
            // from launcher. Since there is no callback for when the activity has finished
            // launching, enable the press state and keep this reference to reset the press
            // state when we return to launcher.
            BubbleTextView btv = (BubbleTextView) v;
            btv.setStayPressed(true);
            addOnResumeCallback(() -> btv.setStayPressed(false));
            result.add(() -> btv.setStayPressed(false));
        }
        return success;
        return result;
    }

    boolean isHotseatLayout(View layout) {
+2 −1
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ public class DefaultSearchAdapterProvider extends SearchAdapterProvider<Activity
        if (mHighlightedView instanceof BubbleTextView
                && mHighlightedView.getTag() instanceof ItemInfo) {
            ItemInfo itemInfo = (ItemInfo) mHighlightedView.getTag();
            return mLauncher.startActivitySafely(mHighlightedView, itemInfo.getIntent(), itemInfo);
            return mLauncher.startActivitySafely(
                    mHighlightedView, itemInfo.getIntent(), itemInfo) != null;
        }
        return false;
    }
Loading