Merge "Adding main thread binder tracing in development build." into udc-qpr-dev

This commit is contained in:
Sunny Goyal authored and Android (Google) Code Review committed 2023-06-01 17:27:21 +00:00
commit 50c9126cc3
25 files changed
+280 -1197

No files matched your search

+14 -17
View File
@@ -442,8 +442,7 @@ public class Launcher extends StatefulActivity<LauncherState>
Trace.beginAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME,
DISPLAY_ALL_APPS_TRACE_COOKIE);
}
Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT,
TraceHelper.FLAG_UI_EVENT);
TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT);
if (DEBUG_STRICT_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
@@ -577,7 +576,7 @@ public class Launcher extends StatefulActivity<LauncherState>
LauncherOverlayPlugin.class, false /* allowedMultiple */);
mRotationHelper.initialize();
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener(
() -> getStateManager().goToState(NORMAL));
@@ -1075,15 +1074,14 @@ public class Launcher extends StatefulActivity<LauncherState>
@Override
protected void onStart() {
Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT,
TraceHelper.FLAG_UI_EVENT);
TraceHelper.INSTANCE.beginSection(ON_START_EVT);
super.onStart();
if (!mDeferOverlayCallbacks) {
mOverlayManager.onActivityStarted(this);
}
mAppWidgetHolder.setActivityStarted(true);
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
@Override
@@ -1254,8 +1252,7 @@ public class Launcher extends StatefulActivity<LauncherState>
@Override
protected void onResume() {
Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT,
TraceHelper.FLAG_UI_EVENT);
TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT);
super.onResume();
if (mDeferOverlayCallbacks) {
@@ -1265,7 +1262,7 @@ public class Launcher extends StatefulActivity<LauncherState>
}
DragView.removeAllViews(this);
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
@Override
@@ -1653,7 +1650,7 @@ public class Launcher extends StatefulActivity<LauncherState>
if (Utilities.isRunningInTestHarness()) {
Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Launcher.onNewIntent: " + intent);
}
Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
super.onNewIntent(intent);
boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
@@ -1700,7 +1697,7 @@ public class Launcher extends StatefulActivity<LauncherState>
showAllAppsWorkTabFromIntent(alreadyOnHome);
}
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
protected void toggleAllAppsFromIntent(boolean alreadyOnHome) {
@@ -2299,7 +2296,7 @@ public class Launcher extends StatefulActivity<LauncherState>
* Implementation of the method from LauncherModel.Callbacks.
*/
public void startBinding() {
Object traceToken = TraceHelper.INSTANCE.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.
@@ -2317,7 +2314,7 @@ public class Launcher extends StatefulActivity<LauncherState>
if (mHotseat != null) {
mHotseat.resetLayout(getDeviceProfile().isVerticalBarLayout());
}
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
@Override
@@ -2570,7 +2567,7 @@ public class Launcher extends StatefulActivity<LauncherState>
return view;
}
Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
try {
final LauncherAppWidgetProviderInfo appWidgetInfo;
@@ -2700,7 +2697,7 @@ public class Launcher extends StatefulActivity<LauncherState>
}
prepareAppWidget(view, item);
} finally {
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
return view;
@@ -2793,7 +2790,7 @@ public class Launcher extends StatefulActivity<LauncherState>
* Implementation of the method from LauncherModel.Callbacks.
*/
public void finishBindingItems(IntSet pagesBoundFirst) {
Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems");
TraceHelper.INSTANCE.beginSection("finishBindingItems");
mWorkspace.restoreInstanceStateForRemainingPages();
setWorkspaceLoading(false);
@@ -2818,7 +2815,7 @@ public class Launcher extends StatefulActivity<LauncherState>
mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
getViewCache().setCacheSize(R.layout.folder_page, 2);
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
mWorkspace.removeExtraEmptyScreen(true);
}
@@ -201,7 +201,7 @@ public class LoaderTask implements Runnable {
}
}
Object traceToken = TraceHelper.INSTANCE.beginSection(TAG);
TraceHelper.INSTANCE.beginSection(TAG);
LoaderMemoryLogger memoryLogger = new LoaderMemoryLogger();
try (LauncherModel.LoaderTransaction transaction = mApp.getModel().beginLoader(this)) {
List<ShortcutInfo> allShortcuts = new ArrayList<>();
@@ -325,7 +325,7 @@ public class LoaderTask implements Runnable {
memoryLogger.printLogs();
throw e;
}
TraceHelper.INSTANCE.endSection(traceToken);
TraceHelper.INSTANCE.endSection();
}
public synchronized void stopLocked() {
@@ -42,14 +42,7 @@ public class InstantAppResolver implements ResourceBasedOverride {
return false;
}
public boolean isInstantApp(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
try {
return isInstantApp(packageManager.getPackageInfo(packageName, 0).applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
Log.e("InstantAppResolver", "Failed to determine whether package is instant app "
+ packageName, e);
}
public boolean isInstantApp(String packageName, int userId) {
return false;
}
}
@@ -164,13 +164,6 @@ public class PackageManagerHelper {
}
}
public static Intent getStyleWallpapersIntent(Context context) {
return new Intent(Intent.ACTION_SET_WALLPAPER).setComponent(
new ComponentName(context.getString(R.string.wallpaper_picker_package),
context.getString(R.string.custom_activity_picker)
));
}
/**
* Starts the details activity for {@code info}
*/
+23 -22
View File
@@ -21,6 +21,8 @@ import androidx.annotation.MainThread;
import java.util.function.Supplier;
import kotlin.random.Random;
/**
* A wrapper around {@link Trace} to allow better testing.
*
@@ -36,54 +38,53 @@ public class TraceHelper {
// Temporarily ignore blocking binder calls for this trace.
public static final int FLAG_IGNORE_BINDERS = 1 << 1;
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();
/**
* @return a token to pass into {@link #endSection(Object)}.
* @see Trace#beginSection(String)
*/
public Object beginSection(String sectionName) {
return beginSection(sectionName, 0);
}
public Object beginSection(String sectionName, int flags) {
public void beginSection(String sectionName) {
Trace.beginSection(sectionName);
return null;
}
/**
* @param token the token returned from {@link #beginSection(String, int)}
* @see Trace#endSection()
*/
public void endSection(Object token) {
public void endSection() {
Trace.endSection();
}
/**
* Similar to {@link #beginSection} but doesn't add a trace section.
* @see Trace#beginAsyncSection(String, int)
* @return a SafeCloseable that can be used to end the session
*/
public Object beginFlagsOverride(int flags) {
return null;
public SafeCloseable beginAsyncSection(String sectionName) {
int cookie = Random.Default.nextInt();
Trace.beginAsyncSection(sectionName, cookie);
return () -> Trace.endAsyncSection(sectionName, cookie);
}
public void endFlagsOverride(Object token) { }
/**
* Returns a SafeCloseable to temporarily ignore blocking binder calls.
*/
public SafeCloseable allowIpcs(String rpcName) {
int cookie = Random.Default.nextInt();
Trace.beginAsyncSection(rpcName, cookie);
return () -> Trace.endAsyncSection(rpcName, cookie);
}
/**
* Temporarily ignore blocking binder calls for the duration of this {@link Supplier}.
*
* Note, new features should be designed to not rely on mainThread RPCs.
*/
@MainThread
public static <T> T allowIpcs(String rpcName, Supplier<T> supplier) {
Object traceToken = INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
try {
try (SafeCloseable c = INSTANCE.allowIpcs(rpcName)) {
return supplier.get();
} finally {
INSTANCE.endSection(traceToken);
}
}
}
@@ -55,7 +55,6 @@ import com.android.launcher3.popup.ArrowPopup;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import java.util.ArrayList;
@@ -190,14 +189,9 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
*/
public static ArrayList<OptionItem> getOptions(Launcher launcher) {
ArrayList<OptionItem> options = new ArrayList<>();
boolean styleWallpaperExists = styleWallpapersExists(launcher);
int resString = styleWallpaperExists
? R.string.styles_wallpaper_button_text : R.string.wallpaper_button_text;
int resDrawable = styleWallpaperExists
? R.drawable.ic_palette : R.drawable.ic_wallpaper;
options.add(new OptionItem(launcher,
resString,
resDrawable,
R.string.styles_wallpaper_button_text,
R.drawable.ic_palette,
IGNORE,
OptionsPopupView::startWallpaperPicker));
if (!WidgetsModel.GO_DISABLE_WIDGETS) {
@@ -274,12 +268,8 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra(EXTRA_WALLPAPER_OFFSET,
launcher.getWorkspace().getWallpaperOffsetForCenterPage())
.putExtra(EXTRA_WALLPAPER_LAUNCH_SOURCE, "app_launched_launcher");
if (!styleWallpapersExists(launcher)) {
intent.putExtra(EXTRA_WALLPAPER_FLAVOR, "wallpaper_only");
} else {
intent.putExtra(EXTRA_WALLPAPER_FLAVOR, "focus_wallpaper");
}
.putExtra(EXTRA_WALLPAPER_LAUNCH_SOURCE, "app_launched_launcher")
.putExtra(EXTRA_WALLPAPER_FLAVOR, "focus_wallpaper");
String pickerPackage = launcher.getString(R.string.wallpaper_picker_package);
if (!TextUtils.isEmpty(pickerPackage)) {
intent.setPackage(pickerPackage);
@@ -322,9 +312,4 @@ public class OptionsPopupView extends ArrowPopup<Launcher>
this.clickListener = clickListener;
}
}
private static boolean styleWallpapersExists(Context context) {
return context.getPackageManager().resolveActivity(
PackageManagerHelper.getStyleWallpapersIntent(context), 0) != null;
}
}