Skip to content

Commit

Permalink
Do not hardcode "WordPress Android" in the header of the log.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloercoli committed Oct 25, 2016
1 parent 8c0fe91 commit 023ee88
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.wordpress.android.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.util.Log;

Expand Down Expand Up @@ -236,8 +239,19 @@ private static String getStringStackTrace(Throwable throwable) {
public static ArrayList<String> toHtmlList(Context context) {
ArrayList<String> items = new ArrayList<String>();

PackageManager packageManager = context.getPackageManager();
PackageInfo pkInfo = PackageUtils.getPackageInfo(context);

ApplicationInfo applicationInfo = pkInfo != null ? pkInfo.applicationInfo : null;
String appName;
if (applicationInfo != null && packageManager.getApplicationLabel(applicationInfo) != null) {
appName = packageManager.getApplicationLabel(applicationInfo).toString();
} else {
appName = "Unknown";
}

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

Iterator<LogEntry> it = mLogEntries.iterator();
Expand All @@ -255,9 +269,21 @@ public static ArrayList<String> toHtmlList(Context context) {
public static String toPlainText(Context context) {
StringBuilder sb = new StringBuilder();

PackageManager packageManager = context.getPackageManager();
PackageInfo pkInfo = PackageUtils.getPackageInfo(context);

ApplicationInfo applicationInfo = pkInfo != null ? pkInfo.applicationInfo : null;
String appName;
if (applicationInfo != null && packageManager.getApplicationLabel(applicationInfo) != null) {
appName = packageManager.getApplicationLabel(applicationInfo).toString();
} else {
appName = "Unknown";
}

// add version & device info
sb.append("WordPress Android version: " + PackageUtils.getVersionName(context)).append("\n")
.append("Android device name: " + DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");
sb.append(appName).append(" - ").append(PackageUtils.getVersionName(context))
.append(" - Version code:").append(PackageUtils.getVersionCode(context)).append("\n")
.append("Android device name: ").append(DeviceUtils.getInstance().getDeviceName(context)).append("\n\n");

Iterator<LogEntry> it = mLogEntries.iterator();
int lineNum = 1;
Expand Down

0 comments on commit 023ee88

Please sign in to comment.