Example usage for android.content ComponentName getPackageName

List of usage examples for android.content ComponentName getPackageName

Introduction

In this page you can find the example usage for android.content ComponentName getPackageName.

Prototype

public @NonNull String getPackageName() 

Source Link

Document

Return the package name of this component.

Usage

From source file:com.fairphone.fplauncher3.Workspace.java

public void updatePackageState(ArrayList<PackageInstallInfo> installInfos) {
    HashSet<String> completedPackages = new HashSet<String>();

    for (final PackageInstallInfo installInfo : installInfos) {
        mapOverItems(MAP_RECURSE, new ItemOperator() {
            @Override/*from   ww w .j ava 2s. c o m*/
            public boolean evaluate(ItemInfo info, View v, View parent) {
                if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                    ShortcutInfo si = (ShortcutInfo) info;
                    ComponentName cn = si.getTargetComponent();
                    if (si.isPromise() && (cn != null) && installInfo.packageName.equals(cn.getPackageName())) {
                        si.setInstallProgress(installInfo.progress);
                        if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                            // Mark this info as broken.
                            si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
                        }
                        ((BubbleTextView) v).applyState(false);
                    }
                } else if (v instanceof PendingAppWidgetHostView && info instanceof LauncherAppWidgetInfo
                        && ((LauncherAppWidgetInfo) info).providerName.getPackageName()
                                .equals(installInfo.packageName)) {
                    ((LauncherAppWidgetInfo) info).installProgress = installInfo.progress;
                    ((PendingAppWidgetHostView) v).applyState();
                }

                // process all the shortcuts
                return false;
            }
        });

        if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
            completedPackages.add(installInfo.packageName);
        }
    }

    // Note that package states are sent only for myUser
    if (!completedPackages.isEmpty()) {
        restorePendingWidgets(completedPackages);
    }
}

From source file:com.android.launcher3.Workspace.java

void removeItemsByPackageName(final ArrayList<String> packages, final UserHandleCompat user) {
    final HashSet<String> packageNames = new HashSet<String>();
    packageNames.addAll(packages);/*from  www.  ja v a2 s  .  c om*/

    // Filter out all the ItemInfos that this is going to affect
    final HashSet<ItemInfo> infos = new HashSet<ItemInfo>();
    final HashSet<ComponentName> cns = new HashSet<ComponentName>();
    ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
    for (CellLayout layoutParent : cellLayouts) {
        ViewGroup layout = layoutParent.getShortcutsAndWidgets();
        int childCount = layout.getChildCount();
        for (int i = 0; i < childCount; ++i) {
            View view = layout.getChildAt(i);
            infos.add((ItemInfo) view.getTag());
        }
    }
    LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() {
        @Override
        public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
            if (packageNames.contains(cn.getPackageName()) && info.user.equals(user)) {
                cns.add(cn);
                return true;
            }
            return false;
        }
    };
    LauncherModel.filterItemInfos(infos, filter);

    // Remove the affected components
    removeItemsByComponentName(cns, user);
}

From source file:com.android.soma.Launcher.java

public void startVoice() {
    try {/*from  w w w.  ja  v a2  s  .  c o  m*/
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        ComponentName activityName = searchManager.getGlobalSearchActivity();
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (activityName != null) {
            intent.setPackage(activityName.getPackageName());
        }
        startActivity(null, intent, "onClickVoiceButton");
    } catch (ActivityNotFoundException e) {
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivitySafely(null, intent, "onClickVoiceButton");
    }
}

From source file:com.fairphone.fplauncher3.Workspace.java

