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

Commit 45486d26 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor getPackageName into ComponentUtils" into main

parents 2e3e21c5 54eb7e64
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.wm.shell.common

import android.app.PendingIntent
import android.content.ComponentName
import android.content.Intent
import com.android.wm.shell.ShellTaskOrganizer

/** Utils to obtain [ComponentName]s. */
object ComponentUtils {
    /** Retrieves the package name from an [Intent].  */
    @JvmStatic
    fun getPackageName(intent: Intent?): String? = intent?.component?.packageName

    /** Retrieves the package name from a [PendingIntent].  */
    @JvmStatic
    fun getPackageName(pendingIntent: PendingIntent?): String? =
        getPackageName(pendingIntent?.intent)

    /** Retrieves the package name from a [taskId].  */
    @JvmStatic
    fun getPackageName(taskId: Int, taskOrganizer: ShellTaskOrganizer): String? {
        val taskInfo = taskOrganizer.getRunningTaskInfo(taskId)
        return getPackageName(taskInfo?.baseIntent)
    }
}
+0 −29
Original line number Diff line number Diff line
@@ -27,14 +27,10 @@ import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSIT
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED;

import android.app.ActivityManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;

import androidx.annotation.Nullable;

import com.android.internal.util.ArrayUtils;
import com.android.wm.shell.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
@@ -65,31 +61,6 @@ public class SplitScreenUtils {
                && ArrayUtils.contains(CONTROLLED_WINDOWING_MODES, taskInfo.getWindowingMode());
    }

    /** Retrieve package name from an intent */
    @Nullable
    public static String getPackageName(Intent intent) {
        if (intent == null || intent.getComponent() == null) {
            return null;
        }
        return intent.getComponent().getPackageName();
    }

    /** Retrieve package name from a PendingIntent */
    @Nullable
    public static String getPackageName(PendingIntent pendingIntent) {
        if (pendingIntent == null || pendingIntent.getIntent() == null) {
            return null;
        }
        return getPackageName(pendingIntent.getIntent());
    }

    /** Retrieve package name from a taskId */
    @Nullable
    public static String getPackageName(int taskId, ShellTaskOrganizer taskOrganizer) {
        final ActivityManager.RunningTaskInfo taskInfo = taskOrganizer.getRunningTaskInfo(taskId);
        return taskInfo != null ? getPackageName(taskInfo.baseIntent) : null;
    }

    /** Retrieve user id from a taskId */
    public static int getUserId(int taskId, ShellTaskOrganizer taskOrganizer) {
        final ActivityManager.RunningTaskInfo taskInfo = taskOrganizer.getRunningTaskInfo(taskId);
+2 −2
Original line number Diff line number Diff line
@@ -68,12 +68,12 @@ import androidx.annotation.Nullable;
import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.R;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.ComponentUtils;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipDisplayLayoutState;
import com.android.wm.shell.common.pip.PipMenuController;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.common.split.SplitScreenUtils;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.shared.pip.PipContentOverlay;
@@ -1359,7 +1359,7 @@ public class PipTransition extends PipTransitionController {
    public boolean isPackageActiveInPip(@Nullable String packageName) {
        final TaskInfo inPipTask = mPipOrganizer.getTaskInfo();
        return packageName != null && inPipTask != null && mPipOrganizer.isInPip()
                && packageName.equals(SplitScreenUtils.getPackageName(inPipTask.baseIntent));
                && packageName.equals(ComponentUtils.getPackageName(inPipTask.baseIntent));
    }

    private void updatePipForUnhandledTransition(@NonNull TransitionInfo.Change pipChange,
+2 −2
Original line number Diff line number Diff line
@@ -57,12 +57,12 @@ import androidx.annotation.Nullable;
import com.android.internal.util.Preconditions;
import com.android.window.flags.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.ComponentUtils;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipDisplayLayoutState;
import com.android.wm.shell.common.pip.PipMenuController;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.common.split.SplitScreenUtils;
import com.android.wm.shell.desktopmode.DesktopRepository;
import com.android.wm.shell.desktopmode.DesktopUserRepositories;
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider;
@@ -1008,6 +1008,6 @@ public class PipTransition extends PipTransitionController implements
    public boolean isPackageActiveInPip(@Nullable String packageName) {
        final TaskInfo inPipTask = mPipTransitionState.getPipTaskInfo();
        return packageName != null && inPipTask != null && mPipTransitionState.isInPip()
                && packageName.equals(SplitScreenUtils.getPackageName(inPipTask.baseIntent));
                && packageName.equals(ComponentUtils.getPackageName(inPipTask.baseIntent));
    }
}
+8 −7
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ import com.android.launcher3.icons.IconProvider;
import com.android.wm.shell.R;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.ComponentUtils;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayImeController;
import com.android.wm.shell.common.DisplayInsetsController;
@@ -682,7 +683,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
        final String packageName1 = shortcutInfo.getPackage();
        // NOTE: This doesn't correctly pull out packageName2 if taskId is referring to a task in
        //       recents that hasn't launched and is not being organized
        final String packageName2 = SplitScreenUtils.getPackageName(taskId, mTaskOrganizer);
        final String packageName2 = ComponentUtils.getPackageName(taskId, mTaskOrganizer);
        final int userId1 = shortcutInfo.getUserId();
        final int userId2 = SplitScreenUtils.getUserId(taskId, mTaskOrganizer);
        if (samePackage(packageName1, packageName2, userId1, userId2)) {
@@ -727,10 +728,10 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
            @SplitPosition int splitPosition, @PersistentSnapPosition int snapPosition,
            @Nullable RemoteTransition remoteTransition, InstanceId instanceId) {
        Intent fillInIntent = null;
        final String packageName1 = SplitScreenUtils.getPackageName(pendingIntent);
        final String packageName1 = ComponentUtils.getPackageName(pendingIntent);
        // NOTE: This doesn't correctly pull out packageName2 if taskId is referring to a task in
        //       recents that hasn't launched and is not being organized
        final String packageName2 = SplitScreenUtils.getPackageName(taskId, mTaskOrganizer);
        final String packageName2 = ComponentUtils.getPackageName(taskId, mTaskOrganizer);
        final int userId2 = SplitScreenUtils.getUserId(taskId, mTaskOrganizer);
        boolean setSecondIntentMultipleTask = false;
        if (samePackage(packageName1, packageName2, userId1, userId2)) {
@@ -766,8 +767,8 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
            InstanceId instanceId) {
        Intent fillInIntent1 = null;
        Intent fillInIntent2 = null;
        final String packageName1 = SplitScreenUtils.getPackageName(pendingIntent1);
        final String packageName2 = SplitScreenUtils.getPackageName(pendingIntent2);
        final String packageName1 = ComponentUtils.getPackageName(pendingIntent1);
        final String packageName2 = ComponentUtils.getPackageName(pendingIntent2);
        final ActivityOptions activityOptions1 = options1 != null
                ? ActivityOptions.fromBundle(options1) : ActivityOptions.makeBasic();
        final ActivityOptions activityOptions2 = options2 != null
@@ -835,7 +836,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
        if (fillInIntent == null) fillInIntent = new Intent();
        fillInIntent.addFlags(FLAG_ACTIVITY_NO_USER_ACTION);

        final String packageName1 = SplitScreenUtils.getPackageName(intent);
        final String packageName1 = ComponentUtils.getPackageName(intent);
        final String packageName2 = getPackageName(reverseSplitPosition(position), hideTaskToken);
        final int userId2 = getUserId(reverseSplitPosition(position), hideTaskToken);
        final ComponentName component = intent.getIntent().getComponent();
@@ -900,7 +901,7 @@ public class SplitScreenController implements SplitDragPolicy.Starter,
            }
        }

        return taskInfo != null ? SplitScreenUtils.getPackageName(taskInfo.baseIntent) : null;
        return taskInfo != null ? ComponentUtils.getPackageName(taskInfo.baseIntent) : null;
    }

    /**
Loading