[CD Taskbar] Cache displayId & Consolidate DisplayController methods
TaskbarActivityContext should store displayId and return a cached value to avoid unnessary binder calls. Flag: com.android.window.flags.enable_taskbar_connected_displays Bug: 406019031 Test: m Change-Id: I808352e7098ee731abc7362b2f8f1b7a675457f9
This commit is contained in:
1 parent
21c065ae3d
commit
5da5e1c9e1
9 files changed
+132
-108
No files matched your search
@@ -207,8 +207,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
debugTaskbarManager("onDisplayInfoChanged: Navigation mode changed", displayId);
|
||||
}
|
||||
if ((flags & CHANGE_DESKTOP_MODE) != 0) {
|
||||
debugTaskbarManager("onDisplayInfoChanged: Desktop mode changed",
|
||||
context.getDisplayId());
|
||||
debugTaskbarManager("onDisplayInfoChanged: Desktop mode changed", displayId);
|
||||
handleDisplayUpdatesForPerceptibleTasks();
|
||||
}
|
||||
if ((flags & CHANGE_TASKBAR_PINNING) != 0) {
|
||||
@@ -316,8 +315,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
public void onExitDesktopMode(int duration) {
|
||||
for (int taskbarIndex = 0; taskbarIndex < mTaskbars.size(); taskbarIndex++) {
|
||||
int displayId = mTaskbars.keyAt(taskbarIndex);
|
||||
if (DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()
|
||||
&& !isDefaultDisplay(displayId)) {
|
||||
if (isExternalDisplay(displayId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -329,8 +327,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
AnimatorSet animatorSet = taskbarActivityContext.onDestroyAnimation(
|
||||
TASKBAR_DESTROY_DURATION);
|
||||
animatorSet.addListener(AnimatorListeners.forEndCallback(
|
||||
() -> recreateTaskbarForDisplay(getDefaultDisplayId(),
|
||||
duration)));
|
||||
() -> recreateTaskbarForDisplay(mPrimaryDisplayId, duration)));
|
||||
animatorSet.start();
|
||||
}
|
||||
}
|
||||
@@ -340,8 +337,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
public void onEnterDesktopMode(int duration) {
|
||||
for (int taskbarIndex = 0; taskbarIndex < mTaskbars.size(); taskbarIndex++) {
|
||||
int displayId = mTaskbars.keyAt(taskbarIndex);
|
||||
if (DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()
|
||||
&& !isDefaultDisplay(displayId)) {
|
||||
if (isExternalDisplay(displayId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -352,8 +348,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
AnimatorSet animatorSet = taskbarActivityContext.onDestroyAnimation(
|
||||
TASKBAR_DESTROY_DURATION);
|
||||
animatorSet.addListener(AnimatorListeners.forEndCallback(
|
||||
() -> recreateTaskbarForDisplay(getDefaultDisplayId(),
|
||||
duration)));
|
||||
() -> recreateTaskbarForDisplay(mPrimaryDisplayId, duration)));
|
||||
animatorSet.start();
|
||||
}
|
||||
}
|
||||
@@ -378,7 +373,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
private final Runnable mActivityOnDestroyCallback = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int displayId = getDefaultDisplayId();
|
||||
int displayId = mPrimaryDisplayId;
|
||||
debugTaskbarManager("onActivityDestroyed:", displayId);
|
||||
if (mActivity != null) {
|
||||
displayId = mActivity.getDisplayId();
|
||||
@@ -444,14 +439,14 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
|
||||
// Set up primary display.
|
||||
debugPrimaryTaskbar("TaskbarManager constructor");
|
||||
mPrimaryWindowContext = createWindowContext(getDefaultDisplayId());
|
||||
mPrimaryWindowContext = createWindowContext(mPrimaryDisplayId);
|
||||
mPrimaryWindowManager = mPrimaryWindowContext.getSystemService(WindowManager.class);
|
||||
DesktopVisibilityController.INSTANCE.get(
|
||||
mPrimaryWindowContext).registerTaskbarDesktopModeListener(
|
||||
mTaskbarDesktopModeListener);
|
||||
createTaskbarRootLayout(getDefaultDisplayId());
|
||||
createNavButtonController(getDefaultDisplayId());
|
||||
createAndRegisterComponentCallbacks(getDefaultDisplayId());
|
||||
createTaskbarRootLayout(mPrimaryDisplayId);
|
||||
createNavButtonController(mPrimaryDisplayId);
|
||||
createAndRegisterComponentCallbacks(mPrimaryDisplayId);
|
||||
|
||||
SettingsCache.INSTANCE.get(mPrimaryWindowContext)
|
||||
.register(USER_SETUP_COMPLETE_URI, mOnSettingsChangeListener);
|
||||
@@ -596,7 +591,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
* progress.
|
||||
*/
|
||||
public AnimatorPlaybackController createLauncherStartFromSuwAnim(int duration) {
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
return taskbar == null ? null : taskbar.createLauncherStartFromSuwAnim(duration);
|
||||
}
|
||||
|
||||
@@ -727,8 +722,8 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
debugPrimaryTaskbar("recreateTaskbars");
|
||||
// Handles initial creation case.
|
||||
if (mTaskbars.size() == 0) {
|
||||
debugTaskbarManager("recreateTaskbars: create primary taskbar", getDefaultDisplayId());
|
||||
recreateTaskbarForDisplay(getDefaultDisplayId(), 0);
|
||||
debugTaskbarManager("recreateTaskbars: create primary taskbar", mPrimaryDisplayId);
|
||||
recreateTaskbarForDisplay(mPrimaryDisplayId, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -797,8 +792,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
|
||||
// Non default displays should not use LauncherTaskbarUIController as they shouldn't
|
||||
// have access to the Launcher activity.
|
||||
if (!isDefaultDisplay(displayId)
|
||||
&& DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (isExternalDisplay(displayId)) {
|
||||
taskbar.setUIController(createTaskbarUIControllerForNonDefaultDisplay(displayId));
|
||||
} else if (mRecentsViewContainer != null) {
|
||||
taskbar.setUIController(
|
||||
@@ -849,7 +843,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
public void setSetupUIVisible(boolean isVisible) {
|
||||
mSharedState.setupUIVisible = isVisible;
|
||||
mAllAppsActionManager.setSetupUiVisible(isVisible);
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
if (taskbar != null) {
|
||||
taskbar.setSetupUIVisible(isVisible);
|
||||
}
|
||||
@@ -896,7 +890,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
public void appTransitionPending(boolean pending) {
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
if (taskbar != null) {
|
||||
taskbar.appTransitionPending(pending);
|
||||
}
|
||||
@@ -907,7 +901,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
public void onRotationProposal(int rotation, boolean isValid) {
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
if (taskbar != null) {
|
||||
taskbar.onRotationProposal(rotation, isValid);
|
||||
}
|
||||
@@ -934,7 +928,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
|
||||
public void onTransitionModeUpdated(int barMode, boolean checkBarModes) {
|
||||
mSharedState.barMode = barMode;
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
if (taskbar != null) {
|
||||
taskbar.onTransitionModeUpdated(barMode, checkBarModes);
|
||||
}
|
||||
@@ -942,7 +936,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
|
||||
public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
|
||||
mSharedState.navButtonsDarkIntensity = darkIntensity;
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(getDefaultDisplayId());
|
||||
TaskbarActivityContext taskbar = getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
if (taskbar != null) {
|
||||
taskbar.onNavButtonsDarkIntensityChanged(darkIntensity);
|
||||
}
|
||||
@@ -970,13 +964,10 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue() || isDefaultDisplay(
|
||||
displayId)) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
debugTaskbarManager(
|
||||
"onDisplayAddSystemDecorations: not an external display! | "
|
||||
+ "ENABLE_TASKBAR_CONNECTED_DISPLAYS="
|
||||
+ DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()
|
||||
+ " isDefaultDisplay=" + isDefaultDisplay(displayId), displayId);
|
||||
+ "isExternalDisplay=" + isExternalDisplay(displayId), displayId);
|
||||
return;
|
||||
}
|
||||
debugTaskbarManager("onDisplayAddSystemDecorations: creating new windowContext!",
|
||||
@@ -1028,13 +1019,10 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
@Override
|
||||
public void onDisplayRemoved(int displayId) {
|
||||
debugTaskbarManager("onDisplayRemoved: ", displayId);
|
||||
if (!DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue() || isDefaultDisplay(
|
||||
displayId)) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
debugTaskbarManager(
|
||||
"onDisplayRemoved: not an external display! | "
|
||||
+ "ENABLE_TASKBAR_CONNECTED_DISPLAYS="
|
||||
+ DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()
|
||||
+ " isDefaultDisplay=" + isDefaultDisplay(displayId), displayId);
|
||||
+ "isExternalDisplay=" + isExternalDisplay(displayId), displayId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1058,7 +1046,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
|
||||
debugTaskbarManager("onDisplayRemoved: finished!", displayId);
|
||||
} else {
|
||||
debugTaskbarManager("onDisplayRemoved: removing NavButtonController!", displayId);
|
||||
debugTaskbarManager("onDisplayRemoved: windowContext is null!", displayId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1112,7 +1100,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
SystemDecorationChangeObserver.getINSTANCE().get(mPrimaryWindowContext)
|
||||
.unregisterDisplayDecorationListener(this);
|
||||
debugPrimaryTaskbar("destroy: unregistering component callbacks");
|
||||
removeAndUnregisterComponentCallbacks(getDefaultDisplayId());
|
||||
removeAndUnregisterComponentCallbacks(mPrimaryDisplayId);
|
||||
mShutdownReceiver.unregisterReceiverSafely();
|
||||
if (mTaskStackListener != null) {
|
||||
mTaskStackListener.unregisterListener();
|
||||
@@ -1135,7 +1123,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
public @Nullable TaskbarActivityContext getCurrentActivityContext() {
|
||||
return getTaskbarForDisplay(getDefaultDisplayId());
|
||||
return getTaskbarForDisplay(mPrimaryDisplayId);
|
||||
}
|
||||
|
||||
public void dumpLogs(String prefix, PrintWriter pw) {
|
||||
@@ -1264,13 +1252,10 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
TYPE_NAVIGATION_BAR_PANEL, null);
|
||||
}
|
||||
|
||||
boolean isPrimaryDisplay = isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue();
|
||||
|
||||
TaskbarActivityContext newTaskbar = new TaskbarActivityContext(getWindowContext(displayId),
|
||||
navigationBarPanelContext, dp, getNavButtonController(displayId),
|
||||
mUnfoldProgressProvider, isPrimaryDisplay,
|
||||
SystemUiProxy.INSTANCE.get(mBaseContext));
|
||||
TaskbarActivityContext newTaskbar = new TaskbarActivityContext(displayId,
|
||||
getWindowContext(displayId), navigationBarPanelContext, dp,
|
||||
getNavButtonController(displayId), mUnfoldProgressProvider,
|
||||
!isExternalDisplay(displayId), SystemUiProxy.INSTANCE.get(mBaseContext));
|
||||
|
||||
addTaskbarToMap(displayId, newTaskbar);
|
||||
return newTaskbar;
|
||||
@@ -1314,9 +1299,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isPrimary = isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue();
|
||||
if (isPrimary) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
return idp.getDeviceProfile(mPrimaryWindowContext);
|
||||
}
|
||||
|
||||
@@ -1373,7 +1356,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
debugPrimaryTaskbar(
|
||||
"onConfigurationChanged: isTaskbarEnabled(dp)=False | "
|
||||
+ "destroyTaskbarForDisplay");
|
||||
destroyTaskbarForDisplay(getDefaultDisplayId());
|
||||
destroyTaskbarForDisplay(mPrimaryDisplayId);
|
||||
} else {
|
||||
debugPrimaryTaskbar("onConfigurationChanged: isTaskbarEnabled(dp)=True");
|
||||
if (ENABLE_TASKBAR_NAVBAR_UNIFICATION) {
|
||||
@@ -1402,8 +1385,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
public void onLowMemory() {
|
||||
}
|
||||
};
|
||||
if (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
mPrimaryComponentCallbacks = callbacks;
|
||||
mPrimaryWindowContext.registerComponentCallbacks(callbacks);
|
||||
} else {
|
||||
@@ -1419,8 +1401,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
* @param displayId The ID of the display.
|
||||
*/
|
||||
private void removeAndUnregisterComponentCallbacks(int displayId) {
|
||||
if (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
mPrimaryWindowContext.unregisterComponentCallbacks(mPrimaryComponentCallbacks);
|
||||
} else {
|
||||
ComponentCallbacks callbacks = mComponentCallbacks.get(displayId);
|
||||
@@ -1436,8 +1417,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
* @param displayId The ID of the display
|
||||
*/
|
||||
private void createNavButtonController(int displayId) {
|
||||
if (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
mPrimaryNavButtonController = new TaskbarNavButtonController(
|
||||
mPrimaryWindowContext,
|
||||
mNavCallbacks,
|
||||
@@ -1456,14 +1436,12 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
private TaskbarNavButtonController getNavButtonController(int displayId) {
|
||||
return (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue())
|
||||
? mPrimaryNavButtonController : mNavButtonControllers.get(displayId);
|
||||
return (!isExternalDisplay(displayId)) ? mPrimaryNavButtonController
|
||||
: mNavButtonControllers.get(displayId);
|
||||
}
|
||||
|
||||
private void removeNavButtonController(int displayId) {
|
||||
if (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
mPrimaryNavButtonController = null;
|
||||
} else {
|
||||
mNavButtonControllers.delete(displayId);
|
||||
@@ -1522,7 +1500,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
private boolean isDefaultDisplay(int displayId) {
|
||||
return displayId == getDefaultDisplayId();
|
||||
return displayId == mPrimaryDisplayId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1589,7 +1567,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
|
||||
int windowType = TYPE_NAVIGATION_BAR_PANEL;
|
||||
if (ENABLE_TASKBAR_NAVBAR_UNIFICATION && isDefaultDisplay(displayId)) {
|
||||
if (ENABLE_TASKBAR_NAVBAR_UNIFICATION && !isExternalDisplay(displayId)) {
|
||||
windowType = TYPE_NAVIGATION_BAR;
|
||||
}
|
||||
debugTaskbarManager(
|
||||
@@ -1622,8 +1600,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
* @return The Window Context {@link Context} for a given display or {@code null}.
|
||||
*/
|
||||
private Context getWindowContext(int displayId) {
|
||||
return (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue())
|
||||
return (!isExternalDisplay(displayId))
|
||||
? mPrimaryWindowContext : mWindowContexts.get(displayId);
|
||||
}
|
||||
|
||||
@@ -1639,8 +1616,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
* @return The window manager {@link WindowManager} for a given display or {@code null}.
|
||||
*/
|
||||
private @Nullable WindowManager getWindowManager(int displayId) {
|
||||
if (isDefaultDisplay(displayId)
|
||||
|| !DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue()) {
|
||||
if (!isExternalDisplay(displayId)) {
|
||||
debugTaskbarManager("cannot get mPrimaryWindowManager", displayId);
|
||||
return mPrimaryWindowManager;
|
||||
}
|
||||
@@ -1677,8 +1653,9 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
}
|
||||
}
|
||||
|
||||
private int getDefaultDisplayId() {
|
||||
return mPrimaryDisplayId;
|
||||
private boolean isExternalDisplay(int displayId) {
|
||||
return DesktopExperienceFlags.ENABLE_TASKBAR_CONNECTED_DISPLAYS.isTrue() && (
|
||||
mPrimaryDisplayId != displayId);
|
||||
}
|
||||
|
||||
private int getFocusedDisplayId() {
|
||||
@@ -1692,7 +1669,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
*/
|
||||
public void debugTaskbarManager(String debugReason, int displayId) {
|
||||
StringJoiner log = new StringJoiner("\n");
|
||||
log.add(debugReason + " displayId=" + displayId + " isDefaultDisplay=" + isDefaultDisplay(
|
||||
log.add(debugReason + " displayId=" + displayId + " isDefaultDisplay=" + isExternalDisplay(
|
||||
displayId));
|
||||
Log.d(TAG, log.toString());
|
||||
}
|
||||
@@ -1719,7 +1696,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
*
|
||||
*/
|
||||
public void debugPrimaryTaskbar(String debugReason) {
|
||||
debugTaskbarManager(debugReason, getDefaultDisplayId(), false);
|
||||
debugTaskbarManager(debugReason, mPrimaryDisplayId, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1728,7 +1705,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
*
|
||||
*/
|
||||
public void debugPrimaryTaskbar(String debugReason, boolean verbose) {
|
||||
debugTaskbarManager(debugReason, getDefaultDisplayId(), verbose);
|
||||
debugTaskbarManager(debugReason, mPrimaryDisplayId, verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user