AppProtocol { @Nullable public String getAppSignature(@NonNull Context context) { final PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException e) { return null; } if (packageInfo == null || packageInfo.signatures.length == 0) { return null; } final MessageDigest messageDigest; try { messageDigest = getSha1MessageDigest(); } catch (NoSuchAlgorithmException e) { return null; } messageDigest.update(packageInfo.signatures[0].toByteArray()); return Base64.encodeToString(messageDigest.digest(), Base64.NO_WRAP); }  boolean validateMinimumVersion(
            @NonNull Context context, @NonNull PackageInfo packageInfo, int minimumVersion); @Deprecated boolean isUberInstalled(@NonNull Context context); boolean isInstalled(@NonNull Context context, @NonNull SupportedAppType supportedApp); boolean isInstalled(@NonNull Context context, @NonNull SupportedAppType supportedApp, int minimumVersion); @NonNull List<PackageInfo> getInstalledPackages(
            @NonNull Context context, @NonNull SupportedAppType supportedApp, int minimumVersion); boolean isAppLinkSupported(); boolean validateSignature(@NonNull Context context, @NonNull String packageName); @Nullable String getAppSignature(@NonNull Context context); @Deprecated
    static final String[] UBER_PACKAGE_NAMES; static final String PLATFORM; }
@Test public void getApplicationSignature_whenValidPackageSignature_shouldSucceed() { stubAppSignature(GOOD_SIGNATURE); assertThat(appProtocol.getAppSignature(activity)).isEqualTo(GOOD_HASH); }
@Test public void getPackageSignature_whenNameNotFoundException_shouldReturnNull() throws Exception { stubAppSignature(GOOD_SIGNATURE); final Throwable throwable = new PackageManager.NameNotFoundException(); doThrow(throwable).when(packageManager) .getPackageInfo(AppProtocol.RIDER_PACKAGE_NAMES[0], PackageManager.GET_SIGNATURES); assertThat(appProtocol.getAppSignature(activity)).isNull(); }
@Test public void getPackageSignature_whenNullPackageInfo_shouldReturnNull() throws Exception { stubAppSignature(GOOD_SIGNATURE); when(packageManager.getPackageInfo(AppProtocol.RIDER_PACKAGE_NAMES[0], PackageManager.GET_SIGNATURES)) .thenReturn(null); assertThat(appProtocol.getAppSignature(activity)).isNull(); }
@Test public void getPackageSignature_whenEmptyPackageInfo_shouldReturnNull() { stubAppSignature(GOOD_SIGNATURE); packageInfo.signatures = new Signature[]{}; assertThat(appProtocol.getAppSignature(activity)).isNull(); }