Check signature

pull/145/head
M66B 6 years ago
parent 2b5ae57b06
commit b01cf117c3

@ -368,7 +368,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
sb.append(context.getString(R.string.title_crash_info_remark) + "\n\n\n\n");
sb.append(String.format("%s: %s\r\n", context.getString(R.string.app_name), BuildConfig.VERSION_NAME));
sb.append(String.format("%s: %s %s/%s\r\n",
context.getString(R.string.app_name),
BuildConfig.APPLICATION_ID,
BuildConfig.VERSION_NAME,
Helper.hasValidFingerprint(context) ? "1" : "3"));
sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
sb.append("\r\n");

@ -88,7 +88,11 @@ public class FragmentAbout extends FragmentEx {
sb.append(context.getString(R.string.title_debug_info_remark) + "\n\n\n\n");
// Get version info
sb.append(String.format("%s: %s\r\n", context.getString(R.string.app_name), BuildConfig.VERSION_NAME));
sb.append(String.format("%s: %s %s/%s\r\n",
context.getString(R.string.app_name),
BuildConfig.APPLICATION_ID,
BuildConfig.VERSION_NAME,
Helper.hasValidFingerprint(context) ? "1" : "3"));
sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT));
sb.append("\r\n");
@ -250,8 +254,8 @@ public class FragmentAbout extends FragmentEx {
});
boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
btnLog.setVisibility(debug ? View.VISIBLE : View.GONE);
btnDebugInfo.setVisibility(debug ? View.VISIBLE : View.GONE);
btnLog.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
btnDebugInfo.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
return view;
}

@ -23,6 +23,8 @@ import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.net.Uri;
import android.preference.PreferenceManager;
@ -328,6 +330,30 @@ public class Helper {
}
}
public static String getFingerprint(Context context) {
try {
PackageManager pm = context.getPackageManager();
String pkg = context.getPackageName();
PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
byte[] cert = info.signatures[0].toByteArray();
MessageDigest digest = MessageDigest.getInstance("SHA1");
byte[] bytes = digest.digest(cert);
StringBuilder sb = new StringBuilder();
for (byte b : bytes)
sb.append(Integer.toString(b & 0xff, 16).toUpperCase());
return sb.toString();
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
return null;
}
}
public static boolean hasValidFingerprint(Context context) {
String signed = getFingerprint(context);
String expected = context.getString(R.string.fingerprint);
return (signed != null && signed.equals(expected));
}
static boolean isPro(Context context) {
if (false && BuildConfig.DEBUG)
return true;

@ -302,4 +302,6 @@
<item>@color/grey</item>
<item>@color/dark_grey</item>
</array>
<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>
</resources>

Loading…
Cancel
Save