Search in sources :

Example 86 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by DirtyUnicorns.

the class RecentTasks method cleanupLocked.

/**
     * Update the recent tasks lists: make sure tasks should still be here (their
     * applications / activities still exist), update their availability, fix-up ordering
     * of affiliations.
     */
void cleanupLocked(int userId) {
    int recentsCount = size();
    if (recentsCount == 0) {
        // or just any empty list.
        return;
    }
    final IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = recentsCount - 1; i >= 0; i--) {
        final TaskRecord task = get(i);
        if (userId != UserHandle.USER_ALL && task.userId != userId) {
            // Only look at tasks for the user ID of interest.
            continue;
        }
        if (task.autoRemoveRecents && task.getTopActivity() == null) {
            // This situation is broken, and we should just get rid of it now.
            remove(i);
            task.removedFromRecents();
            Slog.w(TAG, "Removing auto-remove without activity: " + task);
            continue;
        }
        // Check whether this activity is currently available.
        if (task.realActivity != null) {
            ActivityInfo ai = mTmpAvailActCache.get(task.realActivity);
            if (ai == null) {
                try {
                    // At this first cut, we're only interested in
                    // activities that are fully runnable based on
                    // current system state.
                    ai = pm.getActivityInfo(task.realActivity, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userId);
                } catch (RemoteException e) {
                    // Will never happen.
                    continue;
                }
                if (ai == null) {
                    ai = mTmpActivityInfo;
                }
                mTmpAvailActCache.put(task.realActivity, ai);
            }
            if (ai == mTmpActivityInfo) {
                // This could be either because the activity no longer exists, or the
                // app is temporarily gone. For the former we want to remove the recents
                // entry; for the latter we want to mark it as unavailable.
                ApplicationInfo app = mTmpAvailAppCache.get(task.realActivity.getPackageName());
                if (app == null) {
                    try {
                        app = pm.getApplicationInfo(task.realActivity.getPackageName(), PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
                    } catch (RemoteException e) {
                        // Will never happen.
                        continue;
                    }
                    if (app == null) {
                        app = mTmpAppInfo;
                    }
                    mTmpAvailAppCache.put(task.realActivity.getPackageName(), app);
                }
                if (app == mTmpAppInfo || (app.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                    // Doesn't exist any more! Good-bye.
                    remove(i);
                    task.removedFromRecents();
                    Slog.w(TAG, "Removing no longer valid recent: " + task);
                    continue;
                } else {
                    // Otherwise just not available for now.
                    if (DEBUG_RECENTS && task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent unavailable: " + task);
                    task.isAvailable = false;
                }
            } else {
                if (!ai.enabled || !ai.applicationInfo.enabled || (ai.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
                    if (DEBUG_RECENTS && task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent unavailable: " + task + " (enabled=" + ai.enabled + "/" + ai.applicationInfo.enabled + " flags=" + Integer.toHexString(ai.applicationInfo.flags) + ")");
                    task.isAvailable = false;
                } else {
                    if (DEBUG_RECENTS && !task.isAvailable)
                        Slog.d(TAG_RECENTS, "Making recent available: " + task);
                    task.isAvailable = true;
                }
            }
        }
    }
    // Verify the affiliate chain for each task.
    int i = 0;
    recentsCount = size();
    while (i < recentsCount) {
        i = processNextAffiliateChainLocked(i);
    }
// recent tasks are now in sorted, affiliated order.
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 87 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by DirtyUnicorns.

the class InputManagerService method visitAllKeyboardLayouts.

private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) {
    final PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
    for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE)) {
        final ActivityInfo activityInfo = resolveInfo.activityInfo;
        final int priority = resolveInfo.priority;
        visitKeyboardLayoutsInPackage(pm, activityInfo, null, priority, visitor);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 88 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by DirtyUnicorns.

the class Searchables method findWebSearchActivity.

/**
     * Finds the web search activity.
     *
     * Only looks in the package of the global search activity.
     */
private ComponentName findWebSearchActivity(ComponentName globalSearchActivity) {
    if (globalSearchActivity == null) {
        return null;
    }
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.setPackage(globalSearchActivity.getPackageName());
    List<ResolveInfo> activities = queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (activities != null && !activities.isEmpty()) {
        ActivityInfo ai = activities.get(0).activityInfo;
        // TODO: do some sanity checks here?
        return new ComponentName(ai.packageName, ai.name);
    }
    Log.w(LOG_TAG, "No web search activity found");
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 89 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by DirtyUnicorns.

the class Searchables method updateSearchableList.

/**
     * Builds an entire list (suitable for display) of
     * activities that are searchable, by iterating the entire set of
     * ACTION_SEARCH & ACTION_WEB_SEARCH intents.
     *
     * Also clears the hash of all activities -> searches which will
     * refill as the user clicks "search".
     *
     * This should only be done at startup and again if we know that the
     * list has changed.
     *
     * TODO: every activity that provides a ACTION_SEARCH intent should
     * also provide searchability meta-data.  There are a bunch of checks here
     * that, if data is not found, silently skip to the next activity.  This
     * won't help a developer trying to figure out why their activity isn't
     * showing up in the list, but an exception here is too rough.  I would
     * like to find a better notification mechanism.
     *
     * TODO: sort the list somehow?  UI choice.
     */
public void updateSearchableList() {
    // These will become the new values at the end of the method
    HashMap<ComponentName, SearchableInfo> newSearchablesMap = new HashMap<ComponentName, SearchableInfo>();
    ArrayList<SearchableInfo> newSearchablesList = new ArrayList<SearchableInfo>();
    ArrayList<SearchableInfo> newSearchablesInGlobalSearchList = new ArrayList<SearchableInfo>();
    // Use intent resolver to generate list of ACTION_SEARCH & ACTION_WEB_SEARCH receivers.
    List<ResolveInfo> searchList;
    final Intent intent = new Intent(Intent.ACTION_SEARCH);
    long ident = Binder.clearCallingIdentity();
    try {
        searchList = queryIntentActivities(intent, PackageManager.GET_META_DATA | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
        List<ResolveInfo> webSearchInfoList;
        final Intent webSearchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
        webSearchInfoList = queryIntentActivities(webSearchIntent, PackageManager.GET_META_DATA | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
        // analyze each one, generate a Searchables record, and record
        if (searchList != null || webSearchInfoList != null) {
            int search_count = (searchList == null ? 0 : searchList.size());
            int web_search_count = (webSearchInfoList == null ? 0 : webSearchInfoList.size());
            int count = search_count + web_search_count;
            for (int ii = 0; ii < count; ii++) {
                // for each component, try to find metadata
                ResolveInfo info = (ii < search_count) ? searchList.get(ii) : webSearchInfoList.get(ii - search_count);
                ActivityInfo ai = info.activityInfo;
                // Check first to avoid duplicate entries.
                if (newSearchablesMap.get(new ComponentName(ai.packageName, ai.name)) == null) {
                    SearchableInfo searchable = SearchableInfo.getActivityMetaData(mContext, ai, mUserId);
                    if (searchable != null) {
                        newSearchablesList.add(searchable);
                        newSearchablesMap.put(searchable.getSearchActivity(), searchable);
                        if (searchable.shouldIncludeInGlobalSearch()) {
                            newSearchablesInGlobalSearchList.add(searchable);
                        }
                    }
                }
            }
        }
        List<ResolveInfo> newGlobalSearchActivities = findGlobalSearchActivities();
        // Find the global search activity
        ComponentName newGlobalSearchActivity = findGlobalSearchActivity(newGlobalSearchActivities);
        // Find the web search activity
        ComponentName newWebSearchActivity = findWebSearchActivity(newGlobalSearchActivity);
        // Store a consistent set of new values
        synchronized (this) {
            mSearchablesMap = newSearchablesMap;
            mSearchablesList = newSearchablesList;
            mSearchablesInGlobalSearchList = newSearchablesInGlobalSearchList;
            mGlobalSearchActivities = newGlobalSearchActivities;
            mCurrentGlobalSearchActivity = newGlobalSearchActivity;
            mWebSearchActivity = newWebSearchActivity;
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) HashMap(java.util.HashMap) SearchableInfo(android.app.SearchableInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 90 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by DirtyUnicorns.

the class ShortcutManager method loadShortcuts.

private void loadShortcuts() {
    PackageManager packageManager = mContext.getPackageManager();
    try {
        XmlResourceParser parser = mContext.getResources().getXml(com.android.internal.R.xml.bookmarks);
        XmlUtils.beginDocument(parser, TAG_BOOKMARKS);
        while (true) {
            XmlUtils.nextElement(parser);
            if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
                break;
            }
            if (!TAG_BOOKMARK.equals(parser.getName())) {
                break;
            }
            String packageName = parser.getAttributeValue(null, ATTRIBUTE_PACKAGE);
            String className = parser.getAttributeValue(null, ATTRIBUTE_CLASS);
            String shortcutName = parser.getAttributeValue(null, ATTRIBUTE_SHORTCUT);
            String categoryName = parser.getAttributeValue(null, ATTRIBUTE_CATEGORY);
            String shiftName = parser.getAttributeValue(null, ATTRIBUTE_SHIFT);
            if (TextUtils.isEmpty(shortcutName)) {
                Log.w(TAG, "Unable to get shortcut for: " + packageName + "/" + className);
                continue;
            }
            final int shortcutChar = shortcutName.charAt(0);
            final boolean isShiftShortcut = (shiftName != null && shiftName.equals("true"));
            final Intent intent;
            final String title;
            if (packageName != null && className != null) {
                ActivityInfo info = null;
                ComponentName componentName = new ComponentName(packageName, className);
                try {
                    info = packageManager.getActivityInfo(componentName, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_UNINSTALLED_PACKAGES);
                } catch (PackageManager.NameNotFoundException e) {
                    String[] packages = packageManager.canonicalToCurrentPackageNames(new String[] { packageName });
                    componentName = new ComponentName(packages[0], className);
                    try {
                        info = packageManager.getActivityInfo(componentName, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE | PackageManager.MATCH_UNINSTALLED_PACKAGES);
                    } catch (PackageManager.NameNotFoundException e1) {
                        Log.w(TAG, "Unable to add bookmark: " + packageName + "/" + className, e);
                        continue;
                    }
                }
                intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setComponent(componentName);
                title = info.loadLabel(packageManager).toString();
            } else if (categoryName != null) {
                intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, categoryName);
                title = "";
            } else {
                Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutName + ": missing package/class or category attributes");
                continue;
            }
            ShortcutInfo shortcut = new ShortcutInfo(title, intent);
            if (isShiftShortcut) {
                mShiftShortcuts.put(shortcutChar, shortcut);
            } else {
                mShortcuts.put(shortcutChar, shortcut);
            }
        }
    } catch (XmlPullParserException e) {
        Log.w(TAG, "Got exception parsing bookmarks.", e);
    } catch (IOException e) {
        Log.w(TAG, "Got exception parsing bookmarks.", e);
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) Intent(android.content.Intent) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

ActivityInfo (android.content.pm.ActivityInfo)886 ResolveInfo (android.content.pm.ResolveInfo)360 Intent (android.content.Intent)339 ComponentName (android.content.ComponentName)324 PackageManager (android.content.pm.PackageManager)215 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)141 ArrayList (java.util.ArrayList)139 ApplicationInfo (android.content.pm.ApplicationInfo)115 Test (org.junit.Test)113 RemoteException (android.os.RemoteException)82 Bundle (android.os.Bundle)68 PendingIntent (android.app.PendingIntent)62 Drawable (android.graphics.drawable.Drawable)61 IOException (java.io.IOException)60 PackageInfo (android.content.pm.PackageInfo)59 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)54 XmlResourceParser (android.content.res.XmlResourceParser)43 Point (android.graphics.Point)35 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)34 Context (android.content.Context)33