Get more information for crash report
This commit is contained in:
1 parent
0f9bec5645
commit
697e0026c5
3 files changed
+85
-22
No files matched your search
@@ -25,6 +25,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.hippo.ehviewer.ehclient.EhClient;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -129,7 +131,6 @@ public class Crash {
|
||||
}
|
||||
|
||||
private static void collectDeviceInfo(StringBuffer sb) {
|
||||
boolean getPackageInfo = false;
|
||||
try {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
@@ -140,19 +141,23 @@ public class Crash {
|
||||
sb.append("PackageName=").append(pi.packageName).append("\n");
|
||||
sb.append("VersionName=").append(versionName).append("\n");
|
||||
sb.append("VersionCode=").append(versionCode).append("\n");
|
||||
sb.append("Signature=").append(PackageUtils.getSignature(mContext, pi.packageName)).append("\n");
|
||||
sb.append("\n");
|
||||
|
||||
getPackageInfo = true;
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e(TAG, "an error occured when collect package info", e);
|
||||
}
|
||||
if (!getPackageInfo) {
|
||||
|
||||
sb.append("======== PackageInfo ========\n");
|
||||
sb.append("Can't get package information\n");
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
// Runtime
|
||||
sb.append("======== Runtime ========\n");
|
||||
sb.append("Source=").append(EhClient.getUrlHeader()).append("\n");
|
||||
sb.append("\n");
|
||||
|
||||
// Device info
|
||||
sb.append("======== DeviceInfo ========\n");
|
||||
sb.append("BOARD=").append(Build.BOARD).append("\n");
|
||||
sb.append("BOOTLOADER=").append(Build.BOOTLOADER).append("\n");
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
|
||||
public final class PackageUtils {
|
||||
|
||||
private static final String TAG = PackageUtils.class.getSimpleName();
|
||||
|
||||
public static String getSignature(Context context, String packageName) {
|
||||
try {
|
||||
PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
|
||||
Signature[] ss = pi.signatures;
|
||||
if (ss != null && ss.length >= 1) {
|
||||
return Utils.computeSHA1(ss[1].toByteArray());
|
||||
} else {
|
||||
Log.e(TAG, "Can't find signature in package " + packageName);
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Can't find package " + packageName, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -45,6 +28,25 @@ import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.hippo.ehviewer.AppHandler;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class Utils {
|
||||
@SuppressWarnings("unused")
|
||||
private static String TAG = Utils.class.getSimpleName();
|
||||
@@ -760,4 +762,34 @@ public final class Utils {
|
||||
container[1] = filename.substring(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return looks like A1:43:6B:34... or null
|
||||
*/
|
||||
public static String computeSHA1(final byte[] certRaw) {
|
||||
StringBuilder sb = new StringBuilder(59);
|
||||
MessageDigest md;
|
||||
try {
|
||||
md = MessageDigest.getInstance("SHA1");
|
||||
byte[] sha1 = md.digest(certRaw);
|
||||
int length = sha1.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (i != 0) {
|
||||
sb.append(':');
|
||||
}
|
||||
byte b = sha1[i];
|
||||
String appendStr = Integer.toString(b & 0xff, 16);
|
||||
if (appendStr.length() == 1) {
|
||||
sb.append(0);
|
||||
}
|
||||
sb.append(appendStr);
|
||||
}
|
||||
|
||||
return sb.toString().toUpperCase();
|
||||
}
|
||||
catch (NoSuchAlgorithmException ex) {
|
||||
Log.e(TAG, "Can't final Algorithm SHA1", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user