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

Commit 15e96875 authored by Aaron Liu's avatar Aaron Liu
Browse files

Remove centralsurfaces activitystarter invocations

We want to ensure that ActivityStarterDelegate handles all activitystarter
invocations so that we can route these method to a separate class.

There should be no change in behavior as activitystarter delegate just
asks central surfaces to do these same invocations.

Bug: 278273334
Test: Unit tests
Test: Make sure it builds

Change-Id: I4af5b793ba9b8ab9091782cb17997039c8df2e4d
parent d3d04db5
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -102,6 +102,23 @@ public interface ActivityStarter {
    void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel,
            boolean afterKeyguardGone, @Nullable String customMessage);

    /** Starts an activity and dismisses keyguard. */
    void startActivityDismissingKeyguard(Intent intent,
            boolean onlyProvisioned,
            boolean dismissShade,
            boolean disallowEnterPictureInPictureWhileLaunching,
            Callback callback,
            int flags,
            @Nullable ActivityLaunchAnimator.Controller animationController,
            UserHandle userHandle);

    /** Execute a runnable after dismissing keyguard. */
    void executeRunnableDismissingKeyguard(Runnable runnable,
            Runnable cancelAction,
            boolean dismissShade,
            boolean afterKeyguardGone,
            boolean deferred);

    interface Callback {
        void onActivityStarted(int resultCode);
    }
