Example usage for android.content.pm ApplicationInfo FLAG_SYSTEM

List of usage examples for android.content.pm ApplicationInfo FLAG_SYSTEM

Introduction

In this page you can find the example usage for android.content.pm ApplicationInfo FLAG_SYSTEM.

Prototype

int FLAG_SYSTEM

To view the source code for android.content.pm ApplicationInfo FLAG_SYSTEM.

Click Source Link

Document

Value for #flags : if set, this application is installed in the device's system image.

Usage

From source file:fr.simon.marquis.preferencesmanager.util.Utils.java

public static ArrayList<AppEntry> getApplications(Context ctx) {
    PackageManager pm = ctx.getPackageManager();
    if (pm == null) {
        applications = new ArrayList<AppEntry>();
    } else {//from w w w .  j  av a2  s.c o m
        boolean showSystemApps = isShowSystemApps(ctx);
        List<ApplicationInfo> appsInfo = pm.getInstalledApplications(
                PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
        if (appsInfo == null) {
            appsInfo = new ArrayList<ApplicationInfo>();
        }

        List<AppEntry> entries = new ArrayList<AppEntry>(appsInfo.size());
        for (ApplicationInfo a : appsInfo) {
            if (showSystemApps || (a.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                entries.add(new AppEntry(a, ctx));
            }
        }

        Collections.sort(entries, new MyComparator());
        applications = new ArrayList<AppEntry>(entries);
    }
    Log.d(TAG, "Applications: " + Arrays.toString(applications.toArray()));
    return applications;
}

From source file:com.jtechme.apphub.privileged.views.InstallConfirmActivity.java

private void startInstallConfirm() {

    final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm);
    final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm);

    View appSnippet = findViewById(R.id.app_snippet);
    ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon);
    ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel);

    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();/*from  w  w w  .  j  a va 2s  .  c  om*/
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
        }
    });

    boolean permVisible = false;
    mScrollView = null;
    mOkCanInstall = false;
    int msg = 0;
    AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo);
    if (mAppDiff.mInstalledAppInfo != null) {
        msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                ? R.string.install_confirm_update_system
                : R.string.install_confirm_update;
        mScrollView = new CaffeinatedScrollView(this);
        mScrollView.setFillViewport(true);
        final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0;
        if (newPermissionsFound) {
            permVisible = true;
            mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
        } else {
            throw new RuntimeException(
                    "This should not happen. No new permissions were found but InstallConfirmActivity has been started!");
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView);
    } else {
        findViewById(R.id.tabscontainer).setVisibility(View.GONE);
        findViewById(R.id.divider).setVisibility(View.VISIBLE);
    }
    final int np = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL);
    final int nd = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE);
    if (np > 0 || nd > 0) {
        permVisible = true;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View root = inflater.inflate(R.layout.permissions_list, null);
        if (mScrollView == null) {
            mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
        }
        final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist);
        if (np > 0) {
            privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL));
        } else {
            privacyList.setVisibility(View.GONE);
        }
        final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist);
        if (nd > 0) {
            deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE));
        } else {
            root.findViewById(R.id.devicelist).setVisibility(View.GONE);
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
    }

    if (!permVisible) {
        if (mAppDiff.mInstalledAppInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_update_system_no_perms
                    : R.string.install_confirm_update_no_perms;
        } else {
            // This is a new application with no permissions.
            msg = R.string.install_confirm_no_perms;
        }
        tabHost.setVisibility(View.GONE);
        findViewById(R.id.filler).setVisibility(View.VISIBLE);
        findViewById(R.id.divider).setVisibility(View.GONE);
        mScrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm)).setText(msg);
    }
    mInstallConfirm.setVisibility(View.VISIBLE);
    mOk = (Button) findViewById(R.id.ok_button);
    mCancel = (Button) findViewById(R.id.cancel_button);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);
    if (mScrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        mOk.setText(R.string.menu_install);
        mOkCanInstall = true;
    } else {
        mScrollView.setFullScrollAction(new Runnable() {
            @Override
            public void run() {
                mOk.setText(R.string.menu_install);
                mOkCanInstall = true;
            }
        });
    }
}

