From f464cdb1f3ffbb6d78ac815713b6b58f7f6654f0 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Wed, 20 Aug 2014 17:07:37 +0200 Subject: [PATCH 1/3] move BuildUtils to WPUtils subtree, rename BuildUtils to PackageUtils and add getPackageInfo and getVersionCode methods --- .../wordpress/android/util/PackageUtils.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java new file mode 100644 index 000000000000..52900a0bf27e --- /dev/null +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/PackageUtils.java @@ -0,0 +1,45 @@ +package org.wordpress.android.util; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; + +public class PackageUtils { + /** + * Return true if Debug build. false otherwise. + */ + public static boolean isDebugBuild() { + return BuildConfig.DEBUG; + } + + public static PackageInfo getPackageInfo(Context context) { + try { + PackageManager manager = context.getPackageManager(); + return manager.getPackageInfo(context.getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) { + return null; + } + } + + /** + * Return version code, or 0 if it can't be read + */ + public static int getVersionCode(Context context) { + PackageInfo packageInfo = getPackageInfo(context); + if (packageInfo != null) { + return packageInfo.versionCode; + } + return 0; + } + + /** + * Return version name, or the string "0" if it can't be read + */ + public static String getVersionName(Context context) { + PackageInfo packageInfo = getPackageInfo(context); + if (packageInfo != null) { + return packageInfo.versionName; + } + return "0"; + } +} From 2b0241f0fc204c6bc9d599292b454693d658f2c1 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Wed, 20 Aug 2014 17:17:08 +0200 Subject: [PATCH 2/3] remove unused method from ProfilingUtils --- .../org/wordpress/android/util/ProfilingUtils.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ProfilingUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ProfilingUtils.java index 251db2a3b7fb..991c7680b478 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/ProfilingUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ProfilingUtils.java @@ -1,8 +1,5 @@ package org.wordpress.android.util; -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; import android.os.SystemClock; import org.wordpress.android.util.AppLog.T; @@ -76,16 +73,5 @@ public void dumpToLog() { } AppLog.d(T.PROFILING, mLabel + ": end, " + (now - first) + " ms"); } - - // Returns app version name String - public static String getVersionName(Context context) { - PackageManager pm = context.getPackageManager(); - try { - PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); - return pi.versionName == null ? "" : pi.versionName; - } catch (PackageManager.NameNotFoundException e) { - return ""; - } - } } From b2d18063e68d3f4df4e040ba6a8b3f7e436e3a41 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Thu, 21 Aug 2014 15:08:35 +0200 Subject: [PATCH 3/3] remove ProfilingUtils.getVersionName calls --- .../src/main/java/org/wordpress/android/util/AppLog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java b/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java index 292c974ec7fa..2a11d7ee6f8d 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java @@ -175,7 +175,7 @@ public static ArrayList toHtmlList(Context context) { ArrayList items = new ArrayList(); // add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added - items.add("WordPress Android version: " + ProfilingUtils.getVersionName(context) + ""); + items.add("WordPress Android version: " + PackageUtils.getVersionName(context) + ""); items.add("Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + ""); Iterator it = mLogEntries.iterator(); @@ -193,7 +193,7 @@ public static String toPlainText(Context context) { StringBuilder sb = new StringBuilder(); // add version & device info - sb.append("WordPress Android version: " + ProfilingUtils.getVersionName(context)).append("\n") + sb.append("WordPress Android version: " + PackageUtils.getVersionName(context)).append("\n") .append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n"); Iterator it = mLogEntries.iterator();