Revert "Adding main thread binder tracing in development build."
Revert submission 23482347-launcher-binder-tracing
Reason for revert: Broken Build 10242119 on git_master on errorprone b/285434612
Reverted changes: /q/submissionid:23482347-launcher-binder-tracing
Change-Id: Id9726474265e839a59d6eb34822e7a86d40f0fc9
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ac46c82..db5a27a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -442,7 +442,8 @@
Trace.beginAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME,
DISPLAY_ALL_APPS_TRACE_COOKIE);
}
- TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT);
+ Object traceToken = TraceHelper.INSTANCE.beginSection(ON_CREATE_EVT,
+ TraceHelper.FLAG_UI_EVENT);
if (DEBUG_STRICT_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
@@ -575,7 +576,7 @@
LauncherOverlayPlugin.class, false /* allowedMultiple */);
mRotationHelper.initialize();
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
mUserChangedCallbackCloseable = UserCache.INSTANCE.get(this).addUserChangeListener(
() -> getStateManager().goToState(NORMAL));
@@ -1073,14 +1074,15 @@
@Override
protected void onStart() {
- TraceHelper.INSTANCE.beginSection(ON_START_EVT);
+ Object traceToken = TraceHelper.INSTANCE.beginSection(ON_START_EVT,
+ TraceHelper.FLAG_UI_EVENT);
super.onStart();
if (!mDeferOverlayCallbacks) {
mOverlayManager.onActivityStarted(this);
}
mAppWidgetHolder.setActivityStarted(true);
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
@Override
@@ -1251,7 +1253,8 @@
@Override
protected void onResume() {
- TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT);
+ Object traceToken = TraceHelper.INSTANCE.beginSection(ON_RESUME_EVT,
+ TraceHelper.FLAG_UI_EVENT);
super.onResume();
if (mDeferOverlayCallbacks) {
@@ -1261,7 +1264,7 @@
}
DragView.removeAllViews(this);
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
@Override
@@ -1649,7 +1652,7 @@
if (Utilities.isRunningInTestHarness()) {
Log.d(TestProtocol.PERMANENT_DIAG_TAG, "Launcher.onNewIntent: " + intent);
}
- TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
+ Object traceToken = TraceHelper.INSTANCE.beginSection(ON_NEW_INTENT_EVT);
super.onNewIntent(intent);
boolean alreadyOnHome = hasWindowFocus() && ((intent.getFlags() &
@@ -1696,7 +1699,7 @@
showAllAppsWorkTabFromIntent(alreadyOnHome);
}
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
protected void toggleAllAppsFromIntent(boolean alreadyOnHome) {
@@ -2295,7 +2298,7 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void startBinding() {
- TraceHelper.INSTANCE.beginSection("startBinding");
+ Object traceToken = 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.
@@ -2313,7 +2316,7 @@
if (mHotseat != null) {
mHotseat.resetLayout(getDeviceProfile().isVerticalBarLayout());
}
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
@Override
@@ -2566,7 +2569,7 @@
return view;
}
- TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
+ Object traceToken = TraceHelper.INSTANCE.beginSection("BIND_WIDGET_id=" + item.appWidgetId);
try {
final LauncherAppWidgetProviderInfo appWidgetInfo;
@@ -2696,7 +2699,7 @@
}
prepareAppWidget(view, item);
} finally {
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
return view;
@@ -2789,7 +2792,7 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void finishBindingItems(IntSet pagesBoundFirst) {
- TraceHelper.INSTANCE.beginSection("finishBindingItems");
+ Object traceToken = TraceHelper.INSTANCE.beginSection("finishBindingItems");
mWorkspace.restoreInstanceStateForRemainingPages();
setWorkspaceLoading(false);
@@ -2814,7 +2817,7 @@
mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows);
getViewCache().setCacheSize(R.layout.folder_page, 2);
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
mWorkspace.removeExtraEmptyScreen(true);
}
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 73a06b6..d2a8174 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -201,7 +201,7 @@
}
}
- TraceHelper.INSTANCE.beginSection(TAG);
+ Object traceToken = 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 @@
memoryLogger.printLogs();
throw e;
}
- TraceHelper.INSTANCE.endSection();
+ TraceHelper.INSTANCE.endSection(traceToken);
}
public synchronized void stopLocked() {
diff --git a/src/com/android/launcher3/util/InstantAppResolver.java b/src/com/android/launcher3/util/InstantAppResolver.java
index bdb5e77..6f706d2 100644
--- a/src/com/android/launcher3/util/InstantAppResolver.java
+++ b/src/com/android/launcher3/util/InstantAppResolver.java
@@ -42,7 +42,14 @@
return false;
}
- public boolean isInstantApp(String packageName, int userId) {
+ 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);
+ }
return false;
}
}
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index 91203a7..1d6bc25 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -164,6 +164,13 @@
}
}
+ 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}
*/
diff --git a/src/com/android/launcher3/util/TraceHelper.java b/src/com/android/launcher3/util/TraceHelper.java
index d5056ee..c23df77 100644
--- a/src/com/android/launcher3/util/TraceHelper.java
+++ b/src/com/android/launcher3/util/TraceHelper.java
@@ -21,8 +21,6 @@
import java.util.function.Supplier;
-import kotlin.random.Random;
-
/**
* A wrapper around {@link Trace} to allow better testing.
*
@@ -38,53 +36,54 @@
// 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();
/**
- * @see Trace#beginSection(String)
+ * @return a token to pass into {@link #endSection(Object)}.
*/
- public void beginSection(String sectionName) {
+ public Object beginSection(String sectionName) {
+ return beginSection(sectionName, 0);
+ }
+
+ public Object beginSection(String sectionName, int flags) {
Trace.beginSection(sectionName);
+ return null;
}
/**
- * @see Trace#endSection()
+ * @param token the token returned from {@link #beginSection(String, int)}
*/
- public void endSection() {
+ public void endSection(Object token) {
Trace.endSection();
}
/**
- * @see Trace#beginAsyncSection(String, int)
- * @return a SafeCloseable that can be used to end the session
+ * Similar to {@link #beginSection} but doesn't add a trace section.
*/
- public SafeCloseable beginAsyncSection(String sectionName) {
- int cookie = Random.Default.nextInt();
- Trace.beginAsyncSection(sectionName, cookie);
- return () -> Trace.endAsyncSection(sectionName, cookie);
+ public Object beginFlagsOverride(int flags) {
+ return null;
}
- /**
- * 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);
- }
+ public void endFlagsOverride(Object token) { }
/**
* 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) {
- try (SafeCloseable c = INSTANCE.allowIpcs(rpcName)) {
+ Object traceToken = INSTANCE.beginSection(rpcName, FLAG_IGNORE_BINDERS);
+ try {
return supplier.get();
+ } finally {
+ INSTANCE.endSection(traceToken);
}
}
}
diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java
index 55febc7..aebf752 100644
--- a/src/com/android/launcher3/views/OptionsPopupView.java
+++ b/src/com/android/launcher3/views/OptionsPopupView.java
@@ -55,6 +55,7 @@
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;
@@ -189,9 +190,14 @@
*/
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,
- R.string.styles_wallpaper_button_text,
- R.drawable.ic_palette,
+ resString,
+ resDrawable,
IGNORE,
OptionsPopupView::startWallpaperPicker));
if (!WidgetsModel.GO_DISABLE_WIDGETS) {
@@ -268,8 +274,12 @@
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra(EXTRA_WALLPAPER_OFFSET,
launcher.getWorkspace().getWallpaperOffsetForCenterPage())
- .putExtra(EXTRA_WALLPAPER_LAUNCH_SOURCE, "app_launched_launcher")
- .putExtra(EXTRA_WALLPAPER_FLAVOR, "focus_wallpaper");
+ .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");
+ }
String pickerPackage = launcher.getString(R.string.wallpaper_picker_package);
if (!TextUtils.isEmpty(pickerPackage)) {
intent.setPackage(pickerPackage);
@@ -312,4 +322,9 @@
this.clickListener = clickListener;
}
}
+
+ private static boolean styleWallpapersExists(Context context) {
+ return context.getPackageManager().resolveActivity(
+ PackageManagerHelper.getStyleWallpapersIntent(context), 0) != null;
+ }
}