From source file:org.fdroid.fdroid.installer.InstallConfirmActivity.java

private void startInstallConfirm() {

    final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm);
    final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm);

    View appSnippet = findViewById(R.id.app_snippet);
    ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon);
    ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel);

    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();//from   w  w w.  j a  va  2s . co  m
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
        }
    });

    boolean permVisible = false;
    mScrollView = null;
    mOkCanInstall = false;
    int msg = 0;
    if (mAppDiff.mPkgInfo != null) {
        AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo);
        final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL);
        final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE);
        if (mAppDiff.mInstalledAppInfo != null) {
            msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_update_system
                    : R.string.install_confirm_update;
            mScrollView = new CaffeinatedScrollView(this);
            mScrollView.setFillViewport(true);
            final boolean newPermissionsFound = (perms
                    .getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0);
            if (newPermissionsFound) {
                permVisible = true;
                mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
            } else {
                throw new RuntimeException(
                        "This should not happen. No new permissions were found but InstallConfirmActivity has been started!");
            }
            adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)),
                    mScrollView);
        } else {
            findViewById(R.id.tabscontainer).setVisibility(View.GONE);
            findViewById(R.id.divider).setVisibility(View.VISIBLE);
        }
        if (NP > 0 || ND > 0) {
            permVisible = true;
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View root = inflater.inflate(R.layout.permissions_list, null);
            if (mScrollView == null) {
                mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
            }
            final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist);
            if (NP > 0) {
                privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL));
            } else {
                privacyList.setVisibility(View.GONE);
            }
            final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist);
            if (ND > 0) {
                deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE));
            } else {
                root.findViewById(R.id.devicelist).setVisibility(View.GONE);
            }
            adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
        }
    }
    if (!permVisible) {
        if (mAppDiff.mInstalledAppInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_update_system_no_perms
                    : R.string.install_confirm_update_no_perms;
        } else {
            // This is a new application with no permissions.
            msg = R.string.install_confirm_no_perms;
        }
        tabHost.setVisibility(View.GONE);
        findViewById(R.id.filler).setVisibility(View.VISIBLE);
        findViewById(R.id.divider).setVisibility(View.GONE);
        mScrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm)).setText(msg);
    }
    mInstallConfirm.setVisibility(View.VISIBLE);
    mOk = (Button) findViewById(R.id.ok_button);
    mCancel = (Button) findViewById(R.id.cancel_button);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);
    if (mScrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        mOk.setText(R.string.menu_install);
        mOkCanInstall = true;
    } else {
        mScrollView.setFullScrollAction(new Runnable() {
            @Override
            public void run() {
                mOk.setText(R.string.menu_install);
                mOkCanInstall = true;
            }
        });
    }
}

From source file:com.xargsgrep.portknocker.asynctask.RetrieveApplicationsAsyncTask.java

private boolean isSystemPackage(ApplicationInfo applicationInfo) {
    return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
}

