List of usage examples for android.content.pm PackageManager checkSignatures
@CheckResult public abstract @SignatureResult int checkSignatures(int uid1, int uid2);
From source file:Main.java
public static boolean elitePresent(Context context, boolean versionCheck, int minVersion) { PackageManager pm = context.getPackageManager(); int sigs = pm.checkSignatures("com.noshufou.android.su", "com.noshufou.android.su.elite"); if (sigs != PackageManager.SIGNATURE_MATCH) { return false; } else {//from www. ja v a 2s. co m if (versionCheck) { PackageInfo pi; try { pi = pm.getPackageInfo("com.noshufou.android.su.elite", 0); if (pi.versionCode >= minVersion) { return true; } else { return false; } } catch (NameNotFoundException e) { return false; } } else { return true; } } }
From source file:Main.java
public static boolean canBeStarted(Context context, Intent intent, boolean checkSignature) { final PackageManager manager = context.getApplicationContext().getPackageManager(); final ResolveInfo info = manager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info == null) { return false; }/*from w w w .j a v a 2 s. c om*/ final ActivityInfo activityInfo = info.activityInfo; if (activityInfo == null) { return false; } if (!checkSignature) { return true; } return PackageManager.SIGNATURE_MATCH == manager.checkSignatures(context.getPackageName(), activityInfo.packageName); }
From source file:de.ub0r.android.lib.DonationHelper.java
/** * Check if ads should be hidden./*from w ww . j a v a2 s .co m*/ * * @param context * {@link Context} * @return true if ads should be hidden */ public static boolean hideAds(final Context context) { PackageManager pm = context.getPackageManager(); Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK); ResolveInfo ri = pm.resolveService(donationCheck, 0); // Log.d(TAG, "ri: " + ri); int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE; if (ri != null) { Log.d(TAG, "found package: " + ri.serviceInfo.packageName); ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); // Log.d(TAG, "component name: " + cn); int i = pm.getComponentEnabledSetting(cn); // Log.d(TAG, "component status: " + i); // Log.d(TAG, "package status: " + ri.serviceInfo.enabled); if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) { match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName); } else { Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled); } } Log.i(TAG, "signature match: " + match); if (match != PackageManager.SIGNATURE_UNKNOWN_PACKAGE) { if (Math.random() < CHECK_DONATOR_LIC) { // verify donator license ComponentName cn = context.startService(donationCheck); Log.d(TAG, "Started service: " + cn); if (cn == null) { return false; } } return match == PackageManager.SIGNATURE_MATCH; } pm = null; // no donator app installed, check donation traditionally // do not drop legacy donators boolean ret = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_HIDEADS, false); Log.d(TAG, "legacy donation check: " + ret); return ret; }
From source file:com.farmerbb.taskbar.MainActivity.java
private boolean freeVersionInstalled() { PackageManager pm = getPackageManager(); try {/* ww w .j a v a 2s . c o m*/ PackageInfo pInfo = pm.getPackageInfo(BuildConfig.BASE_APPLICATION_ID, 0); return pInfo.versionCode >= 68 && pm.checkSignatures(BuildConfig.BASE_APPLICATION_ID, BuildConfig.APPLICATION_ID) == PackageManager.SIGNATURE_MATCH; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:net.bluecarrot.lite.MainActivity.java
protected boolean isProInstalled(Context context) { // the packagename of the 'key' app String proPackage = "it.rignanese.leo.donationkey1"; // get the package manager final PackageManager pm = context.getPackageManager(); // get a list of installed packages List<PackageInfo> list = pm.getInstalledPackages(PackageManager.GET_DISABLED_COMPONENTS); // let's iterate through the list Iterator<PackageInfo> i = list.iterator(); while (i.hasNext()) { PackageInfo p = i.next();/*w w w.j a v a2 s . c om*/ // check if proPackage is in the list AND whether that package is signed // with the same signature as THIS package if ((p.packageName.equals(proPackage)) && (pm.checkSignatures(context.getPackageName(), p.packageName) == PackageManager.SIGNATURE_MATCH)) return true; } return false; }
From source file:ro.ciubex.keepscreenlock.MainApplication.java
/** * Check for pro version.//from w ww . ja v a 2 s .c om * * @return True if pro version exist. */ public boolean isProPresent() { PackageManager pm = getPackageManager(); boolean success = false; try { success = (PackageManager.SIGNATURE_MATCH == pm.checkSignatures(this.getPackageName(), "ro.ciubex.keepscreenlockpro")); logD(TAG, "isProPresent: " + success); } catch (Exception e) { logE(TAG, "isProPresent: " + e.getMessage(), e); } return success; }
From source file:com.androzic.Androzic.java
public void onCreateEx() { try {/*from w w w . java2s . c om*/ (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER)).mkdirs(); (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER + "/ghiam")).mkdirs(); } catch (Throwable e) { } if (initialized) return; AndroidGraphicFactory.createInstance(this); try { OzfDecoder.useNativeCalls(); } catch (UnsatisfiedLinkError e) { Toast.makeText(Androzic.this, "Failed to initialize native library: " + e.getMessage(), Toast.LENGTH_LONG).show(); } Resources resources = getResources(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); Configuration config = resources.getConfiguration(); renderingThread = new HandlerThread("RenderingThread"); renderingThread.start(); longOperationsThread = new HandlerThread("LongOperationsThread"); longOperationsThread.setPriority(Thread.MIN_PRIORITY); longOperationsThread.start(); uiHandler = new Handler(); mapsHandler = new Handler(longOperationsThread.getLooper()); // We silently initialize data uri to let location service restart after crash File datadir = new File( settings.getString(getString(R.string.pref_folder_data), Environment.getExternalStorageDirectory() + File.separator + resources.getString(R.string.def_folder_data))); setDataPath(Androzic.PATH_DATA, datadir.getAbsolutePath()); setInstance(this); String intentToCheck = "com.androzic.donate"; String myPackageName = getPackageName(); PackageManager pm = getPackageManager(); PackageInfo pi; try { pi = pm.getPackageInfo(intentToCheck, 0); isPaid = (pm.checkSignatures(myPackageName, pi.packageName) == PackageManager.SIGNATURE_MATCH); } catch (NameNotFoundException e) { // e.printStackTrace(); } File sdcard = Environment.getExternalStorageDirectory(); Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this, sdcard.getAbsolutePath())); DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); if (wm != null) { wm.getDefaultDisplay().getMetrics(displayMetrics); } else { displayMetrics.setTo(resources.getDisplayMetrics()); } BaseMap.viewportWidth = displayMetrics.widthPixels; BaseMap.viewportHeight = displayMetrics.heightPixels; charset = settings.getString(getString(R.string.pref_charset), "UTF-8"); String lang = settings.getString(getString(R.string.pref_locale), ""); if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) { locale = new Locale(lang); Locale.setDefault(locale); config.locale = locale; resources.updateConfiguration(config, resources.getDisplayMetrics()); } magInterval = resources.getInteger(R.integer.def_maginterval) * 1000; overlayManager = new OverlayManager(longOperationsThread.getLooper()); TooltipManager.initialize(this); onSharedPreferenceChanged(settings, getString(R.string.pref_unitcoordinate)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitdistance)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitspeed)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitelevation)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitangle)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitanglemagnetic)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision)); onSharedPreferenceChanged(settings, getString(R.string.pref_unitsunrise)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent)); onSharedPreferenceChanged(settings, getString(R.string.pref_vectormap_textscale)); onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapprescalefactor)); onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapexpiration)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder)); onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder)); onSharedPreferenceChanged(settings, getString(R.string.pref_showwaypoints)); onSharedPreferenceChanged(settings, getString(R.string.pref_showcurrenttrack)); onSharedPreferenceChanged(settings, getString(R.string.pref_showaccuracy)); onSharedPreferenceChanged(settings, getString(R.string.pref_showdistance_int)); settings.registerOnSharedPreferenceChangeListener(this); initialized = true; }