From 9eb9adb1398f032f48cc5cba4305ce9bca0fbd3d Mon Sep 17 00:00:00 2001 From: Mykola Dzyuba <7852483+mdzyuba@users.noreply.github.com> Date: Thu, 11 Mar 2021 22:23:57 -0800 Subject: [PATCH] Update Build.VERSION checks based on minSdkVersion 14 (ICE_CREAM_SANDWICH). --- .../stetho/common/android/FragmentCompat.java | 6 +----- .../android/FragmentCompatFramework.java | 1 - .../SharedPreferencesDumperPlugin.java | 3 --- .../database/SQLiteDatabaseCompat.java | 18 +++-------------- .../elements/android/ActivityTracker.java | 20 ++++++++----------- .../inspector/protocol/module/DOMStorage.java | 9 +-------- .../protocol/module/DatabaseConstants.java | 2 +- 7 files changed, 14 insertions(+), 45 deletions(-) diff --git a/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompat.java b/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompat.java index e6eb5323..3451b937 100644 --- a/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompat.java +++ b/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompat.java @@ -8,7 +8,6 @@ package com.facebook.stetho.common.android; import android.app.Activity; -import android.os.Build; import com.facebook.stetho.common.ReflectionUtil; @@ -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 @@ -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; diff --git a/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatFramework.java b/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatFramework.java index 797b1cc9..b7c84c23 100644 --- a/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatFramework.java +++ b/stetho/src/main/java/com/facebook/stetho/common/android/FragmentCompatFramework.java @@ -19,7 +19,6 @@ import javax.annotation.Nullable; -@TargetApi(Build.VERSION_CODES.HONEYCOMB) final class FragmentCompatFramework extends FragmentCompat { private static final FragmentAccessorFrameworkHoneycomb sFragmentAccessor; diff --git a/stetho/src/main/java/com/facebook/stetho/dumpapp/plugins/SharedPreferencesDumperPlugin.java b/stetho/src/main/java/com/facebook/stetho/dumpapp/plugins/SharedPreferencesDumperPlugin.java index 20d2eec5..027649aa 100644 --- a/stetho/src/main/java/com/facebook/stetho/dumpapp/plugins/SharedPreferencesDumperPlugin.java +++ b/stetho/src/main/java/com/facebook/stetho/dumpapp/plugins/SharedPreferencesDumperPlugin.java @@ -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; @@ -120,7 +118,6 @@ private static String nextArgValue(Iterator iter) throws DumpUsageExcept return nextArg(iter, "Expected "); } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) private static void putStringSet( SharedPreferences.Editor editor, String key, diff --git a/stetho/src/main/java/com/facebook/stetho/inspector/database/SQLiteDatabaseCompat.java b/stetho/src/main/java/com/facebook/stetho/inspector/database/SQLiteDatabaseCompat.java index 9019e525..bc39fe2a 100644 --- a/stetho/src/main/java/com/facebook/stetho/inspector/database/SQLiteDatabaseCompat.java +++ b/stetho/src/main/java/com/facebook/stetho/inspector/database/SQLiteDatabaseCompat.java @@ -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(); } } @@ -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; @@ -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) { - } - } } diff --git a/stetho/src/main/java/com/facebook/stetho/inspector/elements/android/ActivityTracker.java b/stetho/src/main/java/com/facebook/stetho/inspector/elements/android/ActivityTracker.java index d8b38953..01caf9c7 100644 --- a/stetho/src/main/java/com/facebook/stetho/inspector/elements/android/ActivityTracker.java +++ b/stetho/src/main/java/com/facebook/stetho/inspector/elements/android/ActivityTracker.java @@ -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; @@ -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; } @@ -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(); diff --git a/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DOMStorage.java b/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DOMStorage.java index e3e12413..246d6596 100644 --- a/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DOMStorage.java +++ b/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DOMStorage.java @@ -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; @@ -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)value); + editor.putStringSet(key, (Set)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 value) { - editor.putStringSet(key, value); - } - public static class StorageId { @JsonProperty(required = true) public String securityOrigin; diff --git a/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DatabaseConstants.java b/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DatabaseConstants.java index cd7ec869..d965e637 100644 --- a/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DatabaseConstants.java +++ b/stetho/src/main/java/com/facebook/stetho/inspector/protocol/module/DatabaseConstants.java @@ -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; }