From source file:com.shivshankar.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d("TAGRK", "From: " + remoteMessage.getFrom());
    String message = "", title = "", strImageURL = "";
    if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
        Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());

        message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);
        title = "" + remoteMessage.getData().get(Config.TITLE_KEY);
        strImageURL = "" + remoteMessage.getData().get(Config.IMAGE_KEY);
    } else if (remoteMessage.getNotification() != null) {
        Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        message = "" + remoteMessage.getNotification().getBody();
        title = "" + remoteMessage.getNotification().getTitle();
        strImageURL = "" + remoteMessage.getNotification().getIcon();
    }// w w w. j a  va 2  s.c  om

    if (strImageURL != null && !strImageURL.equals("") && !strImageURL.equals("null")) {
        Handler handler = new Handler(Looper.getMainLooper());
        final String finalTitle = title;
        final String finalMessage = message;
        final String finalStrImageURL = strImageURL;
        handler.post(new Runnable() {
            public void run() {
                new ServerAPICallImageBitmap(finalTitle, finalMessage, finalStrImageURL, "").execute();
            }
        });
    } else if (title.equalsIgnoreCase("Logout")) {
        try {
            SharedPreferences.Editor editor = AppPreferences.getPrefs().edit();
            editor.putString(commonVariables.KEY_LOGIN_ID, "0");
            editor.putBoolean(commonVariables.KEY_IS_LOG_IN, false);
            editor.putString(commonVariables.KEY_SELLER_PROFILE, "");
            editor.putString(commonVariables.KEY_BUYER_PROFILE, "");
            editor.putString(commonVariables.KEY_BRAND, "");
            editor.putBoolean(commonVariables.KEY_IS_BRAND, false);
            editor.putBoolean(commonVariables.KEY_IS_SELLER, false);
            editor.putBoolean(commonVariables.KEY_IS_SKIPPED_LOGIN_BUYER, false);
            editor.commit();
            android.os.Process.killProcess(android.os.Process.myPid());
            List<ApplicationInfo> packages;
            PackageManager pm;
            pm = getPackageManager();
            packages = pm.getInstalledApplications(0);

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            String myPackage = getApplicationContext().getPackageName();
            for (ApplicationInfo packageInfo : packages) {
                if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
                    continue;
                if (packageInfo.packageName.equals(myPackage))
                    continue;
                mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            }
            mActivityManager.restartPackage(myPackage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        sendNotification(title, message);
    Log.i("TAGRK", "Received: " + remoteMessage.toString());
}

From source file:com.android.settings.applications.CanBeOnSdCardChecker.java

boolean check(ApplicationInfo info) {
    boolean canBe = false;
    if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
        canBe = true;//from w  ww  .ja va  2s  .  co m
    } else {
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            if (info.installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL
                    || info.installLocation == PackageInfo.INSTALL_LOCATION_AUTO) {
                canBe = true;
            } else if (info.installLocation == PackageInfo.INSTALL_LOCATION_UNSPECIFIED) {
                if (mInstallLocation == PackageHelper.APP_INSTALL_EXTERNAL) {
                    // For apps with no preference and the default value set
                    // to install on sdcard.
                    canBe = true;
                }
            }
        }
    }
    return canBe;
}

From source file:org.durka.hallmonitor.CoreStateManager.java