private void updateShortcutsAndWidgetsPerUser(ArrayList<AppInfo> apps, final UserHandleCompat user) {
    // Create a map of the apps to test against
    final HashMap<ComponentName, AppInfo> appsMap = new HashMap<ComponentName, AppInfo>();
    final HashSet<String> pkgNames = new HashSet<String>();
    for (AppInfo ai : apps) {
        appsMap.put(ai.componentName, ai);
        pkgNames.add(ai.componentName.getPackageName());
    }//from w  ww  .ja  v a2  s .  c o m
    final HashSet<ComponentName> iconsToRemove = new HashSet<ComponentName>();

    mapOverItems(MAP_RECURSE, new ItemOperator() {
        @Override
        public boolean evaluate(ItemInfo info, View v, View parent) {
            if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                ComponentName cn = shortcutInfo.getTargetComponent();
                AppInfo appInfo = appsMap.get(cn);
                if (user.equals(shortcutInfo.user) && cn != null && LauncherModel.isShortcutInfoUpdateable(info)
                        && pkgNames.contains(cn.getPackageName())) {
                    boolean promiseStateChanged = false;
                    boolean infoUpdated = false;
                    if (shortcutInfo.isPromise()) {
                        if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                            // Auto install icon
                            PackageManager pm = getContext().getPackageManager();
                            ResolveInfo matched = pm
                                    .resolveActivity(
                                            new Intent(Intent.ACTION_MAIN).setComponent(cn)
                                                    .addCategory(Intent.CATEGORY_LAUNCHER),
                                            PackageManager.MATCH_DEFAULT_ONLY);
                            if (matched == null) {
                                // Try to find the best match activity.
                                Intent intent = pm.getLaunchIntentForPackage(cn.getPackageName());
                                if (intent != null) {
                                    cn = intent.getComponent();
                                    appInfo = appsMap.get(cn);
                                }

                                if ((intent == null) || (appsMap == null)) {
                                    // Could not find a default activity. Remove this item.
                                    iconsToRemove.add(shortcutInfo.getTargetComponent());

                                    // process next shortcut.
                                    return false;
                                }
                                shortcutInfo.promisedIntent = intent;
                            }
                        }

                        // Restore the shortcut.
                        shortcutInfo.intent = shortcutInfo.promisedIntent;
                        shortcutInfo.promisedIntent = null;
                        shortcutInfo.status &= ~ShortcutInfo.FLAG_RESTORED_ICON
                                & ~ShortcutInfo.FLAG_AUTOINTALL_ICON
                                & ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;

                        promiseStateChanged = true;
                        infoUpdated = true;
                        shortcutInfo.updateIcon(mIconCache);
                        LauncherModel.updateItemInDatabase(getContext(), shortcutInfo);
                    }

                    if (appInfo != null) {
                        shortcutInfo.updateIcon(mIconCache);
                        shortcutInfo.title = appInfo.title.toString();
                        shortcutInfo.contentDescription = appInfo.contentDescription;
                        infoUpdated = true;
                    }

                    if (infoUpdated) {
                        BubbleTextView shortcut = (BubbleTextView) v;
                        shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, promiseStateChanged);

                        if (parent != null) {
                            parent.invalidate();
                        }
                    }
                }
            }
            // process all the shortcuts
            return false;
        }
    });

    if (!iconsToRemove.isEmpty()) {
        removeItemsByComponentName(iconsToRemove, user);
    }
    if (user.equals(UserHandleCompat.myUserHandle())) {
        restorePendingWidgets(pkgNames);
    }
}

From source file:com.android.launcher3.Workspace.java

public void updatePackageState(ArrayList<PackageInstallInfo> installInfos) {
    for (final PackageInstallInfo installInfo : installInfos) {
        if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
            continue;
        }/*from  w w  w . j  av  a 2 s. c  om*/

        mapOverItems(MAP_RECURSE, new ItemOperator() {
            @Override
            public boolean evaluate(ItemInfo info, View v, View parent) {
                if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                    ShortcutInfo si = (ShortcutInfo) info;
                    ComponentName cn = si.getTargetComponent();
                    if (si.isPromise() && (cn != null) && installInfo.packageName.equals(cn.getPackageName())) {
                        si.setInstallProgress(installInfo.progress);
                        if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) {
                            // Mark this info as broken.
                            si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
                        }
                        ((BubbleTextView) v).applyState(false);
                    }
                } else if (v instanceof PendingAppWidgetHostView && info instanceof LauncherAppWidgetInfo
                        && ((LauncherAppWidgetInfo) info).providerName.getPackageName()
                                .equals(installInfo.packageName)) {
                    ((LauncherAppWidgetInfo) info).installProgress = installInfo.progress;
                    ((PendingAppWidgetHostView) v).applyState();
                }

                // process all the shortcuts
                return false;
            }
        });
    }
}

From source file:com.android.launcher3.Workspace.java

public void disableShortcutsByPackageName(final ArrayList<String> packages, final UserHandleCompat user,
        final int reason) {
    final HashSet<String> packageNames = new HashSet<String>();
    packageNames.addAll(packages);//from w  ww . jav  a  2  s.  co m

    mapOverItems(MAP_RECURSE, new ItemOperator() {
        @Override
        public boolean evaluate(ItemInfo info, View v, View parent) {
            if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                ComponentName cn = shortcutInfo.getTargetComponent();
                if (user.equals(shortcutInfo.user) && cn != null
                        && packageNames.contains(cn.getPackageName())) {
                    shortcutInfo.isDisabled |= reason;
                    BubbleTextView shortcut = (BubbleTextView) v;
                    shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false);

                    if (parent != null) {
                        parent.invalidate();
                    }
                }
            }
            // process all the shortcuts
            return false;
        }
    });
}

