Java Code Examples for android.content.pm.PackageManager#getInstallerPackageName()
The following examples show how to use
android.content.pm.PackageManager#getInstallerPackageName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutdatedReminder.java From deltachat-android with GNU General Public License v3.0 | 8 votes |
public static boolean isEligible(Context context) { if (context == null) { return false; } try { final PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); if (packageManager.getInstallerPackageName(packageName) == null) { long lastUpdateTime = packageManager .getPackageInfo(packageName, 0) .lastUpdateTime; long nowTime = System.currentTimeMillis(); long diff = nowTime - lastUpdateTime; long diffInDays = TimeUnit.MILLISECONDS.toDays(diff); return diffInDays >= OUTDATED_THRESHOLD_IN_DAYS; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example 2
Source File: RSVTestCase.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testAppStorePackages(){ assertTrue(TrustedAppStore.isTrustedStore(TrustedAppStore.PLAY_STORE.packageString)); assertTrue(TrustedAppStore.isTrustedStore("com.xiaomi.market")); assertFalse(TrustedAppStore.isTrustedStore("test")); assertFalse(TrustedAppStore.isTrustedStore(null)); rsvp = new RouterServiceValidator(this.mContext); rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK); rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH); PackageManager packageManager = mContext.getPackageManager(); List<PackageInfo> packages = packageManager.getInstalledPackages(0); String appStore; for(PackageInfo info: packages){ appStore = packageManager.getInstallerPackageName(info.packageName); if(TrustedAppStore.isTrustedStore(appStore)){ assertTrue(rsvp.wasInstalledByAppStore(info.packageName)); } } assertFalse(rsvp.wasInstalledByAppStore(null)); }
Example 3
Source File: ReportHandler.java From android-crash-reporting with MIT License | 6 votes |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static void showDefaultReportActivity(Context context, Throwable th) { String packageName = context.getPackageName(); PackageManager pm = context.getPackageManager(); // Not perfect.. but it'll have to do. ApplicationErrorReport report = new ApplicationErrorReport(); report.installerPackageName = pm.getInstallerPackageName(packageName); report.packageName = packageName; report.processName = packageName; report.time = System.currentTimeMillis(); report.systemApp = false; report.type = ApplicationErrorReport.TYPE_CRASH; report.crashInfo = new ApplicationErrorReport.CrashInfo(th); sAppContext.startActivity(new Intent(Intent.ACTION_APP_ERROR) .setPackage("com.google.android.feedback") .putExtra(Intent.EXTRA_BUG_REPORT, report) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); }
Example 4
Source File: ComputeAppListTask.java From exodus-android-app with GNU General Public License v3.0 | 6 votes |
private void applyStoreFilter(List<PackageInfo> packageInfos, DatabaseManager databaseManager, PackageManager packageManager) { List<PackageInfo> toRemove = new ArrayList<>(); for (PackageInfo packageInfo : packageInfos) { String packageName = packageInfo.packageName; String installerPackageName = packageManager.getInstallerPackageName(packageName); if (!gStore.equals(installerPackageName)) { String auid = Utils.getCertificateSHA1Fingerprint(packageManager, packageName); String appuid = databaseManager.getAUID(packageName); if(!auid.equalsIgnoreCase(appuid)) { toRemove.add(packageInfo); } } try { ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName,0); if(!appInfo.enabled) { toRemove.add(packageInfo); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } packageInfos.removeAll(toRemove); }
Example 5
Source File: UserRegisterResponse.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
@Override public void handler() { super.handler(); ProtoUserRegister.UserRegisterResponse.Builder builder = (ProtoUserRegister.UserRegisterResponse.Builder) message; if (G.onUserRegistration != null) G.onUserRegistration.onRegister(builder.getUsername(), builder.getUserId(), builder.getMethod(), builder.getSmsNumberList(), builder.getVerifyCodeRegex(), builder.getVerifyCodeDigitCount(), builder.getAuthorHash(), builder.getCallMethodSupported()); G.userId = builder.getUserId(); G.authorHash = builder.getAuthorHash(); G.displayName = builder.getUsername(); PackageManager pm = G.context.getPackageManager(); String installationSource = pm.getInstallerPackageName(G.context.getPackageName()); if (installationSource == null) { installationSource = "(Unknown Market)"; } Crashlytics.logException(new Exception("installationSource : " + installationSource)); }
Example 6
Source File: Package.java From batteryhub with Apache License 2.0 | 5 votes |
/** * Returns a list of installed packages on the device. Will be called for * the first GreenHub sample on a phone, to get signatures for the malware * detection project. Later on, single package information is got by * receiving the package installed intent. * * @param context The Context * @param filterSystem if true, exclude system packages. * @return a list of installed packages on the device. */ public static Map<String, ProcessInfo> getInstalledPackages(Context context, boolean filterSystem) { Map<String, PackageInfo> packageMap = getPackages(context, true); PackageManager pm = context.getPackageManager(); if (pm == null) return null; Map<String, ProcessInfo> result = new HashMap<>(); for (Map.Entry<String, PackageInfo> entry : packageMap.entrySet()) { try { String pkg = entry.getKey(); PackageInfo pak = entry.getValue(); if (pak != null) { int vc = pak.versionCode; ApplicationInfo appInfo = pak.applicationInfo; String label = pm.getApplicationLabel(appInfo).toString(); // we need application UID to be able to use Android's // TrafficStat API // in order to get the traffic info of a particular app: int appUid = appInfo.uid; // get the amount of transmitted and received bytes by an // app // TODO: disabled for debugging // TrafficRecord trafficRecord = getAppTraffic(appUid); int flags = pak.applicationInfo.flags; // Check if it is a system app boolean isSystemApp = (flags & ApplicationInfo.FLAG_SYSTEM) > 0; isSystemApp = isSystemApp || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) > 0; if (filterSystem & isSystemApp) continue; if (pak.signatures.length > 0) { ProcessInfo pi = new ProcessInfo(); pi.name = pkg; pi.applicationLabel = label; pi.versionCode = vc; pi.processId = -1; pi.isSystemApp = isSystemApp; pi.appSignatures.addAll(Signatures.getSignatureList(pak)); pi.importance = Config.IMPORTANCE_NOT_RUNNING; pi.installationPkg = pm.getInstallerPackageName(pkg); pi.versionName = pak.versionName; // pi.setTrafficRecord(trafficRecord); result.put(pkg, pi); } } } catch (Throwable th) { // Forget about it... } } return result; }
Example 7
Source File: Util.java From XPrivacy with GNU General Public License v3.0 | 5 votes |
public static boolean hasMarketLink(Context context, String packageName) { try { PackageManager pm = context.getPackageManager(); String installer = pm.getInstallerPackageName(packageName); if (installer != null) return installer.equals("com.android.vending") || installer.contains("google"); } catch (Exception ex) { log(null, Log.WARN, ex.toString()); } return false; }
Example 8
Source File: Utils.java From Noyze with Apache License 2.0 | 5 votes |
/** @return The {@link me.barrasso.android.volume.utils.Utils.Installer} of this application. */ public static Installer getInstaller(Context context) { if (("amazon").equals(Build.MANUFACTURER.toLowerCase(Locale.US))) return Installer.AMAZON; PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); String installerPackageName = packageManager.getInstallerPackageName(packageName); if (!TextUtils.isEmpty(installerPackageName)) for (Installer installer : Installer.values()) if (installerPackageName.equals(installer.getPackageName())) return installer; return Installer.UNKNOWN; }
Example 9
Source File: Package.java From batteryhub with Apache License 2.0 | 5 votes |
/** * Returns info about an installed package. Will be called when receiving * the PACKAGE_ADDED or PACKAGE_REPLACED intent. * * @param context the Context. * @return a list of installed packages on the device. */ public static ProcessInfo getInstalledPackage(Context context, String pkg) { PackageManager pm = context.getPackageManager(); if (pm == null) return null; PackageInfo pak; try { pak = pm.getPackageInfo( pkg, PackageManager.GET_SIGNATURES | PackageManager.GET_PERMISSIONS ); } catch (PackageManager.NameNotFoundException e) { return null; } if (pak == null) return null; ProcessInfo pi = new ProcessInfo(); int vc = pak.versionCode; ApplicationInfo info = pak.applicationInfo; String label = pm.getApplicationLabel(info).toString(); int flags = pak.applicationInfo.flags; // Check if it is a system app boolean isSystemApp = (flags & ApplicationInfo.FLAG_SYSTEM) > 0; isSystemApp = isSystemApp || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) > 0; if (pak.signatures.length > 0) { pi.name = pkg; pi.applicationLabel = label; pi.versionCode = vc; pi.processId = -1; pi.isSystemApp = isSystemApp; pi.appSignatures.addAll(Signatures.getSignatureList(pak)); pi.importance = Config.IMPORTANCE_NOT_RUNNING; pi.installationPkg = pm.getInstallerPackageName(pkg); pi.versionName = pak.versionName; } return pi; }
Example 10
Source File: DeviceHelper.java From candybar with Apache License 2.0 | 5 votes |
@NonNull public static String getDeviceInfo(@NonNull Context context) { DisplayMetrics displaymetrics = context.getResources().getDisplayMetrics(); StringBuilder sb = new StringBuilder(); final int height = displaymetrics.heightPixels; final int width = displaymetrics.widthPixels; PackageManager pm = context.getPackageManager(); String installerPackage = pm.getInstallerPackageName(context.getPackageName()); String appVersion = ""; try { appVersion = context.getPackageManager().getPackageInfo( context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException ignored) { } if (installerPackage == null || !installerPackage.contentEquals("com.android.vending")) { appVersion = context.getResources().getString(R.string.version_outside_playstore).replace("{{appVersion}}", appVersion); } else { appVersion = context.getResources().getString(R.string.version_from_playstore).replace("{{appVersion}}", appVersion); } sb.append("Manufacturer : ").append(Build.MANUFACTURER) .append("\nModel : ").append(Build.MODEL) .append("\nProduct : ").append(Build.PRODUCT) .append("\nScreen Resolution : ") .append(width).append(" x ").append(height).append(" pixels") .append("\nAndroid Version : ").append(Build.VERSION.RELEASE) .append("\nApp Version : ").append(appVersion) .append("\nCandyBar Version : ").append(BuildConfig.VERSION_NAME) .append("\n"); return sb.toString(); }
Example 11
Source File: AttributionIdentifiers.java From kognitivo with Apache License 2.0 | 5 votes |
@Nullable private static String getInstallerPackageName(Context context) { PackageManager packageManager = context.getPackageManager(); if (packageManager != null) { return packageManager.getInstallerPackageName(context.getPackageName()); } return null; }
Example 12
Source File: ComputeAppListTask.java From exodus-android-app with GNU General Public License v3.0 | 5 votes |
private ApplicationViewModel buildViewModelFromPackageInfo(PackageInfo pi, DatabaseManager databaseManager, PackageManager packageManager) { ApplicationViewModel vm = new ApplicationViewModel(); vm.versionName = pi.versionName; vm.packageName = pi.packageName; vm.versionCode = pi.versionCode; vm.requestedPermissions = pi.requestedPermissions; if (vm.versionName != null) vm.report = databaseManager.getReportFor(vm.packageName, vm.versionName); else { vm.report = databaseManager.getReportFor(vm.packageName, vm.versionCode); } if (vm.report != null) { vm.trackers = databaseManager.getTrackers(vm.report.trackers); } try { vm.icon = packageManager.getApplicationIcon(vm.packageName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } vm.label = packageManager.getApplicationLabel(pi.applicationInfo); vm.installerPackageName = packageManager.getInstallerPackageName(vm.packageName); vm.isVisible = true; return vm; }
Example 13
Source File: InstallerPackageNameProvider.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
private static String loadInstallerPackageName(Context appContext) { final PackageManager pm = appContext.getPackageManager(); final String hostAppPackageName = appContext.getPackageName(); final String installerPackageName = pm.getInstallerPackageName(hostAppPackageName); // The PackageManager API returns null if the value is not set, but we need a non-null // value for caching, so we return the constant instead return installerPackageName == null ? NO_INSTALLER_PACKAGE_NAME : installerPackageName; }
Example 14
Source File: Utilities.java From BlogDemo with Apache License 2.0 | 5 votes |
public static boolean hasPackageNameInstalled(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); // In theory, if the package installer does not throw an exception, package exists try { packageManager.getInstallerPackageName(packageName); return true; } catch (IllegalArgumentException exception) { exception.printStackTrace(); return false; } }
Example 15
Source File: App.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
private void setFromPackageInfo(PackageManager pm, PackageInfo packageInfo) { this.packageName = packageInfo.packageName; final String installerPackageName = pm.getInstallerPackageName(packageName); CharSequence installerPackageLabel = null; if (!TextUtils.isEmpty(installerPackageName)) { try { ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName, PackageManager.GET_META_DATA); installerPackageLabel = installerAppInfo.loadLabel(pm); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "Could not get app info: " + installerPackageName, e); } } if (TextUtils.isEmpty(installerPackageLabel)) { installerPackageLabel = installerPackageName; } ApplicationInfo appInfo = packageInfo.applicationInfo; final CharSequence appDescription = appInfo.loadDescription(pm); if (TextUtils.isEmpty(appDescription)) { this.summary = "(installed by " + installerPackageLabel + ")"; } else if (appDescription.length() > 40) { this.summary = (String) appDescription.subSequence(0, 40); } else { this.summary = (String) appDescription; } this.added = new Date(packageInfo.firstInstallTime); this.lastUpdated = new Date(packageInfo.lastUpdateTime); this.description = "<p>"; if (!TextUtils.isEmpty(appDescription)) { this.description += appDescription + "\n"; } this.description += "(installed by " + installerPackageLabel + ", first installed on " + this.added + ", last updated on " + this.lastUpdated + ")</p>"; this.name = (String) appInfo.loadLabel(pm); this.iconFromApk = getIconName(packageName, packageInfo.versionCode); this.installedVersionName = packageInfo.versionName; this.installedVersionCode = packageInfo.versionCode; this.compatible = true; }
Example 16
Source File: ApplicationErrorReport.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public static ComponentName getErrorReportReceiver(Context context, String packageName, int appFlags) { // check if error reporting is enabled in secure settings int enabled = Settings.Global.getInt(context.getContentResolver(), Settings.Global.SEND_ACTION_APP_ERROR, 0); if (enabled == 0) { return null; } PackageManager pm = context.getPackageManager(); // look for receiver in the installer package String candidate = null; ComponentName result = null; try { candidate = pm.getInstallerPackageName(packageName); } catch (IllegalArgumentException e) { // the package could already removed } if (candidate != null) { result = getErrorReportReceiver(pm, packageName, candidate); if (result != null) { return result; } } // if the error app is on the system image, look for system apps // error receiver if ((appFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { candidate = SystemProperties.get(SYSTEM_APPS_ERROR_RECEIVER_PROPERTY); result = getErrorReportReceiver(pm, packageName, candidate); if (result != null) { return result; } } // if there is a default receiver, try that candidate = SystemProperties.get(DEFAULT_ERROR_RECEIVER_PROPERTY); return getErrorReportReceiver(pm, packageName, candidate); }
Example 17
Source File: AppRater.java From TextFiction with Apache License 2.0 | 4 votes |
/** * Should be called on every <code>Activity.onCreate()</code>. Checks if the * trial period is over and if so brings up a notification dialog. * * @param ctx * The application context. */ public static void appLaunched(Context ctx) { try { // Don't even bother if not installed from Google Play PackageManager pm = ctx.getPackageManager(); String pn = ctx.getPackageName(); String inst = pm.getInstallerPackageName(pn); if (inst == null || !(inst.startsWith("com.google") || inst.startsWith("com.android"))) { return; } } catch (Exception exp) { Log.w("AppRater",exp); // Just bailout. Don't even try recovery. return; } SharedPreferences prefs = ctx.getSharedPreferences(PREFSFILE, 0); if (prefs.getBoolean("dontshowagain", false)) { return; } SharedPreferences.Editor editor = prefs.edit(); // Increment launch counter long launch_count = prefs.getLong("launch_count", 0) + 1; editor.putLong("launch_count", launch_count); // Get date of first launch Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); if (date_firstLaunch == 0) { date_firstLaunch = System.currentTimeMillis(); editor.putLong("date_firstlaunch", date_firstLaunch); } editor.commit(); // Wait at least n days before opening if (launch_count >= LAUNCHES_UNTIL_PROMPT) { if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { showRateDialog(ctx); } } }
Example 18
Source File: AppRater.java From listmyaps with Apache License 2.0 | 4 votes |
/** * Should be called on every <code>Activity.onCreate()</code>. Checks if the * trial period is over and if so brings up a notification dialog. * * @param ctx * The application context. */ public static void appLaunched(Context ctx) { try { // Don't even bother if not installed from Google Play PackageManager pm = ctx.getPackageManager(); String pn = ctx.getPackageName(); String inst = pm.getInstallerPackageName(pn); if (inst == null || !(inst.startsWith("com.google") || inst.startsWith("com.android"))) { return; } } catch (Exception exp) { Log.w("AppRater",exp); // Just bailout. Don't even try recovery. return; } SharedPreferences prefs = ctx.getSharedPreferences(PREFSFILE, 0); if (prefs.getBoolean("dontshowagain", false)) { return; } SharedPreferences.Editor editor = prefs.edit(); // Increment launch counter long launch_count = prefs.getLong("launch_count", 0) + 1; editor.putLong("launch_count", launch_count); // Get date of first launch Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); if (date_firstLaunch == 0) { date_firstLaunch = System.currentTimeMillis(); editor.putLong("date_firstlaunch", date_firstLaunch); } editor.commit(); // Wait at least n days before opening if (launch_count >= LAUNCHES_UNTIL_PROMPT) { if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { showRateDialog(ctx); } } }
Example 19
Source File: ListTask.java From listmyaps with Apache License 2.0 | 4 votes |
@Override protected ArrayList<SortablePackageInfo> doInBackground(Object... params) { SharedPreferences prefs = listActivity.getSharedPreferences( MainActivity.PREFSFILE, 0); ArrayList<SortablePackageInfo> ret = new ArrayList<SortablePackageInfo>(); PackageManager pm = listActivity.getPackageManager(); List<PackageInfo> list = pm.getInstalledPackages(0); SortablePackageInfo spitmp[] = new SortablePackageInfo[list.size()]; Iterator<PackageInfo> it = list.iterator(); AnnotationsSource aSource = new AnnotationsSource(listActivity); aSource.open(); int idx = 0; while (it.hasNext()) { PackageInfo info = it.next(); try { ApplicationInfo ai = pm.getApplicationInfo(info.packageName, 0); if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != ApplicationInfo.FLAG_SYSTEM && (ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) { spitmp[idx] = new SortablePackageInfo(); spitmp[idx].packageName = info.packageName; spitmp[idx].displayName = pm .getApplicationLabel(info.applicationInfo).toString(); spitmp[idx].installer = pm.getInstallerPackageName(info.packageName); spitmp[idx].appInfo = ai; spitmp[idx].versionCode = info.versionCode; spitmp[idx].version = info.versionName; spitmp[idx].firstInstalled = info.firstInstallTime; spitmp[idx].lastUpdated = info.lastUpdateTime; spitmp[idx].uid = info.applicationInfo.uid; spitmp[idx].dataDir = info.applicationInfo.dataDir; spitmp[idx].comment = aSource.getComment(info.packageName); spitmp[idx].tags=aSource.getTags(info.packageName); spitmp[idx].targetsdk = ai.targetSdkVersion; idx++; } } catch (NameNotFoundException exp) { } } // Reminder: the copying is necessary because we are filtering away the // system apps. SortablePackageInfo spi[] = new SortablePackageInfo[idx]; System.arraycopy(spitmp, 0, spi, 0, idx); Arrays.sort(spi); for (int i = 0; i < spi.length; i++) { spi[i].selected = prefs.getBoolean(MainActivity.SELECTED + "." + spi[i].packageName, false); ret.add(spi[i]); } return ret; }
Example 20
Source File: PlaystoreCheckHelper.java From candybar with Apache License 2.0 | 4 votes |
public static Boolean fromPlaystore(Context context) { PackageManager pm = context.getPackageManager(); String installerPackage = pm.getInstallerPackageName(context.getPackageName()); return installerPackage != null && installerPackage.contentEquals("com.android.vending"); }