import android.telephony.TelephonyManager;
import android.text.ClipboardManager;
import android.util.AndroidRuntimeException;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextThemeWrapper;
+import android.view.Display;
import android.view.LayoutInflater;
import android.view.WindowManagerImpl;
import android.view.accessibility.AccessibilityManager;
*/
class ApplicationContext extends Context {
private final static String TAG = "ApplicationContext";
+ private final static boolean DEBUG = false;
private final static boolean DEBUG_ICONS = false;
private static final Object sSync = new Object();
@Override
public int checkUriPermission(Uri uri, String readPermission,
String writePermission, int pid, int uid, int modeFlags) {
- if (false) {
+ if (DEBUG) {
Log.i("foo", "checkUriPermission: uri=" + uri + "readPermission="
+ readPermission + " writePermission=" + writePermission
+ " pid=" + pid + " uid=" + uid + " mode" + modeFlags);
c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
c.init(pi, null, mMainThread);
if (c.mResources != null) {
+ Resources newRes = c.mResources;
+ if (mResources.getCompatibilityInfo().applicationScale !=
+ newRes.getCompatibilityInfo().applicationScale) {
+ DisplayMetrics dm = mMainThread.getDisplayMetricsLocked(false);
+ c.mResources = new Resources(newRes.getAssets(), dm,
+ newRes.getConfiguration(),
+ mResources.getCompatibilityInfo().copy());
+ if (DEBUG) {
+ Log.d(TAG, "loaded context has different scaling. Using container's" +
+ " compatiblity info:" + mResources.getDisplayMetrics());
+ }
+
+ }
return c;
}
}
if ((mode&MODE_WORLD_WRITEABLE) != 0) {
perms |= FileUtils.S_IWOTH;
}
- if (false) {
+ if (DEBUG) {
Log.i(TAG, "File " + name + ": mode=0x" + Integer.toHexString(mode)
+ ", perms=0x" + Integer.toHexString(perms));
}
}
}
+ private CompatibilityInfo(int appFlags, int compFlags, float scale, float invertedScale) {
+ this.appFlags = appFlags;
+ mCompatibilityFlags = compFlags;
+ applicationScale = scale;
+ applicationInvertedScale = invertedScale;
+ }
+
private CompatibilityInfo() {
- appFlags = ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
+ this(ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
| ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
- | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
- applicationScale = applicationInvertedScale = 1.0f;
- mCompatibilityFlags = EXPANDABLE | CONFIGURED_EXPANDABLE;
+ | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS,
+ EXPANDABLE | CONFIGURED_EXPANDABLE,
+ 1.0f,
+ 1.0f);
}
/**
+ * Returns the copy of this instance.
+ */
+ public CompatibilityInfo copy() {
+ CompatibilityInfo info = new CompatibilityInfo(appFlags, mCompatibilityFlags,
+ applicationScale, applicationInvertedScale);
+ info.setVisibleRect(mXOffset, mWidth, mHeight);
+ return info;
+ }
+
+ /**
* Sets the application's visible rect in compatibility mode.
* @param xOffset the application's x offset that is added to center the content.
* @param widthPixels the application's width in real pixels on the screen.
return mVisibleInsets;
}
}
-}
\ No newline at end of file
+}
*/
public Resources(AssetManager assets, DisplayMetrics metrics,
Configuration config) {
- this(assets, metrics, config, null);
+ this(assets, metrics, config, (ApplicationInfo) null);
}
/**
}
/**
+ * Creates a new resources that uses the given compatibility info. Used to create
+ * a context for widgets using the container's compatibility info.
+ * {@see ApplicationContext#createPackageCotnext}.
+ * @hide
+ */
+ public Resources(AssetManager assets, DisplayMetrics metrics,
+ Configuration config, CompatibilityInfo info) {
+ mAssets = assets;
+ mMetrics.setToDefaults();
+ mCompatibilityInfo = info;
+ updateConfiguration(config, metrics);
+ assets.ensureStringBlocks();
+ if (mCompatibilityInfo.isScalingRequired()) {
+ mPreloadedDrawables = emptySparseArray();
+ } else {
+ mPreloadedDrawables = sPreloadedDrawables;
+ }
+ }
+
+ /**
* Return a global shared Resources object that provides access to only
* system resources (no application resources), and is not configured for
* the current screen (can not use dimension units, does not change based