Merge "ContextImpl: Keep DisplayAdjustments and Display in sync" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0bf31c3fa6
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.app;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentProvider;
|
||||
@@ -30,6 +32,7 @@ import android.content.IntentSender;
|
||||
import android.content.ReceiverCallNotAllowedException;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -155,10 +158,9 @@ class ContextImpl extends Context {
|
||||
private final String mBasePackageName;
|
||||
private final String mOpPackageName;
|
||||
|
||||
private final ResourcesManager mResourcesManager;
|
||||
private final Resources mResources;
|
||||
private final Display mDisplay; // may be null if default display
|
||||
private final DisplayAdjustments mDisplayAdjustments = new DisplayAdjustments();
|
||||
private final @NonNull ResourcesManager mResourcesManager;
|
||||
private final @NonNull Resources mResources;
|
||||
private @Nullable Display mDisplay; // may be null if default display
|
||||
|
||||
private final int mFlags;
|
||||
|
||||
@@ -1897,18 +1899,6 @@ class ContextImpl extends Context {
|
||||
mUser, mFlags, display, null, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
Display getDisplay() {
|
||||
if (mDisplay != null) {
|
||||
return mDisplay;
|
||||
}
|
||||
return ResourcesManager.getInstance().getAdjustedDisplay(
|
||||
Display.DEFAULT_DISPLAY, mDisplayAdjustments);
|
||||
}
|
||||
|
||||
private int getDisplayId() {
|
||||
return mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createDeviceProtectedStorageContext() {
|
||||
final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE)
|
||||
@@ -1940,9 +1930,24 @@ class ContextImpl extends Context {
|
||||
return (mFlags & Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Display getDisplay() {
|
||||
final DisplayAdjustments displayAdjustments = mResources.getDisplayAdjustments();
|
||||
if (mDisplay == null) {
|
||||
return mResourcesManager.getAdjustedDisplay(Display.DEFAULT_DISPLAY,
|
||||
displayAdjustments);
|
||||
}
|
||||
|
||||
if (!mDisplay.getDisplayAdjustments().equals(displayAdjustments)) {
|
||||
mDisplay = mResourcesManager.getAdjustedDisplay(mDisplay.getDisplayId(),
|
||||
displayAdjustments);
|
||||
}
|
||||
return mDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisplayAdjustments getDisplayAdjustments(int displayId) {
|
||||
return mDisplayAdjustments;
|
||||
return mResources.getDisplayAdjustments();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2057,11 +2062,6 @@ class ContextImpl extends Context {
|
||||
? packageInfo.getCompatibilityInfo()
|
||||
: CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
|
||||
}
|
||||
mDisplayAdjustments.setCompatibilityInfo(compatInfo);
|
||||
mDisplayAdjustments.setConfiguration(overrideConfiguration);
|
||||
|
||||
mDisplay = (createDisplayWithId == Display.INVALID_DISPLAY) ? display
|
||||
: ResourcesManager.getInstance().getAdjustedDisplay(displayId, mDisplayAdjustments);
|
||||
|
||||
Resources resources = packageInfo.getResources(mainThread);
|
||||
if (resources != null) {
|
||||
@@ -2101,6 +2101,9 @@ class ContextImpl extends Context {
|
||||
}
|
||||
mResources = resources;
|
||||
|
||||
mDisplay = (createDisplayWithId == Display.INVALID_DISPLAY) ? display
|
||||
: mResourcesManager.getAdjustedDisplay(displayId, mResources.getDisplayAdjustments());
|
||||
|
||||
if (container != null) {
|
||||
mBasePackageName = container.mBasePackageName;
|
||||
mOpPackageName = container.mOpPackageName;
|
||||
|
||||
@@ -310,7 +310,7 @@ public class Presentation extends Dialog {
|
||||
final WindowManagerImpl outerWindowManager =
|
||||
(WindowManagerImpl)outerContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
final WindowManagerImpl displayWindowManager =
|
||||
outerWindowManager.createPresentationWindowManager(display);
|
||||
outerWindowManager.createPresentationWindowManager(displayContext);
|
||||
return new ContextThemeWrapper(displayContext, theme) {
|
||||
@Override
|
||||
public Object getSystemService(String name) {
|
||||
|
||||
@@ -304,10 +304,11 @@ public class ResourcesManager {
|
||||
}
|
||||
|
||||
private @NonNull ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
|
||||
AssetManager assets = createAssetManager(key);
|
||||
DisplayMetrics dm = getDisplayMetrics(key.mDisplayId);
|
||||
Configuration config = generateConfig(key, dm);
|
||||
ResourcesImpl impl = new ResourcesImpl(assets, dm, config, key.mCompatInfo);
|
||||
final AssetManager assets = createAssetManager(key);
|
||||
final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId);
|
||||
final Configuration config = generateConfig(key, dm);
|
||||
final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, key.mCompatInfo,
|
||||
key.mOverrideConfiguration);
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ final class SystemServiceRegistry {
|
||||
new CachedServiceFetcher<WindowManager>() {
|
||||
@Override
|
||||
public WindowManager createService(ContextImpl ctx) {
|
||||
return new WindowManagerImpl(ctx.getDisplay());
|
||||
return new WindowManagerImpl(ctx);
|
||||
}});
|
||||
|
||||
registerService(Context.USER_SERVICE, UserManager.class,
|
||||
|
||||
@@ -4278,6 +4278,11 @@ public abstract class Context {
|
||||
*/
|
||||
public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public abstract Display getDisplay();
|
||||
|
||||
/**
|
||||
* Indicates whether this Context is restricted.
|
||||
*
|
||||
|
||||
@@ -819,6 +819,14 @@ public class ContextWrapper extends Context {
|
||||
return mBase.getDisplayAdjustments(displayId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
public Display getDisplay() {
|
||||
return mBase.getDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createDeviceProtectedStorageContext() {
|
||||
return mBase.createDeviceProtectedStorageContext();
|
||||
|
||||
@@ -51,6 +51,7 @@ import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
import android.util.Pools.SynchronizedPool;
|
||||
import android.util.TypedValue;
|
||||
import android.view.DisplayAdjustments;
|
||||
import android.view.ViewDebug;
|
||||
import android.view.ViewHierarchyEncoder;
|
||||
|
||||
@@ -1800,6 +1801,11 @@ public class Resources {
|
||||
return mResourcesImpl.getDisplayMetrics();
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public DisplayAdjustments getDisplayAdjustments() {
|
||||
return mResourcesImpl.getDisplayAdjustments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current configuration that is in effect for this resource
|
||||
* object. The returned object should be treated as read-only.
|
||||
|
||||
@@ -44,6 +44,8 @@ import android.util.LongSparseArray;
|
||||
import android.util.Slog;
|
||||
import android.util.TypedValue;
|
||||
import android.util.Xml;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayAdjustments;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
@@ -111,7 +113,8 @@ public class ResourcesImpl {
|
||||
|
||||
|
||||
final AssetManager mAssets;
|
||||
final DisplayMetrics mMetrics = new DisplayMetrics();
|
||||
private final DisplayMetrics mMetrics = new DisplayMetrics();
|
||||
private final DisplayAdjustments mDisplayAdjustments = new DisplayAdjustments();
|
||||
|
||||
private PluralRules mPluralRule;
|
||||
|
||||
@@ -134,14 +137,42 @@ public class ResourcesImpl {
|
||||
* selecting/computing resource values (optional).
|
||||
* @param compatInfo this resource's compatibility info. Must not be null.
|
||||
*/
|
||||
public ResourcesImpl(AssetManager assets, DisplayMetrics metrics, Configuration config,
|
||||
CompatibilityInfo compatInfo) {
|
||||
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
|
||||
@Nullable Configuration config, @NonNull CompatibilityInfo compatInfo) {
|
||||
this(assets, metrics, config, compatInfo, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ResourcesImpl object with CompatibilityInfo and assigns a static overrideConfig
|
||||
* that is reported with getDisplayAdjustments(). This is used for updating the Display
|
||||
* when a new ResourcesImpl is created due to multi-window configuration changes.
|
||||
*
|
||||
* @param assets Previously created AssetManager.
|
||||
* @param metrics Current display metrics to consider when selecting/computing resource values.
|
||||
* @param fullConfig Desired device configuration to consider when selecting/computing
|
||||
* resource values.
|
||||
* @param compatInfo this resource's compatibility info. Must not be null.
|
||||
* @param overrideConfig the overrides specific to this ResourcesImpl object. They must already
|
||||
* be applied to the fullConfig and are mainly maintained in order to return a valid
|
||||
* DisplayAdjustments object during configuration changes.
|
||||
*/
|
||||
public ResourcesImpl(@NonNull AssetManager assets, @Nullable DisplayMetrics metrics,
|
||||
@Nullable Configuration fullConfig, @NonNull CompatibilityInfo compatInfo,
|
||||
@Nullable Configuration overrideConfig) {
|
||||
mAssets = assets;
|
||||
mMetrics.setToDefaults();
|
||||
updateConfiguration(config, metrics, compatInfo);
|
||||
mDisplayAdjustments.setCompatibilityInfo(compatInfo);
|
||||
if (overrideConfig != null) {
|
||||
mDisplayAdjustments.setConfiguration(overrideConfig);
|
||||
}
|
||||
updateConfiguration(fullConfig, metrics, compatInfo);
|
||||
mAssets.ensureStringBlocks();
|
||||
}
|
||||
|
||||
public DisplayAdjustments getDisplayAdjustments() {
|
||||
return mDisplayAdjustments;
|
||||
}
|
||||
|
||||
public AssetManager getAssets() {
|
||||
return mAssets;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.Objects;
|
||||
|
||||
/** @hide */
|
||||
public class DisplayAdjustments {
|
||||
public static final boolean DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN = false;
|
||||
|
||||
public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
|
||||
|
||||
private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
|
||||
@@ -74,10 +72,8 @@ public class DisplayAdjustments {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = hash * 31 + mCompatInfo.hashCode();
|
||||
if (DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN) {
|
||||
hash = hash * 31 + (mConfiguration == null ? 0 : mConfiguration.hashCode());
|
||||
}
|
||||
hash = hash * 31 + Objects.hashCode(mCompatInfo);
|
||||
hash = hash * 31 + Objects.hashCode(mConfiguration);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.LayoutTransition;
|
||||
import android.annotation.NonNull;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.ResourcesManager;
|
||||
import android.content.ClipDescription;
|
||||
import android.content.ComponentCallbacks;
|
||||
import android.content.Context;
|
||||
@@ -163,7 +165,7 @@ public final class ViewRootImpl implements ViewParent,
|
||||
final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>();
|
||||
final Context mContext;
|
||||
final IWindowSession mWindowSession;
|
||||
final Display mDisplay;
|
||||
@NonNull Display mDisplay;
|
||||
final DisplayManager mDisplayManager;
|
||||
final String mBasePackageName;
|
||||
|
||||
@@ -307,8 +309,6 @@ public final class ViewRootImpl implements ViewParent,
|
||||
boolean mAdded;
|
||||
boolean mAddedTouchMode;
|
||||
|
||||
final DisplayAdjustments mDisplayAdjustments;
|
||||
|
||||
// These are accessed by multiple threads.
|
||||
final Rect mWinFrame; // frame given by window manager.
|
||||
|
||||
@@ -412,9 +412,6 @@ public final class ViewRootImpl implements ViewParent,
|
||||
mWindowSession = WindowManagerGlobal.getWindowSession();
|
||||
mDisplay = display;
|
||||
mBasePackageName = context.getBasePackageName();
|
||||
|
||||
mDisplayAdjustments = display.getDisplayAdjustments();
|
||||
|
||||
mThread = Thread.currentThread();
|
||||
mLocation = new WindowLeaked(null);
|
||||
mLocation.fillInStackTrace();
|
||||
@@ -588,7 +585,8 @@ public final class ViewRootImpl implements ViewParent,
|
||||
attrs.setSurfaceInsets(view, false /*manual*/, true /*preservePrevious*/);
|
||||
}
|
||||
|
||||
CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo();
|
||||
CompatibilityInfo compatibilityInfo =
|
||||
mDisplay.getDisplayAdjustments().getCompatibilityInfo();
|
||||
mTranslator = compatibilityInfo.getTranslator();
|
||||
|
||||
// If the application owns the surface, don't enable hardware acceleration
|
||||
@@ -1468,7 +1466,8 @@ public final class ViewRootImpl implements ViewParent,
|
||||
surfaceChanged = true;
|
||||
params = lp;
|
||||
}
|
||||
CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo();
|
||||
CompatibilityInfo compatibilityInfo =
|
||||
mDisplay.getDisplayAdjustments().getCompatibilityInfo();
|
||||
if (compatibilityInfo.supportsScreen() == mLastInCompatMode) {
|
||||
params = lp;
|
||||
mFullRedrawNeeded = true;
|
||||
@@ -3306,7 +3305,7 @@ public final class ViewRootImpl implements ViewParent,
|
||||
+ mWindowAttributes.getTitle()
|
||||
+ ": " + config);
|
||||
|
||||
CompatibilityInfo ci = mDisplayAdjustments.getCompatibilityInfo();
|
||||
CompatibilityInfo ci = mDisplay.getDisplayAdjustments().getCompatibilityInfo();
|
||||
if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
|
||||
config = new Configuration(config);
|
||||
ci.applyToConfiguration(mNoncompatDensity, config);
|
||||
@@ -3321,8 +3320,13 @@ public final class ViewRootImpl implements ViewParent,
|
||||
// At this point the resources have been updated to
|
||||
// have the most recent config, whatever that is. Use
|
||||
// the one in them which may be newer.
|
||||
config = mView.getResources().getConfiguration();
|
||||
final Resources localResources = mView.getResources();
|
||||
config = localResources.getConfiguration();
|
||||
if (force || mLastConfiguration.diff(config) != 0) {
|
||||
// Update the display with new DisplayAdjustments.
|
||||
mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(
|
||||
mDisplay.getDisplayId(), localResources.getDisplayAdjustments());
|
||||
|
||||
final int lastLayoutDirection = mLastConfiguration.getLayoutDirection();
|
||||
final int currentLayoutDirection = config.getLayoutDirection();
|
||||
mLastConfiguration.setTo(config);
|
||||
|
||||
@@ -55,26 +55,26 @@ import java.util.List;
|
||||
*/
|
||||
public final class WindowManagerImpl implements WindowManager {
|
||||
private final WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance();
|
||||
private final Display mDisplay;
|
||||
private final Context mContext;
|
||||
private final Window mParentWindow;
|
||||
|
||||
private IBinder mDefaultToken;
|
||||
|
||||
public WindowManagerImpl(Display display) {
|
||||
this(display, null);
|
||||
public WindowManagerImpl(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
private WindowManagerImpl(Display display, Window parentWindow) {
|
||||
mDisplay = display;
|
||||
private WindowManagerImpl(Context context, Window parentWindow) {
|
||||
mContext = context;
|
||||
mParentWindow = parentWindow;
|
||||
}
|
||||
|
||||
public WindowManagerImpl createLocalWindowManager(Window parentWindow) {
|
||||
return new WindowManagerImpl(mDisplay, parentWindow);
|
||||
return new WindowManagerImpl(mContext, parentWindow);
|
||||
}
|
||||
|
||||
public WindowManagerImpl createPresentationWindowManager(Display display) {
|
||||
return new WindowManagerImpl(display, mParentWindow);
|
||||
public WindowManagerImpl createPresentationWindowManager(Context displayContext) {
|
||||
return new WindowManagerImpl(displayContext, mParentWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ public final class WindowManagerImpl implements WindowManager {
|
||||
@Override
|
||||
public void addView(@NonNull View view, @NonNull ViewGroup.LayoutParams params) {
|
||||
applyDefaultToken(params);
|
||||
mGlobal.addView(view, params, mDisplay, mParentWindow);
|
||||
mGlobal.addView(view, params, mContext.getDisplay(), mParentWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,6 +144,6 @@ public final class WindowManagerImpl implements WindowManager {
|
||||
|
||||
@Override
|
||||
public Display getDefaultDisplay() {
|
||||
return mDisplay;
|
||||
return mContext.getDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,6 +702,12 @@ public class MockContext extends Context {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
public Display getDisplay() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getExternalFilesDirs(String type) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
Reference in New Issue
Block a user