Search in sources :

Example 1 with ComponentCallbacks2

use of android.content.ComponentCallbacks2 in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method handleConfigurationChanged.

final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
    int configDiff = 0;
    int diff = 0;
    synchronized (mPackages) {
        if (mPendingConfiguration != null) {
            if (!mPendingConfiguration.isOtherSeqNewer(config)) {
                config = mPendingConfiguration;
                mCurDefaultDisplayDpi = config.densityDpi;
                updateDefaultDensity();
            }
            mPendingConfiguration = null;
        }
        if (config == null) {
            return;
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Handle configuration changed: " + config);
        diff = applyConfigurationToResourcesLocked(config, compat);
        if (mConfiguration == null) {
            mConfiguration = new Configuration();
        }
        if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
            return;
        }
        configDiff = mConfiguration.diff(config);
        mConfiguration.updateFrom(config);
        config = applyCompatConfiguration(mCurDefaultDisplayDpi);
    }
    ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
    // Cleanup hardware accelerated stuff
    WindowManagerGlobal.getInstance().trimLocalMemory();
    freeTextLayoutCachesIfNeeded(configDiff);
    if (callbacks != null) {
        final int N = callbacks.size();
        for (int i = 0; i < N; i++) {
            ComponentCallbacks2 cb = callbacks.get(i);
            // cache, now we need to trigger an update for each application.
            if ((diff & ActivityInfo.CONFIG_THEME_RESOURCE) != 0) {
                if (cb instanceof ContextWrapper) {
                    Context context = ((ContextWrapper) cb).getBaseContext();
                    if (context instanceof ContextImpl) {
                        ((ContextImpl) context).refreshResourcesIfNecessary();
                    }
                }
            }
            performConfigurationChanged(cb, config);
        }
    }
}
Also used : Context(android.content.Context) Configuration(android.content.res.Configuration) ComponentCallbacks2(android.content.ComponentCallbacks2) ContextWrapper(android.content.ContextWrapper)

Example 2 with ComponentCallbacks2

use of android.content.ComponentCallbacks2 in project platform_frameworks_base by android.

the class ActivityThread method attach.

private void attach(boolean system) {
    sCurrentActivityThread = this;
    mSystemThread = system;
    if (!system) {
        ViewRootImpl.addFirstDrawHandler(new Runnable() {

            @Override
            public void run() {
                ensureJitEnabled();
            }
        });
        android.ddm.DdmHandleAppName.setAppName("<pre-initialized>", UserHandle.myUserId());
        RuntimeInit.setApplicationObject(mAppThread.asBinder());
        final IActivityManager mgr = ActivityManagerNative.getDefault();
        try {
            mgr.attachApplication(mAppThread);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
        // Watch for getting close to heap limit.
        BinderInternal.addGcWatcher(new Runnable() {

            @Override
            public void run() {
                if (!mSomeActivitiesChanged) {
                    return;
                }
                Runtime runtime = Runtime.getRuntime();
                long dalvikMax = runtime.maxMemory();
                long dalvikUsed = runtime.totalMemory() - runtime.freeMemory();
                if (dalvikUsed > ((3 * dalvikMax) / 4)) {
                    if (DEBUG_MEMORY_TRIM)
                        Slog.d(TAG, "Dalvik max=" + (dalvikMax / 1024) + " total=" + (runtime.totalMemory() / 1024) + " used=" + (dalvikUsed / 1024));
                    mSomeActivitiesChanged = false;
                    try {
                        mgr.releaseSomeActivities(mAppThread);
                    } catch (RemoteException e) {
                        throw e.rethrowFromSystemServer();
                    }
                }
            }
        });
    } else {
        // Don't set application object here -- if the system crashes,
        // we can't display an alert, we just want to die die die.
        android.ddm.DdmHandleAppName.setAppName("system_process", UserHandle.myUserId());
        try {
            mInstrumentation = new Instrumentation();
            ContextImpl context = ContextImpl.createAppContext(this, getSystemContext().mPackageInfo);
            mInitialApplication = context.mPackageInfo.makeApplication(true, null);
            mInitialApplication.onCreate();
        } catch (Exception e) {
            throw new RuntimeException("Unable to instantiate Application():" + e.toString(), e);
        }
    }
    // add dropbox logging to libcore
    DropBox.setReporter(new DropBoxReporter());
    ViewRootImpl.addConfigCallback(new ComponentCallbacks2() {

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            synchronized (mResourcesManager) {
                // hierarchy will be informed about it.
                if (mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null)) {
                    updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), mResourcesManager.getConfiguration().getLocales());
                    // everyone about it.
                    if (mPendingConfiguration == null || mPendingConfiguration.isOtherSeqNewer(newConfig)) {
                        mPendingConfiguration = newConfig;
                        sendMessage(H.CONFIGURATION_CHANGED, newConfig);
                    }
                }
            }
        }

        @Override
        public void onLowMemory() {
        }

        @Override
        public void onTrimMemory(int level) {
        }
    });
}
Also used : 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) VMRuntime(dalvik.system.VMRuntime) AndroidRuntimeException(android.util.AndroidRuntimeException) ComponentCallbacks2(android.content.ComponentCallbacks2) RemoteException(android.os.RemoteException)

Example 3 with ComponentCallbacks2

use of android.content.ComponentCallbacks2 in project platform_frameworks_base by android.

the class ActivityThread method handleConfigurationChanged.

