List of usage examples for android.content.pm PackageManager GET_SERVICES
int GET_SERVICES
To view the source code for android.content.pm PackageManager GET_SERVICES.
Click Source Link
From source file:Main.java
public static boolean isAntRadioServiceInstalled(Context context) { return isPackageInstalled(context, "com.dsi.ant.service.socket", PackageManager.GET_SERVICES); }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context, String apkFilepath) { return getPackageInfo(context, apkFilepath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES); }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context, String apkFilePath) { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = null;//from w w w.jav a 2 s . co m try { packageInfo = pm.getPackageArchiveInfo(apkFilePath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES); } catch (Exception e) { e.printStackTrace(); } return packageInfo; }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context, String apkFilepath) { PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = null;//from w w w . j a v a2 s .co m try { pkgInfo = pm.getPackageArchiveInfo(apkFilepath, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES); } catch (Exception e) { // should be something wrong with parse e.printStackTrace(); } return pkgInfo; }
From source file:Main.java
/** * Return <tt>true</tt> if the caller runs in a process dedicated to the Capptain service.<br/> * Return <tt>false</tt> otherwise, e.g. if it's the application process (even if the Capptain * service is running in it) or another process.<br/> * This method is useful when the <b>android:process</b> attribute has been set on the Capptain * service, if this method return <tt>true</tt>, application initialization must not be done in * that process. This method is used by {@link CapptainApplication}. * @param context the application context. * @return <tt>true</tt> if the caller is running in a process dedicated to the Capptain service, * <tt>false</tt> otherwise. * @see CapptainApplication/*from w w w . j a va 2 s. c o m*/ */ public static boolean isInDedicatedCapptainProcess(Context context) { /* Get our package info */ PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SERVICES); } catch (Exception e) { /* * NameNotFoundException (uninstalling?) or in some rare scenario an undocumented * "RuntimeException: Package manager has died.", probably caused by a system app process * crash. */ return false; } /* Get main process name */ String mainProcess = packageInfo.applicationInfo.processName; /* Get embedded Capptain process name */ String capptainProcess = null; if (packageInfo.services != null) for (ServiceInfo serviceInfo : packageInfo.services) if ("com.ubikod.capptain.android.service.CapptainService".equals(serviceInfo.name)) { capptainProcess = serviceInfo.processName; break; } /* If the embedded Capptain service runs on its own process */ if (capptainProcess != null && !capptainProcess.equals(mainProcess)) { /* The result is to check if the current process is the capptain process */ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningAppProcessInfo rapInfo : activityManager.getRunningAppProcesses()) if (rapInfo.pid == Process.myPid()) return rapInfo.processName.equals(capptainProcess); } /* Otherwise capptain is not running in a separate process (or not running at all) */ return false; }
From source file:Main.java
/** * Return <tt>true</tt> if the caller runs in a process dedicated to the Engagement service.<br/> * Return <tt>false</tt> otherwise, e.g. if it's the application process (even if the Engagement * service is running in it) or another process.<br/> * This method is useful when the <b>android:process</b> attribute has been set on the Engagement * service, if this method return <tt>true</tt>, application initialization must not be done in * that process. This method is used by {@link EngagementApplication}. * @param context the application context. * @return <tt>true</tt> if the caller is running in a process dedicated to the Engagement * service, <tt>false</tt> otherwise. * @see EngagementApplication/* w ww. j ava 2 s.co m*/ */ public static boolean isInDedicatedEngagementProcess(Context context) { /* Get our package info */ PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SERVICES); } catch (Exception e) { /* * NameNotFoundException (uninstalling?) or in some rare scenario an undocumented * "RuntimeException: Package manager has died.", probably caused by a system app process * crash. */ return false; } /* Get main process name */ String mainProcess = packageInfo.applicationInfo.processName; /* Get embedded Engagement process name */ String engagementProcess = null; if (packageInfo.services != null) for (ServiceInfo serviceInfo : packageInfo.services) if (SERVICE_CLASS.equals(serviceInfo.name)) { engagementProcess = serviceInfo.processName; break; } /* If the embedded Engagement service runs on its own process */ if (engagementProcess != null && !engagementProcess.equals(mainProcess)) { /* The result is to check if the current process is the engagement process */ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningAppProcessInfo rapInfo : activityManager.getRunningAppProcesses()) if (rapInfo.pid == Process.myPid()) return rapInfo.processName.equals(engagementProcess); } /* Otherwise engagement is not running in a separate process (or not running at all) */ return false; }
From source file:com.nachtimwald.android.serviceexplorer.ServiceListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_servicelist, container, false); ListView lv = (ListView) view.findViewById(R.id.serviceList); List<Map<String, String>> serviceData = new ArrayList<>(); if (getArguments().getBoolean("allServices")) { for (PackageInfo packageInfo : getActivity().getPackageManager() .getInstalledPackages(PackageManager.GET_SERVICES)) { if (packageInfo.services == null) { continue; }/*ww w.ja v a 2s.c om*/ for (ServiceInfo serviceInfo : packageInfo.services) { Map<String, String> datum = new HashMap<>(); datum.put("name", serviceInfo.name); datum.put("package", serviceInfo.packageName); datum.put("search", serviceInfo.name.replace(".", " ").replace("$", " ")); serviceData.add(datum); } } } else { ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> runningServiceInfos = activityManager .getRunningServices(Integer.MAX_VALUE); for (ActivityManager.RunningServiceInfo info : runningServiceInfos) { Map<String, String> datum = new HashMap<>(); datum.put("name", info.service.getClassName()); datum.put("package", info.service.getPackageName()); datum.put("search", info.service.getClassName().replace(".", " ").replace("$", " ")); serviceData.add(datum); } } mServicesAdapter = new SimpleAdapter(getActivity(), serviceData, android.R.layout.simple_list_item_2, new String[] { "name", "package", "search" }, new int[] { android.R.id.text1, android.R.id.text2, 0 }); lv.setAdapter(mServicesAdapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), DetailActivity.class); i.putExtra("name", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("name")); i.putExtra("package", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("package")); startActivity(i); } }); if (savedInstanceState != null) { lv.onRestoreInstanceState(savedInstanceState.getParcelable(STATE_LISTPOS)); } return view; }
From source file:org.adaway.util.ScanAdwareLoader.java
/** * Finds all installed packages that look like they include a known ad framework *///from w ww.java 2s .co m private List<PackageInfo> getAdPackages() { Set<PackageInfo> adPackages = new HashSet<PackageInfo>(); PackageManager pm = context.getPackageManager(); // It'd be simpler to just use pm.getInstalledPackages here, but apparently it's broken List<ApplicationInfo> appInfos = pm.getInstalledApplications(0); for (ApplicationInfo appInfo : appInfos) { if (canceled) { adPackages.clear(); break; } try { PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES); Log.v(Constants.TAG, "Scanning package " + pkgInfo.packageName); if (pkgInfo.activities != null) { for (ActivityInfo activity : pkgInfo.activities) { Log.v(Constants.TAG, "[ACTIVITY] " + activity.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (activity.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as activity " + activity.name); adPackages.add(pkgInfo); } } } } if (pkgInfo.receivers != null) { for (ActivityInfo receiver : pkgInfo.receivers) { Log.v(Constants.TAG, "[RECEIVER] " + receiver.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (receiver.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as receiver " + receiver.name); adPackages.add(pkgInfo); break; } } } } if (pkgInfo.services != null) { for (ServiceInfo service : pkgInfo.services) { Log.v(Constants.TAG, "[SERVICE] " + service.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (service.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as service " + service.name); adPackages.add(pkgInfo); break; } } } } } catch (Exception e) { Log.e(Constants.TAG, "Scan Adware Exception", e); } } return new ArrayList<PackageInfo>(adPackages); }
From source file:com.github.michalbednarski.intentslab.AppComponentsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPackageName = ((AppInfoHost) getActivity()).getViewedPackageName(); final PackageManager packageManager = getActivity().getPackageManager(); ArrayList<Integer> presentSections = new ArrayList<Integer>(); try {/*from ww w . ja v a2 s . c o m*/ final PackageInfo packageInfo = packageManager.getPackageInfo(mPackageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_PROVIDERS | PackageManager.GET_PERMISSIONS); // Scan activities and group them as exported and not exported { ArrayList<ActivityInfo> exportedActivities = new ArrayList<ActivityInfo>(); ArrayList<ActivityInfo> notExportedActivities = new ArrayList<ActivityInfo>(); if (packageInfo.activities != null && packageInfo.activities.length != 0) { for (ActivityInfo activity : packageInfo.activities) { (activity.exported ? exportedActivities : notExportedActivities).add(activity); } } if (exportedActivities.size() != 0) { mActivities = exportedActivities.toArray(new ComponentInfo[exportedActivities.size()]); presentSections.add(SECTION_ACTIVITIES); } if (notExportedActivities.size() != 0) { mActivitiesNotExported = notExportedActivities .toArray(new ComponentInfo[notExportedActivities.size()]); presentSections.add(SECTION_ACTIVITIES_NOT_EXPORTED); } } // Check receivers, services and providers if (packageInfo.receivers != null) { mReceivers = packageInfo.receivers; presentSections.add(SECTION_RECEIVERS); } if (packageInfo.services != null) { mServices = packageInfo.services; presentSections.add(SECTION_SERVICES); } if (packageInfo.providers != null) { mProviders = packageInfo.providers; presentSections.add(SECTION_PROVIDERS); } // Scan defined permissions if (packageInfo.permissions != null) { mDefinedPermissions = new String[packageInfo.permissions.length]; for (int i = 0; i < packageInfo.permissions.length; i++) { mDefinedPermissions[i] = packageInfo.permissions[i].name; } presentSections.add(SECTION_DEFINED_PERMISSIONS); } // Scan requested permissions (granted and denied) HashSet<String> testedPermissions = new HashSet<String>(); if (packageInfo.requestedPermissions != null) { ArrayList<String> grantedPermissions = new ArrayList<String>(); ArrayList<String> deniedPermissions = new ArrayList<String>(); for (String permission : packageInfo.requestedPermissions) { if (packageManager.checkPermission(permission, mPackageName) == PackageManager.PERMISSION_GRANTED) { grantedPermissions.add(permission); } else { deniedPermissions.add(permission); } testedPermissions.add(permission); } if (grantedPermissions.size() != 0) { mGrantedPermissions = grantedPermissions.toArray(new String[grantedPermissions.size()]); presentSections.add(SECTION_GRANTED_PERMISSIONS); } if (deniedPermissions.size() != 0) { mDeniedPermissions = deniedPermissions.toArray(new String[deniedPermissions.size()]); presentSections.add(SECTION_DENIED_PERMISSIONS); } } // Scan shared user packages for permissions (implicitly granted) { ArrayList<String> implicitlyGrantedPermissions = new ArrayList<String>(); for (String sharedUidPackageName : packageManager .getPackagesForUid(packageInfo.applicationInfo.uid)) { if (mPackageName.equals(sharedUidPackageName)) { continue; } final PackageInfo sharedUidPackageInfo = packageManager.getPackageInfo(sharedUidPackageName, PackageManager.GET_PERMISSIONS); if (sharedUidPackageInfo.requestedPermissions == null) { continue; } for (String permission : sharedUidPackageInfo.requestedPermissions) { if (!testedPermissions.contains(permission)) { testedPermissions.add(permission); if (packageManager.checkPermission(permission, mPackageName) == PackageManager.PERMISSION_GRANTED) { implicitlyGrantedPermissions.add(permission); } } } } if (implicitlyGrantedPermissions.size() != 0) { mImplicitlyGrantedPermissions = implicitlyGrantedPermissions .toArray(new String[implicitlyGrantedPermissions.size()]); presentSections.add(SECTION_IMPLICITLY_GRANTED_PERMISSIONS); } } // Save present sections list as array mPresentSections = new int[presentSections.size()]; for (int i = 0; i < presentSections.size(); i++) { mPresentSections[i] = presentSections.get(i); } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.example.helloworldlinked.backend.HelloWorldService.java
private boolean isProviderInstalled() { PackageManager pm = getPackageManager(); try {/* w w w. ja va2 s . com*/ pm.getPackageInfo(HELLO_WORLD_PROVIDER_PACKAGE_NAME, PackageManager.GET_SERVICES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }