OSDN Git Service

Simplify logic for getting system properties
authorBraden Farmer <farmerbb@gmail.com>
Tue, 13 Aug 2019 03:59:16 +0000 (21:59 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Tue, 13 Aug 2019 03:59:16 +0000 (21:59 -0600)
app/src/androidx86/java/com/farmerbb/taskbar/util/DependencyUtils.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/playstore/java/com/farmerbb/taskbar/util/DependencyUtils.java
app/src/playstore/java/com/jrummyapps/android/os/SystemProperties.java [deleted file]

index 7dc245c..44594ba 100644 (file)
@@ -31,9 +31,5 @@ public class DependencyUtils {
         return new ToastFrameworkImpl(context, message, length);
     }
 
-    static String getSystemProperty(String key) {
-        return null;
-    }
-
     public static void requestTaskerQuery(Context context) {}
 }
index 4dfaf34..b9dca23 100644 (file)
@@ -1092,11 +1092,11 @@ public class U {
     public static boolean isBlissOs(Context context) {
         boolean validBlissOsBuildProp = false;
 
-        String blissVersion = DependencyUtils.getSystemProperty("ro.bliss.version");
+        String blissVersion = getSystemProperty("ro.bliss.version");
         if(blissVersion != null && !blissVersion.isEmpty())
             validBlissOsBuildProp = true;
 
-        String buildUser = DependencyUtils.getSystemProperty("ro.build.user");
+        String buildUser = getSystemProperty("ro.build.user");
         if(buildUser != null && buildUser.equals("electrikjesus"))
             validBlissOsBuildProp = true;
 
@@ -1547,4 +1547,14 @@ public class U {
 
         return false;
     }
+
+    @SuppressLint("PrivateApi")
+    private static String getSystemProperty(String key) {
+        try {
+            Class<?> cls = Class.forName("android.os.SystemProperties");
+            return cls.getMethod("get", String.class).invoke(null, key).toString();
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }
index 6b440cf..ab79ab4 100644 (file)
@@ -21,7 +21,6 @@ import android.os.Build;
 
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.activity.TaskerConditionActivity;
-import com.jrummyapps.android.os.SystemProperties;
 import com.mikepenz.iconics.Iconics;
 
 // Utility class meant for abstracting out all third-party dependencies.
@@ -46,10 +45,6 @@ public class DependencyUtils {
             return new ToastCompatImpl(context, message, length);
     }
 
-    static String getSystemProperty(String key) {
-        return SystemProperties.get(key);
-    }
-
     public static void requestTaskerQuery(Context context) {
         Intent query = new Intent(com.twofortyfouram.locale.api.Intent.ACTION_REQUEST_QUERY);
         query.putExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_ACTIVITY_CLASS_NAME, TaskerConditionActivity.class.getName());
diff --git a/app/src/playstore/java/com/jrummyapps/android/os/SystemProperties.java b/app/src/playstore/java/com/jrummyapps/android/os/SystemProperties.java
deleted file mode 100644 (file)
index 77f67aa..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2015 Jared Rummler <jared.rummler@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.jrummyapps.android.os;
-
-/**
- * Gives access to the system properties store. The system properties tore contains a list of string
- * key-value pairs.
- *
- * @author Jared Rummler <jared.rummler@gmail.com>
- * @since Feb 8, 2015
- */
-public class SystemProperties {
-
-    // ===========================================================
-    // STATIC FIELDS
-    // ===========================================================
-
-    private static Class<?> CLASS;
-
-    // ===========================================================
-    // STATIC INITIALIZERS
-    // ===========================================================
-
-    static {
-        try {
-            CLASS = Class.forName("android.os.SystemProperties");
-        } catch (ClassNotFoundException e) {
-        }
-    }
-
-    // ===========================================================
-    // STATIC METHODS
-    // ===========================================================
-
-    /** Get the value for the given key. */
-    public static String get(String key) {
-        try {
-            return (String) CLASS.getMethod("get", String.class).invoke(null, key);
-        } catch (Exception e) {
-            return null;
-        }
-    }
-
-    /**
-     * Get the value for the given key.
-     * 
-     * @return if the key isn't found, return def if it isn't null, or an empty string otherwise
-     */
-    public static String get(String key, String def) {
-        try {
-            return (String) CLASS.getMethod("get", String.class, String.class).invoke(null, key,
-                def);
-        } catch (Exception e) {
-            return def;
-        }
-    }
-
-    /**
-     * Get the value for the given key, and return as an integer.
-     * 
-     * @param key
-     *            the key to lookup
-     * @param def
-     *            a default value to return
-     * @return the key parsed as an integer, or def if the key isn't found or cannot be parsed
-     */
-    public static int getInt(String key, int def) {
-        try {
-            return (Integer) CLASS.getMethod("getInt", String.class, int.class).invoke(null, key,
-                def);
-        } catch (Exception e) {
-            return def;
-        }
-    }
-
-    /**
-     * Get the value for the given key, and return as a long.
-     * 
-     * @param key
-     *            the key to lookup
-     * @param def
-     *            a default value to return
-     * @return the key parsed as a long, or def if the key isn't found or cannot be parsed
-     */
-    public static long getLong(String key, long def) {
-        try {
-            return (Long) CLASS.getMethod("getLong", String.class, long.class).invoke(null, key,
-                def);
-        } catch (Exception e) {
-            return def;
-        }
-    }
-
-    /**
-     * Get the value for the given key, returned as a boolean. Values 'n', 'no', '0', 'false' or
-     * 'off' are considered false. Values 'y', 'yes', '1', 'true' or 'on' are considered true. (case
-     * sensitive). If the key does not exist, or has any other value, then the default result is
-     * returned.
-     * 
-     * @param key
-     *            the key to lookup
-     * @param def
-     *            a default value to return
-     * @return the key parsed as a boolean, or def if the key isn't found or is not able to be
-     *         parsed as a boolean.
-     */
-    public static boolean getBoolean(String key, boolean def) {
-        try {
-            return (Boolean) CLASS.getMethod("getBoolean", String.class, boolean.class).invoke(
-                null, key, def);
-        } catch (Exception e) {
-            return def;
-        }
-    }
-
-    /** Set the value for the given key. */
-    public static void set(String key, String val) {
-        try {
-            CLASS.getMethod("set", String.class, String.class).invoke(null, key, val);
-        } catch (Exception ignored) {
-        }
-    }
-
-    public static void addChangeCallback(Runnable callback) {
-        try {
-            CLASS.getMethod("addChangeCallback", Runnable.class).invoke(null, callback);
-        } catch (Exception ignored) {
-        }
-    }
-
-    public static void callChangeCallbacks() {
-        try {
-            CLASS.getMethod("callChangeCallbacks").invoke(null, (Object[]) null);
-        } catch (Exception ignored) {
-        }
-    }
-
-    private SystemProperties() {
-
-    }
-}
\ No newline at end of file