| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.common; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.os.RemoteException; |
| 21 |
import android.util.Slog; |
| 22 |
import android.view.IDisplayChangeWindowCallback; |
| 23 |
import android.view.IDisplayChangeWindowController; |
| 24 |
import android.view.IWindowManager; |
| 25 |
import android.window.DisplayAreaInfo; |
| 26 |
import android.window.WindowContainerTransaction; |
| 27 |
|
| 28 |
import androidx.annotation.BinderThread; |
| 29 |
|
| 30 |
import com.android.wm.shell.common.annotations.ShellMainThread; |
| 31 |
import com.android.wm.shell.sysui.ShellInit; |
| 32 |
|
| 33 |
import java.util.concurrent.CopyOnWriteArrayList; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class DisplayChangeController { |
| 42 |
private static final String TAG = DisplayChangeController.class.getSimpleName(); |
| 43 |
|
| 44 |
private final ShellExecutor mMainExecutor; |
| 45 |
private final IWindowManager mWmService; |
| 46 |
private final IDisplayChangeWindowController mControllerImpl; |
| 47 |
|
| 48 |
private final CopyOnWriteArrayList<OnDisplayChangingListener> mDisplayChangeListener = |
| 49 |
new CopyOnWriteArrayList<>(); |
| 50 |
|
| 51 |
public DisplayChangeController(IWindowManager wmService, ShellInit shellInit, |
| 52 |
ShellExecutor mainExecutor) { |
| 53 |
mMainExecutor = mainExecutor; |
| 54 |
mWmService = wmService; |
| 55 |
mControllerImpl = new DisplayChangeWindowControllerImpl(); |
| 56 |
shellInit.addInitCallback(this::onInit, this); |
| 57 |
} |
| 58 |
|
| 59 |
private void onInit() { |
| 60 |
try { |
| 61 |
mWmService.setDisplayChangeWindowController(mControllerImpl); |
| 62 |
} catch (RemoteException e) { |
| 63 |
throw new RuntimeException("Unable to register rotation controller"); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public void addDisplayChangeListener(OnDisplayChangingListener listener) { |
| 71 |
mDisplayChangeListener.add(listener); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public void removeDisplayChangeListener(OnDisplayChangingListener listener) { |
| 78 |
mDisplayChangeListener.remove(listener); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
public void dispatchOnDisplayChange(WindowContainerTransaction outWct, int displayId, |
| 83 |
int fromRotation, int toRotation, DisplayAreaInfo newDisplayAreaInfo) { |
| 84 |
for (OnDisplayChangingListener c : mDisplayChangeListener) { |
| 85 |
c.onDisplayChange(displayId, fromRotation, toRotation, newDisplayAreaInfo, outWct); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
private void onDisplayChange(int displayId, int fromRotation, int toRotation, |
| 90 |
DisplayAreaInfo newDisplayAreaInfo, IDisplayChangeWindowCallback callback) { |
| 91 |
WindowContainerTransaction t = new WindowContainerTransaction(); |
| 92 |
dispatchOnDisplayChange(t, displayId, fromRotation, toRotation, newDisplayAreaInfo); |
| 93 |
try { |
| 94 |
callback.continueDisplayChange(t); |
| 95 |
} catch (RemoteException e) { |
| 96 |
Slog.e(TAG, "Failed to continue handling display change", e); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
@BinderThread |
| 101 |
private class DisplayChangeWindowControllerImpl |
| 102 |
extends IDisplayChangeWindowController.Stub { |
| 103 |
@Override |
| 104 |
public void onDisplayChange(int displayId, int fromRotation, int toRotation, |
| 105 |
DisplayAreaInfo newDisplayAreaInfo, IDisplayChangeWindowCallback callback) { |
| 106 |
mMainExecutor.execute(() -> DisplayChangeController.this |
| 107 |
.onDisplayChange(displayId, fromRotation, toRotation, |
| 108 |
newDisplayAreaInfo, callback)); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
@ShellMainThread |
| 117 |
public interface OnDisplayChangingListener { |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
void onDisplayChange(int displayId, int fromRotation, int toRotation, |
| 128 |
@Nullable DisplayAreaInfo newDisplayAreaInfo, WindowContainerTransaction t); |
| 129 |
} |
| 130 |
} |