Example usage for android.content.pm PackageManager GET_SERVICES

List of usage examples for android.content.pm PackageManager GET_SERVICES

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_SERVICES.

Prototype

int GET_SERVICES

To view the source code for android.content.pm PackageManager GET_SERVICES.

Click Source Link

Document

PackageInfo flag: return information about services in the package in PackageInfo#services .

Usage

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
Object getEntries(Context context) {
    PackageManager pm = context.getPackageManager();
    int requestedPackageInfoFlags = type | PackageManager.GET_DISABLED_COMPONENTS
            | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0);

    boolean workAroundSmallBinderBuffer = false;
    List<PackageInfo> allPackages = null;
    try {//from  w w  w.jav  a 2s  .  c  om
        allPackages = pm.getInstalledPackages(requestedPackageInfoFlags);
    } catch (Exception e) {
        Log.w(TAG, "Loading all apps at once failed, retrying separately", e);
    }

    if (allPackages == null || allPackages.isEmpty()) {
        workAroundSmallBinderBuffer = true;
        allPackages = pm.getInstalledPackages(0);
    }

    ArrayList<Category> selectedApps = new ArrayList<Category>();

    for (PackageInfo pack : allPackages) {
        // Filter out non-applications
        if (pack.applicationInfo == null) {
            continue;
        }

        // System app filter
        if ((((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER)
                & appType) == 0) {
            continue;
        }

        // Load component information separately if they were to big to send them all at once
        if (workAroundSmallBinderBuffer) {
            try {
                pack = pm.getPackageInfo(pack.packageName, requestedPackageInfoFlags);
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "getPackageInfo() thrown NameNotFoundException for " + pack.packageName, e);
                continue;
            }
        }

        // Scan components
        ArrayList<Component> selectedComponents = new ArrayList<Component>();

        if ((type & PackageManager.GET_ACTIVITIES) != 0) {
            scanComponents(pm, pack.activities, selectedComponents);
        }
        if ((type & PackageManager.GET_RECEIVERS) != 0) {
            scanComponents(pm, pack.receivers, selectedComponents);
        }
        if ((type & PackageManager.GET_SERVICES) != 0) {
            scanComponents(pm, pack.services, selectedComponents);
        }
        if ((type & PackageManager.GET_PROVIDERS) != 0) {
            scanComponents(pm, pack.providers, selectedComponents);
        }

        // Check if we filtered out all components and skip whole app if so
        if (selectedComponents.isEmpty()) {
            continue;
        }

        // Build and add app descriptor
        Category app = new Category();
        app.title = String.valueOf(pack.applicationInfo.loadLabel(pm));
        app.subtitle = pack.packageName;
        app.components = selectedComponents.toArray(new Component[selectedComponents.size()]);
        selectedApps.add(app);

        // Allow cancelling task
        if (Thread.interrupted()) {
            return null;
        }
    }
    return selectedApps.toArray(new Category[selectedApps.size()]);
}

From source file:org.tomahawk.tomahawk_android.dialogs.ResolverRedirectConfigDialog.java

