1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wm.shell.draganddrop; 18 19 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; 20 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; 21 22 import android.app.ActivityManager; 23 import android.app.ActivityTaskManager; 24 import android.app.PendingIntent; 25 import android.app.WindowConfiguration; 26 import android.content.ClipData; 27 import android.content.ClipDescription; 28 import android.content.Intent; 29 import android.content.pm.ActivityInfo; 30 31 import androidx.annotation.Nullable; 32 33 import com.android.wm.shell.common.DisplayLayout; 34 35 import java.util.List; 36 37 /** 38 * Per-drag session data. 39 */ 40 public class DragSession { 41 private final ActivityTaskManager mActivityTaskManager; 42 private final ClipData mInitialDragData; 43 private final int mInitialDragFlags; 44 45 final DisplayLayout displayLayout; 46 // The activity info associated with the activity in the appData or the launchableIntent 47 @Nullable 48 ActivityInfo activityInfo; 49 // The intent bundle that includes data about an app-type drag that is started by 50 // Launcher/SysUI. Only one of appDragData OR launchableIntent will be non-null for a session. 51 @Nullable 52 Intent appData; 53 // A launchable intent that is specified in the ClipData directly. 54 // Only one of appDragData OR launchableIntent will be non-null for a session. 55 @Nullable 56 PendingIntent launchableIntent; 57 // Stores the current running task at the time that the drag was initiated 58 ActivityManager.RunningTaskInfo runningTaskInfo; 59 @WindowConfiguration.WindowingMode 60 int runningTaskWinMode = WINDOWING_MODE_UNDEFINED; 61 @WindowConfiguration.ActivityType 62 int runningTaskActType = ACTIVITY_TYPE_STANDARD; 63 boolean dragItemSupportsSplitscreen; 64 DragSession(ActivityTaskManager activityTaskManager, DisplayLayout dispLayout, ClipData data, int dragFlags)65 DragSession(ActivityTaskManager activityTaskManager, 66 DisplayLayout dispLayout, ClipData data, int dragFlags) { 67 mActivityTaskManager = activityTaskManager; 68 mInitialDragData = data; 69 mInitialDragFlags = dragFlags; 70 displayLayout = dispLayout; 71 } 72 73 /** 74 * Returns the clip description associated with the drag. 75 * @return 76 */ getClipDescription()77 ClipDescription getClipDescription() { 78 return mInitialDragData.getDescription(); 79 } 80 81 /** 82 * Updates the session data based on the current state of the system. 83 */ update()84 void update() { 85 List<ActivityManager.RunningTaskInfo> tasks = 86 mActivityTaskManager.getTasks(1, false /* filterOnlyVisibleRecents */); 87 if (!tasks.isEmpty()) { 88 final ActivityManager.RunningTaskInfo task = tasks.get(0); 89 runningTaskInfo = task; 90 runningTaskWinMode = task.getWindowingMode(); 91 runningTaskActType = task.getActivityType(); 92 } 93 94 activityInfo = mInitialDragData.getItemAt(0).getActivityInfo(); 95 // TODO: This should technically check & respect config_supportsNonResizableMultiWindow 96 dragItemSupportsSplitscreen = activityInfo == null 97 || ActivityInfo.isResizeableMode(activityInfo.resizeMode); 98 appData = mInitialDragData.getItemAt(0).getIntent(); 99 launchableIntent = DragUtils.getLaunchIntent(mInitialDragData, mInitialDragFlags); 100 } 101 } 102