+29 −0
Original line number Diff line number Diff line
@@ -91,6 +91,14 @@ public class ActivityStarterDelegate implements ActivityStarter {
                starter -> starter.startActivity(intent, dismissShade));
    }

    @Override
    public void startActivity(Intent intent,
            boolean dismissShade,
            @Nullable ActivityLaunchAnimator.Controller animationController) {
        mActualStarterOptionalLazy.get().ifPresent(
                starter -> starter.startActivity(intent, dismissShade, animationController));
    }

    @Override
    public void startActivity(Intent intent, boolean dismissShade,
            @Nullable ActivityLaunchAnimator.Controller animationController,
@@ -177,4 +185,25 @@ public class ActivityStarterDelegate implements ActivityStarter {
                starter -> starter.dismissKeyguardThenExecute(action, cancel, afterKeyguardGone,
                        customMessage));
    }

    @Override
    public void startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned,
            boolean dismissShade, boolean disallowEnterPictureInPictureWhileLaunching,
            Callback callback, int flags,
            @Nullable ActivityLaunchAnimator.Controller animationController,
            UserHandle userHandle) {
        mActualStarterOptionalLazy.get().ifPresent(
                starter -> starter.startActivityDismissingKeyguard(intent, onlyProvisioned,
                        dismissShade, disallowEnterPictureInPictureWhileLaunching, callback,
                        flags, animationController, userHandle));
    }

    @Override
    public void executeRunnableDismissingKeyguard(Runnable runnable,
            Runnable cancelAction, boolean dismissShade,
            boolean afterKeyguardGone, boolean deferred) {
        mActualStarterOptionalLazy.get().ifPresent(
                starter -> starter.executeRunnableDismissingKeyguard(runnable, cancelAction,
                        dismissShade, afterKeyguardGone, deferred));
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -23,15 +23,16 @@ import android.os.RemoteException;
import android.util.Log;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.statusbar.phone.CentralSurfaces;

import dagger.Lazy;

import java.util.Optional;

import javax.inject.Inject;

import dagger.Lazy;

/**
 * An implementation of the Recents interface which proxies to the OverviewProxyService.
 */
@@ -44,13 +45,15 @@ public class OverviewProxyRecentsImpl implements RecentsImplementation {

    private Handler mHandler;
    private final OverviewProxyService mOverviewProxyService;
    private final ActivityStarter mActivityStarter;

    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
    @Inject
    public OverviewProxyRecentsImpl(Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
            OverviewProxyService overviewProxyService) {
            OverviewProxyService overviewProxyService, ActivityStarter activityStarter) {
        mCentralSurfacesOptionalLazy = centralSurfacesOptionalLazy;
        mOverviewProxyService = overviewProxyService;
        mActivityStarter = activityStarter;
    }

    @Override
@@ -101,7 +104,7 @@ public class OverviewProxyRecentsImpl implements RecentsImplementation {
            final Optional<CentralSurfaces> centralSurfacesOptional =
                    mCentralSurfacesOptionalLazy.get();
            if (centralSurfacesOptional.map(CentralSurfaces::isKeyguardShowing).orElse(false)) {
                centralSurfacesOptional.get().executeRunnableDismissingKeyguard(
                mActivityStarter.executeRunnableDismissingKeyguard(
                        () -> mHandler.post(toggleRecents), null, true /* dismissShade */,
                        false /* afterKeyguardGone */,
                        true /* deferred */);
+9 −15
Original line number Diff line number Diff line
@@ -33,11 +33,9 @@ import android.util.Log;
import android.view.RemoteAnimationAdapter;
import android.view.WindowManagerGlobal;

import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.DisplayTracker;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.statusbar.phone.CentralSurfaces;

import java.util.Optional;

import javax.inject.Inject;

@@ -48,20 +46,20 @@ import javax.inject.Inject;
public class ActionProxyReceiver extends BroadcastReceiver {
    private static final String TAG = "ActionProxyReceiver";

    private final CentralSurfaces mCentralSurfaces;
    private final ActivityManagerWrapper mActivityManagerWrapper;
    private final ScreenshotSmartActions mScreenshotSmartActions;
    private final DisplayTracker mDisplayTracker;
    private final ActivityStarter mActivityStarter;

    @Inject
    public ActionProxyReceiver(Optional<CentralSurfaces> centralSurfacesOptional,
            ActivityManagerWrapper activityManagerWrapper,
    public ActionProxyReceiver(ActivityManagerWrapper activityManagerWrapper,
            ScreenshotSmartActions screenshotSmartActions,
            DisplayTracker displayTracker) {
        mCentralSurfaces = centralSurfacesOptional.orElse(null);
            DisplayTracker displayTracker,
            ActivityStarter activityStarter) {
        mActivityManagerWrapper = activityManagerWrapper;
        mScreenshotSmartActions = screenshotSmartActions;
        mDisplayTracker = displayTracker;
        mActivityStarter = activityStarter;
    }

    @Override
@@ -92,13 +90,9 @@ public class ActionProxyReceiver extends BroadcastReceiver {

        };

        if (mCentralSurfaces != null) {
            mCentralSurfaces.executeRunnableDismissingKeyguard(startActivityRunnable, null,
        mActivityStarter.executeRunnableDismissingKeyguard(startActivityRunnable, null,
                true /* dismissShade */, true /* afterKeyguardGone */,
                true /* deferred */);
        } else {
            startActivityRunnable.run();
        }

        if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) {
            String actionType = Intent.ACTION_EDIT.equals(intent.getAction())
+23 −32
Original line number Diff line number Diff line
@@ -21,27 +21,25 @@ import android.util.Log
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.shade.ShadeExpansionStateManager
import com.android.systemui.statusbar.phone.CentralSurfaces
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Optional
import javax.inject.Inject

/**
 * Provides state from the main SystemUI process on behalf of the Screenshot process.
 */
internal class ScreenshotProxyService @Inject constructor(
/** Provides state from the main SystemUI process on behalf of the Screenshot process. */
internal class ScreenshotProxyService
@Inject
constructor(
    private val mExpansionMgr: ShadeExpansionStateManager,
    private val mCentralSurfacesOptional: Optional<CentralSurfaces>,
    @Main private val mMainDispatcher: CoroutineDispatcher,
    private val activityStarter: ActivityStarter,
) : LifecycleService() {

    private val mBinder: IBinder = object : IScreenshotProxy.Stub() {
        /**
         * @return true when the notification shade is partially or fully expanded.
         */
    private val mBinder: IBinder =
        object : IScreenshotProxy.Stub() {
            /** @return true when the notification shade is partially or fully expanded. */
            override fun isNotificationShadeExpanded(): Boolean {
                val expanded = !mExpansionMgr.isClosed()
                Log.d(TAG, "isNotificationShadeExpanded(): $expanded")
@@ -49,26 +47,19 @@ internal class ScreenshotProxyService @Inject constructor(
            }

            override fun dismissKeyguard(callback: IOnDoneCallback) {
            lifecycleScope.launch {
                executeAfterDismissing(callback)
            }
                lifecycleScope.launch { executeAfterDismissing(callback) }
            }
        }

    private suspend fun executeAfterDismissing(callback: IOnDoneCallback) =
        withContext(mMainDispatcher) {
            mCentralSurfacesOptional.ifPresentOrElse(
                    {
                        it.executeRunnableDismissingKeyguard(
                                Runnable {
                                    callback.onDone(true)
                                }, null,
                                true /* dismissShade */, true /* afterKeyguardGone */,
            activityStarter.executeRunnableDismissingKeyguard(
                Runnable { callback.onDone(true) },
                null,
                true /* dismissShade */,
                true /* afterKeyguardGone */,
                true /* deferred */
            )
                    },
                    { callback.onDone(false) }
            )
        }

    override fun onBind(intent: Intent): IBinder? {
Loading