Created
January 27, 2015 15:52
-
-
Save Den-Rimus/2aaecb5e8ab24d7dc0b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean checkBuildType() { | |
boolean isDebugBuild = false; | |
try { | |
Signature[] signatures = getPackageManager() | |
.getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures; | |
CertificateFactory cf = CertificateFactory.getInstance("X.509"); | |
X500Principal debugSertificateSubject = new X500Principal(DEBUG_CERTIFICATE_SUBJECT_NAME); | |
for (Signature signature : signatures) { | |
ByteArrayInputStream stream = new ByteArrayInputStream(signature.toByteArray()); | |
X509Certificate cert = (X509Certificate) cf.generateCertificate(stream); | |
isDebugBuild = cert.getSubjectX500Principal().equals(debugSertificateSubject); | |
if (isDebugBuild) | |
break; | |
} | |
} catch (PackageManager.NameNotFoundException e) { | |
Log.e("Application -> checkBuildType()", "Error while retrieving package data." + | |
"Run will be treated as of production build"); | |
} catch (CertificateException e) { | |
Log.e("Application -> checkBuildType()", "Error while retrieving package data. " + | |
"\"X.509\" certificate is not available." + | |
"Run will be treated as of production build"); | |
} | |
return isDebugBuild; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment