From a13654529cb557abd946da4d4637593565917ecd Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 1 Oct 2015 15:46:24 -0700 Subject: Adding some information in bug reports > Dumping workspace items > Dumping loader logs for crashes and data deletion > Removing unnecessary log dumps Change-Id: Ia320988c2e3665e4d605d6e88bca77738e749273 --- src/com/android/launcher3/Launcher.java | 122 +++++++----------------- src/com/android/launcher3/LauncherModel.java | 62 ++++-------- src/com/android/launcher3/LauncherProvider.java | 23 ++--- src/com/android/launcher3/Workspace.java | 6 +- 4 files changed, 61 insertions(+), 152 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d223f3e74..0816d4611 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -141,7 +141,6 @@ public class Launcher extends Activity static final boolean DEBUG_WIDGETS = true; static final boolean DEBUG_STRICT_MODE = false; static final boolean DEBUG_RESUME_TIME = false; - static final boolean DEBUG_DUMP_LOG = false; static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run @@ -308,12 +307,10 @@ public class Launcher extends Activity private final ArrayList mSynchronouslyBoundPages = new ArrayList(); private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false; - static final ArrayList sDumpLogs = new ArrayList(); - static Date sDateStamp = new Date(); - static DateFormat sDateFormat = + private static final ArrayList sDumpLogs = new ArrayList(); + private static final Date sDateStamp = new Date(); + private static final DateFormat sDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - static long sRunStart = System.currentTimeMillis(); - static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent"; // We only want to get the SharedPreferences once since it does an FS stat each time we get // it from the context. @@ -4629,51 +4626,47 @@ public class Launcher extends Activity @Override public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { super.dump(prefix, fd, writer, args); - synchronized (sDumpLogs) { - writer.println(" "); - writer.println("Debug logs: "); - for (int i = 0; i < sDumpLogs.size(); i++) { - writer.println(" " + sDumpLogs.get(i)); + // Dump workspace + writer.println(prefix + "Workspace Items"); + for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) { + writer.println(prefix + " Homescreen " + i); + + ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets(); + for (int j = 0; j < layout.getChildCount(); j++) { + Object tag = layout.getChildAt(j).getTag(); + if (tag != null) { + writer.println(prefix + " " + tag.toString()); + } } } - if (mLauncherCallbacks != null) { - mLauncherCallbacks.dump(prefix, fd, writer, args); + + writer.println(prefix + " Hotseat"); + ViewGroup layout = mHotseat.getLayout().getShortcutsAndWidgets(); + for (int j = 0; j < layout.getChildCount(); j++) { + Object tag = layout.getChildAt(j).getTag(); + if (tag != null) { + writer.println(prefix + " " + tag.toString()); + } } - } - public static void dumpDebugLogsToConsole() { - if (DEBUG_DUMP_LOG) { - synchronized (sDumpLogs) { - Log.d(TAG, ""); - Log.d(TAG, "*********************"); - Log.d(TAG, "Launcher debug logs: "); - for (int i = 0; i < sDumpLogs.size(); i++) { - Log.d(TAG, " " + sDumpLogs.get(i)); - } - Log.d(TAG, "*********************"); - Log.d(TAG, ""); + synchronized (sDumpLogs) { + writer.println(); + writer.println(prefix + "Debug logs"); + for (String log : sDumpLogs) { + writer.println(prefix + " " + log); } } - } - public static void addDumpLog(String tag, String log, boolean debugLog) { - addDumpLog(tag, log, null, debugLog); + if (mLauncherCallbacks != null) { + mLauncherCallbacks.dump(prefix, fd, writer, args); + } } - public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) { - if (debugLog) { - if (e != null) { - Log.d(tag, log, e); - } else { - Log.d(tag, log); - } - } - if (DEBUG_DUMP_LOG) { + public static void addDumpLog(String tag, String log) { + Log.d(tag, log); + synchronized(sDumpLogs) { sDateStamp.setTime(System.currentTimeMillis()); - synchronized (sDumpLogs) { - sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log - + (e == null ? "" : (", Exception: " + e))); - } + sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log); } } @@ -4684,53 +4677,6 @@ public class Launcher extends Activity public static HashMap getCustomAppWidgets() { return sCustomAppWidgets; } - - public void dumpLogsToLocalData() { - if (DEBUG_DUMP_LOG) { - new AsyncTask() { - public Void doInBackground(Void ... args) { - boolean success = false; - sDateStamp.setTime(sRunStart); - String FILENAME = sDateStamp.getMonth() + "-" - + sDateStamp.getDay() + "_" - + sDateStamp.getHours() + "-" - + sDateStamp.getMinutes() + "_" - + sDateStamp.getSeconds() + ".txt"; - - FileOutputStream fos = null; - File outFile = null; - try { - outFile = new File(getFilesDir(), FILENAME); - outFile.createNewFile(); - fos = new FileOutputStream(outFile); - } catch (Exception e) { - e.printStackTrace(); - } - if (fos != null) { - PrintWriter writer = new PrintWriter(fos); - - writer.println(" "); - writer.println("Debug logs: "); - synchronized (sDumpLogs) { - for (int i = 0; i < sDumpLogs.size(); i++) { - writer.println(" " + sDumpLogs.get(i)); - } - } - writer.close(); - } - try { - if (fos != null) { - fos.close(); - success = true; - } - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR); - } - } } interface DebugIntents { diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 97a55590b..cd4f39c4d 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -210,7 +210,6 @@ public class LauncherModel extends BroadcastReceiver public boolean isAllAppsButtonRank(int rank); public void onPageBoundSynchronously(int page); public void executeOnNextDraw(ViewOnDrawExecutor executor); - public void dumpLogsToLocalData(); } public interface ItemInfoFilter { @@ -1384,8 +1383,7 @@ public class LauncherModel extends BroadcastReceiver try { screenIds.add(sc.getLong(idIndex)); } catch (Exception e) { - Launcher.addDumpLog(TAG, "Desktop items loading interrupted" - + " - invalid screens: " + e, true); + addDumpLog("Invalid screen id: " + e); } } } finally { @@ -1728,17 +1726,17 @@ public class LauncherModel extends BroadcastReceiver } if ((mFlags & LOADER_FLAG_CLEAR_WORKSPACE) != 0) { - Launcher.addDumpLog(TAG, "loadWorkspace: resetting launcher database", true); + Log.d(TAG, "loadWorkspace: resetting launcher database"); LauncherAppState.getLauncherProvider().deleteDatabase(); } if ((mFlags & LOADER_FLAG_MIGRATE_SHORTCUTS) != 0) { // append the user's Launcher2 shortcuts - Launcher.addDumpLog(TAG, "loadWorkspace: migrating from launcher2", true); + Log.d(TAG, "loadWorkspace: migrating from launcher2"); LauncherAppState.getLauncherProvider().migrateLauncher2Shortcuts(); } else { // Make sure the default workspace is loaded - Launcher.addDumpLog(TAG, "loadWorkspace: loading default favorites", false); + Log.d(TAG, "loadWorkspace: loading default favorites"); LauncherAppState.getLauncherProvider().loadDefaultFavoritesIfNecessary(); } @@ -1862,8 +1860,7 @@ public class LauncherModel extends BroadcastReceiver if (intent == null) { // The app is installed but the component is no // longer available. - Launcher.addDumpLog(TAG, - "Invalid component removed: " + cn, true); + addDumpLog("Invalid component removed: " + cn); itemsToRemove.add(id); continue; } else { @@ -1874,8 +1871,7 @@ public class LauncherModel extends BroadcastReceiver } else if (restored) { // Package is not yet available but might be // installed later. - Launcher.addDumpLog(TAG, - "package not yet restored: " + cn, true); + addDumpLog("package not yet restored: " + cn); if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) { // Restore has started once. @@ -1901,14 +1897,12 @@ public class LauncherModel extends BroadcastReceiver itemReplaced = true; } else if (REMOVE_UNRESTORED_ICONS) { - Launcher.addDumpLog(TAG, - "Unrestored package removed: " + cn, true); + addDumpLog("Unrestored package removed: " + cn); itemsToRemove.add(id); continue; } } else if (REMOVE_UNRESTORED_ICONS) { - Launcher.addDumpLog(TAG, - "Unrestored package removed: " + cn, true); + addDumpLog("Unrestored package removed: " + cn); itemsToRemove.add(id); continue; } @@ -1921,8 +1915,7 @@ public class LauncherModel extends BroadcastReceiver } else if (!isSdCardReady) { // SdCard is not ready yet. Package might get available, // once it is ready. - Launcher.addDumpLog(TAG, "Invalid package: " + cn - + " (check again later)", true); + Log.d(TAG, "Invalid package: " + cn + " (check again later)"); HashSet pkgs = sPendingPackages.get(user); if (pkgs == null) { pkgs = new HashSet(); @@ -1935,8 +1928,7 @@ public class LauncherModel extends BroadcastReceiver } else { // Do not wait for external media load anymore. // Log the invalid package, and remove it - Launcher.addDumpLog(TAG, - "Invalid package removed: " + cn, true); + addDumpLog("Invalid package removed: " + cn); itemsToRemove.add(id); continue; } @@ -1946,8 +1938,7 @@ public class LauncherModel extends BroadcastReceiver restored = false; } } catch (URISyntaxException e) { - Launcher.addDumpLog(TAG, - "Invalid uri: " + intentDescription, true); + addDumpLog("Invalid uri: " + intentDescription); itemsToRemove.add(id); continue; } @@ -1967,9 +1958,6 @@ public class LauncherModel extends BroadcastReceiver } } else if (restored) { if (user.equals(UserHandleCompat.myUserHandle())) { - Launcher.addDumpLog(TAG, - "constructing info for partially restored package", - true); info = getRestoredItemInfo(c, titleIndex, intent, promiseType, itemType, cursorIconInfo, context); intent = getRestoredItemIntent(c, context, intent); @@ -2124,11 +2112,8 @@ public class LauncherModel extends BroadcastReceiver final boolean isProviderReady = isValidProvider(provider); if (!isSafeMode && !customWidget && wasProviderReady && !isProviderReady) { - String log = "Deleting widget that isn't installed anymore: " - + "id=" + id + " appWidgetId=" + appWidgetId; - - Log.e(TAG, log); - Launcher.addDumpLog(TAG, log, false); + addDumpLog("Deleting widget that isn't installed anymore: " + + provider); itemsToRemove.add(id); } else { if (isProviderReady) { @@ -2169,8 +2154,7 @@ public class LauncherModel extends BroadcastReceiver appWidgetInfo.restoreStatus |= LauncherAppWidgetInfo.FLAG_RESTORE_STARTED; } else if (REMOVE_UNRESTORED_ICONS && !isSafeMode) { - Launcher.addDumpLog(TAG, - "Unrestored widget removed: " + component, true); + addDumpLog("Unrestored widget removed: " + component); itemsToRemove.add(id); continue; } @@ -2222,7 +2206,7 @@ public class LauncherModel extends BroadcastReceiver break; } } catch (Exception e) { - Launcher.addDumpLog(TAG, "Desktop items loading interrupted", e, true); + Log.e(TAG, "Desktop items loading interrupted", e); } } } finally { @@ -2940,10 +2924,8 @@ public class LauncherModel extends BroadcastReceiver boolean packageOnSdcard = launcherApps.isAppEnabled( manager, pkg, PackageManager.GET_UNINSTALLED_PACKAGES); if (packageOnSdcard) { - Launcher.addDumpLog(TAG, "Package found on sd-card: " + pkg, true); packagesUnavailable.add(pkg); } else { - Launcher.addDumpLog(TAG, "Package not found: " + pkg, true); packagesRemoved.add(pkg); } } @@ -3301,16 +3283,6 @@ public class LauncherModel extends BroadcastReceiver loadAndBindWidgetsAndShortcuts(callbacks, needToRefresh); } - - // Write all the logs to disk - mHandler.post(new Runnable() { - public void run() { - Callbacks cb = getCallback(); - if (callbacks == cb && cb != null) { - callbacks.dumpLogsToLocalData(); - } - } - }); } } @@ -3747,4 +3719,8 @@ public class LauncherModel extends BroadcastReceiver public static Looper getWorkerLooper() { return sWorkerThread.getLooper(); } + + @Thunk static final void addDumpLog(String log) { + Launcher.addDumpLog(TAG, log); + } } diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index c6827dae4..3044b98cf 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -1160,17 +1160,10 @@ public class LauncherProvider extends ContentProvider { } if (userHandle == null) { - Launcher.addDumpLog(TAG, "skipping deleted user", true); + Log.d(TAG, "skipping deleted user"); continue; } - Launcher.addDumpLog(TAG, "migrating \"" - + c.getString(titleIndex) + "\" (" - + cellX + "," + cellY + "@" - + LauncherSettings.Favorites.containerToString(container) - + "/" + screen - + "): " + intentStr, true); - if (itemType != Favorites.ITEM_TYPE_FOLDER) { final Intent intent; @@ -1179,22 +1172,20 @@ public class LauncherProvider extends ContentProvider { intent = Intent.parseUri(intentStr, 0); } catch (URISyntaxException e) { // bogus intent? - Launcher.addDumpLog(TAG, - "skipping invalid intent uri", true); + Log.d(TAG, "skipping invalid intent uri"); continue; } cn = intent.getComponent(); if (TextUtils.isEmpty(intentStr)) { // no intent? no icon - Launcher.addDumpLog(TAG, "skipping empty intent", true); + Log.d(TAG, "skipping empty intent"); continue; } else if (cn != null && !LauncherModel.isValidPackageActivity(mContext, cn, userHandle)) { // component no longer exists. - Launcher.addDumpLog(TAG, "skipping item whose component " + - "no longer exists.", true); + Log.d(TAG, "skipping item whose component no longer exists."); continue; } else if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { @@ -1210,7 +1201,7 @@ public class LauncherProvider extends ContentProvider { final String key = intent.toUri(0); intent.setFlags(flags); if (seenIntents.contains(key)) { - Launcher.addDumpLog(TAG, "skipping duplicate", true); + Log.d(TAG, "skipping duplicate"); continue; } else { seenIntents.add(key); @@ -1350,8 +1341,8 @@ public class LauncherProvider extends ContentProvider { } } - Launcher.addDumpLog(TAG, "migrated " + count + " icons from Launcher2 into " - + (curScreen+1) + " screens", true); + Log.d(TAG, "migrated " + count + " icons from Launcher2 into " + + (curScreen+1) + " screens"); // ensure that new screens are created to hold these icons setFlagJustLoadedOldDb(); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index c6b67524d..ada937421 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -682,7 +682,6 @@ public class Workspace extends PagedView private void convertFinalScreenToEmptyScreenIfNecessary() { if (mLauncher.isWorkspaceLoading()) { // Invalid and dangerous operation if workspace is loading - Launcher.addDumpLog(TAG, " - workspace loading, skip", true); return; } @@ -715,7 +714,6 @@ public class Workspace extends PagedView final int delay, final boolean stripEmptyScreens) { if (mLauncher.isWorkspaceLoading()) { // Don't strip empty screens if the workspace is still loading - Launcher.addDumpLog(TAG, " - workspace loading, skip", true); return; } @@ -801,7 +799,6 @@ public class Workspace extends PagedView public long commitExtraEmptyScreen() { if (mLauncher.isWorkspaceLoading()) { // Invalid and dangerous operation if workspace is loading - Launcher.addDumpLog(TAG, " - workspace loading, skip", true); return -1; } @@ -857,7 +854,6 @@ public class Workspace extends PagedView if (mLauncher.isWorkspaceLoading()) { // Don't strip empty screens if the workspace is still loading. // This is dangerous and can result in data loss. - Launcher.addDumpLog(TAG, " - workspace loading, skip", true); return; } @@ -1017,7 +1013,7 @@ public class Workspace extends PagedView // TODO: This branch occurs when the workspace is adding views // outside of the defined grid // maybe we should be deleting these items from the LauncherModel? - Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout", true); + Log.e(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout"); } if (!(child instanceof Folder)) { -- cgit v1.2.3