private boolean isPluginInstalled() {
    List<PackageInfo> packageInfos = getActivity().getPackageManager()
            .getInstalledPackages(PackageManager.GET_SERVICES);
    String pluginPackageName = "";
    int pluginMinVersionCode = 0;
    switch (mScriptResolver.getId()) {
    case TomahawkApp.PLUGINNAME_SPOTIFY:
        pluginPackageName = SpotifyMediaPlayer.get().getPackageName();
        pluginMinVersionCode = SpotifyMediaPlayer.get().getMinVersionCode();
        break;//from w  ww  . j  a v a 2 s  .  co m
    case TomahawkApp.PLUGINNAME_DEEZER:
        pluginPackageName = DeezerMediaPlayer.get().getPackageName();
        pluginMinVersionCode = DeezerMediaPlayer.get().getMinVersionCode();
        break;
    case TomahawkApp.PLUGINNAME_RDIO:
        pluginPackageName = RdioMediaPlayer.get().getPackageName();
        pluginMinVersionCode = RdioMediaPlayer.get().getMinVersionCode();
        break;
    }
    for (PackageInfo info : packageInfos) {
        if (pluginPackageName.equals(info.packageName)) {
            // Remove the first digit that identifies the architecture type
            String versionCodeString = String.valueOf(info.versionCode);
            versionCodeString = versionCodeString.substring(1, versionCodeString.length());
            int versionCode = Integer.valueOf(versionCodeString);
            if (versionCode >= pluginMinVersionCode) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.github.michalbednarski.intentslab.browser.BrowseComponentsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (mFetcher.onOptionsItemSelected(itemId)) {
        setFetcher(mFetcher);/*from   w  w  w .j av a2  s  . c  o m*/
        return true;
    }

    switch (itemId) {
    case R.id.custom_filter:
        FetcherOptionsDialog fetcherOptionsDialog = new FetcherOptionsDialog();
        fetcherOptionsDialog.setTargetFragment(this, 0);
        fetcherOptionsDialog.show(getFragmentManager(), "filterOptions");
        return true;
    case R.id.activities:
    case R.id.broadcasts:
    case R.id.services:
    case R.id.content_providers: {
        // Fetcher isn't component fetcher, otherwise it would intercept this above
        ComponentFetcher fetcher = new ComponentFetcher();
        fetcher.type = itemId == R.id.activities ? PackageManager.GET_ACTIVITIES
                : itemId == R.id.broadcasts ? PackageManager.GET_RECEIVERS
                        : itemId == R.id.services ? PackageManager.GET_SERVICES
                                : itemId == R.id.content_providers ? PackageManager.GET_PROVIDERS : 0;
        if (mFetcher instanceof ApplicationFetcher) {
            fetcher.appType = ((ApplicationFetcher) mFetcher).appType;
        }
        setFetcher(fetcher);
        return true;
    }
    case R.id.applications: {
        if (!(mFetcher instanceof ApplicationFetcher)) {
            ApplicationFetcher fetcher = new ApplicationFetcher();
            if (mFetcher instanceof ComponentFetcher) {
                fetcher.appType = ((ComponentFetcher) mFetcher).appType;
            }
            setFetcher(fetcher);
        }
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

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 ww w .  jav  a  2 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.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void initConfigurationForm(final FetcherOptionsDialog dialog) {
    // Disable development permission checkbox if it's not available
    if (!DEVELOPMENT_PERMISSIONS_SUPPORTED) {
        dialog.findView(R.id.permission_filter_development).setEnabled(false);
    }//from w  ww .  j  a v a  2 s.  c  o  m

    // Prepare protection preset spinner
    {
        // Find current preset
        int currentPresetId = PROTECTION_PRESETS.length; // "Custom" if nothing found
        if (!testWritePermissionForProviders) {
            for (int i = 0; i < PROTECTION_PRESETS.length; i++) {
                if (protection == PROTECTION_PRESETS[i]) {
                    currentPresetId = i;
                    dialog.findView(R.id.permission_filter_details).setVisibility(View.GONE);
                    break;
                }
            }
        }

        // Fill spinner
        Spinner protectionPresetSpinner = (Spinner) dialog.findView(R.id.permission_filter_spinner);
        Activity activity = dialog.getActivity();
        protectionPresetSpinner
                .setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,
                        new String[] { activity.getString(R.string.permission_filter_show_all), // 0
                                activity.getString(R.string.permission_filter_show_exported), // 1
                                activity.getString(R.string.permission_filter_show_obtainable), // 2
                                activity.getString(R.string.permission_filter_world_accessible), // 3
                                activity.getString(R.string.filter_custom) // 4
                        }));
        protectionPresetSpinner.setSelection(currentPresetId);

        // Set up spinner event
        protectionPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                boolean isCustom = position == PROTECTION_PRESETS.length;
                if (!isCustom) {
                    int preset = PROTECTION_PRESETS[position];
                    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
                            (preset & PROTECTION_WORLD_ACCESSIBLE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_normal, (preset & PROTECTION_NORMAL) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_dangerous,
                            (preset & PROTECTION_DANGEROUS) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_signature,
                            (preset & PROTECTION_SIGNATURE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_system, (preset & PROTECTION_SYSTEM) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_development,
                            (preset & PROTECTION_DEVELOPMENT) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unexported,
                            (preset & PROTECTION_UNEXPORTED) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unknown, (preset & PROTECTION_UNKNOWN) != 0);
                    dialog.setBoxChecked(R.id.read_permission, true);
                }
                dialog.findView(R.id.permission_filter_details)
                        .setVisibility(isCustom ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // Spinner cannot have nothing selected
            }
        });
    }

    // Fill form
    dialog.setBoxChecked(R.id.system_apps, (appType & APP_TYPE_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.user_apps, (appType & APP_TYPE_USER) != 0);

    dialog.setBoxChecked(R.id.activities, (type & PackageManager.GET_ACTIVITIES) != 0);
    dialog.setBoxChecked(R.id.receivers, (type & PackageManager.GET_RECEIVERS) != 0);
    dialog.setBoxChecked(R.id.services, (type & PackageManager.GET_SERVICES) != 0);
    dialog.setBoxChecked(R.id.content_providers, (type & PackageManager.GET_PROVIDERS) != 0);

    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
            (protection & PROTECTION_WORLD_ACCESSIBLE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_normal, (protection & PROTECTION_NORMAL) != 0);
    dialog.setBoxChecked(R.id.permission_filter_dangerous, (protection & PROTECTION_DANGEROUS) != 0);
    dialog.setBoxChecked(R.id.permission_filter_signature, (protection & PROTECTION_SIGNATURE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_system, (protection & PROTECTION_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.permission_filter_development, (protection & PROTECTION_DEVELOPMENT) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unexported, (protection & PROTECTION_UNEXPORTED) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unknown, (protection & PROTECTION_UNKNOWN) != 0);

    dialog.setBoxChecked(testWritePermissionForProviders ? R.id.write_permission : R.id.read_permission, true);
    dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission,
            includeOnlyProvidersAllowingPermissionGranting);

    dialog.setBoxChecked(R.id.metadata, requireMetaDataSubstring != null);
    dialog.setTextInField(R.id.metadata_substring, requireMetaDataSubstring);

    // Set up sections showing when their checkboxes are checked
    dialog.findView(R.id.content_provider_permission_type)
            .setVisibility(testWritePermissionForProviders ? View.VISIBLE : View.GONE);
    dialog.findView(R.id.content_provider_options)
            .setVisibility((type & PackageManager.GET_PROVIDERS) != 0 ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.content_providers))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.content_provider_permission_type)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    dialog.findView(R.id.content_provider_options)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setBoxChecked(R.id.read_permission, true);
                        dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, false);
                    }
                }
            });

    dialog.findView(R.id.metadata_details)
            .setVisibility(requireMetaDataSubstring != null ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.metadata))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.metadata_details).setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setTextInField(R.id.metadata_substring, "");
                    }
                }
            });
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void updateFromConfigurationForm(FetcherOptionsDialog dialog) {
    appType = (dialog.isBoxChecked(R.id.system_apps) ? APP_TYPE_SYSTEM : 0)
            | (dialog.isBoxChecked(R.id.user_apps) ? APP_TYPE_USER : 0);

    type = (dialog.isBoxChecked(R.id.activities) ? PackageManager.GET_ACTIVITIES : 0)
            | (dialog.isBoxChecked(R.id.receivers) ? PackageManager.GET_RECEIVERS : 0)
            | (dialog.isBoxChecked(R.id.services) ? PackageManager.GET_SERVICES : 0)
            | (dialog.isBoxChecked(R.id.content_providers) ? PackageManager.GET_PROVIDERS : 0);

    protection = (dialog.isBoxChecked(R.id.permission_filter_world_accessible) ? PROTECTION_WORLD_ACCESSIBLE
            : 0) | (dialog.isBoxChecked(R.id.permission_filter_normal) ? PROTECTION_NORMAL : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_dangerous) ? PROTECTION_DANGEROUS : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_signature) ? PROTECTION_SIGNATURE : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_system) ? PROTECTION_SYSTEM : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_development) ? PROTECTION_DEVELOPMENT : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_unexported) ? PROTECTION_UNEXPORTED : 0)
            | (dialog.isBoxChecked(R.id.permission_filter_unknown) ? PROTECTION_UNKNOWN : 0);

    includeOnlyProvidersAllowingPermissionGranting = dialog
            .isBoxChecked(R.id.only_providers_with_grant_uri_permission);

    boolean requireMetaData = dialog.isBoxChecked(R.id.metadata);
    requireMetaDataSubstring = requireMetaData ? dialog.getTextFromField(R.id.metadata_substring) : null;

    testWritePermissionForProviders = dialog.isBoxChecked(R.id.write_permission);
}

