diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/sysui/ShellSharedConstants.java b/libs/WindowManager/Shell/src/com/android/wm/shell/sysui/ShellSharedConstants.java index 5f54f58557d1d..56c0d0e67cab3 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/sysui/ShellSharedConstants.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/sysui/ShellSharedConstants.java @@ -38,8 +38,6 @@ public class ShellSharedConstants { public static final String KEY_EXTRA_SHELL_RECENT_TASKS = "extra_shell_recent_tasks"; // See IBackAnimation.aidl public static final String KEY_EXTRA_SHELL_BACK_ANIMATION = "extra_shell_back_animation"; - // See IFloatingTasks.aidl - public static final String KEY_EXTRA_SHELL_FLOATING_TASKS = "extra_shell_floating_tasks"; // See IDesktopMode.aidl public static final String KEY_EXTRA_SHELL_DESKTOP_MODE = "extra_shell_desktop_mode"; // See IDragAndDrop.aidl diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java index ca064efd4f76e..4b14d3cff7180 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java @@ -42,8 +42,6 @@ public class QuickStepContract { "com.google.android.apps.nexuslauncher.NexusLauncherActivity"; public static final String KEY_EXTRA_SYSUI_PROXY = "extra_sysui_proxy"; - public static final String KEY_EXTRA_WINDOW_CORNER_RADIUS = "extra_window_corner_radius"; - public static final String KEY_EXTRA_SUPPORTS_WINDOW_CORNERS = "extra_supports_window_corners"; public static final String KEY_EXTRA_UNFOLD_ANIMATION_FORWARDER = "extra_unfold_animation"; // See ISysuiUnlockAnimationController.aidl public static final String KEY_EXTRA_UNLOCK_ANIMATION_CONTROLLER = "unlock_animation"; diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java deleted file mode 100644 index 74c325dea15c6..0000000000000 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java +++ /dev/null @@ -1,541 +0,0 @@ -/* - * Copyright (C) 2020 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.systemui.shared.system; - -import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; -import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; -import static android.view.WindowManager.TRANSIT_CHANGE; -import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_LOCKED; -import static android.view.WindowManager.TRANSIT_SLEEP; - -import android.annotation.SuppressLint; -import android.app.ActivityManager; -import android.app.ActivityTaskManager; -import android.app.IApplicationThread; -import android.graphics.Rect; -import android.os.IBinder; -import android.os.RemoteException; -import android.util.ArrayMap; -import android.util.Log; -import android.view.IRecentsAnimationController; -import android.view.RemoteAnimationTarget; -import android.view.SurfaceControl; -import android.window.IRemoteTransition; -import android.window.IRemoteTransitionFinishedCallback; -import android.window.PictureInPictureSurfaceTransaction; -import android.window.RemoteTransition; -import android.window.TaskSnapshot; -import android.window.TransitionInfo; -import android.window.WindowContainerToken; -import android.window.WindowContainerTransaction; - -import com.android.internal.annotations.VisibleForTesting; -import com.android.wm.shell.util.TransitionUtil; - -import java.util.ArrayList; -import java.util.HashMap; - -/** - * Helper class to build {@link RemoteTransition} objects - */ -public class RemoteTransitionCompat { - private static final String TAG = "RemoteTransitionCompat"; - - /** Constructor specifically for recents animation */ - public static RemoteTransition newRemoteTransition(RecentsAnimationListener recents, - IApplicationThread appThread) { - IRemoteTransition remote = new IRemoteTransition.Stub() { - final RecentsControllerWrap mRecentsSession = new RecentsControllerWrap(); - IBinder mToken = null; - - @Override - public void startAnimation(IBinder transition, TransitionInfo info, - SurfaceControl.Transaction t, - IRemoteTransitionFinishedCallback finishedCallback) { - // TODO(b/177438007): Move this set-up logic into launcher's animation impl. - mToken = transition; - mRecentsSession.start(recents, mToken, info, t, finishedCallback); - } - - @Override - public void mergeAnimation(IBinder transition, TransitionInfo info, - SurfaceControl.Transaction t, IBinder mergeTarget, - IRemoteTransitionFinishedCallback finishedCallback) { - if (mergeTarget.equals(mToken) && mRecentsSession.merge(info, t)) { - try { - finishedCallback.onTransitionFinished(null /* wct */, null /* sct */); - } catch (RemoteException e) { - Log.e(TAG, "Error merging transition.", e); - } - // commit taskAppeared after merge transition finished. - mRecentsSession.commitTasksAppearedIfNeeded(); - } else { - t.close(); - info.releaseAllSurfaces(); - } - } - }; - return new RemoteTransition(remote, appThread, "Recents"); - } - - /** - * Wrapper to hook up parts of recents animation to shell transition. - * TODO(b/177438007): Remove this once Launcher handles shell transitions directly. - */ - @VisibleForTesting - static class RecentsControllerWrap extends IRecentsAnimationController.Default { - private RecentsAnimationListener mListener = null; - private IRemoteTransitionFinishedCallback mFinishCB = null; - - /** - * List of tasks that we are switching away from via this transition. Upon finish, these - * pausing tasks will become invisible. - * These need to be ordered since the order must be restored if there is no task-switch. - */ - private ArrayList mPausingTasks = null; - - /** - * List of tasks that we are switching to. Upon finish, these will remain visible and - * on top. - */ - private ArrayList mOpeningTasks = null; - - private WindowContainerToken mPipTask = null; - private WindowContainerToken mRecentsTask = null; - private int mRecentsTaskId = 0; - private TransitionInfo mInfo = null; - private boolean mOpeningSeparateHome = false; - private ArrayMap mLeashMap = null; - private PictureInPictureSurfaceTransaction mPipTransaction = null; - private IBinder mTransition = null; - private boolean mKeyguardLocked = false; - private RemoteAnimationTarget[] mAppearedTargets; - private boolean mWillFinishToHome = false; - - /** The animation is idle, waiting for the user to choose a task to switch to. */ - private static final int STATE_NORMAL = 0; - - /** The user chose a new task to switch to and the animation is animating to it. */ - private static final int STATE_NEW_TASK = 1; - - /** The latest state that the recents animation is operating in. */ - private int mState = STATE_NORMAL; - - void start(RecentsAnimationListener listener, - IBinder transition, TransitionInfo info, SurfaceControl.Transaction t, - IRemoteTransitionFinishedCallback finishedCallback) { - if (mInfo != null) { - throw new IllegalStateException("Trying to run a new recents animation while" - + " recents is already active."); - } - mListener = listener; - mInfo = info; - mFinishCB = finishedCallback; - mPausingTasks = new ArrayList<>(); - mOpeningTasks = new ArrayList<>(); - mPipTask = null; - mRecentsTask = null; - mRecentsTaskId = -1; - mLeashMap = new ArrayMap<>(); - mTransition = transition; - mKeyguardLocked = (info.getFlags() & TRANSIT_FLAG_KEYGUARD_LOCKED) != 0; - mState = STATE_NORMAL; - - final ArrayList apps = new ArrayList<>(); - final ArrayList wallpapers = new ArrayList<>(); - TransitionUtil.LeafTaskFilter leafTaskFilter = new TransitionUtil.LeafTaskFilter(); - // About layering: we divide up the "layer space" into 3 regions (each the size of - // the change count). This lets us categorize things into above/below/between - // while maintaining their relative ordering. - for (int i = 0; i < info.getChanges().size(); ++i) { - final TransitionInfo.Change change = info.getChanges().get(i); - final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo(); - if (TransitionUtil.isWallpaper(change)) { - final RemoteAnimationTarget target = TransitionUtil.newTarget(change, - // wallpapers go into the "below" layer space - info.getChanges().size() - i, info, t, mLeashMap); - wallpapers.add(target); - // Make all the wallpapers opaque since we want them visible from the start - t.setAlpha(target.leash, 1); - } else if (leafTaskFilter.test(change)) { - // start by putting everything into the "below" layer space. - final RemoteAnimationTarget target = TransitionUtil.newTarget(change, - info.getChanges().size() - i, info, t, mLeashMap); - apps.add(target); - if (TransitionUtil.isClosingType(change.getMode())) { - // raise closing (pausing) task to "above" layer so it isn't covered - t.setLayer(target.leash, info.getChanges().size() * 3 - i); - mPausingTasks.add(new TaskState(change, target.leash)); - if (taskInfo.pictureInPictureParams != null - && taskInfo.pictureInPictureParams.isAutoEnterEnabled()) { - mPipTask = taskInfo.token; - } - } else if (taskInfo != null - && taskInfo.topActivityType == ACTIVITY_TYPE_RECENTS) { - // There's a 3p launcher, so make sure recents goes above that. - t.setLayer(target.leash, info.getChanges().size() * 3 - i); - mRecentsTask = taskInfo.token; - mRecentsTaskId = taskInfo.taskId; - } else if (taskInfo != null && taskInfo.topActivityType == ACTIVITY_TYPE_HOME) { - mRecentsTask = taskInfo.token; - mRecentsTaskId = taskInfo.taskId; - } else if (TransitionUtil.isOpeningType(change.getMode())) { - mOpeningTasks.add(new TaskState(change, target.leash)); - } - } - } - t.apply(); - mListener.onAnimationStart(new RecentsAnimationControllerCompat(this), - apps.toArray(new RemoteAnimationTarget[apps.size()]), - wallpapers.toArray(new RemoteAnimationTarget[wallpapers.size()]), - new Rect(0, 0, 0, 0), new Rect()); - } - - @SuppressLint("NewApi") - boolean merge(TransitionInfo info, SurfaceControl.Transaction t) { - if (info.getType() == TRANSIT_SLEEP) { - // A sleep event means we need to stop animations immediately, so cancel here. - mListener.onAnimationCanceled(new HashMap<>()); - finish(mWillFinishToHome, false /* userLeaveHint */); - return false; - } - ArrayList openingTasks = null; - ArrayList closingTasks = null; - mAppearedTargets = null; - mOpeningSeparateHome = false; - TransitionInfo.Change recentsOpening = null; - boolean foundRecentsClosing = false; - boolean hasChangingApp = false; - final TransitionUtil.LeafTaskFilter leafTaskFilter = - new TransitionUtil.LeafTaskFilter(); - for (int i = 0; i < info.getChanges().size(); ++i) { - final TransitionInfo.Change change = info.getChanges().get(i); - final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo(); - final boolean isLeafTask = leafTaskFilter.test(change); - if (TransitionUtil.isOpeningType(change.getMode())) { - if (mRecentsTask.equals(change.getContainer())) { - recentsOpening = change; - } else if (isLeafTask) { - if (taskInfo.topActivityType == ACTIVITY_TYPE_HOME) { - // This is usually a 3p launcher - mOpeningSeparateHome = true; - } - if (openingTasks == null) { - openingTasks = new ArrayList<>(); - } - openingTasks.add(change); - } - } else if (TransitionUtil.isClosingType(change.getMode())) { - if (mRecentsTask.equals(change.getContainer())) { - foundRecentsClosing = true; - } else if (isLeafTask) { - if (closingTasks == null) { - closingTasks = new ArrayList<>(); - } - closingTasks.add(change); - } - } else if (change.getMode() == TRANSIT_CHANGE) { - // Finish recents animation if the display is changed, so the default - // transition handler can play the animation such as rotation effect. - if (change.hasFlags(TransitionInfo.FLAG_IS_DISPLAY)) { - mListener.onSwitchToScreenshot(() -> finish(false /* toHome */, - false /* userLeaveHint */)); - return false; - } - hasChangingApp = true; - } - } - if (hasChangingApp && foundRecentsClosing) { - // This happens when a visible app is expanding (usually PiP). In this case, - // that transition probably has a special-purpose animation, so finish recents - // now and let it do its animation (since recents is going to be occluded). - if (!mListener.onSwitchToScreenshot( - () -> finish(true /* toHome */, false /* userLeaveHint */))) { - Log.w(TAG, "Recents callback doesn't support support switching to screenshot" - + ", there might be a flicker."); - finish(true /* toHome */, false /* userLeaveHint */); - } - return false; - } - if (recentsOpening != null) { - // the recents task re-appeared. This happens if the user gestures before the - // task-switch (NEW_TASK) animation finishes. - if (mState == STATE_NORMAL) { - Log.e(TAG, "Returning to recents while recents is already idle."); - } - if (closingTasks == null || closingTasks.size() == 0) { - Log.e(TAG, "Returning to recents without closing any opening tasks."); - } - // Setup may hide it initially since it doesn't know that overview was still active. - t.show(recentsOpening.getLeash()); - t.setAlpha(recentsOpening.getLeash(), 1.f); - mState = STATE_NORMAL; - } - boolean didMergeThings = false; - if (closingTasks != null) { - // Cancelling a task-switch. Move the tasks back to mPausing from mOpening - for (int i = 0; i < closingTasks.size(); ++i) { - final TransitionInfo.Change change = closingTasks.get(i); - int openingIdx = TaskState.indexOf(mOpeningTasks, change); - if (openingIdx < 0) { - Log.e(TAG, "Back to existing recents animation from an unrecognized " - + "task: " + change.getTaskInfo().taskId); - continue; - } - mPausingTasks.add(mOpeningTasks.remove(openingIdx)); - didMergeThings = true; - } - } - if (openingTasks != null && openingTasks.size() > 0) { - // Switching to some new tasks, add to mOpening and remove from mPausing. Also, - // enter NEW_TASK state since this will start the switch-to animation. - final int layer = mInfo.getChanges().size() * 3; - final RemoteAnimationTarget[] targets = - new RemoteAnimationTarget[openingTasks.size()]; - for (int i = 0; i < openingTasks.size(); ++i) { - final TransitionInfo.Change change = openingTasks.get(i); - int pausingIdx = TaskState.indexOf(mPausingTasks, change); - if (pausingIdx >= 0) { - // Something is showing/opening a previously-pausing app. - targets[i] = TransitionUtil.newTarget(change, layer, - mPausingTasks.get(pausingIdx).mLeash); - mOpeningTasks.add(mPausingTasks.remove(pausingIdx)); - // Setup hides opening tasks initially, so make it visible again (since we - // are already showing it). - t.show(change.getLeash()); - t.setAlpha(change.getLeash(), 1.f); - } else { - // We are receiving new opening tasks, so convert to onTasksAppeared. - targets[i] = TransitionUtil.newTarget(change, layer, info, t, mLeashMap); - // reparent into the original `mInfo` since that's where we are animating. - final int rootIdx = TransitionUtil.rootIndexFor(change, mInfo); - t.reparent(targets[i].leash, mInfo.getRoot(rootIdx).getLeash()); - t.setLayer(targets[i].leash, layer); - mOpeningTasks.add(new TaskState(change, targets[i].leash)); - } - } - didMergeThings = true; - mState = STATE_NEW_TASK; - mAppearedTargets = targets; - } - if (!didMergeThings) { - // Didn't recognize anything in incoming transition so don't merge it. - Log.w(TAG, "Don't know how to merge this transition."); - return false; - } - t.apply(); - // not using the incoming anim-only surfaces - info.releaseAnimSurfaces(); - return true; - } - - private void commitTasksAppearedIfNeeded() { - if (mAppearedTargets != null) { - mListener.onTasksAppeared(mAppearedTargets); - mAppearedTargets = null; - } - } - - @Override public TaskSnapshot screenshotTask(int taskId) { - try { - return ActivityTaskManager.getService().takeTaskSnapshot(taskId, - true /* updateCache */); - } catch (RemoteException e) { - Log.e(TAG, "Failed to screenshot task", e); - } - return null; - } - - @Override public void setInputConsumerEnabled(boolean enabled) { - if (!enabled) return; - // transient launches don't receive focus automatically. Since we are taking over - // the gesture now, take focus explicitly. - // This also moves recents back to top if the user gestured before a switch - // animation finished. - try { - ActivityTaskManager.getService().setFocusedTask(mRecentsTaskId); - } catch (RemoteException e) { - Log.e(TAG, "Failed to set focused task", e); - } - } - - @Override public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars) { - } - - @Override public void setFinishTaskTransaction(int taskId, - PictureInPictureSurfaceTransaction finishTransaction, SurfaceControl overlay) { - mPipTransaction = finishTransaction; - } - - @Override - @SuppressLint("NewApi") - public void finish(boolean toHome, boolean sendUserLeaveHint) { - if (mFinishCB == null) { - Log.e(TAG, "Duplicate call to finish", new RuntimeException()); - return; - } - final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); - final WindowContainerTransaction wct = new WindowContainerTransaction(); - - if (mKeyguardLocked && mRecentsTask != null) { - if (toHome) wct.reorder(mRecentsTask, true /* toTop */); - else wct.restoreTransientOrder(mRecentsTask); - } - if (!toHome && !mWillFinishToHome && mPausingTasks != null && mState == STATE_NORMAL) { - // The gesture is returning to the pausing-task(s) rather than continuing with - // recents, so end the transition by moving the app back to the top (and also - // re-showing it's task). - for (int i = mPausingTasks.size() - 1; i >= 0; --i) { - // reverse order so that index 0 ends up on top - wct.reorder(mPausingTasks.get(i).mToken, true /* onTop */); - t.show(mPausingTasks.get(i).mTaskSurface); - } - if (!mKeyguardLocked && mRecentsTask != null) { - wct.restoreTransientOrder(mRecentsTask); - } - } else if (toHome && mOpeningSeparateHome && mPausingTasks != null) { - // Special situation where 3p launcher was changed during recents (this happens - // during tapltests...). Here we get both "return to home" AND "home opening". - // This is basically going home, but we have to restore the recents and home order. - for (int i = 0; i < mOpeningTasks.size(); ++i) { - final TaskState state = mOpeningTasks.get(i); - if (state.mTaskInfo.topActivityType == ACTIVITY_TYPE_HOME) { - // Make sure it is on top. - wct.reorder(state.mToken, true /* onTop */); - } - t.show(state.mTaskSurface); - } - for (int i = mPausingTasks.size() - 1; i >= 0; --i) { - t.hide(mPausingTasks.get(i).mTaskSurface); - } - if (!mKeyguardLocked && mRecentsTask != null) { - wct.restoreTransientOrder(mRecentsTask); - } - } else { - // The general case: committing to recents, going home, or switching tasks. - for (int i = 0; i < mOpeningTasks.size(); ++i) { - t.show(mOpeningTasks.get(i).mTaskSurface); - } - for (int i = 0; i < mPausingTasks.size(); ++i) { - if (!sendUserLeaveHint) { - // This means recents is not *actually* finishing, so of course we gotta - // do special stuff in WMCore to accommodate. - wct.setDoNotPip(mPausingTasks.get(i).mToken); - } - // Since we will reparent out of the leashes, pre-emptively hide the child - // surface to match the leash. Otherwise, there will be a flicker before the - // visibility gets committed in Core when using split-screen (in splitscreen, - // the leaf-tasks are not "independent" so aren't hidden by normal setup). - t.hide(mPausingTasks.get(i).mTaskSurface); - } - if (mPipTask != null && mPipTransaction != null && sendUserLeaveHint) { - t.show(mInfo.getChange(mPipTask).getLeash()); - PictureInPictureSurfaceTransaction.apply(mPipTransaction, - mInfo.getChange(mPipTask).getLeash(), t); - mPipTask = null; - mPipTransaction = null; - } - } - try { - mFinishCB.onTransitionFinished(wct.isEmpty() ? null : wct, t); - } catch (RemoteException e) { - Log.e(TAG, "Failed to call animation finish callback", e); - t.apply(); - } - // Only release the non-local created surface references. The animator is responsible - // for releasing the leashes created by local. - mInfo.releaseAllSurfaces(); - // Reset all members. - mListener = null; - mFinishCB = null; - mPausingTasks = null; - mOpeningTasks = null; - mAppearedTargets = null; - mInfo = null; - mOpeningSeparateHome = false; - mLeashMap = null; - mTransition = null; - mState = STATE_NORMAL; - } - - @Override public void setDeferCancelUntilNextTransition(boolean defer, boolean screenshot) { - } - - @Override public void cleanupScreenshot() { - } - - @Override public void setWillFinishToHome(boolean willFinishToHome) { - mWillFinishToHome = willFinishToHome; - } - - /** - * @see IRecentsAnimationController#removeTask - */ - @Override public boolean removeTask(int taskId) { - return false; - } - - /** - * @see IRecentsAnimationController#detachNavigationBarFromApp - */ - @Override public void detachNavigationBarFromApp(boolean moveHomeToTop) { - try { - ActivityTaskManager.getService().detachNavigationBarFromApp(mTransition); - } catch (RemoteException e) { - Log.e(TAG, "Failed to detach the navigation bar from app", e); - } - } - - /** - * @see IRecentsAnimationController#animateNavigationBarToApp(long) - */ - @Override public void animateNavigationBarToApp(long duration) { - } - } - - /** Utility class to track the state of a task as-seen by recents. */ - private static class TaskState { - WindowContainerToken mToken; - ActivityManager.RunningTaskInfo mTaskInfo; - - /** The surface/leash of the task provided by Core. */ - SurfaceControl mTaskSurface; - - /** The (local) animation-leash created for this task. */ - SurfaceControl mLeash; - - TaskState(TransitionInfo.Change change, SurfaceControl leash) { - mToken = change.getContainer(); - mTaskInfo = change.getTaskInfo(); - mTaskSurface = change.getLeash(); - mLeash = leash; - } - - static int indexOf(ArrayList list, TransitionInfo.Change change) { - for (int i = list.size() - 1; i >= 0; --i) { - if (list.get(i).mToken.equals(change.getContainer())) { - return i; - } - } - return -1; - } - - public String toString() { - return "" + mToken + " : " + mLeash; - } - } -} diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/FrameProtoTracer.java b/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/FrameProtoTracer.java deleted file mode 100644 index 98212e1d91b61..0000000000000 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/FrameProtoTracer.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2019 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.systemui.shared.tracing; - -import android.os.Trace; -import android.util.Log; -import android.view.Choreographer; - -import com.android.internal.util.TraceBuffer; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Queue; -import java.util.function.Consumer; - -/** - * A proto tracer implementation that can be updated directly (upon state change), or on the next - * scheduled frame. - * - * @param

The class type of the proto provider - * @param The proto class type of the encapsulating proto - * @param The proto class type of the individual proto entries in the buffer - * @param The proto class type of the entry root proto in the buffer - */ -public class FrameProtoTracer - implements Choreographer.FrameCallback { - - private static final String TAG = "FrameProtoTracer"; - private static final int BUFFER_CAPACITY = 1024 * 1024; - - private final Object mLock = new Object(); - private final TraceBuffer mBuffer; - private final File mTraceFile; - private final ProtoTraceParams mParams; - private Choreographer mChoreographer; - private final Queue mPool = new ArrayDeque<>(); - private final ArrayList> mTraceables = new ArrayList<>(); - private final ArrayList> mTmpTraceables = new ArrayList<>(); - - private volatile boolean mEnabled; - private boolean mFrameScheduled; - - private final TraceBuffer.ProtoProvider mProvider = - new TraceBuffer.ProtoProvider() { - @Override - public int getItemSize(P proto) { - return mParams.getProtoSize(proto); - } - - @Override - public byte[] getBytes(P proto) { - return mParams.getProtoBytes(proto); - } - - @Override - public void write(S encapsulatingProto, Queue buffer, OutputStream os) - throws IOException { - os.write(mParams.serializeEncapsulatingProto(encapsulatingProto, buffer)); - } - }; - - public interface ProtoTraceParams { - File getTraceFile(); - S getEncapsulatingTraceProto(); - T updateBufferProto(T reuseObj, ArrayList> traceables); - byte[] serializeEncapsulatingProto(S encapsulatingProto, Queue buffer); - byte[] getProtoBytes(P proto); - int getProtoSize(P proto); - } - - public FrameProtoTracer(ProtoTraceParams params) { - mParams = params; - mBuffer = new TraceBuffer<>(BUFFER_CAPACITY, mProvider, new Consumer() { - @Override - public void accept(T t) { - onProtoDequeued(t); - } - }); - mTraceFile = params.getTraceFile(); - } - - public void start() { - synchronized (mLock) { - if (mEnabled) { - return; - } - mBuffer.resetBuffer(); - mEnabled = true; - } - logState(); - } - - public void stop() { - synchronized (mLock) { - if (!mEnabled) { - return; - } - mEnabled = false; - } - writeToFile(); - } - - public boolean isEnabled() { - return mEnabled; - } - - public void add(ProtoTraceable traceable) { - synchronized (mLock) { - mTraceables.add(traceable); - } - } - - public void remove(ProtoTraceable traceable) { - synchronized (mLock) { - mTraceables.remove(traceable); - } - } - - public void scheduleFrameUpdate() { - if (!mEnabled || mFrameScheduled) { - return; - } - - // Schedule an update on the next frame - if (mChoreographer == null) { - mChoreographer = Choreographer.getMainThreadInstance(); - } - mChoreographer.postFrameCallback(this); - mFrameScheduled = true; - } - - public void update() { - if (!mEnabled) { - return; - } - - logState(); - } - - public float getBufferUsagePct() { - return (float) mBuffer.getBufferSize() / BUFFER_CAPACITY; - } - - @Override - public void doFrame(long frameTimeNanos) { - logState(); - } - - private void onProtoDequeued(T proto) { - mPool.add(proto); - } - - private void logState() { - synchronized (mLock) { - mTmpTraceables.addAll(mTraceables); - } - - mBuffer.add(mParams.updateBufferProto(mPool.poll(), mTmpTraceables)); - mTmpTraceables.clear(); - mFrameScheduled = false; - } - - private void writeToFile() { - try { - Trace.beginSection("ProtoTracer.writeToFile"); - mBuffer.writeTraceToFile(mTraceFile, mParams.getEncapsulatingTraceProto()); - } catch (IOException e) { - Log.e(TAG, "Unable to write buffer to file", e); - } finally { - Trace.endSection(); - } - } -} - - diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/ProtoTraceable.java b/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/ProtoTraceable.java deleted file mode 100644 index e05b0b074449c..0000000000000 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/tracing/ProtoTraceable.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017 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.systemui.shared.tracing; - -/** - * @see FrameProtoTracer - */ -public interface ProtoTraceable { - - /** - * NOTE: Implementations should update all fields in this proto. - */ - void writeToProto(T proto); -} diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index 1f1b154ef1c8a..04acd0b911736 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -123,7 +123,6 @@ import com.android.systemui.statusbar.policy.UserSwitcherController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.statusbar.window.StatusBarWindowController; import com.android.systemui.telephony.TelephonyListenerManager; -import com.android.systemui.tracing.ProtoTracer; import com.android.systemui.tuner.TunablePadding.TunablePaddingService; import com.android.systemui.tuner.TunerService; import com.android.systemui.util.DeviceConfigProxy; @@ -335,7 +334,6 @@ public class Dependency { @Inject Lazy mWallpaperManager; @Inject Lazy mCommandQueue; @Inject Lazy mRecordingController; - @Inject Lazy mProtoTracer; @Inject Lazy mMediaOutputDialogFactory; @Inject Lazy mDeviceConfigProxy; @Inject Lazy mTelephonyListenerManager; @@ -528,7 +526,6 @@ public class Dependency { mProviders.put(DozeParameters.class, mDozeParameters::get); mProviders.put(IWallpaperManager.class, mWallpaperManager::get); mProviders.put(CommandQueue.class, mCommandQueue::get); - mProviders.put(ProtoTracer.class, mProtoTracer::get); mProviders.put(DeviceConfigProxy.class, mDeviceConfigProxy::get); mProviders.put(TelephonyListenerManager.class, mTelephonyListenerManager::get); diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java index a8af67a9fc97f..b21b0017208c4 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -88,11 +88,7 @@ import com.android.systemui.shared.system.QuickStepContract; import com.android.systemui.shared.system.SysUiStatsLog; import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListeners; -import com.android.systemui.shared.tracing.ProtoTraceable; import com.android.systemui.statusbar.phone.LightBarController; -import com.android.systemui.tracing.ProtoTracer; -import com.android.systemui.tracing.nano.EdgeBackGestureHandlerProto; -import com.android.systemui.tracing.nano.SystemUiTraceProto; import com.android.systemui.util.Assert; import com.android.wm.shell.back.BackAnimation; import com.android.wm.shell.desktopmode.DesktopMode; @@ -115,8 +111,7 @@ import javax.inject.Provider; /** * Utility class to handle edge swipes for back gesture */ -public class EdgeBackGestureHandler implements PluginListener, - ProtoTraceable { +public class EdgeBackGestureHandler implements PluginListener { private static final String TAG = "EdgeBackGestureHandler"; private static final int MAX_LONG_PRESS_TIMEOUT = SystemProperties.getInt( @@ -192,7 +187,6 @@ public class EdgeBackGestureHandler implements PluginListener mButtonForcedVisibleCallback; private final PluginManager mPluginManager; - private final ProtoTracer mProtoTracer; private final NavigationModeController mNavigationModeController; private final BackPanelController.Factory mBackPanelControllerFactory; private final ViewConfiguration mViewConfiguration; @@ -402,7 +396,6 @@ public class EdgeBackGestureHandler implements PluginListener { - - private static final String TAG = "ProtoTracer"; - private static final long MAGIC_NUMBER_VALUE = ((long) MAGIC_NUMBER_H << 32) | MAGIC_NUMBER_L; - - private final Context mContext; - private final FrameProtoTracer mProtoTracer; - - @Inject - public ProtoTracer(Context context, DumpManager dumpManager) { - mContext = context; - mProtoTracer = new FrameProtoTracer<>(this); - dumpManager.registerDumpable(this); - } - - @Override - public File getTraceFile() { - return new File(mContext.getFilesDir(), "sysui_trace.pb"); - } - - @Override - public SystemUiTraceFileProto getEncapsulatingTraceProto() { - return new SystemUiTraceFileProto(); - } - - @Override - public SystemUiTraceEntryProto updateBufferProto(SystemUiTraceEntryProto reuseObj, - ArrayList> traceables) { - SystemUiTraceEntryProto proto = reuseObj != null - ? reuseObj - : new SystemUiTraceEntryProto(); - proto.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos(); - proto.systemUi = proto.systemUi != null ? proto.systemUi : new SystemUiTraceProto(); - for (ProtoTraceable t : traceables) { - t.writeToProto(proto.systemUi); - } - return proto; - } - - @Override - public byte[] serializeEncapsulatingProto(SystemUiTraceFileProto encapsulatingProto, - Queue buffer) { - encapsulatingProto.magicNumber = MAGIC_NUMBER_VALUE; - encapsulatingProto.entry = buffer.toArray(new SystemUiTraceEntryProto[0]); - return MessageNano.toByteArray(encapsulatingProto); - } - - @Override - public byte[] getProtoBytes(MessageNano proto) { - return MessageNano.toByteArray(proto); - } - - @Override - public int getProtoSize(MessageNano proto) { - return proto.getCachedSize(); - } - - public void start() { - mProtoTracer.start(); - } - - public void stop() { - mProtoTracer.stop(); - } - - public boolean isEnabled() { - return mProtoTracer.isEnabled(); - } - - public void add(ProtoTraceable traceable) { - mProtoTracer.add(traceable); - } - - public void remove(ProtoTraceable traceable) { - mProtoTracer.remove(traceable); - } - - public void scheduleFrameUpdate() { - mProtoTracer.scheduleFrameUpdate(); - } - - public void update() { - mProtoTracer.update(); - } - - @Override - public void dump(@NonNull PrintWriter pw, @NonNull String[] args) { - pw.println("ProtoTracer:"); - pw.print(" "); pw.println("enabled: " + mProtoTracer.isEnabled()); - pw.print(" "); pw.println("usagePct: " + mProtoTracer.getBufferUsagePct()); - pw.print(" "); pw.println("file: " + getTraceFile()); - } -} diff --git a/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto b/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto deleted file mode 100644 index d940a6b5c4600..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/tracing/sysui_trace.proto +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -syntax = "proto2"; - -package com.android.systemui.tracing; - -option java_multiple_files = true; - -message SystemUiTraceProto { - - optional EdgeBackGestureHandlerProto edge_back_gesture_handler = 1; -} - -message EdgeBackGestureHandlerProto { - - optional bool allow_gesture = 1; -} - -/* represents a file full of system ui trace entries. - Encoded, it should start with 0x9 0x53 0x59 0x53 0x55 0x49 0x54 0x52 0x43 (.SYSUITRC), such - that they can be easily identified. */ -message SystemUiTraceFileProto { - - /* constant; MAGIC_NUMBER = (long) MAGIC_NUMBER_H << 32 | MagicNumber.MAGIC_NUMBER_L - (this is needed because enums have to be 32 bits and there's no nice way to put 64bit - constants into .proto files. */ - enum MagicNumber { - INVALID = 0; - MAGIC_NUMBER_L = 0x55535953; /* SYSU (little-endian ASCII) */ - MAGIC_NUMBER_H = 0x43525449; /* ITRC (little-endian ASCII) */ - } - - optional fixed64 magic_number = 1; /* Must be the first field, set to value in MagicNumber */ - repeated SystemUiTraceEntryProto entry = 2; -} - -/* one system ui trace entry. */ -message SystemUiTraceEntryProto { - /* required: elapsed realtime in nanos since boot of when this entry was logged */ - optional fixed64 elapsed_realtime_nanos = 1; - - optional SystemUiTraceProto system_ui = 3; -} diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index 5144d19662227..943e906a1ebc4 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -51,15 +51,11 @@ import com.android.systemui.model.SysUiState; import com.android.systemui.notetask.NoteTaskInitializer; import com.android.systemui.settings.DisplayTracker; import com.android.systemui.settings.UserTracker; -import com.android.systemui.shared.tracing.ProtoTraceable; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; -import com.android.systemui.tracing.ProtoTracer; -import com.android.systemui.tracing.nano.SystemUiTraceProto; import com.android.wm.shell.desktopmode.DesktopMode; import com.android.wm.shell.desktopmode.DesktopModeTaskRepository; -import com.android.wm.shell.nano.WmShellTraceProto; import com.android.wm.shell.onehanded.OneHanded; import com.android.wm.shell.onehanded.OneHandedEventCallback; import com.android.wm.shell.onehanded.OneHandedTransitionCallback; @@ -94,8 +90,7 @@ import javax.inject.Inject; @SysUISingleton public final class WMShell implements CoreStartable, - CommandQueue.Callbacks, - ProtoTraceable { + CommandQueue.Callbacks { private static final String TAG = WMShell.class.getName(); private static final int INVALID_SYSUI_STATE_MASK = SYSUI_STATE_DIALOG_SHOWING @@ -122,7 +117,6 @@ public final class WMShell implements private final ScreenLifecycle mScreenLifecycle; private final SysUiState mSysUiState; private final WakefulnessLifecycle mWakefulnessLifecycle; - private final ProtoTracer mProtoTracer; private final UserTracker mUserTracker; private final DisplayTracker mDisplayTracker; private final NoteTaskInitializer mNoteTaskInitializer; @@ -184,7 +178,6 @@ public final class WMShell implements KeyguardUpdateMonitor keyguardUpdateMonitor, ScreenLifecycle screenLifecycle, SysUiState sysUiState, - ProtoTracer protoTracer, WakefulnessLifecycle wakefulnessLifecycle, UserTracker userTracker, DisplayTracker displayTracker, @@ -203,7 +196,6 @@ public final class WMShell implements mOneHandedOptional = oneHandedOptional; mDesktopModeOptional = desktopMode; mWakefulnessLifecycle = wakefulnessLifecycle; - mProtoTracer = protoTracer; mUserTracker = userTracker; mDisplayTracker = displayTracker; mNoteTaskInitializer = noteTaskInitializer; @@ -223,7 +215,6 @@ public final class WMShell implements // Subscribe to user changes mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor()); - mProtoTracer.add(this); mCommandQueue.addCallback(this); mPipOptional.ifPresent(this::initPip); mSplitScreenOptional.ifPresent(this::initSplitScreen); @@ -360,12 +351,6 @@ public final class WMShell implements }, mSysUiMainExecutor); } - @Override - public void writeToProto(SystemUiTraceProto proto) { - // Dump to WMShell proto here - // TODO: Figure out how we want to synchronize while dumping to proto - } - @Override public void dump(PrintWriter pw, String[] args) { // Handle commands if provided diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java index 9de7a87c8b82a..ef0adbb91a632 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java @@ -34,7 +34,6 @@ import com.android.systemui.settings.UserTracker; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; -import com.android.systemui.tracing.ProtoTracer; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.desktopmode.DesktopMode; import com.android.wm.shell.desktopmode.DesktopModeTaskRepository; @@ -76,7 +75,6 @@ public class WMShellTest extends SysuiTestCase { @Mock SplitScreen mSplitScreen; @Mock OneHanded mOneHanded; @Mock WakefulnessLifecycle mWakefulnessLifecycle; - @Mock ProtoTracer mProtoTracer; @Mock UserTracker mUserTracker; @Mock ShellExecutor mSysUiMainExecutor; @Mock NoteTaskInitializer mNoteTaskInitializer; @@ -99,7 +97,6 @@ public class WMShellTest extends SysuiTestCase { mKeyguardUpdateMonitor, mScreenLifecycle, mSysUiState, - mProtoTracer, mWakefulnessLifecycle, mUserTracker, displayTracker,