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;
}
Aggregations