CoreStateManager(Context context) {
    mAppContext = context;//  w w  w.jav  a  2  s.  c om
    mPowerManager = (PowerManager) mAppContext.getSystemService(Context.POWER_SERVICE);
    daPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreStateManager");
    daPartialWakeLock.setReferenceCounted(false);
    globalPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver");
    globalPartialWakeLock.setReferenceCounted(true);

    preference_all = PreferenceManager.getDefaultSharedPreferences(mAppContext);

    // Enable access to sleep mode
    systemApp = (mAppContext.getApplicationInfo().flags
            & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    if (systemApp) {
        Log.d(LOG_TAG, "We are a system app.");
    } else {
        Log.d(LOG_TAG, "We are not a system app.");
        preference_all.edit().putBoolean("pref_internal_power_management", false).commit();
    }

    refreshAdminApp();
    refreshRootApp();

    refreshLockMode();
    refreshOsPowerManagement();
    refreshInternalPowerManagement();

    refreshInternalService();

    if (preference_all.getBoolean("pref_proximity", false)) {
        forceCheckCoverState = true;
    }

    hmAppWidgetManager = new HMAppWidgetManager(this);

    if (preference_all.getBoolean("pref_default_widget", false)) {
        int widgetId = preference_all.getInt("default_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("default");
        } else {
            createWidget("default");
        }
    }

    if (preference_all.getBoolean("pref_media_widget", false)) {
        audioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

        int widgetId = preference_all.getInt("media_widget_id", -1);
        if (widgetId == -1) {
            registerWidget("media");
        } else {
            createWidget("media");
        }
    }

    this.hardwareAccelerated = preference_all.getBoolean("pref_hardwareAccelerated", false);

    // we might have missed a phone-state revelation
    phone_ringing = ((TelephonyManager) mAppContext.getSystemService(Context.TELEPHONY_SERVICE))
            .getCallState() == TelephonyManager.CALL_STATE_RINGING;
    // we might have missed an alarm alert
    // TODO: find a way
    // alarm_firing =
    // ((TelephonyManager)
    // mAppContext.getSystemService(Context.TELEPHONY_SERVICE)).getCallState()
    // == TelephonyManager.CALL_STATE_RINGING;
    Intent stateIntent = mAppContext.registerReceiver(null, new IntentFilter(CoreReceiver.TORCH_STATE_CHANGED));
    torch_on = stateIntent != null && stateIntent.getIntExtra("state", 0) != 0;

    init = true;
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void startInstallConfirm() {
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();/*from   w  w w  .java  2  s .com*/
    tabHost.setVisibility(View.VISIBLE);
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager);
    // If the app supports runtime permissions the new permissions will
    // be requested at runtime, hence we do not show them at install.
    boolean supportsRuntimePermissions = mPkgInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M;
    boolean permVisible = false;
    mScrollView = null;
    mOkCanInstall = false;
    int msg = 0;

    AppSecurityPermissions perms = new AppSecurityPermissions(this, mPkgInfo);
    final int N = perms.getPermissionCount(AppSecurityPermissions.WHICH_ALL);
    if (mAppInfo != null) {
        msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                ? R.string.install_confirm_question_update_system
                : R.string.install_confirm_question_update;
        mScrollView = new CaffeinatedScrollView(this);
        mScrollView.setFillViewport(true);
        boolean newPermissionsFound = false;
        if (!supportsRuntimePermissions) {
            newPermissionsFound = (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0);
            if (newPermissionsFound) {
                permVisible = true;
                mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW));
            }
        }
        if (!supportsRuntimePermissions && !newPermissionsFound) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            TextView label = (TextView) inflater.inflate(R.layout.label, null);
            label.setText(R.string.no_new_perms);
            mScrollView.addView(label);
        }
        adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView);
    } else {
        findViewById(R.id.tabscontainer).setVisibility(View.GONE);
        findViewById(R.id.spacer).setVisibility(View.VISIBLE);
    }
    if (!supportsRuntimePermissions && N > 0) {
        permVisible = true;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View root = inflater.inflate(R.layout.permissions_list, null);
        if (mScrollView == null) {
            mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview);
        }
        ((ViewGroup) root.findViewById(R.id.permission_list))
                .addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_ALL));
        adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root);
    }
    if (!permVisible) {
        if (mAppInfo != null) {
            // This is an update to an application, but there are no
            // permissions at all.
            msg = (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
                    ? R.string.install_confirm_question_update_system_no_perms
                    : R.string.install_confirm_question_update_no_perms;

            findViewById(R.id.spacer).setVisibility(View.VISIBLE);
        } else {
            // This is a new application with no permissions.
            msg = R.string.install_confirm_question_no_perms;
        }
        tabHost.setVisibility(View.INVISIBLE);
        mScrollView = null;
    }
    if (msg != 0) {
        ((TextView) findViewById(R.id.install_confirm_question)).setText(msg);
    }
    mInstallConfirm.setVisibility(View.VISIBLE);
    mOk.setEnabled(true);
    if (mScrollView == null) {
        // There is nothing to scroll view, so the ok button is immediately
        // set to install.
        mOk.setText(R.string.install);
        mOkCanInstall = true;
    } else {
        mScrollView.setFullScrollAction(new Runnable() {
            @Override
            public void run() {
                mOk.setText(R.string.install);
                mOkCanInstall = true;
            }
        });
    }
}

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 ww.  j a v a 2  s.  c  o  m*/
        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.wso2.app.catalog.api.ApplicationManager.java

/**
 * Returns whether the app is a system app.
 *
 * @param packageInfo - Package of the app which you need the status.
 * @return - App status.//www .ja  va2 s  .  co  m
 */
private boolean isSystemPackage(PackageInfo packageInfo) {
    return ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
}