Skip to content

Commit

Permalink
Merge pull request #1764 from wordpress-mobile/issue/1713-send-versio…
Browse files Browse the repository at this point in the history
…n-code-to-mixpanel

fix #1713 send version code to mixpanel
  • Loading branch information
nbradbury committed Aug 25, 2014
2 parents efd0501 + cdbab65 commit bba036d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static ArrayList<String> toHtmlList(Context context) {
ArrayList<String> items = new ArrayList<String>();

// add version & device info - be sure to change HEADER_LINE_COUNT if additional lines are added
items.add("<strong>WordPress Android version: " + ProfilingUtils.getVersionName(context) + "</strong>");
items.add("<strong>WordPress Android version: " + PackageUtils.getVersionName(context) + "</strong>");
items.add("<strong>Android device name: " + DeviceUtils.getInstance().getDeviceName(context) + "</strong>");

Iterator<LogEntry> it = mLogEntries.iterator();
Expand All @@ -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<LogEntry> it = mLogEntries.iterator();
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 "";
}
}
}

0 comments on commit bba036d

Please sign in to comment.