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

Commit 2bf3b1b2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing error calculating the top pinned activity."

parents 5559543e 734c9c05
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -86,9 +86,12 @@ public class PipManager {
            // another package than the top activity in the stack
            boolean expandPipToFullscreen = true;
            if (sourceComponent != null) {
                ComponentName topActivity = PipUtils.getTopPinnedActivity(mActivityManager);
                expandPipToFullscreen = topActivity != null && topActivity.getPackageName().equals(
                        sourceComponent.getPackageName());
                ComponentName topActivity = PipUtils.getTopPinnedActivity(mContext,
                        mActivityManager);
                if (topActivity != null && topActivity.getPackageName().equals(
                        sourceComponent.getPackageName())) {
                    expandPipToFullscreen = false;
                }
            }
            if (expandPipToFullscreen) {
                mTouchHandler.expandPinnedStackToFullscreen();
+2 −1
Original line number Diff line number Diff line
@@ -148,7 +148,8 @@ public class PipMediaController {
     */
    private void resolveActiveMediaController(List<MediaController> controllers) {
        if (controllers != null) {
            final ComponentName topActivity = PipUtils.getTopPinnedActivity(mActivityManager);
            final ComponentName topActivity = PipUtils.getTopPinnedActivity(mContext,
                    mActivityManager);
            if (topActivity != null) {
                for (int i = 0; i < controllers.size(); i++) {
                    final MediaController controller = controllers.get(i);
+14 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
import android.app.ActivityManager.StackInfo;
import android.app.IActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.RemoteException;
import android.util.Log;

@@ -29,14 +30,23 @@ public class PipUtils {
    private static final String TAG = "PipUtils";

    /**
     * @return the ComponentName of the top activity in the pinned stack, or null if none exists.
     * @return the ComponentName of the top non-SystemUI activity in the pinned stack, or null if
     *         none exists.
     */
    public static ComponentName getTopPinnedActivity(IActivityManager activityManager) {
    public static ComponentName getTopPinnedActivity(Context context,
            IActivityManager activityManager) {
        try {
            StackInfo pinnedStackInfo = activityManager.getStackInfo(PINNED_STACK_ID);
            final String sysUiPackageName = context.getPackageName();
            final StackInfo pinnedStackInfo = activityManager.getStackInfo(PINNED_STACK_ID);
            if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null &&
                    pinnedStackInfo.taskIds.length > 0) {
                return pinnedStackInfo.topActivity;
                for (int i = pinnedStackInfo.taskNames.length - 1; i >= 0; i--) {
                    ComponentName cn = ComponentName.unflattenFromString(
                            pinnedStackInfo.taskNames[i]);
                    if (cn != null && !cn.getPackageName().equals(sysUiPackageName)) {
                        return cn;
                    }
                }
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to get pinned stack.");