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

Commit 5be8de34 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

More compatibility mode improvements.

We now correctly adjust display metrics, fixing for example issues
seen in Barcode Scanner.  In addition the decision about when to use
compatibility mode has a bug fixed where certain apps would not go
out of compatibility mode even though they should be able to.

Change-Id: I5971206323df0f11ce653d1c790c700f457f0582
parent ef89cc14
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.CompatibilityInfo;
import android.content.res.Resources;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
@@ -78,6 +79,7 @@ import android.content.ClipboardManager;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.WindowManagerImpl;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.InputMethodManager;
@@ -423,7 +425,11 @@ class ContextImpl extends Context {

        registerService(WINDOW_SERVICE, new ServiceFetcher() {
                public Object getService(ContextImpl ctx) {
                    return WindowManagerImpl.getDefault();
                    RuntimeException e = new RuntimeException("foo");
                    e.fillInStackTrace();
                    Log.i(TAG, "Getting window manager", e);
                    CompatibilityInfo ci = ctx.mResources.getCompatibilityInfo();
                    return WindowManagerImpl.getDefault(ci);
                }});
    }

+1 −1
Original line number Diff line number Diff line
@@ -1045,7 +1045,7 @@ public class Instrumentation {
            }
        }
        
        activity.onCreate(icicle);
        activity.performCreate(icicle);
        
        if (mActivityMonitors != null) {
            synchronized (mSync) {
+11 −8
Original line number Diff line number Diff line
@@ -125,14 +125,16 @@ public class CompatibilityInfo implements Parcelable {
        if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
            compatFlags |= XLARGE_SCREENS | EXPANDABLE;
        }
        if (!forceCompat) {
        if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
            compatFlags |= EXPANDABLE;
        }

        if (forceCompat) {
            // If we are forcing compatibility mode, then ignore an app that
            // just says it is resizable for screens.  We'll only have it fill
            // the screen if it explicitly says it supports the screen size we
            // are running in.
            if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
                compatFlags |= EXPANDABLE;
            }
            compatFlags &= ~EXPANDABLE;
        }

        boolean supportsScreen = false;
@@ -155,12 +157,10 @@ public class CompatibilityInfo implements Parcelable {
                break;
        }

        if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) == 0) {
        if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) != 0) {
            if ((compatFlags&EXPANDABLE) != 0) {
                supportsScreen = true;
            }
            if ((compatFlags&EXPANDABLE) == 0 &&
                    (appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) == 0) {
            } else if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) == 0) {
                compatFlags |= ALWAYS_COMPAT;
            }
        }
@@ -382,6 +382,9 @@ public class CompatibilityInfo implements Parcelable {
            // This is a larger screen device and the app is not
            // compatible with large screens, so diddle it.
            CompatibilityInfo.updateCompatibleScreenFrame(inoutDm, null, inoutDm);
        } else {
            inoutDm.widthPixels = inoutDm.realWidthPixels;
            inoutDm.heightPixels = inoutDm.realHeightPixels;
        }

        if (isScalingRequired()) {
+3 −2
Original line number Diff line number Diff line
@@ -316,10 +316,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        StringBuilder sb = new StringBuilder(128);
        sb.append("{");
        sb.append(fontScale);
        sb.append("x imsi=");
        sb.append(" ");
        sb.append(mcc);
        sb.append("/");
        sb.append("mcc");
        sb.append(mnc);
        sb.append("mnc");
        if (locale != null) {
            sb.append(" ");
            sb.append(locale);
+9 −19
Original line number Diff line number Diff line
@@ -115,7 +115,6 @@ public class Resources {
    private NativePluralRules mPluralRule;
    
    private CompatibilityInfo mCompatibilityInfo;
    private Display mDefaultDisplay;

    private static final LongSparseArray<Object> EMPTY_ARRAY = new LongSparseArray<Object>(0) {
        @Override
@@ -1426,6 +1425,15 @@ public class Resources {
            }
            if (metrics != null) {
                mMetrics.setTo(metrics);
                // NOTE: We should re-arrange this code to create a Display
                // with the CompatibilityInfo that is used everywhere we deal
                // with the display in relation to this app, rather than
                // doing the conversion here.  This impl should be okay because
                // we make sure to return a compatible display in the places
                // where there are public APIs to retrieve the display...  but
                // it would be cleaner and more maintainble to just be
                // consistently dealing with a compatible display everywhere in
                // the framework.
                mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
            }
            mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
@@ -2121,24 +2129,6 @@ public class Resources {
                + Integer.toHexString(id));
    }

    /**
     * Returns the display adjusted for the Resources' metrics.
     * @hide
     */
    public Display getDefaultDisplay(Display defaultDisplay) {
        if (mDefaultDisplay == null) {
            if (!mCompatibilityInfo.isScalingRequired() && mCompatibilityInfo.supportsScreen()) {
                // the app supports the display. just use the default one.
                mDefaultDisplay = defaultDisplay;
            } else {
                // display needs adjustment.
                mDefaultDisplay = Display.createMetricsBasedDisplay(
                        defaultDisplay.getDisplayId(), mMetrics);
            }
        }
        return mDefaultDisplay;
    }

    private TypedArray getCachedStyledAttributes(int len) {
        synchronized (mTmpValue) {
            TypedArray attrs = mCachedStyledAttributes;
Loading