Search in sources :

Example 96 with Signature

use of android.content.pm.Signature in project dropbox-sdk-java by dropbox.

the class DbxOfficialAppConnector method getDropboxAppPackage.

/**
     * Verify that intent will be processed by Dropbox App
     *
     * @return PackageInfo of DropboxApp if Dropbox App can process intent, else null
     */
static PackageInfo getDropboxAppPackage(Context context, Intent intent) {
    PackageManager manager = context.getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
    if (null == infos || 1 != infos.size()) {
        // is available, or multiple activities are confusing us.
        return null;
    } else {
        // The official app exists. Make sure it's the correct one by
        // checking signing keys.
        ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
        if (resolveInfo == null) {
            return null;
        }
        final PackageInfo packageInfo;
        try {
            packageInfo = manager.getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_SIGNATURES);
        } catch (NameNotFoundException e) {
            return null;
        }
        for (Signature signature : packageInfo.signatures) {
            for (String dbSignature : DROPBOX_APP_SIGNATURES) {
                if (dbSignature.equals(signature.toCharsString())) {
                    return packageInfo;
                }
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature)

Aggregations

Signature (android.content.pm.Signature)96 PackageManager (android.content.pm.PackageManager)33 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)30 PackageInfo (android.content.pm.PackageInfo)25 ArrayList (java.util.ArrayList)16 MessageDigest (java.security.MessageDigest)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 ArraySet (android.util.ArraySet)11 IOException (java.io.IOException)8 PublicKey (java.security.PublicKey)8 File (java.io.File)7 Intent (android.content.Intent)6 HashSet (java.util.HashSet)6 ResolveInfo (android.content.pm.ResolveInfo)5 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)5 NetworkPolicyManagerService (com.android.server.net.NetworkPolicyManagerService)5 IActivityManager (android.app.IActivityManager)4 INotificationManager (android.app.INotificationManager)4 IProcessObserver (android.app.IProcessObserver)4 PackageParser (android.content.pm.PackageParser)4