Unifying various tracing calls
Change-Id: Iedf6662ad1d7281b850bdc43b3a1e373ce535ac6
diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java
index 00a06ae..d24de8e 100644
--- a/src/com/android/launcher3/BaseDraggingActivity.java
+++ b/src/com/android/launcher3/BaseDraggingActivity.java
@@ -36,11 +36,11 @@
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.shortcuts.DeepShortcutManager;
-import com.android.launcher3.uioverrides.DejankBinderTracker;
import com.android.launcher3.uioverrides.DisplayRotationListener;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Themes;
+import com.android.launcher3.util.TraceHelper;
/**
* Extension of BaseActivity allowing support for drag-n-drop
@@ -66,8 +66,10 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mIsSafeModeEnabled = DejankBinderTracker.whitelistIpcs(() ->
- getPackageManager().isSafeMode());
+
+
+ mIsSafeModeEnabled = TraceHelper.whitelistIpcs("isSafeMode",
+ () -> getPackageManager().isSafeMode());
mRotationListener = new DisplayRotationListener(this, this::onDeviceRotationChanged);
// Update theme
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c92d917..a19ba21 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -32,8 +32,6 @@
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
import static com.android.launcher3.logging.LoggerUtils.newTarget;
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
-import static com.android.launcher3.util.RaceConditionTracker.ENTER;
-import static com.android.launcher3.util.RaceConditionTracker.EXIT;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -115,7 +113,6 @@
import com.android.launcher3.qsb.QsbContainerView;
import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.touch.ItemClickHandler;
-import com.android.launcher3.uioverrides.DejankBinderTracker;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.userevent.nano.LauncherLogProto;
@@ -132,7 +129,6 @@
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
-import com.android.launcher3.util.RaceConditionTracker;
import com.android.launcher3.util.ShortcutUtil;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.Themes;
@@ -214,9 +210,11 @@
private static final String RUNTIME_STATE_PENDING_ACTIVITY_RESULT = "launcher.activity_result";
// Type: SparseArray<Parcelable>
private static final String RUNTIME_STATE_WIDGET_PANEL = "launcher.widget_panel";
+
public static final String ON_CREATE_EVT = "Launcher.onCreate";
- private static final String ON_START_EVT = "Launcher.onStart";
- private static final String ON_RESUME_EVT = "Launcher.onResume";
+ public static final String ON_START_EVT = "Launcher.onStart";
+ public static final String ON_RESUME_EVT = "Launcher.onResume";
+ public static final String ON_NEW_INTENT_EVT = "Launcher.onNewIntent";
private LauncherStateManager mStateManager;
@@ -313,8 +311,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
- DejankBinderTracker.allowBinderTrackingInTests();
- RaceConditionTracker.onEvent(ON_CREATE_EVT, ENTER);
+ TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT, TraceHelper.FLAG_UI_EVENT);
if (DEBUG_STRICT_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
@@ -329,10 +326,8 @@
.penaltyDeath()
.build());
}
- TraceHelper.beginSection("Launcher-onCreate");
super.onCreate(savedInstanceState);
- TraceHelper.partitionSection("Launcher-onCreate", "super call");
LauncherAppState app = LauncherAppState.getInstance(this);
mOldConfig = new Configuration(getResources().getConfiguration());
@@ -414,8 +409,6 @@
mRotationHelper.initialize();
- TraceHelper.endSection("Launcher-onCreate");
- RaceConditionTracker.onEvent(ON_CREATE_EVT, EXIT);
mStateManager.addStateListener(new LauncherStateManager.StateListener() {
@Override
public void onStateTransitionStart(LauncherState toState) {
@@ -435,7 +428,8 @@
}
}
});
- DejankBinderTracker.disallowBinderTrackingInTests();
+
+ TraceHelper.INSTANCE.endSection();
}
protected LauncherOverlayManager getDefaultOverlay() {
@@ -940,16 +934,14 @@
@Override
protected void onStart() {
- DejankBinderTracker.allowBinderTrackingInTests();
- RaceConditionTracker.onEvent(ON_START_EVT, ENTER);
+ TraceHelper.INSTANCE.beginSection(ON_START_EVT, TraceHelper.FLAG_UI_EVENT);
super.onStart();
if (!mDeferOverlayCallbacks) {
mOverlayManager.onActivityStarted(this);
}
mAppWidgetHost.setListenIfResumed(true);
- RaceConditionTracker.onEvent(ON_START_EVT, EXIT);
- DejankBinderTracker.disallowBinderTrackingInTests();
+ TraceHelper.INSTANCE.endSection();
}
private void handleDeferredResume() {
@@ -1044,11 +1036,8 @@
@Override
protected void onResume() {
- DejankBinderTracker.allowBinderTrackingInTests();
- RaceConditionTracker.onEvent(ON_RESUME_EVT, ENTER);
- TraceHelper.beginSection("ON_RESUME");
+ TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT, TraceHelper.FLAG_UI_EVENT);
super.onResume();
- TraceHelper.partitionSection("ON_RESUME", "superCall");
mHandler.removeCallbacks(mHandleDeferredResume);
Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
@@ -1068,9 +1057,7 @@
mOverlayManager.onActivityResumed(this);
}
- TraceHelper.endSection("ON_RESUME");
- RaceConditionTracker.onEvent(ON_RESUME_EVT, EXIT);
- DejankBinderTracker.disallowBinderTrackingInTests();
+ TraceHelper.INSTANCE.endSection();
}
@Override
@@ -1429,7 +1416,7 @@
@Override
protected void onNewIntent(Intent intent) {
- TraceHelper.beginSection("NEW_INTENT");
+ TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
super.onNewIntent(intent);
boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
@@ -1481,7 +1468,7 @@
mOverlayManager.hideOverlay(isStarted() && !isForceInvisible());
}
- TraceHelper.endSection("NEW_INTENT");
+ TraceHelper.INSTANCE.endSection();
}
@Override
@@ -1984,7 +1971,7 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void startBinding() {
- TraceHelper.beginSection("startBinding");
+ TraceHelper.INSTANCE.beginSection("startBinding");
// Floating panels (except the full widget sheet) are associated with individual icons. If
// we are starting a fresh bind, close all such panels as all the icons are about
// to go away.
@@ -2002,7 +1989,7 @@
if (mHotseat != null) {
mHotseat.resetLayout(getWallpaperDeviceProfile().isVerticalBarLayout());
}
- TraceHelper.endSection("startBinding");
+ TraceHelper.INSTANCE.endSection();
}
@Override
@@ -2195,112 +2182,113 @@
return null;
}
}
-
+ final AppWidgetHostView view;
if (mIsSafeModeEnabled) {
- PendingAppWidgetHostView view =
- new PendingAppWidgetHostView(this, item, mIconCache, true);
+ view = new PendingAppWidgetHostView(this, item, mIconCache, true);
prepareAppWidget(view, item);
return view;
}
- TraceHelper.beginSection("BIND_WIDGET");
+ TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
- final LauncherAppWidgetProviderInfo appWidgetInfo;
+ try {
+ final LauncherAppWidgetProviderInfo appWidgetInfo;
- if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
- // If the provider is not ready, bind as a pending widget.
- appWidgetInfo = null;
- } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
- // The widget id is not valid. Try to find the widget based on the provider info.
- appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
- } else {
- appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
- }
-
- // If the provider is ready, but the width is not yet restored, try to restore it.
- if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) &&
- (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
- if (appWidgetInfo == null) {
- Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
- + " belongs to component " + item.providerName
- + ", as the provider is null");
- getModelWriter().deleteItemFromDatabase(item);
- return null;
+ if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) {
+ // If the provider is not ready, bind as a pending widget.
+ appWidgetInfo = null;
+ } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
+ // The widget id is not valid. Try to find the widget based on the provider info.
+ appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user);
+ } else {
+ appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId);
}
- // If we do not have a valid id, try to bind an id.
- if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
- if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
- // Id has not been allocated yet. Allocate a new id.
- item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
- item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
+ // If the provider is ready, but the width is not yet restored, try to restore it.
+ if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
+ && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) {
+ if (appWidgetInfo == null) {
+ Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
+ + " belongs to component " + item.providerName
+ + ", as the provider is null");
+ getModelWriter().deleteItemFromDatabase(item);
+ return null;
+ }
- // Also try to bind the widget. If the bind fails, the user will be shown
- // a click to setup UI, which will ask for the bind permission.
- PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
- pendingInfo.spanX = item.spanX;
- pendingInfo.spanY = item.spanY;
- pendingInfo.minSpanX = item.minSpanX;
- pendingInfo.minSpanY = item.minSpanY;
- Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
- pendingInfo);
+ // If we do not have a valid id, try to bind an id.
+ if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
+ if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
+ // Id has not been allocated yet. Allocate a new id.
+ item.appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+ item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED;
- boolean isDirectConfig =
- item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
- if (isDirectConfig && item.bindOptions != null) {
- Bundle newOptions = item.bindOptions.getExtras();
- if (options != null) {
- newOptions.putAll(options);
+ // Also try to bind the widget. If the bind fails, the user will be shown
+ // a click to setup UI, which will ask for the bind permission.
+ PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo);
+ pendingInfo.spanX = item.spanX;
+ pendingInfo.spanY = item.spanY;
+ pendingInfo.minSpanX = item.minSpanX;
+ pendingInfo.minSpanY = item.minSpanY;
+ Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this,
+ pendingInfo);
+
+ boolean isDirectConfig =
+ item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG);
+ if (isDirectConfig && item.bindOptions != null) {
+ Bundle newOptions = item.bindOptions.getExtras();
+ if (options != null) {
+ newOptions.putAll(options);
+ }
+ options = newOptions;
}
- options = newOptions;
+ boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
+ item.appWidgetId, appWidgetInfo, options);
+
+ // We tried to bind once. If we were not able to bind, we would need to
+ // go through the permission dialog, which means we cannot skip the config
+ // activity.
+ item.bindOptions = null;
+ item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
+
+ // Bind succeeded
+ if (success) {
+ // If the widget has a configure activity, it is still needs to set it
+ // up, otherwise the widget is ready to go.
+ item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
+ ? LauncherAppWidgetInfo.RESTORE_COMPLETED
+ : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
+ }
+
+ getModelWriter().updateItemInDatabase(item);
}
- boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
- item.appWidgetId, appWidgetInfo, options);
-
- // We tried to bind once. If we were not able to bind, we would need to
- // go through the permission dialog, which means we cannot skip the config
- // activity.
- item.bindOptions = null;
- item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
-
- // Bind succeeded
- if (success) {
- // If the widget has a configure activity, it is still needs to set it up,
- // otherwise the widget is ready to go.
- item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig
- ? LauncherAppWidgetInfo.RESTORE_COMPLETED
- : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
- }
-
+ } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
+ && (appWidgetInfo.configure == null)) {
+ // The widget was marked as UI not ready, but there is no configure activity to
+ // update the UI.
+ item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
getModelWriter().updateItemInDatabase(item);
}
- } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY)
- && (appWidgetInfo.configure == null)) {
- // The widget was marked as UI not ready, but there is no configure activity to
- // update the UI.
- item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
- getModelWriter().updateItemInDatabase(item);
- }
- }
-
- final AppWidgetHostView view;
- if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
- // Verify that we own the widget
- if (appWidgetInfo == null) {
- FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
- getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
- return null;
}
- item.minSpanX = appWidgetInfo.minSpanX;
- item.minSpanY = appWidgetInfo.minSpanY;
- view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
- } else {
- view = new PendingAppWidgetHostView(this, item, mIconCache, false);
- }
- prepareAppWidget(view, item);
+ if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
+ // Verify that we own the widget
+ if (appWidgetInfo == null) {
+ FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
+ getModelWriter().deleteWidgetInfo(item, getAppWidgetHost());
+ return null;
+ }
- TraceHelper.endSection("BIND_WIDGET", "id=" + item.appWidgetId);
+ item.minSpanX = appWidgetInfo.minSpanX;
+ item.minSpanY = appWidgetInfo.minSpanY;
+ view = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
+ } else {
+ view = new PendingAppWidgetHostView(this, item, mIconCache, false);
+ }
+ prepareAppWidget(view, item);
+ } finally {
+ TraceHelper.INSTANCE.endSection();
+ }
+
return view;
}
@@ -2378,7 +2366,7 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void finishBindingItems(int pageBoundFirst) {
- TraceHelper.beginSection("finishBindingItems");
+ TraceHelper.INSTANCE.beginSection("finishBindingItems");
mWorkspace.restoreInstanceStateForRemainingPages();
setWorkspaceLoading(false);
@@ -2402,7 +2390,7 @@
mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
getViewCache().setCacheSize(R.layout.folder_page, 2);
- TraceHelper.endSection("finishBindingItems");
+ TraceHelper.INSTANCE.endSection();
}
private boolean canRunNewAppsAnimation() {
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index a29b7e1..2d4a816 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -40,6 +40,7 @@
import android.util.Log;
import android.util.LongSparseArray;
import android.util.MutableInt;
+import android.util.TimingLogger;
import com.android.launcher3.AppInfo;
import com.android.launcher3.FolderInfo;
@@ -169,82 +170,84 @@
}
}
- TraceHelper.beginSection(TAG);
+ TraceHelper.INSTANCE.beginSection(TAG);
+ TimingLogger logger = new TimingLogger(TAG, "run");
try (LauncherModel.LoaderTransaction transaction = mApp.getModel().beginLoader(this)) {
- TraceHelper.partitionSection(TAG, "step 1.1: loading workspace");
loadWorkspace();
+ logger.addSplit("loadWorkspace");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 1.2: bind workspace workspace");
mResults.bindWorkspace();
+ logger.addSplit("bindWorkspace");
// Notify the installer packages of packages with active installs on the first screen.
- TraceHelper.partitionSection(TAG, "step 1.3: send first screen broadcast");
sendFirstScreenActiveInstallsBroadcast();
+ logger.addSplit("sendFirstScreenActiveInstallsBroadcast");
// Take a break
- TraceHelper.partitionSection(TAG, "step 1 completed, wait for idle");
waitForIdle();
+ logger.addSplit("step 1 complete");
verifyNotStopped();
// second step
- TraceHelper.partitionSection(TAG, "step 2.1: loading all apps");
List<LauncherActivityInfo> allActivityList = loadAllApps();
+ logger.addSplit("loadAllApps");
- TraceHelper.partitionSection(TAG, "step 2.2: Binding all apps");
verifyNotStopped();
mResults.bindAllApps();
+ logger.addSplit("bindAllApps");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 2.3: Update icon cache");
IconCacheUpdateHandler updateHandler = mIconCache.getUpdateHandler();
setIgnorePackages(updateHandler);
updateHandler.updateIcons(allActivityList,
LauncherActivityCachingLogic.newInstance(mApp.getContext()),
mApp.getModel()::onPackageIconsUpdated);
+ logger.addSplit("update icon cache");
// Take a break
- TraceHelper.partitionSection(TAG, "step 2 completed, wait for idle");
waitForIdle();
+ logger.addSplit("step 2 complete");
verifyNotStopped();
// third step
- TraceHelper.partitionSection(TAG, "step 3.1: loading deep shortcuts");
loadDeepShortcuts();
+ logger.addSplit("loadDeepShortcuts");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 3.2: bind deep shortcuts");
mResults.bindDeepShortcuts();
+ logger.addSplit("bindDeepShortcuts");
// Take a break
- TraceHelper.partitionSection(TAG, "step 3 completed, wait for idle");
waitForIdle();
+ logger.addSplit("step 3 complete");
verifyNotStopped();
// fourth step
- TraceHelper.partitionSection(TAG, "step 4.1: loading widgets");
List<ComponentWithLabel> allWidgetsList = mBgDataModel.widgetsModel.update(mApp, null);
+ logger.addSplit("load widgets");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 4.2: Binding widgets");
mResults.bindWidgets();
-
+ logger.addSplit("bindWidgets");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 4.3: save widgets in icon cache");
updateHandler.updateIcons(allWidgetsList, new ComponentCachingLogic(
mApp.getContext(), true), mApp.getModel()::onWidgetLabelsUpdated);
+ logger.addSplit("save widgets in icon cache");
verifyNotStopped();
- TraceHelper.partitionSection(TAG, "step 5: Finish icon cache update");
updateHandler.finish();
+ logger.addSplit("finish icon update");
transaction.commit();
} catch (CancellationException e) {
// Loader stopped, ignore
- TraceHelper.partitionSection(TAG, "Cancelled");
+ logger.addSplit("Cancelled");
+ } finally {
+ logger.dumpToLog();
}
- TraceHelper.endSection(TAG);
+ TraceHelper.INSTANCE.endSection();
}
public synchronized void stopLocked() {
diff --git a/src/com/android/launcher3/util/MainThreadInitializedObject.java b/src/com/android/launcher3/util/MainThreadInitializedObject.java
index cf4e8c7..520a9ed 100644
--- a/src/com/android/launcher3/util/MainThreadInitializedObject.java
+++ b/src/com/android/launcher3/util/MainThreadInitializedObject.java
@@ -22,7 +22,6 @@
import androidx.annotation.VisibleForTesting;
-import com.android.launcher3.uioverrides.DejankBinderTracker;
import com.android.launcher3.util.ResourceBasedOverride.Overrides;
import java.util.concurrent.ExecutionException;
@@ -42,8 +41,8 @@
public T get(Context context) {
if (mValue == null) {
if (Looper.myLooper() == Looper.getMainLooper()) {
- mValue = DejankBinderTracker.whitelistIpcs(() ->
- mProvider.get(context.getApplicationContext()));
+ mValue = TraceHelper.whitelistIpcs("main.thread.object",
+ () -> mProvider.get(context.getApplicationContext()));
} else {
try {
return MAIN_EXECUTOR.submit(() -> get(context)).get();
diff --git a/src/com/android/launcher3/util/RaceConditionTracker.java b/src/com/android/launcher3/util/RaceConditionTracker.java
deleted file mode 100644
index 6954d0e..0000000
--- a/src/com/android/launcher3/util/RaceConditionTracker.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2018 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.util;
-
-/**
- * Event tracker for reliably reproducing race conditions in tests.
- * The app should call onEvent() for events that the test will try to reproduce in all possible
- * orders.
- */
-public class RaceConditionTracker {
- public final static boolean ENTER = true;
- public final static boolean EXIT = false;
- static final String ENTER_POSTFIX = "enter";
- static final String EXIT_POSTFIX = "exit";
-
- public interface EventProcessor {
- void onEvent(String eventName);
- }
-
- private static EventProcessor sEventProcessor;
-
- static void setEventProcessor(EventProcessor eventProcessor) {
- sEventProcessor = eventProcessor;
- }
-
- public static void onEvent(String eventName) {
- if (sEventProcessor != null) sEventProcessor.onEvent(eventName);
- }
-
- public static void onEvent(String eventName, boolean isEnter) {
- if (sEventProcessor != null) {
- sEventProcessor.onEvent(enterExitEvt(eventName, isEnter));
- }
- }
-
- public static String enterExitEvt(String eventName, boolean isEnter) {
- return eventName + ":" + (isEnter ? ENTER_POSTFIX : EXIT_POSTFIX);
- }
-
- public static String enterEvt(String eventName) {
- return enterExitEvt(eventName, ENTER);
- }
-
- public static String exitEvt(String eventName) {
- return enterExitEvt(eventName, EXIT);
- }
-}
diff --git a/src/com/android/launcher3/util/TraceHelper.java b/src/com/android/launcher3/util/TraceHelper.java
index c24bb67..073fb6a 100644
--- a/src/com/android/launcher3/util/TraceHelper.java
+++ b/src/com/android/launcher3/util/TraceHelper.java
@@ -15,19 +15,14 @@
*/
package com.android.launcher3.util;
-import static android.util.Log.VERBOSE;
-import static android.util.Log.isLoggable;
-
-import android.os.SystemClock;
import android.os.Trace;
-import android.util.ArrayMap;
-import android.util.Log;
-import android.util.MutableLong;
-import com.android.launcher3.config.FeatureFlags;
+import androidx.annotation.MainThread;
+
+import java.util.function.Supplier;
/**
- * A wrapper around {@link Trace} with some utility information.
+ * A wrapper around {@link Trace} to allow better testing.
*
* To enable any tracing log, execute the following command:
* $ adb shell setprop log.tag.LAUNCHER_TRACE VERBOSE
@@ -35,65 +30,51 @@
*/
public class TraceHelper {
- private static final boolean ENABLED = isLoggable("LAUNCHER_TRACE", VERBOSE);
+ // Track binder class for this trace
+ public static final int FLAG_ALLOW_BINDER_TRACKING = 1 << 0;
- private static final boolean SYSTEM_TRACE = ENABLED;
- private static final ArrayMap<String, MutableLong> sUpTimes = ENABLED ? new ArrayMap<>() : null;
+ // Temporarily ignore blocking binder calls for this trace.
+ public static final int FLAG_IGNORE_BINDERS = 1 << 1;
- public static void beginSection(String sectionName) {
- if (ENABLED) {
- synchronized (sUpTimes) {
- MutableLong time = sUpTimes.get(sectionName);
- if (time == null) {
- time = new MutableLong(isLoggable(sectionName, VERBOSE) ? 0 : -1);
- sUpTimes.put(sectionName, time);
- }
- if (time.value >= 0) {
- if (SYSTEM_TRACE) {
- Trace.beginSection(sectionName);
- }
- time.value = SystemClock.uptimeMillis();
- }
- }
- }
+ public static final int FLAG_CHECK_FOR_RACE_CONDITIONS = 1 << 2;
+
+ public static final int FLAG_UI_EVENT =
+ FLAG_ALLOW_BINDER_TRACKING | FLAG_CHECK_FOR_RACE_CONDITIONS;
+
+ /**
+ * Static instance of Trace helper, overridden in tests.
+ */
+ public static TraceHelper INSTANCE = new TraceHelper();
+
+ public void beginSection(String sectionName) {
+ beginSection(sectionName, 0);
}
- public static void partitionSection(String sectionName, String partition) {
- if (ENABLED) {
- synchronized (sUpTimes) {
- MutableLong time = sUpTimes.get(sectionName);
- if (time != null && time.value >= 0) {
-
- if (SYSTEM_TRACE) {
- Trace.endSection();
- Trace.beginSection(sectionName);
- }
-
- long now = SystemClock.uptimeMillis();
- Log.d(sectionName, partition + " : " + (now - time.value));
- time.value = now;
- }
- }
- }
+ public void beginSection(String sectionName, int flags) {
+ Trace.beginSection(sectionName);
}
- public static void endSection(String sectionName) {
- if (ENABLED) {
- endSection(sectionName, "End");
- }
+ public void endSection() {
+ Trace.endSection();
}
- public static void endSection(String sectionName, String msg) {
- if (ENABLED) {
- synchronized (sUpTimes) {
- MutableLong time = sUpTimes.get(sectionName);
- if (time != null && time.value >= 0) {
- if (SYSTEM_TRACE) {
- Trace.endSection();
- }
- Log.d(sectionName, msg + " : " + (SystemClock.uptimeMillis() - time.value));
- }
- }
+ /**
+ * Similar to {@link #beginSection} but doesn't add a trace section.
+ */
+ public void beginFlagsOverride(int flags) { }
+
+ public void endFlagsOverride() { }
+
+ /**
+ * Temporarily ignore blocking binder calls for the duration of this {@link Supplier}.
+ */
+ @MainThread
+ public static <T> T whitelistIpcs(String rpcName, Supplier<T> supplier) {
+ INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
+ try {
+ return supplier.get();
+ } finally {
+ INSTANCE.endSection();
}
}
}