Skip to content

Commit f0229fc

Browse files
committed
Merge pull request #1764 from wordpress-mobile/issue/1713-send-version-code-to-mixpanel
fix #1713 send version code to mixpanel
2 parents 8b37df5 + b2d1806 commit f0229fc

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

WordPressUtils/src/main/java/org/wordpress/android/util/ProfilingUtils.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.wordpress.android.util;
22

3-
import android.content.Context;
4-
import android.content.pm.PackageInfo;
5-
import android.content.pm.PackageManager;
63
import android.os.SystemClock;
74

85
import 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

0 commit comments

Comments
 (0)