| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.pip; |
| 18 |
|
| 19 |
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 20 |
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 21 |
|
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.app.ActivityTaskManager; |
| 24 |
import android.app.ActivityTaskManager.RootTaskInfo; |
| 25 |
import android.app.RemoteAction; |
| 26 |
import android.content.ComponentName; |
| 27 |
import android.content.Context; |
| 28 |
import android.os.RemoteException; |
| 29 |
import android.util.Log; |
| 30 |
import android.util.Pair; |
| 31 |
import android.window.TaskSnapshot; |
| 32 |
|
| 33 |
import com.android.internal.protolog.common.ProtoLog; |
| 34 |
import com.android.wm.shell.protolog.ShellProtoLogGroup; |
| 35 |
|
| 36 |
import java.util.List; |
| 37 |
import java.util.Objects; |
| 38 |
|
| 39 |
|
| 40 |
public class PipUtils { |
| 41 |
private static final String TAG = "PipUtils"; |
| 42 |
|
| 43 |
|
| 44 |
private static final double EPSILON = 1e-7; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public static Pair<ComponentName, Integer> getTopPipActivity(Context context) { |
| 51 |
try { |
| 52 |
final String sysUiPackageName = context.getPackageName(); |
| 53 |
final RootTaskInfo pinnedTaskInfo = ActivityTaskManager.getService().getRootTaskInfo( |
| 54 |
WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); |
| 55 |
if (pinnedTaskInfo != null && pinnedTaskInfo.childTaskIds != null |
| 56 |
&& pinnedTaskInfo.childTaskIds.length > 0) { |
| 57 |
for (int i = pinnedTaskInfo.childTaskNames.length - 1; i >= 0; i--) { |
| 58 |
ComponentName cn = ComponentName.unflattenFromString( |
| 59 |
pinnedTaskInfo.childTaskNames[i]); |
| 60 |
if (cn != null && !cn.getPackageName().equals(sysUiPackageName)) { |
| 61 |
return new Pair<>(cn, pinnedTaskInfo.childTaskUserIds[i]); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
} catch (RemoteException e) { |
| 66 |
ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, |
| 67 |
"%s: Unable to get pinned stack.", TAG); |
| 68 |
} |
| 69 |
return new Pair<>(null, 0); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static boolean aspectRatioChanged(float aspectRatio1, float aspectRatio2) { |
| 76 |
return Math.abs(aspectRatio1 - aspectRatio2) > EPSILON; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public static boolean remoteActionsMatch(RemoteAction action1, RemoteAction action2) { |
| 84 |
if (action1 == action2) return true; |
| 85 |
if (action1 == null || action2 == null) return false; |
| 86 |
return action1.isEnabled() == action2.isEnabled() |
| 87 |
&& action1.shouldShowIcon() == action2.shouldShowIcon() |
| 88 |
&& Objects.equals(action1.getTitle(), action2.getTitle()) |
| 89 |
&& Objects.equals(action1.getContentDescription(), action2.getContentDescription()) |
| 90 |
&& Objects.equals(action1.getActionIntent(), action2.getActionIntent()); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public static boolean remoteActionsChanged(List<RemoteAction> list1, List<RemoteAction> list2) { |
| 98 |
if (list1 == null && list2 == null) { |
| 99 |
return false; |
| 100 |
} |
| 101 |
if (list1 == null || list2 == null) { |
| 102 |
return true; |
| 103 |
} |
| 104 |
if (list1.size() != list2.size()) { |
| 105 |
return true; |
| 106 |
} |
| 107 |
for (int i = 0; i < list1.size(); i++) { |
| 108 |
if (!remoteActionsMatch(list1.get(i), list2.get(i))) { |
| 109 |
return true; |
| 110 |
} |
| 111 |
} |
| 112 |
return false; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
@Nullable |
| 117 |
public static TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) { |
| 118 |
if (taskId <= 0) return null; |
| 119 |
try { |
| 120 |
return ActivityTaskManager.getService().getTaskSnapshot( |
| 121 |
taskId, isLowResolution, false ); |
| 122 |
} catch (RemoteException e) { |
| 123 |
Log.e(TAG, "Failed to get task snapshot, taskId=" + taskId, e); |
| 124 |
return null; |
| 125 |
} |
| 126 |
} |
| 127 |
} |