Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34a2d31f authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Adding a utility class for persistant logging." into ub-launcher3-calgary

parents ac6d3a87 713edfce
Loading
Loading
Loading
Loading
+6 −22
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.ViewOnDrawExecutor;
@@ -123,11 +124,9 @@ import com.android.launcher3.widget.WidgetsContainerView;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -307,11 +306,6 @@ public class Launcher extends Activity
    private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
    private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;

    private static final ArrayList<String> sDumpLogs = new ArrayList<String>();
    private static final Date sDateStamp = new Date();
    private static final DateFormat sDateFormat =
            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    // We only want to get the SharedPreferences once since it does an FS stat each time we get
    // it from the context.
    private SharedPreferences mSharedPrefs;
@@ -3979,7 +3973,7 @@ public class Launcher extends Activity

            // Verify that we own the widget
            if (appWidgetInfo == null) {
                Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
                FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
                deleteWidgetInfo(item);
                return;
            }
@@ -4652,12 +4646,10 @@ public class Launcher extends Activity
            }
        }

        synchronized (sDumpLogs) {
            writer.println();
            writer.println(prefix + "Debug logs");
            for (String log : sDumpLogs) {
                writer.println(prefix + "  " + log);
            }
        try {
            FileLog.flushAll(writer);
        } catch (Exception e) {
            // Ignore
        }

        if (mLauncherCallbacks != null) {
@@ -4665,14 +4657,6 @@ public class Launcher extends Activity
        }
    }

    public static void addDumpLog(String tag, String log) {
        Log.d(tag, log);
        synchronized(sDumpLogs) {
            sDateStamp.setTime(System.currentTimeMillis());
            sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log);
        }
    }

    public static CustomAppWidget getCustomAppWidget(String name) {
        return sCustomAppWidgets.get(name);
    }
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;

@@ -79,6 +80,7 @@ public class LauncherAppState {
        // is the first component to get created. Initializing application context here ensures
        // that LauncherAppState always exists in the main process.
        sContext = provider.getContext().getApplicationContext();
        FileLog.setDir(sContext.getFilesDir());
    }

    private LauncherAppState() {
+11 −16
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.launcher3.model.GridSizeMigrationTask;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.CursorIconInfo;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
@@ -1335,7 +1336,7 @@ public class LauncherModel extends BroadcastReceiver
                try {
                    screenIds.add(sc.getLong(idIndex));
                } catch (Exception e) {
                    addDumpLog("Invalid screen id: " + e);
                    FileLog.d(TAG, "Invalid screen id", e);
                }
            }
        } finally {
@@ -1813,7 +1814,7 @@ public class LauncherModel extends BroadcastReceiver
                                            if (intent == null) {
                                                // The app is installed but the component is no
                                                // longer available.
                                                addDumpLog("Invalid component removed: " + cn);
                                                FileLog.d(TAG, "Invalid component removed: " + cn);
                                                itemsToRemove.add(id);
                                                continue;
                                            } else {
@@ -1824,7 +1825,7 @@ public class LauncherModel extends BroadcastReceiver
                                        } else if (restored) {
                                            // Package is not yet available but might be
                                            // installed later.
                                            addDumpLog("package not yet restored: " + cn);
                                            FileLog.d(TAG, "package not yet restored: " + cn);

                                            if ((promiseType & ShortcutInfo.FLAG_RESTORE_STARTED) != 0) {
                                                // Restore has started once.
@@ -1850,12 +1851,12 @@ public class LauncherModel extends BroadcastReceiver
                                                    itemReplaced = true;

                                                } else if (REMOVE_UNRESTORED_ICONS) {
                                                    addDumpLog("Unrestored package removed: " + cn);
                                                    FileLog.d(TAG, "Unrestored package removed: " + cn);
                                                    itemsToRemove.add(id);
                                                    continue;
                                                }
                                            } else if (REMOVE_UNRESTORED_ICONS) {
                                                addDumpLog("Unrestored package removed: " + cn);
                                                FileLog.d(TAG, "Unrestored package removed: " + cn);
                                                itemsToRemove.add(id);
                                                continue;
                                            }
@@ -1880,7 +1881,7 @@ public class LauncherModel extends BroadcastReceiver
                                        } else {
                                            // Do not wait for external media load anymore.
                                            // Log the invalid package, and remove it
                                            addDumpLog("Invalid package removed: " + cn);
                                            FileLog.d(TAG, "Invalid package removed: " + cn);
                                            itemsToRemove.add(id);
                                            continue;
                                        }
@@ -1890,7 +1891,7 @@ public class LauncherModel extends BroadcastReceiver
                                        restored = false;
                                    }
                                } catch (URISyntaxException e) {
                                    addDumpLog("Invalid uri: " + intentDescription);
                                    FileLog.d(TAG, "Invalid uri: " + intentDescription);
                                    itemsToRemove.add(id);
                                    continue;
                                }
@@ -2073,7 +2074,7 @@ public class LauncherModel extends BroadcastReceiver
                                final boolean isProviderReady = isValidProvider(provider);
                                if (!isSafeMode && !customWidget &&
                                        wasProviderReady && !isProviderReady) {
                                    addDumpLog("Deleting widget that isn't installed anymore: "
                                    FileLog.d(TAG, "Deleting widget that isn't installed anymore: "
                                            + provider);
                                    itemsToRemove.add(id);
                                } else {
@@ -2115,7 +2116,7 @@ public class LauncherModel extends BroadcastReceiver
                                            appWidgetInfo.restoreStatus |=
                                                    LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
                                        } else if (REMOVE_UNRESTORED_ICONS && !isSafeMode) {
                                            addDumpLog("Unrestored widget removed: " + component);
                                            FileLog.d(TAG, "Unrestored widget removed: " + component);
                                            itemsToRemove.add(id);
                                            continue;
                                        }
@@ -2171,9 +2172,7 @@ public class LauncherModel extends BroadcastReceiver
                        }
                    }
                } finally {
                    if (c != null) {
                        c.close();
                    }
                    Utilities.closeSilently(c);
                }

                // Break early if we've stopped loading
@@ -3541,8 +3540,4 @@ public class LauncherModel extends BroadcastReceiver
    public static Looper getWorkerLooper() {
        return sWorkerThread.getLooper();
    }

    @Thunk static final void addDumpLog(String log) {
        Launcher.addDumpLog(TAG, log);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -63,9 +63,11 @@ import android.widget.Toast;

import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.util.IconNormalizer;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -845,6 +847,18 @@ public final class Utilities {
        return true;
    }

    public static void closeSilently(Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (ProviderConfig.IS_DOGFOOD_BUILD) {
                    Log.d(TAG, "Error closing", e);
                }
            }
        }
    }

    /**
     * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
     * This allows the badging to be done based on the action bitmap size rather than
+1 −1
Original line number Diff line number Diff line
@@ -20,5 +20,5 @@ public class ProviderConfig {

    public static final String AUTHORITY = "com.android.launcher3.settings".intern();

    public static boolean IS_DOGFOOD_BUILD = false;
    public static boolean IS_DOGFOOD_BUILD = true;
}
Loading