List of usage examples for android.content.pm Signature toCharsString
public String toCharsString()
From source file:Main.java
public static String getSignature(Context context, String pkgname) { boolean isEmpty = TextUtils.isEmpty(pkgname); if (isEmpty) { return null; } else {/*from www . j a va 2 s. c om*/ try { PackageManager manager = context.getPackageManager(); PackageInfo packageInfo = manager.getPackageInfo(pkgname, PackageManager.GET_SIGNATURES); Signature[] signatures = packageInfo.signatures; StringBuilder builder = new StringBuilder(); for (Signature signature : signatures) { builder.append(signature.toCharsString()); } String signature = builder.toString(); return signature; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } return null; }
From source file:com.easy.facebook.android.facebook.FBLoginManager.java
private boolean validateAppSignatureForIntent(Activity activity, Intent intent) { ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, 0); if (resolveInfo == null) { return false; }//from ww w . ja va2s . c o m String packageName = resolveInfo.activityInfo.packageName; PackageInfo packageInfo; try { packageInfo = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (NameNotFoundException e) { return false; } for (Signature signature : packageInfo.signatures) { if (signature.toCharsString().equals(FB_APP_SIGNATURE)) { return true; } } return false; }
From source file:cm.aptoide.com.facebook.android.Facebook.java
/** * Query the signature for the application that would be invoked by the * given intent and verify that it matches the FB application's signature. * * @param context// w ww . j av a 2s . c om * @param packageName * @return true if the app's signature matches the expected signature. */ private boolean validateAppSignatureForPackage(Context context, String packageName) { PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (NameNotFoundException e) { return false; } for (Signature signature : packageInfo.signatures) { if (signature.toCharsString().equals(FB_APP_SIGNATURE)) { return true; } } return false; }
From source file:com.landenlabs.all_devtool.PackageFragment.java
boolean addPackageInfo(PackageInfo packInfo) { if (packInfo == null) return false; String packageName = packInfo.packageName.trim(); for (PackingItem item : m_workList) { if (item.fieldStr().equals(packageName)) { return false; }// w w w . j ava 2 s.co m } ArrayListPairString pkgList = new ArrayListPairString(); String appName = packInfo.applicationInfo.loadLabel(getActivity().getPackageManager()).toString().trim(); long pkgSize = 0; addList(pkgList, "Version", packInfo.versionName); addList(pkgList, "VerCode", String.valueOf(packInfo.versionCode)); // addList(pkgList, "Directory", packInfo.applicationInfo.sourceDir); try { File file = new File(packInfo.applicationInfo.sourceDir); pkgSize = file.length(); addList(pkgList, "FileSize", NumberFormat.getNumberInstance(Locale.getDefault()).format(pkgSize)); } catch (Exception ex) { } if (!TextUtils.isEmpty(packInfo.applicationInfo.permission)) addList(pkgList, "Permission", packInfo.applicationInfo.permission); if (packInfo.applicationInfo.sharedLibraryFiles != null) addList(pkgList, "ShrLibs", packInfo.applicationInfo.sharedLibraryFiles.toString()); addList(pkgList, "TargetSDK", String.valueOf(packInfo.applicationInfo.targetSdkVersion)); m_date.setTime(packInfo.firstInstallTime); addList(pkgList, "Install First", s_timeFormat.format(m_date)); m_date.setTime(packInfo.lastUpdateTime); addList(pkgList, "Install Last", s_timeFormat.format(m_date)); if (packInfo.requestedPermissions != null) { // addList(pkgList, "RegPermissions", Arrays.toString(packInfo.requestedPermissions).replaceAll("[a-z]*", "").replaceAll(",", "\n")); addList(pkgList, m_regPermissionsStr, String.format(" #%d", packInfo.requestedPermissions.length)); if (false) { for (int pidx = 0; pidx != packInfo.requestedPermissions.length; pidx++) { String perm = packInfo.requestedPermissions[pidx].replaceAll("[a-z.]*", ""); if (perm.length() > 30) perm = perm.substring(0, 30); addList(pkgList, String.format(" %2d", pidx), perm); } } } if (packInfo.permissions != null) { addList(pkgList, m_permissionsStr, String.format(" #%d", packInfo.permissions.length)); } if (packInfo.activities != null) { addList(pkgList, m_activitiesStr, String.format(" #%d", packInfo.activities.length)); } if (packInfo.services != null) { addList(pkgList, m_servicesStr, String.format(" #%d", packInfo.services.length)); } if (Build.VERSION.SDK_INT > 21) { if (packInfo.splitNames != null && packInfo.splitNames.length != 0) { for (int splitIdx = 0; splitIdx != packInfo.splitNames.length; splitIdx++) { addList(pkgList, String.format(" SplitName%2d", splitIdx), packInfo.splitNames[splitIdx]); } } } addList(pkgList, "Apk File", packInfo.applicationInfo.publicSourceDir); StringBuilder flagStr = new StringBuilder(); if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) flagStr.append(" Debug "); if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_IS_GAME) != 0) flagStr.append(" Game "); if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) flagStr.append(" AllowBackup "); if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) flagStr.append(" System "); if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_LARGE_HEAP) != 0) flagStr.append(" LargeHeap "); if (flagStr.length() != 0) { addList(pkgList, "Flags", flagStr.toString()); } if (packInfo.signatures != null) { String signatures = ""; for (android.content.pm.Signature sig : packInfo.signatures) { signatures = signatures + " " + sig.toCharsString(); } addList(pkgList, "Signature", signatures); } if (packInfo.providers != null) { addList(pkgList, m_providers, String.valueOf(packInfo.providers.length)); if (false) { String providers = ""; for (ProviderInfo providerInfo : packInfo.providers) { providers = providers + " " + providerInfo.name; } addList(pkgList, "Providers", providers); } } m_workList.add(new PackingItem(packInfo.packageName.trim(), pkgList, packInfo, pkgSize, appName)); return true; }