Skip to content

Commit

Permalink
Update Build.VERSION checks based on minSdkVersion 14 (ICE_CREAM_SAND…
Browse files Browse the repository at this point in the history
…WICH).
  • Loading branch information
mdzyuba committed Mar 12, 2021
1 parent bdd2cfd commit 9eb9adb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.facebook.stetho.common.android;

import android.app.Activity;
import android.os.Build;

import com.facebook.stetho.common.ReflectionUtil;

Expand All @@ -18,8 +17,6 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import androidx.annotation.NonNull;

/**
* Compatibility abstraction which allows us to generalize access to both the
* support library's fragments and the built-in framework version. Note: both versions
Expand Down Expand Up @@ -52,8 +49,7 @@ public abstract class FragmentCompat<

@Nullable
public static FragmentCompat getFrameworkInstance() {
if (sFrameworkInstance == null &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (sFrameworkInstance == null) {
sFrameworkInstance = new FragmentCompatFramework();
}
return sFrameworkInstance;
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 @@ -8,10 +8,8 @@
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;
Expand Down Expand Up @@ -120,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 @@ -32,10 +32,8 @@ public abstract class SQLiteDatabaseCompat {
static {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
sInstance = new JellyBeanAndBeyondImpl();
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
sInstance = new HoneycombImpl();
} else {
sInstance = new NoopImpl();
sInstance = new IceCreamSandwichImpl();
}
}

Expand Down Expand Up @@ -65,8 +63,8 @@ public void enableFeatures(@SQLiteOpenOptions int openOptions, SQLiteDatabase db
}
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static class HoneycombImpl extends SQLiteDatabaseCompat {
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static class IceCreamSandwichImpl extends SQLiteDatabaseCompat {
@Override
public int provideOpenFlags(@SQLiteOpenOptions int openOptions) {
return 0;
Expand All @@ -84,14 +82,4 @@ public void enableFeatures(@SQLiteOpenOptions int openOptions, SQLiteDatabase db
}
}

private static class NoopImpl extends SQLiteDatabaseCompat {
@Override
public int provideOpenFlags(@SQLiteOpenOptions int openOptions) {
return 0;
}

@Override
public void enableFeatures(@SQLiteOpenOptions int openOptions, SQLiteDatabase db) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.os.Bundle;
import android.os.Looper;

import androidx.annotation.NonNull;

import com.facebook.stetho.common.Util;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -75,12 +77,10 @@ public void unregisterListener(Listener listener) {
public boolean beginTrackingIfPossible(Application application) {
if (mAutomaticTracker == null) {
AutomaticTracker automaticTracker =
AutomaticTracker.newInstanceIfPossible(application, this /* tracker */);
if (automaticTracker != null) {
AutomaticTracker.newInstance(application, this /* tracker */);
automaticTracker.register();
mAutomaticTracker = automaticTracker;
return true;
}
}
return false;
}
Expand Down Expand Up @@ -148,15 +148,11 @@ public interface Listener {
}

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;
}
@NonNull
public static AutomaticTracker newInstance(
Application application,
ActivityTracker tracker) {
return new AutomaticTrackerICSAndBeyond(application, tracker);
}

public abstract void register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

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;
Expand Down Expand Up @@ -162,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface DatabaseConstants {
/**
* Minimum API version required to use the {@link Database}.
*/
public static final int MIN_API_LEVEL = Build.VERSION_CODES.HONEYCOMB;
public static final int MIN_API_LEVEL = Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}

0 comments on commit 9eb9adb

Please sign in to comment.