Search in sources :

Example 46 with ActivityInfo

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

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
    flags = service.updateFlagsForResolve(flags, userId, intent);
    List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0);
    if (PackageManagerService.DEBUG_PREFERRED)
        Log.d(TAG, "Queried " + intent + " results: " + ri);
    int systemMatch = 0;
    int thirdPartyMatch = 0;
    if (ri != null && ri.size() > 1) {
        boolean haveAct = false;
        ComponentName haveNonSys = null;
        ComponentName[] set = new ComponentName[ri.size()];
        for (int i = 0; i < ri.size(); i++) {
            ActivityInfo ai = ri.get(i).activityInfo;
            set[i] = new ComponentName(ai.packageName, ai.name);
            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (ri.get(i).match >= thirdPartyMatch) {
                    // want to set a preferred app for this intent.
                    if (PackageManagerService.DEBUG_PREFERRED)
                        Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!");
                    haveNonSys = set[i];
                    break;
                }
            } else if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!");
                haveAct = true;
                systemMatch = ri.get(i).match;
            } else {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped");
            }
        }
        if (haveNonSys != null && thirdPartyMatch < systemMatch) {
            // If we have a matching third party app, but its match is not as
            // good as the built-in system app, then we don't want to actually
            // consider it a match because presumably the built-in app is still
            // the thing we want users to see by default.
            haveNonSys = null;
        }
        if (haveAct && haveNonSys == null) {
            IntentFilter filter = new IntentFilter();
            if (intent.getAction() != null) {
                filter.addAction(intent.getAction());
            }
            if (intent.getCategories() != null) {
                for (String cat : intent.getCategories()) {
                    filter.addCategory(cat);
                }
            }
            if ((flags & MATCH_DEFAULT_ONLY) != 0) {
                filter.addCategory(Intent.CATEGORY_DEFAULT);
            }
            if (scheme != null) {
                filter.addDataScheme(scheme);
            }
            if (ssp != null) {
                filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType());
            }
            if (auth != null) {
                filter.addDataAuthority(auth);
            }
            if (path != null) {
                filter.addDataPath(path);
            }
            if (intent.getType() != null) {
                try {
                    filter.addDataType(intent.getType());
                } catch (IntentFilter.MalformedMimeTypeException ex) {
                    Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
                }
            }
            PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true);
            editPreferredActivitiesLPw(userId).addFilter(pa);
        } else if (haveNonSys == null) {
            StringBuilder sb = new StringBuilder();
            sb.append("No component ");
            sb.append(cn.flattenToShortString());
            sb.append(" found setting preferred ");
            sb.append(intent);
            sb.append("; possible matches are ");
            for (int i = 0; i < set.length; i++) {
                if (i > 0)
                    sb.append(", ");
                sb.append(set[i].flattenToShortString());
            }
            Slog.w(TAG, sb.toString());
        } else {
            Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " + haveNonSys.flattenToShortString());
        }
    } else {
        Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred " + cn.flattenToShortString());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) IntentFilter(android.content.IntentFilter) ComponentName(android.content.ComponentName)

Example 47 with ActivityInfo

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

the class ShortcutParser method parseShortcuts.

@Nullable
public static List<ShortcutInfo> parseShortcuts(ShortcutService service, String packageName, @UserIdInt int userId) throws IOException, XmlPullParserException {
    if (ShortcutService.DEBUG) {
        Slog.d(TAG, String.format("Scanning package %s for manifest shortcuts on user %d", packageName, userId));
    }
    final List<ResolveInfo> activities = service.injectGetMainActivities(packageName, userId);
    if (activities == null || activities.size() == 0) {
        return null;
    }
    List<ShortcutInfo> result = null;
    try {
        final int size = activities.size();
        for (int i = 0; i < size; i++) {
            final ActivityInfo activityInfoNoMetadata = activities.get(i).activityInfo;
            if (activityInfoNoMetadata == null) {
                continue;
            }
            final ActivityInfo activityInfoWithMetadata = service.getActivityInfoWithMetadata(activityInfoNoMetadata.getComponentName(), userId);
            if (activityInfoWithMetadata != null) {
                result = parseShortcutsOneFile(service, activityInfoWithMetadata, packageName, userId, result);
            }
        }
    } catch (RuntimeException e) {
        // Resource ID mismatch may cause various runtime exceptions when parsing XMLs,
        // But we don't crash the device, so just swallow them.
        service.wtf("Exception caught while parsing shortcut XML for package=" + packageName, e);
        return null;
    }
    return result;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) Nullable(android.annotation.Nullable)

Example 48 with ActivityInfo

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

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 49 with ActivityInfo

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

the class TvInputManagerService method buildTvContentRatingSystemListLocked.

private void buildTvContentRatingSystemListLocked(int userId) {
    UserState userState = getOrCreateUserStateLocked(userId);
    userState.contentRatingSystemList.clear();
    final PackageManager pm = mContext.getPackageManager();
    Intent intent = new Intent(TvInputManager.ACTION_QUERY_CONTENT_RATING_SYSTEMS);
    for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA)) {
        ActivityInfo receiver = resolveInfo.activityInfo;
        Bundle metaData = receiver.metaData;
        if (metaData == null) {
            continue;
        }
        int xmlResId = metaData.getInt(TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS);
        if (xmlResId == 0) {
            Slog.w(TAG, "Missing meta-data '" + TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS + "' on receiver " + receiver.packageName + "/" + receiver.name);
            continue;
        }
        userState.contentRatingSystemList.add(TvContentRatingSystemInfo.createTvContentRatingSystemInfo(xmlResId, receiver.applicationInfo));
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 50 with ActivityInfo

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

the class ActivityThread method performLaunchActivity.

private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
    // System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");
    ActivityInfo aInfo = r.activityInfo;
    if (r.packageInfo == null) {
        r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, Context.CONTEXT_INCLUDE_CODE);
    }
    ComponentName component = r.intent.getComponent();
    if (component == null) {
        component = r.intent.resolveActivity(mInitialApplication.getPackageManager());
        r.intent.setComponent(component);
    }
    if (r.activityInfo.targetActivity != null) {
        component = new ComponentName(r.activityInfo.packageName, r.activityInfo.targetActivity);
    }
    Activity activity = null;
    try {
        java.lang.ClassLoader cl = r.packageInfo.getClassLoader();
        activity = mInstrumentation.newActivity(cl, component.getClassName(), r.intent);
        StrictMode.incrementExpectedActivityCount(activity.getClass());
        r.intent.setExtrasClassLoader(cl);
        r.intent.prepareToEnterProcess();
        if (r.state != null) {
            r.state.setClassLoader(cl);
        }
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            throw new RuntimeException("Unable to instantiate activity " + component + ": " + e.toString(), e);
        }
    }
    try {
        Application app = r.packageInfo.makeApplication(false, mInstrumentation);
        if (localLOGV)
            Slog.v(TAG, "Performing launch of " + r);
        if (localLOGV)
            Slog.v(TAG, r + ": app=" + app + ", appName=" + app.getPackageName() + ", pkg=" + r.packageInfo.getPackageName() + ", comp=" + r.intent.getComponent().toShortString() + ", dir=" + r.packageInfo.getAppDir());
        if (activity != null) {
            Context appContext = createBaseContextForActivity(r, activity);
            CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
            Configuration config = new Configuration(mCompatConfiguration);
            if (r.overrideConfig != null) {
                config.updateFrom(r.overrideConfig);
            }
            if (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Launching activity " + r.activityInfo.name + " with config " + config);
            Window window = null;
            if (r.mPendingRemoveWindow != null && r.mPreserveWindow) {
                window = r.mPendingRemoveWindow;
                r.mPendingRemoveWindow = null;
                r.mPendingRemoveWindowManager = null;
            }
            activity.attach(appContext, this, getInstrumentation(), r.token, r.ident, app, r.intent, r.activityInfo, title, r.parent, r.embeddedID, r.lastNonConfigurationInstances, config, r.referrer, r.voiceInteractor, window);
            if (customIntent != null) {
                activity.mIntent = customIntent;
            }
            r.lastNonConfigurationInstances = null;
            activity.mStartedActivity = false;
            int theme = r.activityInfo.getThemeResource();
            if (theme != 0) {
                activity.setTheme(theme);
            }
            activity.mCalled = false;
            if (r.isPersistable()) {
                mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);
            } else {
                mInstrumentation.callActivityOnCreate(activity, r.state);
            }
            if (!activity.mCalled) {
                throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onCreate()");
            }
            r.activity = activity;
            r.stopped = true;
            if (!r.activity.mFinished) {
                activity.performStart();
                r.stopped = false;
            }
            if (!r.activity.mFinished) {
                if (r.isPersistable()) {
                    if (r.state != null || r.persistentState != null) {
                        mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state, r.persistentState);
                    }
                } else if (r.state != null) {
                    mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state);
                }
            }
            if (!r.activity.mFinished) {
                activity.mCalled = false;
                if (r.isPersistable()) {
                    mInstrumentation.callActivityOnPostCreate(activity, r.state, r.persistentState);
                } else {
                    mInstrumentation.callActivityOnPostCreate(activity, r.state);
                }
                if (!activity.mCalled) {
                    throw new SuperNotCalledException("Activity " + r.intent.getComponent().toShortString() + " did not call through to super.onPostCreate()");
                }
            }
        }
        r.paused = true;
        mActivities.put(r.token, r);
    } catch (SuperNotCalledException e) {
        throw e;
    } catch (Exception e) {
        if (!mInstrumentation.onException(activity, e)) {
            throw new RuntimeException("Unable to start activity " + component + ": " + e.toString(), e);
        }
    }
    return activity;
}
Also used : Context(android.content.Context) Window(android.view.Window) ActivityInfo(android.content.pm.ActivityInfo) Configuration(android.content.res.Configuration) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) SuperNotCalledException(android.util.SuperNotCalledException) TransactionTooLargeException(android.os.TransactionTooLargeException) AndroidRuntimeException(android.util.AndroidRuntimeException) ComponentName(android.content.ComponentName) SuperNotCalledException(android.util.SuperNotCalledException)

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