Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1396dfe authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android Git Automerger
Browse files

am 02140891: Merge "Work on issue #4518815: Compatibility mode introduces...

am 02140891: Merge "Work on issue #4518815: Compatibility mode introduces compatibility regression..." into honeycomb-mr2

* commit '02140891':
  Work on issue #4518815: Compatibility mode introduces compatibility regression...
parents 735463d1 02140891
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ int move_dex(const char *src, const char *dst)
    if (create_cache_path(src_dex, src)) return -1;
    if (create_cache_path(dst_dex, dst)) return -1;

    LOGI("move %s -> %s\n", src_dex, dst_dex);
    LOGV("move %s -> %s\n", src_dex, dst_dex);
    if (rename(src_dex, dst_dex) < 0) {
        LOGE("Couldn't move %s: %s\n", src_dex, strerror(errno));
        return -1;
@@ -229,7 +229,7 @@ int rm_dex(const char *path)
    if (!is_valid_apk_path(path)) return -1;
    if (create_cache_path(dex_path, path)) return -1;

    LOGI("unlink %s\n", dex_path);
    LOGV("unlink %s\n", dex_path);
    if (unlink(dex_path) < 0) {
        LOGE("Couldn't unlink %s: %s\n", dex_path, strerror(errno));
        return -1;
@@ -428,7 +428,7 @@ static int wait_dexopt(pid_t pid, const char* apk_path)
    }

    if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
        LOGD("DexInv: --- END '%s' (success) ---\n", apk_path);
        LOGV("DexInv: --- END '%s' (success) ---\n", apk_path);
        return 0;
    } else {
        LOGW("DexInv: --- END '%s' --- status=0x%04x, process failed\n",
@@ -495,7 +495,7 @@ int dexopt(const char *apk_path, uid_t uid, int is_public)
        goto fail;
    }

    LOGD("DexInv: --- BEGIN '%s' ---\n", apk_path);
    LOGV("DexInv: --- BEGIN '%s' ---\n", apk_path);

    pid_t pid;
    pid = fork();
@@ -563,7 +563,7 @@ void mkinnerdirs(char* path, int basepos, mode_t mode, int uid, int gid,
        if (path[basepos] == '/') {
            path[basepos] = 0;
            if (lstat(path, statbuf) < 0) {
                LOGI("Making directory: %s\n", path);
                LOGV("Making directory: %s\n", path);
                if (mkdir(path, mode) == 0) {
                    chown(path, uid, gid);
                } else {
@@ -595,7 +595,7 @@ int movefileordir(char* srcpath, char* dstpath, int dstbasepos,
    if ((statbuf->st_mode&S_IFDIR) == 0) {
        mkinnerdirs(dstpath, dstbasepos, S_IRWXU|S_IRWXG|S_IXOTH,
                dstuid, dstgid, statbuf);
        LOGI("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
        LOGV("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
        if (rename(srcpath, dstpath) >= 0) {
            if (chown(dstpath, dstuid, dstgid) < 0) {
                LOGE("cannot chown %s: %s\n", dstpath, strerror(errno));
+69 −29
Original line number Diff line number Diff line
@@ -155,7 +155,9 @@ public final class ActivityThread {
            = new HashMap<IBinder, Service>();
    AppBindData mBoundApplication;
    Configuration mConfiguration;
    Configuration mCompatConfiguration;
    Configuration mResConfiguration;
    CompatibilityInfo mResCompatibilityInfo;
    Application mInitialApplication;
    final ArrayList<Application> mAllApplications
            = new ArrayList<Application>();
@@ -181,8 +183,8 @@ public final class ActivityThread {
            = new HashMap<String, WeakReference<LoadedApk>>();
    final HashMap<String, WeakReference<LoadedApk>> mResourcePackages
            = new HashMap<String, WeakReference<LoadedApk>>();
    Display mDisplay = null;
    DisplayMetrics mDisplayMetrics = null;
    final HashMap<CompatibilityInfo, DisplayMetrics> mDisplayMetrics
            = new HashMap<CompatibilityInfo, DisplayMetrics>();
    final HashMap<ResourcesKey, WeakReference<Resources> > mActiveResources
            = new HashMap<ResourcesKey, WeakReference<Resources> >();
    final ArrayList<ActivityClientRecord> mRelaunchingActivities
@@ -1267,20 +1269,45 @@ public final class ActivityThread {
        return sPackageManager;
    }

    DisplayMetrics getDisplayMetricsLocked(boolean forceUpdate) {
        if (mDisplayMetrics != null && !forceUpdate) {
            return mDisplayMetrics;
    DisplayMetrics getDisplayMetricsLocked(CompatibilityInfo ci, boolean forceUpdate) {
        DisplayMetrics dm = mDisplayMetrics.get(ci);
        if (dm != null && !forceUpdate) {
            return dm;
        }
        if (mDisplay == null) {
            WindowManager wm = WindowManagerImpl.getDefault();
            mDisplay = wm.getDefaultDisplay();
        if (dm == null) {
            dm = new DisplayMetrics();
            mDisplayMetrics.put(ci, dm);
        }
        DisplayMetrics metrics = mDisplayMetrics = new DisplayMetrics();
        mDisplay.getMetrics(metrics);
        Display d = WindowManagerImpl.getDefault(ci).getDefaultDisplay();
        d.getMetrics(dm);
        //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
        //        + metrics.heightPixels + " den=" + metrics.density
        //        + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);
        return metrics;
        return dm;
    }

    static Configuration applyConfigCompat(Configuration config, CompatibilityInfo compat) {
        if (config == null) {
            return null;
        }
        if (compat != null && !compat.supportsScreen()) {
            config = new Configuration(config);
            compat.applyToConfiguration(config);
        }
        return config;
    }

    private final Configuration mMainThreadConfig = new Configuration();
    Configuration applyConfigCompatMainThread(Configuration config, CompatibilityInfo compat) {
        if (config == null) {
            return null;
        }
        if (compat != null && !compat.supportsScreen()) {
            mMainThreadConfig.setTo(config);
            config = mMainThreadConfig;
            compat.applyToConfiguration(config);
        }
        return config;
    }

    /**
@@ -1322,7 +1349,7 @@ public final class ActivityThread {
        }

        //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
        DisplayMetrics metrics = getDisplayMetricsLocked(false);
        DisplayMetrics metrics = getDisplayMetricsLocked(compInfo, false);
        r = new Resources(assets, metrics, getConfiguration(), compInfo);
        if (false) {
            Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
@@ -1350,7 +1377,7 @@ public final class ActivityThread {
     * Creates the top level resources for the given package.
     */
    Resources getTopLevelResources(String resDir, LoadedApk pkgInfo) {
        return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo);
        return getTopLevelResources(resDir, pkgInfo.mCompatibilityInfo.get());
    }

    final Handler getHandler() {
@@ -1517,7 +1544,8 @@ public final class ActivityThread {
                        CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
                context.init(info, null, this);
                context.getResources().updateConfiguration(
                        getConfiguration(), getDisplayMetricsLocked(false));
                        getConfiguration(), getDisplayMetricsLocked(
                                CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, false));
                mSystemContext = context;
                //Slog.i(TAG, "Created system resources " + context.getResources()
                //        + ": " + context.getResources().getConfiguration());
@@ -1730,7 +1758,7 @@ public final class ActivityThread {
                appContext.init(r.packageInfo, r.token, this);
                appContext.setOuterContext(activity);
                CharSequence title = r.activityInfo.loadLabel(appContext.getPackageManager());
                Configuration config = new Configuration(mConfiguration);
                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,
@@ -2763,13 +2791,14 @@ public final class ActivityThread {
    private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data) {
        LoadedApk apk = peekPackageInfo(data.pkg, false);
        if (apk != null) {
            apk.mCompatibilityInfo = data.info;
            apk.mCompatibilityInfo.set(data.info);
        }
        apk = peekPackageInfo(data.pkg, true);
        if (apk != null) {
            apk.mCompatibilityInfo = data.info;
            apk.mCompatibilityInfo.set(data.info);
        }
        handleConfigurationChanged(mConfiguration, data.info);
        WindowManagerImpl.getDefault().reportNewConfiguration(mConfiguration);
    }

    private final void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
@@ -3192,20 +3221,22 @@ public final class ActivityThread {
                ActivityClientRecord ar = it.next();
                Activity a = ar.activity;
                if (a != null) {
                    Configuration thisConfig = applyConfigCompatMainThread(newConfig,
                            ar.packageInfo.mCompatibilityInfo.getIfNeeded());
                    if (!ar.activity.mFinished && (allActivities ||
                            (a != null && !ar.paused))) {
                        // If the activity is currently resumed, its configuration
                        // needs to change right now.
                        callbacks.add(a);
                    } else if (newConfig != null) {
                    } else if (thisConfig != null) {
                        // Otherwise, we will tell it about the change
                        // the next time it is resumed or shown.  Note that
                        // the activity manager may, before then, decide the
                        // activity needs to be destroyed to handle its new
                        // configuration.
                        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Setting activity "
                                + ar.activityInfo.name + " newConfig=" + newConfig);
                        ar.newConfig = newConfig;
                                + ar.activityInfo.name + " newConfig=" + thisConfig);
                        ar.newConfig = thisConfig;
                    }
                }
            }
@@ -3252,7 +3283,6 @@ public final class ActivityThread {
            // onConfigurationChanged
            int diff = activity.mCurrentConfig.diff(config);
            if (diff != 0) {

                // If this activity doesn't handle any of the config changes
                // then don't bother calling onConfigurationChanged as we're
                // going to destroy it.
@@ -3296,7 +3326,15 @@ public final class ActivityThread {
            return false;
        }
        int changes = mResConfiguration.updateFrom(config);
        DisplayMetrics dm = getDisplayMetricsLocked(true);
        DisplayMetrics dm = getDisplayMetricsLocked(compat, true);

        if (compat != null && (mResCompatibilityInfo == null ||
                !mResCompatibilityInfo.equals(compat))) {
            mResCompatibilityInfo = compat;
            changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT
                    | ActivityInfo.CONFIG_SCREEN_SIZE
                    | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
        }

        // set it for java, this also affects newly created Resources
        if (config.locale != null) {
@@ -3358,13 +3396,14 @@ public final class ActivityThread {
                return;
            }
            mConfiguration.updateFrom(config);
            if (compat != null) {
                // Can't do this here, because it causes us to report the
                // comatible config back to the am as the current config
                // of the activity, and much unhappiness results.
                //compat.applyToConfiguration(mConfiguration);
            if (mCompatConfiguration == null) {
                mCompatConfiguration = new Configuration();
            }
            mCompatConfiguration.setTo(mConfiguration);
            if (mResCompatibilityInfo != null && !mResCompatibilityInfo.supportsScreen()) {
                mResCompatibilityInfo.applyToConfiguration(mCompatConfiguration);
                config = mCompatConfiguration;
            }

            callbacks = collectComponentCallbacksLocked(false, config);
        }

@@ -3385,7 +3424,7 @@ public final class ActivityThread {
        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
                + r.activityInfo.name);
        
        performConfigurationChanged(r.activity, mConfiguration);
        performConfigurationChanged(r.activity, mCompatConfiguration);
    }

    final void handleProfilerControl(boolean start, ProfilerControlData pcd) {
@@ -3480,6 +3519,7 @@ public final class ActivityThread {
    private final void handleBindApplication(AppBindData data) {
        mBoundApplication = data;
        mConfiguration = new Configuration(data.config);
        mCompatConfiguration = new Configuration(data.config);

        // send up app name; do this *before* waiting for debugger
        Process.setArgV0(data.processName);
+3 −1
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import android.content.res.Configuration;
 * when first constructing the singleton.</p>
 */
public class Application extends ContextWrapper implements ComponentCallbacks {
    /** @hide */
    public LoadedApk mLoadedApk;
    
    public Application() {
        super(null);
@@ -75,6 +77,6 @@ public class Application extends ContextWrapper implements ComponentCallbacks {
     */
    /* package */ final void attach(Context context) {
        attachBaseContext(context);
        mLoadedApk = ContextImpl.getImpl(context).mPackageInfo;
    }

}
+10 −2
Original line number Diff line number Diff line
@@ -425,11 +425,19 @@ class ContextImpl extends Context {

        registerService(WINDOW_SERVICE, new ServiceFetcher() {
                public Object getService(ContextImpl ctx) {
                    CompatibilityInfo ci = ctx.mResources.getCompatibilityInfo();
                    return WindowManagerImpl.getDefault(ci);
                    return WindowManagerImpl.getDefault(ctx.mPackageInfo.mCompatibilityInfo);
                }});
    }

    static ContextImpl getImpl(Context context) {
        Context nextContext;
        while ((context instanceof ContextWrapper) &&
                (nextContext=((ContextWrapper)context).getBaseContext()) != null) {
            context = nextContext;
        }
        return (ContextImpl)context;
    }

    // The system service cache for the system services that are
    // cached per-ContextImpl.  Package-scoped to avoid accessor
    // methods.
+6 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.RemoteException;
import android.os.StrictMode;
import android.util.AndroidRuntimeException;
import android.util.Slog;
import android.view.CompatibilityInfoHolder;

import java.io.File;
import java.io.IOException;
@@ -64,7 +65,7 @@ final class ServiceConnectionLeaked extends AndroidRuntimeException {
 * Local state maintained about a currently loaded .apk.
 * @hide
 */
final class LoadedApk {
public final class LoadedApk {

    private final ActivityThread mActivityThread;
    private final ApplicationInfo mApplicationInfo;
@@ -78,10 +79,10 @@ final class LoadedApk {
    private final ClassLoader mBaseClassLoader;
    private final boolean mSecurityViolation;
    private final boolean mIncludeCode;
    public final CompatibilityInfoHolder mCompatibilityInfo = new CompatibilityInfoHolder();
    Resources mResources;
    private ClassLoader mClassLoader;
    private Application mApplication;
    CompatibilityInfo mCompatibilityInfo;

    private final HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>> mReceivers
        = new HashMap<Context, HashMap<BroadcastReceiver, LoadedApk.ReceiverDispatcher>>();
@@ -121,7 +122,7 @@ final class LoadedApk {
        mBaseClassLoader = baseLoader;
        mSecurityViolation = securityViolation;
        mIncludeCode = includeCode;
        mCompatibilityInfo = compatInfo;
        mCompatibilityInfo.set(compatInfo);

        if (mAppDir == null) {
            if (ActivityThread.mSystemContext == null) {
@@ -129,7 +130,7 @@ final class LoadedApk {
                    ContextImpl.createSystemContext(mainThread);
                ActivityThread.mSystemContext.getResources().updateConfiguration(
                         mainThread.getConfiguration(),
                         mainThread.getDisplayMetricsLocked(false),
                         mainThread.getDisplayMetricsLocked(compatInfo, false),
                         compatInfo);
                //Slog.i(TAG, "Created system resources "
                //        + mSystemContext.getResources() + ": "
@@ -157,7 +158,7 @@ final class LoadedApk {
        mIncludeCode = true;
        mClassLoader = systemContext.getClassLoader();
        mResources = systemContext.getResources();
        mCompatibilityInfo = compatInfo;
        mCompatibilityInfo.set(compatInfo);
    }

    public String getPackageName() {
Loading