List of usage examples for android.content.pm ApplicationInfo FLAG_SYSTEM
int FLAG_SYSTEM
To view the source code for android.content.pm ApplicationInfo FLAG_SYSTEM.
Click Source Link
From source file:Main.java
static List<Pair<String, Resources>> findSystemApks(String action, PackageManager pm) { final Intent intent = new Intent(action); List<Pair<String, Resources>> systemApks = new ArrayList<Pair<String, Resources>>(); for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) { if (info.activityInfo != null && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String packageName = info.activityInfo.packageName; try { final Resources res = pm.getResourcesForApplication(packageName); systemApks.add(Pair.create(packageName, res)); } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + packageName); }//from www .j a va 2 s. c o m } } return systemApks; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private static File searchLibrary(ApplicationInfo applicationInfo) { // Search for library path String[] libraryPaths;/*from w w w. j a v a 2s . c o m*/ if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String property = System.getProperty("java.library.path"); libraryPaths = property.split(":"); } else { libraryPaths = new String[1]; libraryPaths[0] = applicationInfo.nativeLibraryDir; } if (libraryPaths[0] == null) { Log.e(TAG, "can't find library path"); return null; } // Search for libvlcjni.so File lib; for (String libraryPath : libraryPaths) { lib = new File(libraryPath, "libvlcjni.so"); if (lib.exists() && lib.canRead()) return lib; } Log.e(TAG, "WARNING: Can't find shared library"); return null; }
From source file:Main.java
/** * whether packageName is system application * * @param packageManager//from w w w. jav a 2 s . c om * @param packageName * @return <ul> * <li>if packageManager is null, return false</li> * <li>if package name is null or is empty, return false</li> * <li>if package name not exit, return false</li> * <li>if package name exit, but not system app, return false</li> * <li>else return true</li> * </ul> */ public static boolean isSystemApplication(PackageManager packageManager, String packageName) { if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
/** * whether packageName is system application * //ww w .j a v a2s . c o m * @param packageManager * @param packageName * @return <ul> * <li>if packageManager is null, return false</li> * <li>if package name is null or is empty, return false</li> * <li>if package name not exit, return false</li> * <li>if package name exit, but not system app, return false</li> * <li>else return true</li> * </ul> */ public static boolean isSystemApplication(PackageManager packageManager, String packageName) { if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
static boolean isSystemApp(Context context, Intent intent) { PackageManager pm = context.getPackageManager(); ComponentName cn = intent.getComponent(); String packageName = null;//from w w w .j a va 2 s. c om if (cn == null) { ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if ((info != null) && (info.activityInfo != null)) { packageName = info.activityInfo.packageName; } } else { packageName = cn.getPackageName(); } if (packageName != null) { try { PackageInfo info = pm.getPackageInfo(packageName, 0); return (info != null) && (info.applicationInfo != null) && ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); } catch (NameNotFoundException e) { return false; } } else { return false; } }
From source file:io.digibyte.tools.util.Utils.java
public static boolean isUsingCustomInputMethod(Activity context) { if (context == null) return false; InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { return false; }//w w w . ja va2 s. co m List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList(); final int N = mInputMethodProperties.size(); for (int i = 0; i < N; i++) { InputMethodInfo imi = mInputMethodProperties.get(i); if (imi.getId().equals(Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return true; } } } return false; }
From source file:com.lambdal.railgun.PInfo.java
static private boolean isSystemPackage(PackageInfo pkgInfo) { return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); }
From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME); PackageManager pm = getPackageManager(); ApplicationInfo appInfo;/* www. j av a 2s .c om*/ try { //noinspection WrongConstant (lint is actually wrong here!) appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Failed to get ApplicationInfo for uninstalling"); } final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; if (isSystem && !isUpdate) { // Cannot remove system apps unless we're uninstalling updates throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates"); } int messageId; if (isUpdate) { messageId = R.string.uninstall_update_confirm; } else { messageId = R.string.uninstall_confirm; } // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final AlertDialog.Builder builder = new AlertDialog.Builder(theme); builder.setTitle(appInfo.loadLabel(pm)); builder.setIcon(appInfo.loadIcon(pm)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent data = new Intent(); data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName); setResult(Activity.RESULT_OK, intent); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setMessage(messageId); builder.create().show(); }
From source file:com.github.michalbednarski.intentslab.browser.ApplicationFetcher.java
@Override Object getEntries(Context context) { PackageManager pm = context.getPackageManager(); int requestedPackageInfoFlags = PackageManager.GET_DISABLED_COMPONENTS | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0); List<PackageInfo> allPackages = pm.getInstalledPackages(requestedPackageInfoFlags); ArrayList<Component> selectedApps = new ArrayList<Component>(); for (PackageInfo pack : allPackages) { ApplicationInfo applicationInfo = pack.applicationInfo; // Filter out non-applications if (applicationInfo == null) { continue; }/*from ww w. j av a2 s.co m*/ // System app filter if ((((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER) & appType) == 0) { continue; } // Metadata filter if (!checkMetaDataFilter(applicationInfo)) { continue; } // Build and add app descriptor Component app = new Component(); app.title = String.valueOf(applicationInfo.loadLabel(pm)); app.subtitle = pack.packageName; app.componentInfo = applicationInfo; selectedApps.add(app); // Allow cancelling task if (Thread.interrupted()) { return null; } } return selectedApps.toArray(new Component[selectedApps.size()]); }
From source file:com.emetophobe.permissionviewer.PermissionScanner.java
@Override public void run() { // Get the list of installed packages PackageManager pm = mContext.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); // Send a message to the main thread to display the progress dialog sendMessage(MESSAGE_PROGRESS_INIT, packages.size()); String packageName, appName, permissionName; PackageInfo packageInfo;/*from w ww . ja v a2 s .c om*/ boolean system; int count = 0; // Iterate over each package in the list for (ApplicationInfo appInfo : packages) { // Get the package name and label packageName = appInfo.packageName; try { appName = pm.getApplicationLabel(appInfo).toString(); } catch (Resources.NotFoundException e) { // application not found appName = packageName; } // Get the system flag system = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; try { // Get the list of permissions packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); if (packageInfo.requestedPermissions != null) { for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) { if (packageInfo.requestedPermissions[i].startsWith(ANDROID_PERMISSION)) { permissionName = packageInfo.requestedPermissions[i] .substring(ANDROID_PERMISSION.length()); // Add a separate entry for each permission addPackage(appName, packageName, permissionName, system); } } } else { // Add an empty permission entry for packages that contain zero permissions addPackage(appName, packageName, null, system); } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, e.toString()); } // Send a message to the main thread to update the progress dialog sendMessage(MESSAGE_PROGRESS_UPDATE, ++count); } // Send a message to the main thread that the thread is finished. sendMessage(MESSAGE_PROGRESS_COMPLETE, 0); }