final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
    int configDiff = 0;
    synchronized (mResourcesManager) {
        if (mPendingConfiguration != null) {
            if (!mPendingConfiguration.isOtherSeqNewer(config)) {
                config = mPendingConfiguration;
                mCurDefaultDisplayDpi = config.densityDpi;
                updateDefaultDensity();
            }
            mPendingConfiguration = null;
        }
        if (config == null) {
            return;
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Handle configuration changed: " + config);
        mResourcesManager.applyConfigurationToResourcesLocked(config, compat);
        updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), mResourcesManager.getConfiguration().getLocales());
        if (mConfiguration == null) {
            mConfiguration = new Configuration();
        }
        if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
            return;
        }
        configDiff = mConfiguration.updateFrom(config);
        config = applyCompatConfiguration(mCurDefaultDisplayDpi);
        final Theme systemTheme = getSystemContext().getTheme();
        if ((systemTheme.getChangingConfigurations() & configDiff) != 0) {
            systemTheme.rebase();
        }
    }
    ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
    freeTextLayoutCachesIfNeeded(configDiff);
    if (callbacks != null) {
        final int N = callbacks.size();
        for (int i = 0; i < N; i++) {
            ComponentCallbacks2 cb = callbacks.get(i);
            if (cb instanceof Activity) {
                // If callback is an Activity - call corresponding method to consider override
                // config and avoid onConfigurationChanged if it hasn't changed.
                Activity a = (Activity) cb;
                performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), config, REPORT_TO_ACTIVITY);
            } else {
                performConfigurationChanged(cb, null, config, null, REPORT_TO_ACTIVITY);
            }
        }
    }
}
Also used : Configuration(android.content.res.Configuration) Theme(android.content.res.Resources.Theme) ComponentCallbacks2(android.content.ComponentCallbacks2)

Example 4 with ComponentCallbacks2

use of android.content.ComponentCallbacks2 in project XobotOS by xamarin.

the class ActivityThread method attach.

private void attach(boolean system) {
    sThreadLocal.set(this);
    mSystemThread = system;
    if (!system) {
        ViewRootImpl.addFirstDrawHandler(new Runnable() {

            public void run() {
                ensureJitEnabled();
            }
        });
        android.ddm.DdmHandleAppName.setAppName("<pre-initialized>");
        RuntimeInit.setApplicationObject(mAppThread.asBinder());
        IActivityManager mgr = ActivityManagerNative.getDefault();
        try {
            mgr.attachApplication(mAppThread);
        } catch (RemoteException ex) {
        // Ignore
        }
    } else {
        // Don't set application object here -- if the system crashes,
        // we can't display an alert, we just want to die die die.
        android.ddm.DdmHandleAppName.setAppName("system_process");
        try {
            mInstrumentation = new Instrumentation();
            ContextImpl context = new ContextImpl();
            context.init(getSystemContext().mPackageInfo, null, this);
            Application app = Instrumentation.newApplication(Application.class, context);
            mAllApplications.add(app);
            mInitialApplication = app;
            app.onCreate();
        } catch (Exception e) {
            throw new RuntimeException("Unable to instantiate Application():" + e.toString(), e);
        }
    }
    ViewRootImpl.addConfigCallback(new ComponentCallbacks2() {

        public void onConfigurationChanged(Configuration newConfig) {
            synchronized (mPackages) {
                // hierarchy will be informed about it.
                if (applyConfigurationToResourcesLocked(newConfig, null)) {
                    // everyone about it.
                    if (mPendingConfiguration == null || mPendingConfiguration.isOtherSeqNewer(newConfig)) {
                        mPendingConfiguration = newConfig;
                        queueOrSendMessage(H.CONFIGURATION_CHANGED, newConfig);
                    }
                }
            }
        }

        public void onLowMemory() {
        }

        public void onTrimMemory(int level) {
        }
    });
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) Configuration(android.content.res.Configuration) ComponentCallbacks2(android.content.ComponentCallbacks2) RemoteException(android.os.RemoteException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 5 with ComponentCallbacks2

use of android.content.ComponentCallbacks2 in project XobotOS by xamarin.

the class ActivityThread method handleConfigurationChanged.

final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
    ArrayList<ComponentCallbacks2> callbacks = null;
    synchronized (mPackages) {
        if (mPendingConfiguration != null) {
            if (!mPendingConfiguration.isOtherSeqNewer(config)) {
                config = mPendingConfiguration;
            }
            mPendingConfiguration = null;
        }
        if (config == null) {
            return;
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Handle configuration changed: " + config);
        applyConfigurationToResourcesLocked(config, compat);
        if (mConfiguration == null) {
            mConfiguration = new Configuration();
        }
        if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
            return;
        }
        mConfiguration.updateFrom(config);
        config = applyCompatConfiguration();
        callbacks = collectComponentCallbacksLocked(false, config);
    }
    // Cleanup hardware accelerated stuff
    WindowManagerImpl.getDefault().trimLocalMemory();
    if (callbacks != null) {
        final int N = callbacks.size();
        for (int i = 0; i < N; i++) {
            performConfigurationChanged(callbacks.get(i), config);
        }
    }
}
Also used : Configuration(android.content.res.Configuration) ComponentCallbacks2(android.content.ComponentCallbacks2)

Aggregations

ComponentCallbacks2 (android.content.ComponentCallbacks2)21 Configuration (android.content.res.Configuration)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 RemoteException (android.os.RemoteException)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Theme (android.content.res.Resources.Theme)5 TransactionTooLargeException (android.os.TransactionTooLargeException)5 ErrnoException (android.system.ErrnoException)5 SuperNotCalledException (android.util.SuperNotCalledException)5 VMRuntime (dalvik.system.VMRuntime)5 Context (android.content.Context)1 ContextWrapper (android.content.ContextWrapper)1 InflateException (android.view.InflateException)1 WindowManagerGlobal (android.view.WindowManagerGlobal)1