2021-05-20 20:18:47 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.taskbar;
|
|
|
|
|
|
|
|
|
|
import static android.view.Display.DEFAULT_DISPLAY;
|
|
|
|
|
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
|
|
|
|
|
|
|
|
|
import static com.android.launcher3.util.DisplayController.CHANGE_ACTIVE_SCREEN;
|
|
|
|
|
import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
|
|
|
|
|
import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.hardware.display.DisplayManager;
|
|
|
|
|
import android.view.Display;
|
|
|
|
|
|
2021-06-18 12:41:22 -07:00
|
|
|
import androidx.annotation.NonNull;
|
2021-05-20 20:18:47 +00:00
|
|
|
|
|
|
|
|
import com.android.launcher3.BaseQuickstepLauncher;
|
|
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
|
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
|
|
|
|
import com.android.launcher3.util.DisplayController;
|
|
|
|
|
import com.android.launcher3.util.DisplayController.Info;
|
|
|
|
|
import com.android.quickstep.SysUINavigationMode;
|
|
|
|
|
import com.android.quickstep.SysUINavigationMode.Mode;
|
2021-06-30 10:24:11 +00:00
|
|
|
import com.android.quickstep.SystemUiProxy;
|
2021-05-20 20:18:47 +00:00
|
|
|
import com.android.quickstep.TouchInteractionService;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-25 19:26:48 -07:00
|
|
|
* Class to manage taskbar lifecycle
|
2021-05-20 20:18:47 +00:00
|
|
|
*/
|
|
|
|
|
public class TaskbarManager implements DisplayController.DisplayInfoChangeListener,
|
2021-05-25 14:35:01 -07:00
|
|
|
SysUINavigationMode.NavigationModeChangeListener {
|
2021-05-20 20:18:47 +00:00
|
|
|
|
|
|
|
|
private final Context mContext;
|
|
|
|
|
private final DisplayController mDisplayController;
|
|
|
|
|
private final SysUINavigationMode mSysUINavigationMode;
|
|
|
|
|
private final TaskbarNavButtonController mNavButtonController;
|
|
|
|
|
|
|
|
|
|
private TaskbarActivityContext mTaskbarActivityContext;
|
|
|
|
|
private BaseQuickstepLauncher mLauncher;
|
2021-06-07 16:42:43 -07:00
|
|
|
/**
|
|
|
|
|
* Cache a copy here so we can initialize state whenever taskbar is recreated, since
|
|
|
|
|
* this class does not get re-initialized w/ new taskbars.
|
|
|
|
|
*/
|
|
|
|
|
private int mSysuiStateFlags;
|
2021-05-20 20:18:47 +00:00
|
|
|
|
|
|
|
|
private static final int CHANGE_FLAGS =
|
|
|
|
|
CHANGE_ACTIVE_SCREEN | CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS;
|
|
|
|
|
|
2021-05-20 13:45:58 -07:00
|
|
|
private boolean mUserUnlocked = false;
|
|
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
public TaskbarManager(TouchInteractionService service) {
|
|
|
|
|
mDisplayController = DisplayController.INSTANCE.get(service);
|
|
|
|
|
mSysUINavigationMode = SysUINavigationMode.INSTANCE.get(service);
|
|
|
|
|
Display display =
|
|
|
|
|
service.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY);
|
|
|
|
|
mContext = service.createWindowContext(display, TYPE_APPLICATION_OVERLAY, null);
|
|
|
|
|
mNavButtonController = new TaskbarNavButtonController(service);
|
|
|
|
|
|
|
|
|
|
mDisplayController.addChangeListener(this);
|
|
|
|
|
mSysUINavigationMode.addModeChangeListener(this);
|
|
|
|
|
recreateTaskbar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNavigationModeChanged(Mode newMode) {
|
|
|
|
|
recreateTaskbar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDisplayInfoChanged(Context context, Info info, int flags) {
|
|
|
|
|
if ((flags & CHANGE_FLAGS) != 0) {
|
|
|
|
|
recreateTaskbar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void destroyExistingTaskbar() {
|
|
|
|
|
if (mTaskbarActivityContext != null) {
|
|
|
|
|
mTaskbarActivityContext.onDestroy();
|
|
|
|
|
mTaskbarActivityContext = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 13:45:58 -07:00
|
|
|
/**
|
|
|
|
|
* Called when the user is unlocked
|
|
|
|
|
*/
|
|
|
|
|
public void onUserUnlocked() {
|
|
|
|
|
mUserUnlocked = true;
|
|
|
|
|
recreateTaskbar();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
/**
|
2021-06-18 12:41:22 -07:00
|
|
|
* Sets a launcher to act as taskbar callback
|
2021-05-20 20:18:47 +00:00
|
|
|
*/
|
2021-06-18 12:41:22 -07:00
|
|
|
public void setLauncher(@NonNull BaseQuickstepLauncher launcher) {
|
2021-05-20 20:18:47 +00:00
|
|
|
mLauncher = launcher;
|
|
|
|
|
if (mTaskbarActivityContext != null) {
|
2021-06-18 12:41:22 -07:00
|
|
|
mTaskbarActivityContext.setUIController(
|
|
|
|
|
new LauncherTaskbarUIController(launcher, mTaskbarActivityContext));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clears a previously set Launcher
|
|
|
|
|
*/
|
|
|
|
|
public void clearLauncher(@NonNull BaseQuickstepLauncher launcher) {
|
|
|
|
|
if (mLauncher == launcher) {
|
|
|
|
|
mLauncher = null;
|
|
|
|
|
if (mTaskbarActivityContext != null) {
|
|
|
|
|
mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
|
|
|
|
|
}
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recreateTaskbar() {
|
|
|
|
|
destroyExistingTaskbar();
|
2021-06-30 10:24:11 +00:00
|
|
|
|
|
|
|
|
DeviceProfile dp =
|
|
|
|
|
mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;
|
|
|
|
|
|
|
|
|
|
boolean isTaskBarEnabled =
|
|
|
|
|
FeatureFlags.ENABLE_TASKBAR.get() && dp != null && dp.isTaskbarPresent;
|
|
|
|
|
|
|
|
|
|
if (!isTaskBarEnabled) {
|
|
|
|
|
SystemUiProxy.INSTANCE.get(mContext)
|
|
|
|
|
.notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
|
2021-05-20 20:18:47 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-30 10:24:11 +00:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
mTaskbarActivityContext = new TaskbarActivityContext(
|
2021-05-25 14:35:01 -07:00
|
|
|
mContext, dp.copy(mContext), mNavButtonController);
|
2021-05-20 20:18:47 +00:00
|
|
|
mTaskbarActivityContext.init();
|
|
|
|
|
if (mLauncher != null) {
|
|
|
|
|
mTaskbarActivityContext.setUIController(
|
2021-05-20 20:18:47 +00:00
|
|
|
new LauncherTaskbarUIController(mLauncher, mTaskbarActivityContext));
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
2021-06-07 16:42:43 -07:00
|
|
|
onSysuiFlagsChangedInternal(mSysuiStateFlags, true /* forceUpdate */);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onSystemUiFlagsChanged(int systemUiStateFlags) {
|
2021-06-07 16:42:43 -07:00
|
|
|
onSysuiFlagsChangedInternal(systemUiStateFlags, false /* forceUpdate */);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 16:42:43 -07:00
|
|
|
private void onSysuiFlagsChangedInternal(int systemUiStateFlags, boolean forceUpdate) {
|
|
|
|
|
mSysuiStateFlags = systemUiStateFlags;
|
2021-05-25 14:35:01 -07:00
|
|
|
if (mTaskbarActivityContext != null) {
|
2021-06-07 16:42:43 -07:00
|
|
|
mTaskbarActivityContext.updateSysuiStateFlags(systemUiStateFlags, forceUpdate);
|
2021-05-25 19:26:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onRotationProposal(int rotation, boolean isValid) {
|
2021-05-25 14:35:01 -07:00
|
|
|
if (mTaskbarActivityContext != null) {
|
|
|
|
|
mTaskbarActivityContext.onRotationProposal(rotation, isValid);
|
2021-05-25 19:26:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 15:35:46 -07:00
|
|
|
public void disableNavBarElements(int displayId, int state1, int state2, boolean animate) {
|
2021-05-25 14:35:01 -07:00
|
|
|
if (mTaskbarActivityContext != null) {
|
2021-06-04 15:35:46 -07:00
|
|
|
mTaskbarActivityContext.disableNavBarElements(displayId, state1, state2, animate);
|
2021-05-25 19:26:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onSystemBarAttributesChanged(int displayId, int behavior) {
|
2021-05-25 14:35:01 -07:00
|
|
|
if (mTaskbarActivityContext != null) {
|
|
|
|
|
mTaskbarActivityContext.onSystemBarAttributesChanged(displayId, behavior);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the manager is no longer needed
|
|
|
|
|
*/
|
|
|
|
|
public void destroy() {
|
|
|
|
|
destroyExistingTaskbar();
|
|
|
|
|
mDisplayController.removeChangeListener(this);
|
|
|
|
|
mSysUINavigationMode.removeModeChangeListener(this);
|
|
|
|
|
}
|
|
|
|
|
}
|