From source file:android.content.pm.PackageParser.java

public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags,
        long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state,
        int userId) {

    if (!checkUseInstalledOrHidden(flags, state)) {
        return null;
    }//from w w w.j av a 2 s .co  m
    PackageInfo pi = new PackageInfo();
    pi.packageName = p.packageName;
    pi.splitNames = p.splitNames;
    pi.versionCode = p.mVersionCode;
    pi.baseRevisionCode = p.baseRevisionCode;
    pi.splitRevisionCodes = p.splitRevisionCodes;
    pi.versionName = p.mVersionName;
    pi.sharedUserId = p.mSharedUserId;
    pi.sharedUserLabel = p.mSharedUserLabel;
    pi.applicationInfo = generateApplicationInfo(p, flags, state, userId);
    pi.installLocation = p.installLocation;
    pi.coreApp = p.coreApp;
    if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
            || (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
        pi.requiredForAllUsers = p.mRequiredForAllUsers;
    }
    pi.restrictedAccountType = p.mRestrictedAccountType;
    pi.requiredAccountType = p.mRequiredAccountType;
    pi.overlayTarget = p.mOverlayTarget;
    pi.firstInstallTime = firstInstallTime;
    pi.lastUpdateTime = lastUpdateTime;
    if ((flags & PackageManager.GET_GIDS) != 0) {
        pi.gids = gids;
    }
    if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) {
        int N = p.configPreferences != null ? p.configPreferences.size() : 0;
        if (N > 0) {
            pi.configPreferences = new ConfigurationInfo[N];
            p.configPreferences.toArray(pi.configPreferences);
        }
        N = p.reqFeatures != null ? p.reqFeatures.size() : 0;
        if (N > 0) {
            pi.reqFeatures = new FeatureInfo[N];
            p.reqFeatures.toArray(pi.reqFeatures);
        }
        N = p.featureGroups != null ? p.featureGroups.size() : 0;
        if (N > 0) {
            pi.featureGroups = new FeatureGroupInfo[N];
            p.featureGroups.toArray(pi.featureGroups);
        }
    }
    if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
        int N = p.activities.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.activities = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.activities.get(i).info.enabled)
                        num++;
                }
                pi.activities = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.activities.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_RECEIVERS) != 0) {
        int N = p.receivers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.receivers = new ActivityInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.receivers.get(i).info.enabled)
                        num++;
                }
                pi.receivers = new ActivityInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Activity activity = p.receivers.get(i);
                if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SERVICES) != 0) {
        int N = p.services.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.services = new ServiceInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.services.get(i).info.enabled)
                        num++;
                }
                pi.services = new ServiceInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Service service = p.services.get(i);
                if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.services[j++] = generateServiceInfo(p.services.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_PROVIDERS) != 0) {
        int N = p.providers.size();
        if (N > 0) {
            if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                pi.providers = new ProviderInfo[N];
            } else {
                int num = 0;
                for (int i = 0; i < N; i++) {
                    if (p.providers.get(i).info.enabled)
                        num++;
                }
                pi.providers = new ProviderInfo[num];
            }
            for (int i = 0, j = 0; i < N; i++) {
                final Provider provider = p.providers.get(i);
                if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
                    pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, state, userId);
                }
            }
        }
    }
    if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) {
        int N = p.instrumentation.size();
        if (N > 0) {
            pi.instrumentation = new InstrumentationInfo[N];
            for (int i = 0; i < N; i++) {
                pi.instrumentation[i] = generateInstrumentationInfo(p.instrumentation.get(i), flags);
            }
        }
    }
    if ((flags & PackageManager.GET_PERMISSIONS) != 0) {
        int N = p.permissions.size();
        if (N > 0) {
            pi.permissions = new PermissionInfo[N];
            for (int i = 0; i < N; i++) {
                pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags);
            }
        }
        N = p.requestedPermissions.size();
        if (N > 0) {
            pi.requestedPermissions = new String[N];
            pi.requestedPermissionsFlags = new int[N];
            for (int i = 0; i < N; i++) {
                final String perm = p.requestedPermissions.get(i);
                pi.requestedPermissions[i] = perm;
                // The notion of required permissions is deprecated but for compatibility.
                pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED;
                if (grantedPermissions != null && grantedPermissions.contains(perm)) {
                    pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED;
                }
            }
        }
    }
    if ((flags & PackageManager.GET_SIGNATURES) != 0) {
        int N = (p.mSignatures != null) ? p.mSignatures.length : 0;
        if (N > 0) {
            pi.signatures = new Signature[N];
            System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N);
        }
    }
    return pi;
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void onPrepareOptionsMenu(Menu menu) {
    if (appType == APP_TYPE_USER) {
        menu.findItem(R.id.system_apps).setVisible(true);
    } else if (appType == APP_TYPE_SYSTEM) {
        menu.findItem(R.id.user_apps).setVisible(true);
    }/* w  w  w.  ja  v a  2 s .  c  o  m*/

    if (type == PackageManager.GET_ACTIVITIES) {
        menu.findItem(R.id.activities).setChecked(true);
    } else if (type == PackageManager.GET_RECEIVERS) {
        menu.findItem(R.id.broadcasts).setChecked(true);
    } else if (type == PackageManager.GET_SERVICES) {
        menu.findItem(R.id.services).setChecked(true);
    } else if (type == PackageManager.GET_PROVIDERS) {
        menu.findItem(R.id.content_providers).setChecked(true);
    }

    menu.findItem(R.id.simple_filter_permission).setVisible(true);
    for (int i = 0; i < PROTECTION_PRESETS_MENU_IDS.length; i++) {
        if (protection == PROTECTION_PRESETS[i]) {
            menu.findItem(PROTECTION_PRESETS_MENU_IDS[i]).setChecked(true);
        }
    }
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
boolean onOptionsItemSelected(int id) {
    switch (id) {
    case R.id.system_apps:
        appType = APP_TYPE_SYSTEM;// w  ww  .jav  a2  s  .  c o m
        return true;
    case R.id.user_apps:
        appType = APP_TYPE_USER;
        return true;

    case R.id.activities:
        type = PackageManager.GET_ACTIVITIES;
        return true;
    case R.id.broadcasts:
        type = PackageManager.GET_RECEIVERS;
        return true;
    case R.id.services:
        type = PackageManager.GET_SERVICES;
        return true;
    case R.id.content_providers:
        type = PackageManager.GET_PROVIDERS;
        return true;

    case R.id.permission_filter_all:
        protection = PROTECTION_ANY;
        return true;
    case R.id.permission_filter_exported:
        protection = PROTECTION_ANY_EXPORTED;
        return true;
    case R.id.permission_filter_obtainable:
        protection = PROTECTION_ANY_OBTAINABLE;
        return true;
    case R.id.permission_filter_world_accessible:
        protection = PROTECTION_WORLD_ACCESSIBLE;
        return true;
    }
    return false;
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Load installed (user or system) packages.
 *//* w w w.jav a 2s  .c o  m*/
void loadInstalledPackages() {
    try {
        m_workList = new ArrayList<PackingItem>();
        int flags1 = PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS // use hides some app, may require permissions
                | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS // use hides some app, may require permissions
                | PackageManager.GET_SERVICES;

        int flags2 = PackageManager.GET_PERMISSIONS | PackageManager.GET_ACTIVITIES
                | PackageManager.GET_SERVICES;

        int flags3 = PackageManager.GET_PERMISSIONS;
        int flags4 = 0;
        boolean showSys = (m_show == SHOW_SYS);

        // Some packages will not appear with some flags.
        loadAndAddPackages(showSys, flags1);
        loadAndAddPackages(showSys, flags2);
        loadAndAddPackages(showSys, flags3);
        loadAndAddPackages(showSys, flags4);

        // Sort per settings.
        // TODO *** This does not seem to be working ***
        Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST);
        m_handler.sendMessage(msgObj);

    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }
}