Skip to content

Commit

Permalink
Remove more obsolete code now we only support 14 and up
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristan Meijer committed Oct 16, 2019
1 parent 9d3d929 commit ed5eb97
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

package com.facebook.stetho.sample;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.SystemClock;
import android.provider.CalendarContract;
import android.util.Log;

import com.facebook.stetho.DumperPluginsProvider;
import com.facebook.stetho.InspectorModulesProvider;
import com.facebook.stetho.Stetho;
Expand Down Expand Up @@ -66,7 +65,6 @@ public Iterable<ChromeDevtoolsDomain> get() {
.finish();
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private ContentProviderDatabaseDriver createContentProviderDatabaseDriver(Context context) {
ContentProviderSchema calendarsSchema = new ContentProviderSchema.Builder()
.table(new Table.Builder()
Expand Down
27 changes: 7 additions & 20 deletions stetho/src/main/java/com/facebook/stetho/Stetho.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;

import com.facebook.stetho.common.LogUtil;
import com.facebook.stetho.common.Util;
import com.facebook.stetho.dumpapp.DumpappHttpSocketLikeHandler;
import com.facebook.stetho.dumpapp.DumpappSocketLikeHandler;
Expand All @@ -34,7 +32,6 @@
import com.facebook.stetho.inspector.elements.Document;
import com.facebook.stetho.inspector.elements.DocumentProviderFactory;
import com.facebook.stetho.inspector.elements.android.ActivityTracker;
import com.facebook.stetho.inspector.elements.android.AndroidDocumentConstants;
import com.facebook.stetho.inspector.elements.android.AndroidDocumentProviderFactory;
import com.facebook.stetho.inspector.protocol.ChromeDevtoolsDomain;
import com.facebook.stetho.inspector.protocol.module.CSS;
Expand Down Expand Up @@ -66,6 +63,7 @@
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -122,13 +120,7 @@ protected Iterable<ChromeDevtoolsDomain> getInspectorModules() {
public static void initialize(final Initializer initializer) {
// Hook activity tracking so that after Stetho is attached we can figure out what
// activities are present.
boolean isTrackingActivities = ActivityTracker.get().beginTrackingIfPossible(
(Application)initializer.mContext.getApplicationContext());
if (!isTrackingActivities) {
LogUtil.w("Automatic activity tracking not available on this API level, caller must invoke " +
"ActivityTracker methods manually!");
}

ActivityTracker.get().beginTracking((Application)initializer.mContext.getApplicationContext());
initializer.start();
}

Expand Down Expand Up @@ -369,11 +361,9 @@ public Iterable<ChromeDevtoolsDomain> finish() {
provideIfDesired(new Console());
provideIfDesired(new Debugger());
DocumentProviderFactory documentModel = resolveDocumentProvider();
if (documentModel != null) {
Document document = new Document(documentModel);
provideIfDesired(new DOM(document));
provideIfDesired(new CSS(document));
}
Document document = new Document(documentModel);
provideIfDesired(new DOM(document));
provideIfDesired(new CSS(document));
provideIfDesired(new DOMStorage(mContext));
provideIfDesired(new HeapProfiler());
provideIfDesired(new Inspector());
Expand Down Expand Up @@ -408,15 +398,12 @@ public Iterable<ChromeDevtoolsDomain> finish() {
return mDelegate.finish();
}

@Nullable
@Nonnull
private DocumentProviderFactory resolveDocumentProvider() {
if (mDocumentProvider != null) {
return mDocumentProvider;
}
if (Build.VERSION.SDK_INT >= AndroidDocumentConstants.MIN_API_LEVEL) {
return new AndroidDocumentProviderFactory(mContext, Collections.<DescriptorProvider>emptyList());
}
return null;
return new AndroidDocumentProviderFactory(mContext, Collections.<DescriptorProvider>emptyList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import javax.annotation.Nullable;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
final class FragmentCompatFramework
extends FragmentCompat<Fragment, DialogFragment, FragmentManager, Activity> {
private static final FragmentAccessorFrameworkHoneycomb sFragmentAccessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ private static Object findFragmentForViewInActivity(Activity activity, View view
}
}

// Try the actual Android runtime version if we are on a sufficiently high API level for it to
// exist. Note that technically we can have both the support library and the framework
// Use the actual Android runtime version. Note that technically we can have both the support library and the framework
// version in the same object instance due to FragmentActivity extending Activity (which has
// fragment support in the system).
FragmentCompat framework = FragmentCompat.getFrameworkInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
package com.facebook.stetho.dumpapp.plugins;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.text.TextUtils;

import com.facebook.stetho.dumpapp.DumpUsageException;
import com.facebook.stetho.dumpapp.DumperContext;
import com.facebook.stetho.dumpapp.DumperPlugin;
import com.facebook.stetho.inspector.domstorage.SharedPreferencesHelper;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class SharedPreferencesDumperPlugin implements DumperPlugin {

private static final String XML_SUFFIX = ".xml";
Expand Down Expand Up @@ -118,7 +118,6 @@ private static String nextArgValue(Iterator<String> iter) throws DumpUsageExcept
return nextArg(iter, "Expected <value>");
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void putStringSet(
SharedPreferences.Editor editor,
String key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@

package com.facebook.stetho.inspector.elements.android;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import com.facebook.stetho.common.Util;

import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.NotThreadSafe;
import com.facebook.stetho.common.Util;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.NotThreadSafe;

/**
* Tracks which {@link Activity} instances have been created and not yet destroyed in creation
* order for use by Stetho features. Note that automatic tracking is not available for
Expand All @@ -34,6 +33,7 @@
* <p/>
* Most callers can and should ignore this class, though it is necessary if you are implementing
* Activity tracking pre-ICS.
* TODO: we now only support ICS+, is there still a need for this class?
*/
@NotThreadSafe
public final class ActivityTracker {
Expand Down Expand Up @@ -66,22 +66,14 @@ public void unregisterListener(Listener listener) {
}

/**
* Start automatic tracking if we are running on ICS+.
*
* @return Automatic tracking has been started. No need to manually invoke {@link #add} or
* {@link #remove} methods.
* Start automatic tracking.
*/
public boolean beginTrackingIfPossible(Application application) {
public void beginTracking(Application application) {
if (mAutomaticTracker == null) {
AutomaticTracker automaticTracker =
AutomaticTracker.newInstanceIfPossible(application, this /* tracker */);
if (automaticTracker != null) {
automaticTracker.register();
mAutomaticTracker = automaticTracker;
return true;
}
AutomaticTracker automaticTracker = new AutomaticTracker(application, this /* tracker */);
automaticTracker.register();
mAutomaticTracker = automaticTracker;
}
return false;
}

public boolean endTracking() {
Expand Down Expand Up @@ -146,76 +138,59 @@ public interface Listener {
public void onActivityRemoved(Activity activity);
}

private static abstract class AutomaticTracker {
@Nullable
public static AutomaticTracker newInstanceIfPossible(
Application application,
ActivityTracker tracker) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return new AutomaticTrackerICSAndBeyond(application, tracker);
} else {
return null;
}
private static class AutomaticTracker {
private final Application mApplication;
private final ActivityTracker mTracker;

public AutomaticTracker(Application application, ActivityTracker tracker) {
mApplication = application;
mTracker = tracker;
}

public abstract void register();
public abstract void unregister();
public void register() {
mApplication.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static class AutomaticTrackerICSAndBeyond extends AutomaticTracker {
private final Application mApplication;
private final ActivityTracker mTracker;
public void unregister() {
mApplication.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
}

public AutomaticTrackerICSAndBeyond(Application application, ActivityTracker tracker) {
mApplication = application;
mTracker = tracker;
private final Application.ActivityLifecycleCallbacks mLifecycleCallbacks =
new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
mTracker.add(activity);
}

public void register() {
mApplication.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
}
@Override
public void onActivityStarted(Activity activity) {

public void unregister() {
mApplication.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
}

private final Application.ActivityLifecycleCallbacks mLifecycleCallbacks =
new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
mTracker.add(activity);
}

@Override
public void onActivityStarted(Activity activity) {

}

@Override
public void onActivityResumed(Activity activity) {
@Override
public void onActivityResumed(Activity activity) {

}
}

@Override
public void onActivityPaused(Activity activity) {
@Override
public void onActivityPaused(Activity activity) {

}
}

@Override
public void onActivityStopped(Activity activity) {
@Override
public void onActivityStopped(Activity activity) {

}
}

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

}
}

@Override
public void onActivityDestroyed(Activity activity) {
mTracker.remove(activity);
}
};
}
@Override
public void onActivityDestroyed(Activity activity) {
mTracker.remove(activity);
}
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

package com.facebook.stetho.inspector.protocol.module;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;

import com.facebook.stetho.inspector.console.CLog;
import com.facebook.stetho.inspector.domstorage.DOMStoragePeerManager;
import com.facebook.stetho.inspector.domstorage.SharedPreferencesHelper;
Expand All @@ -21,6 +20,7 @@
import com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod;
import com.facebook.stetho.json.ObjectMapper;
import com.facebook.stetho.json.annotation.JsonProperty;

import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -160,17 +160,12 @@ private static void assignByType(
} else if (value instanceof String) {
editor.putString(key, (String)value);
} else if (value instanceof Set) {
putStringSet(editor, key, (Set<String>)value);
editor.putStringSet(key, (Set<String>)value);
} else {
throw new IllegalArgumentException("Unsupported type=" + value.getClass().getName());
}
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void putStringSet(SharedPreferences.Editor editor, String key, Set<String> value) {
editor.putStringSet(key, value);
}

public static class StorageId {
@JsonProperty(required = true)
public String securityOrigin;
Expand Down
Loading

0 comments on commit ed5eb97

Please sign in to comment.