File tree Expand file tree Collapse file tree 3 files changed +47
-16
lines changed
WordPressUtils/src/main/java/org/wordpress/android/util Expand file tree Collapse file tree 3 files changed +47
-16
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ public static ArrayList<String> toHtmlList(Context context) {
175175 ArrayList <String > items = new ArrayList <String >();
176176
177177 // add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added
178- items .add ("<strong>WordPress Android version: " + ProfilingUtils .getVersionName (context ) + "</strong>" );
178+ items .add ("<strong>WordPress Android version: " + PackageUtils .getVersionName (context ) + "</strong>" );
179179 items .add ("<strong>Android device name: " + DeviceUtils .getInstance ().getDeviceName (context ) + "</strong>" );
180180
181181 Iterator <LogEntry > it = mLogEntries .iterator ();
@@ -193,7 +193,7 @@ public static String toPlainText(Context context) {
193193 StringBuilder sb = new StringBuilder ();
194194
195195 // add version & device info
196- sb .append ("WordPress Android version: " + ProfilingUtils .getVersionName (context )).append ("\n " )
196+ sb .append ("WordPress Android version: " + PackageUtils .getVersionName (context )).append ("\n " )
197197 .append ("Android device name: " + DeviceUtils .getInstance ().getDeviceName (context )).append ("\n \n " );
198198
199199 Iterator <LogEntry > it = mLogEntries .iterator ();
Original file line number Diff line number Diff line change 1+ package org .wordpress .android .util ;
2+
3+ import android .content .Context ;
4+ import android .content .pm .PackageInfo ;
5+ import android .content .pm .PackageManager ;
6+
7+ public class PackageUtils {
8+ /**
9+ * Return true if Debug build. false otherwise.
10+ */
11+ public static boolean isDebugBuild () {
12+ return BuildConfig .DEBUG ;
13+ }
14+
15+ public static PackageInfo getPackageInfo (Context context ) {
16+ try {
17+ PackageManager manager = context .getPackageManager ();
18+ return manager .getPackageInfo (context .getPackageName (), 0 );
19+ } catch (PackageManager .NameNotFoundException e ) {
20+ return null ;
21+ }
22+ }
23+
24+ /**
25+ * Return version code, or 0 if it can't be read
26+ */
27+ public static int getVersionCode (Context context ) {
28+ PackageInfo packageInfo = getPackageInfo (context );
29+ if (packageInfo != null ) {
30+ return packageInfo .versionCode ;
31+ }
32+ return 0 ;
33+ }
34+
35+ /**
36+ * Return version name, or the string "0" if it can't be read
37+ */
38+ public static String getVersionName (Context context ) {
39+ PackageInfo packageInfo = getPackageInfo (context );
40+ if (packageInfo != null ) {
41+ return packageInfo .versionName ;
42+ }
43+ return "0" ;
44+ }
45+ }
Original file line number Diff line number Diff line change 11package org .wordpress .android .util ;
22
3- import android .content .Context ;
4- import android .content .pm .PackageInfo ;
5- import android .content .pm .PackageManager ;
63import android .os .SystemClock ;
74
85import org .wordpress .android .util .AppLog .T ;
@@ -76,16 +73,5 @@ public void dumpToLog() {
7673 }
7774 AppLog .d (T .PROFILING , mLabel + ": end, " + (now - first ) + " ms" );
7875 }
79-
80- // Returns app version name String
81- public static String getVersionName (Context context ) {
82- PackageManager pm = context .getPackageManager ();
83- try {
84- PackageInfo pi = pm .getPackageInfo (context .getPackageName (), 0 );
85- return pi .versionName == null ? "" : pi .versionName ;
86- } catch (PackageManager .NameNotFoundException e ) {
87- return "" ;
88- }
89- }
9076}
9177
You can’t perform that action at this time.
0 commit comments