/** * Construct a simple initializer helper which allows you to customize stetho behaviour * with additional features, plugins, etc. See {@link DefaultDumperPluginsBuilder} and * {@link DefaultInspectorModulesBuilder} for more information. * <p /> * For simple use cases, consider {@link #initializeWithDefaults(Context)}. */ public static InitializerBuilder newInitializerBuilder(Context context) { return new InitializerBuilder(context); }
@Override public Iterable<DumperPlugin> get() { return new DefaultDumperPluginsBuilder(context).finish(); } };
@Override public Iterable<ChromeDevtoolsDomain> get() { return new DefaultInspectorModulesBuilder(context).finish(); } };
private void init() { //初始化Leak内存泄露检测工具 LeakCanary.install(this); //初始化Stetho调试工具 Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) .build()); }
@Override public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); } }
/** * Start the listening server. Most of the heavy lifting initialization is deferred until the * first socket connection is received, allowing this to be safely used for debug builds on * even low-end hardware without noticeably affecting performance. */ public static void initializeWithDefaults(final Context context) { initialize(new Initializer(context) { @Override protected Iterable<DumperPlugin> getDumperPlugins() { return new DefaultDumperPluginsBuilder(context).finish(); } @Override protected Iterable<ChromeDevtoolsDomain> getInspectorModules() { return new DefaultInspectorModulesBuilder(context).finish(); } }); }
public Iterable<DumperPlugin> finish() { provideIfDesired(new HprofDumperPlugin(mContext)); provideIfDesired(new SharedPreferencesDumperPlugin(mContext)); provideIfDesired(new CrashDumperPlugin()); provideIfDesired(new FilesDumperPlugin(mContext)); return mDelegate.finish(); } }
/** * @deprecated Convert your custom database driver to {@link DatabaseDriver2}. */ @Deprecated public DefaultInspectorModulesBuilder provideDatabaseDriver(Database.DatabaseDriver databaseDriver) { provideDatabaseDriver(new DatabaseDriver2Adapter(databaseDriver)); return this; }
private DefaultDumperPluginsBuilder provideIfDesired(DumperPlugin plugin) { mDelegate.provideIfDesired(plugin.getName(), plugin); return this; }
public void remove(String pluginName) { throwIfFinished(); mRemovedNames.add(pluginName); }
public DefaultDumperPluginsBuilder remove(String pluginName) { mDelegate.remove(pluginName); return this; }
public Initializer build() { return new BuilderBasedInitializer(this); } }
@Nullable @Override protected Iterable<ChromeDevtoolsDomain> getInspectorModules() { return mInspectorModules != null ? mInspectorModules.get() : null; } }
@Nullable @Override protected Iterable<DumperPlugin> getDumperPlugins() { return mDumperPlugins != null ? mDumperPlugins.get() : null; }
@Override protected Iterable<DumperPlugin> getDumperPlugins() { return new DefaultDumperPluginsBuilder(context).finish(); }
@Override protected Iterable<ChromeDevtoolsDomain> getInspectorModules() { return new DefaultInspectorModulesBuilder(context).finish(); } });
public void provide(String name, T plugin) { throwIfFinished(); mPlugins.add(plugin); mProvidedNames.add(name); }
/** * Remove an existing domain module. * * @deprecated This fine-grained control of the devtools modules is no longer supportable * given the lack of isolation of modules in the actual protocol (many cross dependencies * emerge when you implement more and more of the real protocol). */ @Deprecated public DefaultInspectorModulesBuilder remove(String moduleName) { mDelegate.remove(moduleName); return this; }
public void provideIfDesired(String name, T plugin) { throwIfFinished(); if (!mRemovedNames.contains(name)) { if (mProvidedNames.add(name)) { mPlugins.add(plugin); } } }