Merge "Use DisplayAdjustments when creating display in ResourceManager" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d8b9b642fe
@@ -34706,6 +34706,7 @@ package android.view {
|
||||
field public static final int FLAG_ROUND = 16; // 0x10
|
||||
field public static final int FLAG_SECURE = 2; // 0x2
|
||||
field public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1; // 0x1
|
||||
field public static final int INVALID_DISPLAY = -1; // 0xffffffff
|
||||
field public static final int STATE_DOZE = 3; // 0x3
|
||||
field public static final int STATE_DOZE_SUSPEND = 4; // 0x4
|
||||
field public static final int STATE_OFF = 1; // 0x1
|
||||
|
||||
@@ -36971,6 +36971,7 @@ package android.view {
|
||||
field public static final int FLAG_ROUND = 16; // 0x10
|
||||
field public static final int FLAG_SECURE = 2; // 0x2
|
||||
field public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1; // 0x1
|
||||
field public static final int INVALID_DISPLAY = -1; // 0xffffffff
|
||||
field public static final int STATE_DOZE = 3; // 0x3
|
||||
field public static final int STATE_DOZE_SUSPEND = 4; // 0x4
|
||||
field public static final int STATE_OFF = 1; // 0x1
|
||||
|
||||
@@ -2444,7 +2444,8 @@ public final class ActivityThread {
|
||||
&& r.packageInfo.mPackageName.contains(pkgName)) {
|
||||
for (int id : dm.getDisplayIds()) {
|
||||
if (id != Display.DEFAULT_DISPLAY) {
|
||||
Display display = dm.getRealDisplay(id, r.overrideConfig);
|
||||
Display display =
|
||||
dm.getCompatibleDisplay(id, appContext.getDisplayAdjustments(id));
|
||||
baseContext = appContext.createDisplayContext(display);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1597,7 +1597,7 @@ class ContextImpl extends Context {
|
||||
final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
|
||||
ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken,
|
||||
new UserHandle(UserHandle.getUserId(application.uid)), restricted,
|
||||
mDisplay, null);
|
||||
mDisplay, null, Display.INVALID_DISPLAY);
|
||||
if (c.mResources != null) {
|
||||
return c;
|
||||
}
|
||||
@@ -1620,14 +1620,14 @@ class ContextImpl extends Context {
|
||||
final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
|
||||
if (packageName.equals("system") || packageName.equals("android")) {
|
||||
return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken,
|
||||
user, restricted, mDisplay, null);
|
||||
user, restricted, mDisplay, null, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(),
|
||||
flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier());
|
||||
if (pi != null) {
|
||||
ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken,
|
||||
user, restricted, mDisplay, null);
|
||||
user, restricted, mDisplay, null, Display.INVALID_DISPLAY);
|
||||
if (c.mResources != null) {
|
||||
return c;
|
||||
}
|
||||
@@ -1645,7 +1645,7 @@ class ContextImpl extends Context {
|
||||
}
|
||||
|
||||
return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken,
|
||||
mUser, mRestricted, mDisplay, overrideConfiguration);
|
||||
mUser, mRestricted, mDisplay, overrideConfiguration, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1655,15 +1655,15 @@ class ContextImpl extends Context {
|
||||
}
|
||||
|
||||
return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken,
|
||||
mUser, mRestricted, display, null);
|
||||
mUser, mRestricted, display, null, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
Display getDisplay() {
|
||||
if (mDisplay != null) {
|
||||
return mDisplay;
|
||||
}
|
||||
DisplayManager dm = getSystemService(DisplayManager.class);
|
||||
return dm.getDisplay(Display.DEFAULT_DISPLAY);
|
||||
return ResourcesManager.getInstance().getAdjustedDisplay(
|
||||
Display.DEFAULT_DISPLAY, mDisplayAdjustments);
|
||||
}
|
||||
|
||||
private int getDisplayId() {
|
||||
@@ -1708,7 +1708,7 @@ class ContextImpl extends Context {
|
||||
static ContextImpl createSystemContext(ActivityThread mainThread) {
|
||||
LoadedApk packageInfo = new LoadedApk(mainThread);
|
||||
ContextImpl context = new ContextImpl(null, mainThread,
|
||||
packageInfo, null, null, false, null, null);
|
||||
packageInfo, null, null, false, null, null, Display.INVALID_DISPLAY);
|
||||
context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(),
|
||||
context.mResourcesManager.getDisplayMetricsLocked());
|
||||
return context;
|
||||
@@ -1717,21 +1717,19 @@ class ContextImpl extends Context {
|
||||
static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) {
|
||||
if (packageInfo == null) throw new IllegalArgumentException("packageInfo");
|
||||
return new ContextImpl(null, mainThread,
|
||||
packageInfo, null, null, false, null, null);
|
||||
packageInfo, null, null, false, null, null, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
static ContextImpl createActivityContext(ActivityThread mainThread,
|
||||
LoadedApk packageInfo, int displayId, Configuration overrideConfiguration) {
|
||||
if (packageInfo == null) throw new IllegalArgumentException("packageInfo");
|
||||
final Display display = ResourcesManager.getInstance().getAdjustedDisplay(
|
||||
displayId, overrideConfiguration);
|
||||
return new ContextImpl(null, mainThread, packageInfo, null, null, false, display,
|
||||
overrideConfiguration);
|
||||
return new ContextImpl(null, mainThread, packageInfo, null, null, false,
|
||||
null, overrideConfiguration, displayId);
|
||||
}
|
||||
|
||||
private ContextImpl(ContextImpl container, ActivityThread mainThread,
|
||||
LoadedApk packageInfo, IBinder activityToken, UserHandle user, boolean restricted,
|
||||
Display display, Configuration overrideConfiguration) {
|
||||
Display display, Configuration overrideConfiguration, int createDisplayWithId) {
|
||||
mOuterContext = this;
|
||||
|
||||
mMainThread = mainThread;
|
||||
@@ -1745,9 +1743,10 @@ class ContextImpl extends Context {
|
||||
|
||||
mPackageInfo = packageInfo;
|
||||
mResourcesManager = ResourcesManager.getInstance();
|
||||
mDisplay = display;
|
||||
|
||||
final int displayId = getDisplayId();
|
||||
final int displayId = (createDisplayWithId != Display.INVALID_DISPLAY)
|
||||
? createDisplayWithId : getDisplayId();
|
||||
|
||||
CompatibilityInfo compatInfo = null;
|
||||
if (container != null) {
|
||||
compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo();
|
||||
@@ -1760,6 +1759,9 @@ class ContextImpl extends Context {
|
||||
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) {
|
||||
if (displayId != Display.DEFAULT_DISPLAY
|
||||
|
||||
@@ -31,6 +31,8 @@ import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayAdjustments;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -42,7 +44,7 @@ public class ResourcesManager {
|
||||
private static ResourcesManager sResourcesManager;
|
||||
private final ArrayMap<ResourcesKey, WeakReference<Resources> > mActiveResources =
|
||||
new ArrayMap<>();
|
||||
private final ArrayMap<Pair<Integer, Configuration>, WeakReference<Display>> mDisplays =
|
||||
private final ArrayMap<Pair<Integer, DisplayAdjustments>, WeakReference<Display>> mDisplays =
|
||||
new ArrayMap<>();
|
||||
|
||||
CompatibilityInfo mResCompatibilityInfo;
|
||||
@@ -68,7 +70,8 @@ public class ResourcesManager {
|
||||
|
||||
DisplayMetrics getDisplayMetricsLocked(int displayId) {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
final Display display = getAdjustedDisplay(displayId, Configuration.EMPTY);
|
||||
final Display display =
|
||||
getAdjustedDisplay(displayId, DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
|
||||
if (display != null) {
|
||||
display.getMetrics(dm);
|
||||
} else {
|
||||
@@ -113,12 +116,13 @@ public class ResourcesManager {
|
||||
* available.
|
||||
*
|
||||
* @param displayId display Id.
|
||||
* @param overrideConfiguration override configurations.
|
||||
* @param displayAdjustments display adjustments.
|
||||
*/
|
||||
public Display getAdjustedDisplay(final int displayId, Configuration overrideConfiguration) {
|
||||
final Configuration configCopy = (overrideConfiguration != null)
|
||||
? new Configuration(overrideConfiguration) : new Configuration();
|
||||
final Pair<Integer, Configuration> key = Pair.create(displayId, configCopy);
|
||||
public Display getAdjustedDisplay(final int displayId, DisplayAdjustments displayAdjustments) {
|
||||
final DisplayAdjustments displayAdjustmentsCopy = (displayAdjustments != null)
|
||||
? new DisplayAdjustments(displayAdjustments) : new DisplayAdjustments();
|
||||
final Pair<Integer, DisplayAdjustments> key =
|
||||
Pair.create(displayId, displayAdjustmentsCopy);
|
||||
synchronized (this) {
|
||||
WeakReference<Display> wd = mDisplays.get(key);
|
||||
if (wd != null) {
|
||||
@@ -132,7 +136,7 @@ public class ResourcesManager {
|
||||
// may be null early in system startup
|
||||
return null;
|
||||
}
|
||||
final Display display = dm.getRealDisplay(displayId, key.second);
|
||||
final Display display = dm.getCompatibleDisplay(displayId, key.second);
|
||||
if (display != null) {
|
||||
mDisplays.put(key, new WeakReference<>(display));
|
||||
}
|
||||
|
||||
@@ -192,17 +192,6 @@ public final class DisplayManagerGlobal {
|
||||
return getCompatibleDisplay(displayId, DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about a logical display without applying any compatibility metrics.
|
||||
*
|
||||
* @param displayId The logical display id.
|
||||
* @param configuration the configuration.
|
||||
* @return The display object, or null if there is no display with the given id.
|
||||
*/
|
||||
public Display getRealDisplay(int displayId, Configuration configuration) {
|
||||
return getCompatibleDisplay(displayId, new DisplayAdjustments(configuration));
|
||||
}
|
||||
|
||||
public void registerDisplayListener(DisplayListener listener, Handler handler) {
|
||||
if (listener == null) {
|
||||
throw new IllegalArgumentException("listener must not be null");
|
||||
|
||||
@@ -88,6 +88,11 @@ public final class Display {
|
||||
*/
|
||||
public static final int DEFAULT_DISPLAY = 0;
|
||||
|
||||
/**
|
||||
* Invalid display id.
|
||||
*/
|
||||
public static final int INVALID_DISPLAY = -1;
|
||||
|
||||
/**
|
||||
* Display flag: Indicates that the display supports compositing content
|
||||
* that is stored in protected graphics buffers.
|
||||
|
||||
Reference in New Issue
Block a user