From source file:com.android.soma.Launcher.java

protected boolean updateVoiceSearchIcon(boolean searchVisible) {
    final View voiceButtonContainer = findViewById(R.id.voice_button_container);
    final View voiceButton = findViewById(R.id.voice_button);

    // We only show/update the voice search icon if the search icon is enabled as well
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();

    ComponentName activityName = null;//from  w w w.  j  a va2s.c om
    if (globalSearchActivity != null) {
        // Check if the global search activity handles voice search
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setPackage(globalSearchActivity.getPackageName());
        activityName = intent.resolveActivity(getPackageManager());
    }

    if (activityName == null) {
        // Fallback: check if an activity other than the global search activity
        // resolves this
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        activityName = intent.resolveActivity(getPackageManager());
    }
    if (searchVisible && activityName != null) {
        int coi = getCurrentOrientationIndexForGlobalIcons();
        sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName,
                R.drawable.ic_home_voice_search_holo, TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
        if (sVoiceSearchIcon[coi] == null) {
            sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName,
                    R.drawable.ic_home_voice_search_holo, TOOLBAR_ICON_METADATA_NAME);
        }
        if (voiceButtonContainer != null)
            voiceButtonContainer.setVisibility(View.VISIBLE);
        voiceButton.setVisibility(View.VISIBLE);
        updateVoiceButtonProxyVisible(false);
        invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
        return true;
    } else {
        if (voiceButtonContainer != null)
            voiceButtonContainer.setVisibility(View.GONE);
        if (voiceButton != null)
            voiceButton.setVisibility(View.GONE);
        updateVoiceButtonProxyVisible(false);
        return false;
    }
}

From source file:com.android.launcher3.Workspace.java

public void updatePackageBadge(final String packageName, final UserHandleCompat user) {
    mapOverItems(MAP_RECURSE, new ItemOperator() {
        @Override/*from w w  w.j  av a 2s  .co  m*/
        public boolean evaluate(ItemInfo info, View v, View parent) {
            if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                ComponentName cn = shortcutInfo.getTargetComponent();
                if (user.equals(shortcutInfo.user) && cn != null && shortcutInfo.isPromise()
                        && packageName.equals(cn.getPackageName())) {
                    if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                        // For auto install apps update the icon as well as label.
                        mIconCache.getTitleAndIcon(shortcutInfo, shortcutInfo.promisedIntent, user, true);
                    } else {
                        // Only update the icon for restored apps.
                        shortcutInfo.updateIcon(mIconCache);
                    }
                    BubbleTextView shortcut = (BubbleTextView) v;
                    shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false);

                    if (parent != null) {
                        parent.invalidate();
                    }
                }
            }
            // process all the shortcuts
            return false;
        }
    });
}

From source file:com.android.soma.Launcher.java

boolean startApplicationUninstallActivity(ComponentName componentName, int flags) {
    if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
        // System applications cannot be installed. For now, show a toast explaining that.
        // We may give them the option of disabling apps this way.
        int messageId = R.string.uninstall_system_app_text;
        Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
        return false;
    } else {/*from w w w  .j a  v  a  2s  .  co m*/
        String packageName = componentName.getPackageName();
        String className = componentName.getClassName();
        Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        startActivity(intent);
        return true;
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
public void startActivity(Intent intent) {
    // TODO Auto-generated method stub
    PersonaLog.d("PersonaLauncher", " -- startActivity ----");
    final ComponentName name = intent.getComponent();
    if (name != null) {
        PersonaLog.d("personalauncher", "updateCountersForPackage called from startactivity");
        updateCountersForPackage(name.getPackageName(), 0, 0, 0);
    }/*from  w  w  w. j ava2  s  .  co  m*/
    PersonaLog.d("personalauncher", "parameter passed is " + name.getPackageName());
    PersonaLog.d("personalauncher", "--------inside startactivity----- intent is " + intent.toString());
    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        Toast.makeText(this, getString(R.string.activity_not_found) + "123", Toast.LENGTH_SHORT).show();
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        PersonaLog.e(LOG_TAG,
                "PersonaLauncher does not have the permission to launch " + intent
                        + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                        + "or use the exported attribute for this activity.",
                e);
    }
}