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

Commit 342d59d3 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by The Android Open Source Project
Browse files

am 9189cabb: * Moved supports-density tag under manifest * Refactored...

am 9189cabb: * Moved supports-density tag under manifest * Refactored Compatibility code   * Added CompatibilityInfo class   * Removed getApplicationScale from Context   * Added Resources#getCompatibilityInfo so that RootView can get the compatibility info w/o going through Context * Expandable support   * Added expandable tag under manifest   * Old application w/o expandable is given the default screen size  ([320, 480] x density).   * The non-expandable window is centered.

Merge commit '9189cabb'

* commit '9189cabb':
  * Moved supports-density tag under manifest
parents 138197f9 9189cabb
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -38177,6 +38177,16 @@
 visibility="public"
>
</field>
<field name="expandable"
 type="boolean"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="flags"
 type="int"
 transient="false"
@@ -40034,6 +40044,17 @@
 visibility="public"
>
</field>
<field name="GET_EXPANDABLE"
 type="int"
 transient="false"
 volatile="false"
 value="131072"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="GET_GIDS"
 type="int"
 transient="false"
+12 −67
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public final class ActivityThread {
        return metrics;
    }

    Resources getTopLevelResources(String appDir, float applicationScale) {
    Resources getTopLevelResources(String appDir, PackageInfo pkgInfo) {
        synchronized (mPackages) {
            //Log.w(TAG, "getTopLevelResources: " + appDir);
            WeakReference<Resources> wr = mActiveResources.get(appDir);
@@ -181,23 +181,17 @@ public final class ActivityThread {
            if (assets.addAssetPath(appDir) == 0) {
                return null;
            }
            DisplayMetrics metrics = getDisplayMetricsLocked(false);
            // density used to load resources
            // scaledDensity is calculated in Resources constructor
            //
            boolean usePreloaded = true;

            // TODO: use explicit flag to indicate the compatibility mode.
            if (applicationScale != 1.0f) {
                usePreloaded = false;
                DisplayMetrics newMetrics = new DisplayMetrics();
                newMetrics.setTo(metrics);
                float newDensity = metrics.density / applicationScale;
                newMetrics.updateDensity(newDensity);
                metrics = newMetrics;
            ApplicationInfo appInfo;
            try {
                appInfo = getPackageManager().getApplicationInfo(
                        pkgInfo.getPackageName(),
                        PackageManager.GET_SUPPORTS_DENSITIES | PackageManager.GET_EXPANDABLE);
            } catch (RemoteException e) {
                throw new AssertionError(e);
            }
            //Log.i(TAG, "Resource:" + appDir + ", display metrics=" + metrics);
            r = new Resources(assets, metrics, getConfiguration(), usePreloaded);
            DisplayMetrics metrics = getDisplayMetricsLocked(false);
            r = new Resources(assets, metrics, getConfiguration(), appInfo);
            //Log.i(TAG, "Created app resources " + r + ": " + r.getConfiguration());
            // XXX need to remove entries when weak references go away
            mActiveResources.put(appDir, new WeakReference<Resources>(r));
@@ -225,7 +219,6 @@ public final class ActivityThread {
        private Resources mResources;
        private ClassLoader mClassLoader;
        private Application mApplication;
        private float mApplicationScale;

        private final HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>> mReceivers
            = new HashMap<Context, HashMap<BroadcastReceiver, ReceiverDispatcher>>();
@@ -268,8 +261,6 @@ public final class ActivityThread {
                mClassLoader = mSystemContext.getClassLoader();
                mResources = mSystemContext.getResources();
            }

            mApplicationScale = -1.0f;
        }

        public PackageInfo(ActivityThread activityThread, String name,
@@ -288,7 +279,6 @@ public final class ActivityThread {
            mIncludeCode = true;
            mClassLoader = systemContext.getClassLoader();
            mResources = systemContext.getResources();
            mApplicationScale = systemContext.getApplicationScale();
        }

        public String getPackageName() {
@@ -299,45 +289,6 @@ public final class ActivityThread {
            return mSecurityViolation;
        }

        public float getApplicationScale() {
            if (mApplicationScale > 0.0f) {
                return mApplicationScale;
            }
            DisplayMetrics metrics = mActivityThread.getDisplayMetricsLocked(false);
            // Find out the density scale (relative to 160) of the supported density  that
            // is closest to the system's density.
            try {
                ApplicationInfo ai = getPackageManager().getApplicationInfo(
                        mPackageName, PackageManager.GET_SUPPORTS_DENSITIES);

                float appScale = -1.0f;
                if (ai.supportsDensities != null) {
                    int minDiff = Integer.MAX_VALUE;
                    for (int density : ai.supportsDensities) {
                        int tmpDiff = (int) Math.abs(DisplayMetrics.DEVICE_DENSITY - density);
                        if (tmpDiff == 0) {
                            appScale = 1.0f;
                            break;
                        }
                        // prefer higher density (appScale>1.0), unless that's only option.
                        if (tmpDiff < minDiff && appScale < 1.0f) {
                            appScale = DisplayMetrics.DEVICE_DENSITY / density;
                            minDiff = tmpDiff;
                        }
                    }
                }
                if (appScale < 0.0f) {
                    mApplicationScale = metrics.density;
                } else {
                    mApplicationScale = appScale;
                }
            } catch (RemoteException e) {
                throw new AssertionError(e);
            }
            if (localLOGV) Log.v(TAG, "appScale=" + mApplicationScale + ", pkg=" + mPackageName);
            return mApplicationScale;
        }

        /**
         * Gets the array of shared libraries that are listed as
         * used by the given package.
@@ -495,7 +446,7 @@ public final class ActivityThread {

        public Resources getResources(ActivityThread mainThread) {
            if (mResources == null) {
                mResources = mainThread.getTopLevelResources(mResDir, getApplicationScale());
                mResources = mainThread.getTopLevelResources(mResDir, this);
            }
            return mResources;
        }
@@ -3606,8 +3557,6 @@ public final class ActivityThread {
            }
            mConfiguration.updateFrom(config);
            DisplayMetrics dm = getDisplayMetricsLocked(true);
            DisplayMetrics appDm = new DisplayMetrics();
            appDm.setTo(dm);

            // set it for java, this also affects newly created Resources
            if (config.locale != null) {
@@ -3627,11 +3576,7 @@ public final class ActivityThread {
                    WeakReference<Resources> v = it.next();
                    Resources r = v.get();
                    if (r != null) {
                        // keep the original density based on application cale.
                        appDm.updateDensity(r.getDisplayMetrics().density);
                        r.updateConfiguration(config, appDm);
                        // reset
                        appDm.setTo(dm);
                        r.updateConfiguration(config, dm);
                        //Log.i(TAG, "Updated app resources " + v.getKey()
                        //        + " " + r + ": " + r.getConfiguration());
                    } else {
+1 −15
Original line number Diff line number Diff line
@@ -554,19 +554,6 @@ class ApplicationContext extends Context {
        }
    }

    /**
     * @hide
     */
    @Override
    public float getApplicationScale() {
        if (mPackageInfo != null) {
            return mPackageInfo.getApplicationScale();
        } else {
            // same as system density
            return 1.0f;
        }
    }

    @Override
    public void setWallpaper(Bitmap bitmap) throws IOException  {
        try {
@@ -2044,8 +2031,7 @@ class ApplicationContext extends Context {
            ActivityThread.PackageInfo pi = mContext.mMainThread.getPackageInfoNoCheck(app);
            Resources r = mContext.mMainThread.getTopLevelResources(
                    app.uid == Process.myUid() ? app.sourceDir
                    : app.publicSourceDir,
                    pi.getApplicationScale());
                    : app.publicSourceDir, pi);
            if (r != null) {
                return r;
            }
+0 −10
Original line number Diff line number Diff line
@@ -526,16 +526,6 @@ public abstract class Context {
     */
    public abstract int getWallpaperDesiredMinimumHeight();

    /**
     * Returns the scale in which the application will be drawn on the
     * screen. This is usually 1.0f if the application supports the device's
     * resolution/density. This will be 1.5f, for example, if the application
     * that supports only 160 density runs on 240 density screen.
     *
     * @hide
     */
    public abstract float getApplicationScale();

    /**
     * Change the current system wallpaper to a bitmap.  The given bitmap is
     * converted to a PNG and stored as the wallpaper.  On success, the intent
+0 −8
Original line number Diff line number Diff line
@@ -419,12 +419,4 @@ public class ContextWrapper extends Context {
        throws PackageManager.NameNotFoundException {
        return mBase.createPackageContext(packageName, flags);
    }

    /**
     * @hide
     */
    @Override
    public float getApplicationScale() {
        return mBase.getApplicationScale();
    }
}
Loading