Search in sources :

Example 21 with ActivityInfo

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

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);
        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 (DEBUG_CONFIGURATION)
                Slog.v(TAG, "Launching activity " + r.activityInfo.name + " with config " + config);
            activity.attach(appContext, this, getInstrumentation(), r.token, r.ident, app, r.intent, r.activityInfo, title, r.parent, r.embeddedID, r.lastNonConfigurationInstances, config);
            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;
            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.state != null) {
                    mInstrumentation.callActivityOnRestoreInstanceState(activity, r.state);
                }
            }
            if (!r.activity.mFinished) {
                activity.mCalled = false;
                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)) {
            if (e instanceof InflateException) {
                Log.e(TAG, "Failed to inflate", e);
                String pkg = null;
                if (r.packageInfo != null && !TextUtils.isEmpty(r.packageInfo.getPackageName())) {
                    pkg = r.packageInfo.getPackageName();
                }
                Intent intent = new Intent(Intent.ACTION_APP_LAUNCH_FAILURE, (pkg != null) ? Uri.fromParts("package", pkg, null) : null);
                getSystemContext().sendBroadcast(intent);
            }
            throw new RuntimeException("Unable to start activity " + component + ": " + e.toString(), e);
        }
    }
    return activity;
}
Also used : Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) Configuration(android.content.res.Configuration) Intent(android.content.Intent) InflateException(android.view.InflateException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) AndroidRuntimeException(android.util.AndroidRuntimeException) InflateException(android.view.InflateException) ComponentName(android.content.ComponentName) java.lang(java.lang)

Example 22 with ActivityInfo

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

the class AliasActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    XmlResourceParser parser = null;
    try {
        ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
        parser = ai.loadXmlMetaData(getPackageManager(), ALIAS_META_DATA);
        if (parser == null) {
            throw new RuntimeException("Alias requires a meta-data field " + ALIAS_META_DATA);
        }
        Intent intent = parseAlias(parser);
        if (intent == null) {
            throw new RuntimeException("No <intent> tag found in alias description");
        }
        startActivity(intent);
        finish();
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Error parsing alias", e);
    } catch (XmlPullParserException e) {
        throw new RuntimeException("Error parsing alias", e);
    } catch (IOException e) {
        throw new RuntimeException("Error parsing alias", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 23 with ActivityInfo

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

the class TaskStackBuilder method addParentStack.

/**
     * Add the activity parent chain as specified by the
     * {@link android.R.attr#parentActivityName parentActivityName} attribute of the activity
     * (or activity-alias) element in the application's manifest to the task stack builder.
     *
     * @param sourceActivityName Must specify an Activity component. All parents of
     *                           this activity will be added
     * @return This TaskStackBuilder for method chaining
     */
public TaskStackBuilder addParentStack(ComponentName sourceActivityName) {
    final int insertAt = mIntents.size();
    PackageManager pm = mSourceContext.getPackageManager();
    try {
        ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0);
        String parentActivity = info.parentActivityName;
        while (parentActivity != null) {
            final ComponentName target = new ComponentName(info.packageName, parentActivity);
            info = pm.getActivityInfo(target, 0);
            parentActivity = info.parentActivityName;
            final Intent parent = parentActivity == null && insertAt == 0 ? Intent.makeMainActivity(target) : new Intent().setComponent(target);
            mIntents.add(insertAt, parent);
        }
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
        throw new IllegalArgumentException(e);
    }
    return this;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 24 with ActivityInfo

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

the class SearchDialog method updateSearchAppIcon.

private void updateSearchAppIcon() {
    PackageManager pm = getContext().getPackageManager();
    Drawable icon;
    try {
        ActivityInfo info = pm.getActivityInfo(mLaunchComponent, 0);
        icon = pm.getApplicationIcon(info.applicationInfo);
        if (DBG)
            Log.d(LOG_TAG, "Using app-specific icon");
    } catch (NameNotFoundException e) {
        icon = pm.getDefaultActivityIcon();
        Log.w(LOG_TAG, mLaunchComponent + " not found, using generic app icon");
    }
    mAppIcon.setImageDrawable(icon);
    mAppIcon.setVisibility(View.VISIBLE);
    mSearchPlate.setPadding(SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL, mSearchPlate.getPaddingTop(), mSearchPlate.getPaddingRight(), mSearchPlate.getPaddingBottom());
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable)

Example 25 with ActivityInfo

use of android.content.pm.ActivityInfo in project XobotOS by xamarin.

the class PreferenceManager method inflateFromIntent.

/**
     * Inflates a preference hierarchy from the preference hierarchies of
     * {@link Activity Activities} that match the given {@link Intent}. An
     * {@link Activity} defines its preference hierarchy with meta-data using
     * the {@link #METADATA_KEY_PREFERENCES} key.
     * <p>
     * If a preference hierarchy is given, the new preference hierarchies will
     * be merged in.
     * 
     * @param queryIntent The intent to match activities.
     * @param rootPreferences Optional existing hierarchy to merge the new
     *            hierarchies into.
     * @return The root hierarchy (if one was not provided, the new hierarchy's
     *         root).
     */
PreferenceScreen inflateFromIntent(Intent queryIntent, PreferenceScreen rootPreferences) {
    final List<ResolveInfo> activities = queryIntentActivities(queryIntent);
    final HashSet<String> inflatedRes = new HashSet<String>();
    for (int i = activities.size() - 1; i >= 0; i--) {
        final ActivityInfo activityInfo = activities.get(i).activityInfo;
        final Bundle metaData = activityInfo.metaData;
        if ((metaData == null) || !metaData.containsKey(METADATA_KEY_PREFERENCES)) {
            continue;
        }
        // Need to concat the package with res ID since the same res ID
        // can be re-used across contexts
        final String uniqueResId = activityInfo.packageName + ":" + activityInfo.metaData.getInt(METADATA_KEY_PREFERENCES);
        if (!inflatedRes.contains(uniqueResId)) {
            inflatedRes.add(uniqueResId);
            final Context context;
            try {
                context = mContext.createPackageContext(activityInfo.packageName, 0);
            } catch (NameNotFoundException e) {
                Log.w(TAG, "Could not create context for " + activityInfo.packageName + ": " + Log.getStackTraceString(e));
                continue;
            }
            final PreferenceInflater inflater = new PreferenceInflater(context, this);
            final XmlResourceParser parser = activityInfo.loadXmlMetaData(context.getPackageManager(), METADATA_KEY_PREFERENCES);
            rootPreferences = (PreferenceScreen) inflater.inflate(parser, rootPreferences, true);
            parser.close();
        }
    }
    rootPreferences.onAttachedToHierarchy(this);
    return rootPreferences;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle) HashSet(java.util.HashSet)

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