| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell; |
| 18 |
|
| 19 |
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE; |
| 20 |
|
| 21 |
import android.app.WindowConfiguration; |
| 22 |
import android.util.SparseArray; |
| 23 |
import android.view.SurfaceControl; |
| 24 |
import android.window.DisplayAreaAppearedInfo; |
| 25 |
import android.window.DisplayAreaInfo; |
| 26 |
import android.window.DisplayAreaOrganizer; |
| 27 |
import android.window.WindowContainerTransaction; |
| 28 |
|
| 29 |
import androidx.annotation.NonNull; |
| 30 |
|
| 31 |
import com.android.internal.protolog.common.ProtoLog; |
| 32 |
|
| 33 |
import java.io.PrintWriter; |
| 34 |
import java.util.List; |
| 35 |
import java.util.concurrent.Executor; |
| 36 |
|
| 37 |
|
| 38 |
public class RootDisplayAreaOrganizer extends DisplayAreaOrganizer { |
| 39 |
|
| 40 |
private static final String TAG = RootDisplayAreaOrganizer.class.getSimpleName(); |
| 41 |
|
| 42 |
|
| 43 |
private final SparseArray<DisplayAreaInfo> mDisplayAreasInfo = new SparseArray<>(); |
| 44 |
|
| 45 |
private final SparseArray<SurfaceControl> mLeashes = new SparseArray<>(); |
| 46 |
|
| 47 |
public RootDisplayAreaOrganizer(Executor executor) { |
| 48 |
super(executor); |
| 49 |
List<DisplayAreaAppearedInfo> infos = registerOrganizer(FEATURE_ROOT); |
| 50 |
for (int i = infos.size() - 1; i >= 0; --i) { |
| 51 |
onDisplayAreaAppeared(infos.get(i).getDisplayAreaInfo(), infos.get(i).getLeash()); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public void attachToDisplayArea(int displayId, SurfaceControl.Builder b) { |
| 56 |
final SurfaceControl sc = mLeashes.get(displayId); |
| 57 |
if (sc != null) { |
| 58 |
b.setParent(sc); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public void onDisplayAreaAppeared(@NonNull DisplayAreaInfo displayAreaInfo, |
| 64 |
@NonNull SurfaceControl leash) { |
| 65 |
if (displayAreaInfo.featureId != FEATURE_ROOT) { |
| 66 |
throw new IllegalArgumentException( |
| 67 |
"Unknown feature: " + displayAreaInfo.featureId |
| 68 |
+ "displayAreaInfo:" + displayAreaInfo); |
| 69 |
} |
| 70 |
|
| 71 |
final int displayId = displayAreaInfo.displayId; |
| 72 |
if (mDisplayAreasInfo.get(displayId) != null) { |
| 73 |
throw new IllegalArgumentException( |
| 74 |
"Duplicate DA for displayId: " + displayId |
| 75 |
+ " displayAreaInfo:" + displayAreaInfo |
| 76 |
+ " mDisplayAreasInfo.get():" + mDisplayAreasInfo.get(displayId)); |
| 77 |
} |
| 78 |
|
| 79 |
mDisplayAreasInfo.put(displayId, displayAreaInfo); |
| 80 |
mLeashes.put(displayId, leash); |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public void onDisplayAreaVanished(@NonNull DisplayAreaInfo displayAreaInfo) { |
| 85 |
final int displayId = displayAreaInfo.displayId; |
| 86 |
if (mDisplayAreasInfo.get(displayId) == null) { |
| 87 |
throw new IllegalArgumentException( |
| 88 |
"onDisplayAreaVanished() Unknown DA displayId: " + displayId |
| 89 |
+ " displayAreaInfo:" + displayAreaInfo |
| 90 |
+ " mDisplayAreasInfo.get():" + mDisplayAreasInfo.get(displayId)); |
| 91 |
} |
| 92 |
|
| 93 |
mDisplayAreasInfo.remove(displayId); |
| 94 |
mLeashes.get(displayId).release(); |
| 95 |
mLeashes.remove(displayId); |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public void onDisplayAreaInfoChanged(@NonNull DisplayAreaInfo displayAreaInfo) { |
| 100 |
final int displayId = displayAreaInfo.displayId; |
| 101 |
if (mDisplayAreasInfo.get(displayId) == null) { |
| 102 |
throw new IllegalArgumentException( |
| 103 |
"onDisplayAreaInfoChanged() Unknown DA displayId: " + displayId |
| 104 |
+ " displayAreaInfo:" + displayAreaInfo |
| 105 |
+ " mDisplayAreasInfo.get():" + mDisplayAreasInfo.get(displayId)); |
| 106 |
} |
| 107 |
|
| 108 |
mDisplayAreasInfo.put(displayId, displayAreaInfo); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public WindowContainerTransaction prepareWindowingModeChange(int displayId, |
| 119 |
@WindowConfiguration.WindowingMode int windowingMode) { |
| 120 |
WindowContainerTransaction wct = new WindowContainerTransaction(); |
| 121 |
DisplayAreaInfo displayAreaInfo = mDisplayAreasInfo.get(displayId); |
| 122 |
if (displayAreaInfo == null) { |
| 123 |
ProtoLog.e(WM_SHELL_DESKTOP_MODE, |
| 124 |
"unable to update windowing mode for display %d display not found", displayId); |
| 125 |
return wct; |
| 126 |
} |
| 127 |
|
| 128 |
ProtoLog.d(WM_SHELL_DESKTOP_MODE, |
| 129 |
"setWindowingMode: displayId=%d current wmMode=%d new wmMode=%d", displayId, |
| 130 |
displayAreaInfo.configuration.windowConfiguration.getWindowingMode(), |
| 131 |
windowingMode); |
| 132 |
|
| 133 |
wct.setWindowingMode(displayAreaInfo.token, windowingMode); |
| 134 |
return wct; |
| 135 |
} |
| 136 |
|
| 137 |
public void dump(@NonNull PrintWriter pw, String prefix) { |
| 138 |
final String innerPrefix = prefix + " "; |
| 139 |
final String childPrefix = innerPrefix + " "; |
| 140 |
pw.println(prefix + this); |
| 141 |
|
| 142 |
for (int i = 0; i < mDisplayAreasInfo.size(); i++) { |
| 143 |
int displayId = mDisplayAreasInfo.keyAt(i); |
| 144 |
DisplayAreaInfo displayAreaInfo = mDisplayAreasInfo.get(displayId); |
| 145 |
int windowingMode = |
| 146 |
displayAreaInfo.configuration.windowConfiguration.getWindowingMode(); |
| 147 |
pw.println(innerPrefix + "# displayId=" + displayId + " wmMode=" + windowingMode); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
@Override |
| 152 |
public String toString() { |
| 153 |
return TAG + "#" + mDisplayAreasInfo.size(); |
| 154 |
} |
| 155 |
|
| 156 |
} |