List of usage examples for android.content.pm PackageManager GET_SIGNATURES
int GET_SIGNATURES
To view the source code for android.content.pm PackageManager GET_SIGNATURES.
Click Source Link
From source file:com.aptoide.amethyst.AppViewActivity.java
@Nullable private static PackageInfo getPackageInfo(Context context, String packageName) { try {//from w w w. j a va2 s.com return context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException e) { return null; } }
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mUser = new UserHandle(savedInstanceState.getInt(EXTRA_USER_ID)); } else {/*from w w w .ja v a2s. co m*/ Bundle args = getArguments(); if (args != null) { if (args.containsKey(EXTRA_USER_ID)) { mUser = new UserHandle(args.getInt(EXTRA_USER_ID)); } mNewUser = args.getBoolean(EXTRA_NEW_USER, false); } } if (mUser == null) { mUser = android.os.Process.myUserHandle(); } mHelper = new AppRestrictionsHelper(getContext(), mUser); mHelper.setLeanback(true); mPackageManager = getActivity().getPackageManager(); mIPm = AppGlobals.getPackageManager(); mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); mRestrictedProfile = mUserManager.getUserInfo(mUser.getIdentifier()).isRestricted(); try { mSysPackageInfo = mPackageManager.getPackageInfo("android", PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException nnfe) { Log.e(TAG, "Could not find system package signatures", nnfe); } mAppList = getAppPreferenceGroup(); mAppList.setOrderingAsAdded(false); }
From source file:com.letsgood.sampleapp.SignInActivity.java
private void printFacebookKeyHash() { // Add code to print out the key hash try {/*from w w w. ja v a2 s. c o m*/ PackageInfo info = getPackageManager().getPackageInfo("com.letsgood.sampleapp", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java
public static String shaSignature(String pkg, Context context) { String TAG = "Utils:createSha"; String hashString = ""; PackageManager pm = context.getPackageManager(); try {// w w w . j a va 2s . c o m PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES); Signature[] sigs = info.signatures; for (int i = 0; i < sigs.length; i++) { hashString = hashString + sigs[i].toCharsString(); } Log.i(TAG, "pkg " + pkg); Log.i(TAG, "hashString " + hashString); if (hashString == "") { return hashString; } return makeShaSignature(hashString); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.truebanana.app.AppUtils.java
/** * Since Android apps usually just have one signature, this convenience method returns the key * hash of the first signature of the app with the specified package name which may be needed * when integrating with 3rd party services such as Facebook. * * @param context/*from w ww.ja v a 2 s. c o m*/ * @param packageName The package name of the app * @return The key hash */ public static String getKeyHash(Context context, String packageName) { try { PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); MessageDigest md = MessageDigest.getInstance("SHA"); md.update(info.signatures[0].toByteArray()); return Base64.encodeToString(md.digest(), Base64.DEFAULT); } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return null; }
From source file:com.yeldi.yeldibazaar.AppDetails.java
private boolean reset() { Log.d("FDroid", "Getting application details for " + appid); app = null;//from w w w.j a v a2s. c o m List<DB.App> apps = ((FDroidApp) getApplication()).getApps(); for (DB.App tapp : apps) { if (tapp.id.equals(appid)) { app = tapp; break; } } if (app == null) { Toast toast = Toast.makeText(this, getString(R.string.no_such_app), Toast.LENGTH_LONG); toast.show(); finish(); return false; } // Make sure the app is populated. try { DB db = DB.getDB(); db.populateDetails(app, 0); } catch (Exception ex) { Log.d("FDroid", "Failed to populate app - " + ex.getMessage()); } finally { DB.releaseDB(); } DB.Apk curver = app.getCurrentVersion(); app_currentvercode = curver == null ? 0 : curver.vercode; // Get the signature of the installed package... mInstalledSignature = null; mInstalledSigID = null; if (app.installedVersion != null) { PackageManager pm = getBaseContext().getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(appid, PackageManager.GET_SIGNATURES); mInstalledSignature = pi.signatures[0]; Hasher hash = new Hasher("MD5", mInstalledSignature.toCharsString().getBytes()); mInstalledSigID = hash.getHash(); } catch (NameNotFoundException e) { Log.d("FDroid", "Failed to get installed signature"); } catch (NoSuchAlgorithmException e) { Log.d("FDroid", "Failed to calculate signature MD5 sum"); mInstalledSignature = null; } } return true; }
From source file:org.mozilla.gecko.GeckoApp.java
String[] getPluginDirectories() { // we don't support Honeycomb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT < 14 /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ ) return new String[0]; Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - start of getPluginDirectories"); ArrayList<String> directories = new ArrayList<String>(); PackageManager pm = mAppContext.getPackageManager(); List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(PLUGIN_ACTION), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA); synchronized (mPackageInfoCache) { // clear the list of existing packageInfo objects mPackageInfoCache.clear();//from w ww.j a va2 s. c om for (ResolveInfo info : plugins) { // retrieve the plugin's service information ServiceInfo serviceInfo = info.serviceInfo; if (serviceInfo == null) { Log.w(LOGTAG, "Ignore bad plugin"); continue; } // Blacklist HTC's flash lite. // See bug #704516 - We're not quite sure what Flash Lite does, // but loading it causes Flash to give errors and fail to draw. if (serviceInfo.packageName.equals("com.htc.flashliteplugin")) { Log.w(LOGTAG, "Skipping HTC's flash lite plugin"); continue; } Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName); // retrieve information from the plugin's manifest PackageInfo pkgInfo; try { pkgInfo = pm.getPackageInfo(serviceInfo.packageName, PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES); } catch (Exception e) { Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } if (pkgInfo == null) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Could not load package information."); continue; } /* * find the location of the plugin's shared library. The default * is to assume the app is either a user installed app or an * updated system app. In both of these cases the library is * stored in the app's data directory. */ String directory = pkgInfo.applicationInfo.dataDir + "/lib"; final int appFlags = pkgInfo.applicationInfo.flags; final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; // preloaded system app with no user updates if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) { directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName; } // check if the plugin has the required permissions String permissions[] = pkgInfo.requestedPermissions; if (permissions == null) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission."); continue; } boolean permissionOk = false; for (String permit : permissions) { if (PLUGIN_PERMISSION.equals(permit)) { permissionOk = true; break; } } if (!permissionOk) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2)."); continue; } // check to ensure the plugin is properly signed Signature signatures[] = pkgInfo.signatures; if (signatures == null) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed."); continue; } // determine the type of plugin from the manifest if (serviceInfo.metaData == null) { Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined"); continue; } String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE); if (!TYPE_NATIVE.equals(pluginType)) { Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType); continue; } try { Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name); //TODO implement any requirements of the plugin class here! boolean classFound = true; if (!classFound) { Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class."); continue; } } catch (NameNotFoundException e) { Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } catch (ClassNotFoundException e) { Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name); continue; } // if all checks have passed then make the plugin available mPackageInfoCache.add(pkgInfo); directories.add(directory); } } String[] result = directories.toArray(new String[directories.size()]); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - end of getPluginDirectories"); return result; }
From source file:com.game.simple.Game3.java
private void printKeyHash() { // Add code to print out the key hash try {/*w w w . j a va2s .co m*/ PackageInfo info = getPackageManager().getPackageInfo("com.game.simple", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { Log.d("KeyHash:", e.toString()); } catch (NoSuchAlgorithmException e) { Log.d("KeyHash:", e.toString()); } }
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 a v a2s. c o m * @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.facebook.unity.FB.java
/** * Provides the key hash to solve the openSSL issue with Amazon * @return key hash/*from ww w . j a v a2s . c om*/ */ @TargetApi(Build.VERSION_CODES.FROYO) public static String getKeyHash() { try { // In some cases the unity activity may not exist. This can happen when we are // completing a login and unity activity was killed in the background. In this // situation it's not necessary to send back the keyhash since the app will overwrite // the value with the value they get during the init call and the unity activity // wil be created by the time init is called. Activity activity = getUnityActivity(); if (activity == null) { return ""; } PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d(TAG, "KeyHash: " + keyHash); return keyHash; } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return ""; }