示例#1
0
        public android.app.Application makeApplication(bool forceDefaultAppClass, android.app.Instrumentation
                                                       instrumentation)
        {
            if (mApplication != null)
            {
                return(mApplication);
            }
            android.app.Application app = null;
            string appClass             = mApplicationInfo.className;

            if (forceDefaultAppClass || (appClass == null))
            {
                appClass = "android.app.Application";
            }
            try
            {
                java.lang.ClassLoader   cl         = getClassLoader();
                android.app.ContextImpl appContext = new android.app.ContextImpl();
                appContext.init(this, null, mActivityThread);
                app = mActivityThread.mInstrumentation.newApplication(cl, appClass, appContext);
                appContext.setOuterContext(app);
            }
            catch (System.Exception e)
            {
                if (!mActivityThread.mInstrumentation.onException(app, e))
                {
                    throw new java.lang.RuntimeException("Unable to instantiate application " + appClass
                                                         + ": " + e.ToString(), e);
                }
            }
            mActivityThread.mAllApplications.add(app);
            mApplication = app;
            if (instrumentation != null)
            {
                try
                {
                    instrumentation.callApplicationOnCreate(app);
                }
                catch (System.Exception e)
                {
                    if (!instrumentation.onException(app, e))
                    {
                        throw new java.lang.RuntimeException("Unable to create application " + app.GetType
                                                                 ().FullName + ": " + e.ToString(), e);
                    }
                }
            }
            return(app);
        }
示例#2
0
		public android.app.Application makeApplication(bool forceDefaultAppClass, android.app.Instrumentation
			 instrumentation)
		{
			if (mApplication != null)
			{
				return mApplication;
			}
			android.app.Application app = null;
			string appClass = mApplicationInfo.className;
			if (forceDefaultAppClass || (appClass == null))
			{
				appClass = "android.app.Application";
			}
			try
			{
				java.lang.ClassLoader cl = getClassLoader();
				android.app.ContextImpl appContext = new android.app.ContextImpl();
				appContext.init(this, null, mActivityThread);
				app = mActivityThread.mInstrumentation.newApplication(cl, appClass, appContext);
				appContext.setOuterContext(app);
			}
			catch (System.Exception e)
			{
				if (!mActivityThread.mInstrumentation.onException(app, e))
				{
					throw new java.lang.RuntimeException("Unable to instantiate application " + appClass
						 + ": " + e.ToString(), e);
				}
			}
			mActivityThread.mAllApplications.add(app);
			mApplication = app;
			if (instrumentation != null)
			{
				try
				{
					instrumentation.callApplicationOnCreate(app);
				}
				catch (System.Exception e)
				{
					if (!instrumentation.onException(app, e))
					{
						throw new java.lang.RuntimeException("Unable to create application " + app.GetType
							().FullName + ": " + e.ToString(), e);
					}
				}
			}
			return app;
		}
示例#3
0
		internal android.app.Activity performLaunchActivity(android.app.ActivityThread.ActivityClientRecord
			 r, android.content.Intent customIntent)
		{
			// System.out.println("##### [" + System.currentTimeMillis() + "] ActivityThread.performLaunchActivity(" + r + ")");
			android.content.pm.ActivityInfo aInfo = r.activityInfo;
			if (r.packageInfo == null)
			{
				r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, android.content.Context
					.CONTEXT_INCLUDE_CODE);
			}
			android.content.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 android.content.ComponentName(r.activityInfo.packageName, r.activityInfo
					.targetActivity);
			}
			android.app.Activity activity = null;
			try
			{
				java.lang.ClassLoader cl = r.packageInfo.getClassLoader();
				activity = mInstrumentation.newActivity(cl, component.getClassName(), r.intent);
				android.os.StrictMode.incrementExpectedActivityCount(activity.GetType());
				r.intent.setExtrasClassLoader(cl);
				if (r.state != null)
				{
					r.state.setClassLoader(cl);
				}
			}
			catch (System.Exception e)
			{
				if (!mInstrumentation.onException(activity, e))
				{
					throw new java.lang.RuntimeException("Unable to instantiate activity " + component
						 + ": " + e.ToString(), e);
				}
			}
			try
			{
				android.app.Application app = r.packageInfo.makeApplication(false, mInstrumentation
					);
				if (activity != null)
				{
					android.app.ContextImpl appContext = new android.app.ContextImpl();
					appContext.init(r.packageInfo, r.token, this);
					appContext.setOuterContext(activity);
					java.lang.CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager
						());
					android.content.res.Configuration config = new android.content.res.Configuration(
						mCompatConfiguration);
					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 android.app.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 android.app.SuperNotCalledException("Activity " + r.intent.getComponent
								().toShortString() + " did not call through to super.onPostCreate()");
						}
					}
				}
				r.paused = true;
				mActivities.put(r.token, r);
			}
			catch (android.app.SuperNotCalledException e)
			{
				throw;
			}
			catch (System.Exception e)
			{
				if (!mInstrumentation.onException(activity, e))
				{
					throw new java.lang.RuntimeException("Unable to start activity " + component + ": "
						 + e.ToString(), e);
				}
			}
			return activity;
		}
示例#4
0
		internal android.app.ContextImpl getSystemContext()
		{
			lock (this)
			{
				if (mSystemContext == null)
				{
					android.app.ContextImpl context = android.app.ContextImpl.createSystemContext(this
						);
					android.app.LoadedApk info = new android.app.LoadedApk(this, "android", context, 
						null, android.content.res.CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
					context.init(info, null, this);
					context.getResources().updateConfiguration(getConfiguration(), getDisplayMetricsLocked
						(android.content.res.CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, false));
					mSystemContext = context;
				}
			}
			//Slog.i(TAG, "Created system resources " + context.getResources()
			//        + ": " + context.getResources().getConfiguration());
			return mSystemContext;
		}
示例#5
0
		internal static android.app.ContextImpl createSystemContext(android.app.ActivityThread
			 mainThread)
		{
			android.app.ContextImpl context = new android.app.ContextImpl();
			context.init(android.content.res.Resources.getSystem(), mainThread);
			return context;
		}
示例#6
0
		public override android.content.Context createPackageContext(string packageName, 
			int flags)
		{
			if (packageName.Equals("system") || packageName.Equals("android"))
			{
				return new android.app.ContextImpl(mMainThread.getSystemContext());
			}
			android.app.LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo
				(), flags);
			if (pi != null)
			{
				android.app.ContextImpl c = new android.app.ContextImpl();
				c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
				c.init(pi, null, mMainThread, mResources, mBasePackageName);
				if (c.mResources != null)
				{
					return c;
				}
			}
			// Should be a better exception.
			throw new android.content.pm.PackageManager.NameNotFoundException("Application package "
				 + packageName + " not found");
		}