1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.shared.system; 18 19 import android.annotation.IntDef; 20 import android.os.Build; 21 import android.text.TextUtils; 22 import android.view.View; 23 24 import com.android.internal.jank.InteractionJankMonitor; 25 import com.android.internal.jank.InteractionJankMonitor.Configuration; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 public final class InteractionJankMonitorWrapper { 31 // Launcher journeys. 32 public static final int CUJ_APP_LAUNCH_FROM_RECENTS = 33 InteractionJankMonitor.CUJ_LAUNCHER_APP_LAUNCH_FROM_RECENTS; 34 public static final int CUJ_APP_LAUNCH_FROM_ICON = 35 InteractionJankMonitor.CUJ_LAUNCHER_APP_LAUNCH_FROM_ICON; 36 public static final int CUJ_APP_CLOSE_TO_HOME = 37 InteractionJankMonitor.CUJ_LAUNCHER_APP_CLOSE_TO_HOME; 38 public static final int CUJ_APP_CLOSE_TO_HOME_FALLBACK = 39 InteractionJankMonitor.CUJ_LAUNCHER_APP_CLOSE_TO_HOME_FALLBACK; 40 public static final int CUJ_APP_CLOSE_TO_PIP = 41 InteractionJankMonitor.CUJ_LAUNCHER_APP_CLOSE_TO_PIP; 42 public static final int CUJ_QUICK_SWITCH = 43 InteractionJankMonitor.CUJ_LAUNCHER_QUICK_SWITCH; 44 public static final int CUJ_OPEN_ALL_APPS = 45 InteractionJankMonitor.CUJ_LAUNCHER_OPEN_ALL_APPS; 46 public static final int CUJ_CLOSE_ALL_APPS_SWIPE = 47 InteractionJankMonitor.CUJ_LAUNCHER_CLOSE_ALL_APPS_SWIPE; 48 public static final int CUJ_CLOSE_ALL_APPS_TO_HOME = 49 InteractionJankMonitor.CUJ_LAUNCHER_CLOSE_ALL_APPS_TO_HOME; 50 public static final int CUJ_ALL_APPS_SCROLL = 51 InteractionJankMonitor.CUJ_LAUNCHER_ALL_APPS_SCROLL; 52 public static final int CUJ_APP_LAUNCH_FROM_WIDGET = 53 InteractionJankMonitor.CUJ_LAUNCHER_APP_LAUNCH_FROM_WIDGET; 54 public static final int CUJ_SPLIT_SCREEN_ENTER = 55 InteractionJankMonitor.CUJ_SPLIT_SCREEN_ENTER; 56 public static final int CUJ_LAUNCHER_UNLOCK_ENTRANCE_ANIMATION = 57 InteractionJankMonitor.CUJ_LAUNCHER_UNLOCK_ENTRANCE_ANIMATION; 58 public static final int CUJ_RECENTS_SCROLLING = 59 InteractionJankMonitor.CUJ_RECENTS_SCROLLING; 60 public static final int CUJ_APP_SWIPE_TO_RECENTS = 61 InteractionJankMonitor.CUJ_LAUNCHER_APP_SWIPE_TO_RECENTS; 62 public static final int CUJ_OPEN_SEARCH_RESULT = 63 InteractionJankMonitor.CUJ_LAUNCHER_OPEN_SEARCH_RESULT; 64 public static final int CUJ_SHADE_EXPAND_FROM_STATUS_BAR = 65 InteractionJankMonitor.CUJ_SHADE_EXPAND_FROM_STATUS_BAR; 66 67 @IntDef({ 68 CUJ_APP_LAUNCH_FROM_RECENTS, 69 CUJ_APP_LAUNCH_FROM_ICON, 70 CUJ_APP_CLOSE_TO_HOME, 71 CUJ_APP_CLOSE_TO_HOME_FALLBACK, 72 CUJ_APP_CLOSE_TO_PIP, 73 CUJ_QUICK_SWITCH, 74 CUJ_APP_LAUNCH_FROM_WIDGET, 75 CUJ_LAUNCHER_UNLOCK_ENTRANCE_ANIMATION, 76 CUJ_RECENTS_SCROLLING, 77 CUJ_APP_SWIPE_TO_RECENTS, 78 CUJ_OPEN_ALL_APPS, 79 CUJ_CLOSE_ALL_APPS_SWIPE, 80 CUJ_CLOSE_ALL_APPS_TO_HOME, 81 CUJ_OPEN_SEARCH_RESULT, 82 CUJ_SHADE_EXPAND_FROM_STATUS_BAR, 83 }) 84 @Retention(RetentionPolicy.SOURCE) 85 public @interface CujType { 86 } 87 88 /** 89 * Begin a trace session. 90 * 91 * @param v an attached view. 92 * @param cujType the specific {@link InteractionJankMonitor.CujType}. 93 */ begin(View v, @CujType int cujType)94 public static void begin(View v, @CujType int cujType) { 95 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return; 96 InteractionJankMonitor.getInstance().begin(v, cujType); 97 } 98 99 /** 100 * Begin a trace session. 101 * 102 * @param v an attached view. 103 * @param cujType the specific {@link InteractionJankMonitor.CujType}. 104 * @param timeout duration to cancel the instrumentation in ms 105 */ begin(View v, @CujType int cujType, long timeout)106 public static void begin(View v, @CujType int cujType, long timeout) { 107 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return; 108 Configuration.Builder builder = 109 Configuration.Builder.withView(cujType, v) 110 .setTimeout(timeout); 111 InteractionJankMonitor.getInstance().begin(builder); 112 } 113 114 /** 115 * Begin a trace session. 116 * 117 * @param v an attached view. 118 * @param cujType the specific {@link InteractionJankMonitor.CujType}. 119 * @param tag the tag to distinguish different flow of same type CUJ. 120 */ begin(View v, @CujType int cujType, String tag)121 public static void begin(View v, @CujType int cujType, String tag) { 122 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return; 123 Configuration.Builder builder = 124 Configuration.Builder.withView(cujType, v); 125 if (!TextUtils.isEmpty(tag)) { 126 builder.setTag(tag); 127 } 128 InteractionJankMonitor.getInstance().begin(builder); 129 } 130 131 /** 132 * End a trace session. 133 * 134 * @param cujType the specific {@link InteractionJankMonitor.CujType}. 135 */ end(@ujType int cujType)136 public static void end(@CujType int cujType) { 137 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return; 138 InteractionJankMonitor.getInstance().end(cujType); 139 } 140 141 /** 142 * Cancel the trace session. 143 */ cancel(@ujType int cujType)144 public static void cancel(@CujType int cujType) { 145 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return; 146 InteractionJankMonitor.getInstance().cancel(cujType); 147 } 148 } 149