forked from ostrya/PresencePublisher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
112 additions
and
68 deletions.
There are no files selected for viewing
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
12 changes: 0 additions & 12 deletions
12
app/src/main/java/org/ostrya/presencepublisher/ui/preference/about/AppIdPreferenceDummy.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
.../main/java/org/ostrya/presencepublisher/ui/preference/about/BuildTypePreferenceDummy.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
.../main/java/org/ostrya/presencepublisher/ui/preference/about/SignaturePreferenceDummy.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.ostrya.presencepublisher.ui.preference.about; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.Signature; | ||
import android.os.Build; | ||
import com.hypertrack.hyperlog.HyperLog; | ||
import org.ostrya.presencepublisher.R; | ||
import org.ostrya.presencepublisher.ui.preference.common.StringDummy; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
|
||
public class SignaturePreferenceDummy extends StringDummy { | ||
private static final String TAG = "SignaturePreferenceDummy"; | ||
|
||
public SignaturePreferenceDummy(Context context) { | ||
super(context, R.string.signature_title, getSignatures(context)); | ||
} | ||
|
||
private static String getSignatures(Context context) { | ||
try { | ||
Signature[] signatures; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES); | ||
if (info.signingInfo == null) { | ||
signatures = null; | ||
} else if (info.signingInfo.hasMultipleSigners()) { | ||
signatures = info.signingInfo.getApkContentsSigners(); | ||
} else { | ||
signatures = info.signingInfo.getSigningCertificateHistory(); | ||
} | ||
} else { | ||
signatures = getLegacySignatures(context); | ||
} | ||
if (signatures == null) { | ||
HyperLog.i(TAG, "No signing info found"); | ||
return context.getString(R.string.value_undefined); | ||
} | ||
boolean moreThanOne = false; | ||
StringBuilder sb = new StringBuilder(); | ||
for (Signature s : signatures) { | ||
if (moreThanOne) { | ||
sb.append("\n"); | ||
} else { | ||
moreThanOne = true; | ||
} | ||
sb.append(signatureToString(s, context.getString(R.string.value_undefined))); | ||
} | ||
return sb.toString(); | ||
} catch (PackageManager.NameNotFoundException e) { | ||
HyperLog.w(TAG, "Unable to find this package", e); | ||
return context.getString(R.string.value_undefined); | ||
} | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@SuppressLint("PackageManagerGetSignatures") | ||
private static Signature[] getLegacySignatures(Context context) throws PackageManager.NameNotFoundException { | ||
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); | ||
return info.signatures; | ||
} | ||
|
||
private static String signatureToString(Signature signature, String defaultValue) { | ||
try { | ||
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509") | ||
.generateCertificate(new ByteArrayInputStream(signature.toByteArray())); | ||
return cert.toString(); | ||
} catch (CertificateException e) { | ||
HyperLog.w(TAG, "Unable to instantiate X.509 certificate factory", e); | ||
return defaultValue; | ||
} | ||
} | ||
} |
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
12 changes: 0 additions & 12 deletions
12
...src/main/java/org/ostrya/presencepublisher/ui/preference/about/VersionCodePreference.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...ain/java/org/ostrya/presencepublisher/ui/preference/about/VersionInfoPreferenceDummy.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.ostrya.presencepublisher.ui.preference.about; | ||
|
||
import android.content.Context; | ||
import org.ostrya.presencepublisher.BuildConfig; | ||
import org.ostrya.presencepublisher.R; | ||
import org.ostrya.presencepublisher.ui.preference.common.StringDummy; | ||
|
||
public class VersionInfoPreferenceDummy extends StringDummy { | ||
public VersionInfoPreferenceDummy(Context context) { | ||
super(context, R.string.version_title, context.getString(R.string.version_summary, BuildConfig.APPLICATION_ID, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, BuildConfig.BUILD_TYPE)); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
...src/main/java/org/ostrya/presencepublisher/ui/preference/about/VersionNamePreference.java
This file was deleted.
Oops, something went wrong.
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
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
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