Merge "Respect UI Context for getDisplay" into rvc-qpr-dev
This commit is contained in:
@@ -1914,10 +1914,8 @@ class ContextImpl extends Context {
|
|||||||
@Override
|
@Override
|
||||||
public Object getSystemService(String name) {
|
public Object getSystemService(String name) {
|
||||||
if (vmIncorrectContextUseEnabled()) {
|
if (vmIncorrectContextUseEnabled()) {
|
||||||
// We may override this API from outer context.
|
|
||||||
final boolean isUiContext = isUiContext() || isOuterUiContext();
|
|
||||||
// Check incorrect Context usage.
|
// Check incorrect Context usage.
|
||||||
if (isUiComponent(name) && !isUiContext) {
|
if (isUiComponent(name) && !isSelfOrOuterUiContext()) {
|
||||||
final String errorMessage = "Tried to access visual service "
|
final String errorMessage = "Tried to access visual service "
|
||||||
+ SystemServiceRegistry.getSystemServiceClassName(name)
|
+ SystemServiceRegistry.getSystemServiceClassName(name)
|
||||||
+ " from a non-visual Context:" + getOuterContext();
|
+ " from a non-visual Context:" + getOuterContext();
|
||||||
@@ -1934,15 +1932,17 @@ class ContextImpl extends Context {
|
|||||||
return SystemServiceRegistry.getSystemService(this, name);
|
return SystemServiceRegistry.getSystemService(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOuterUiContext() {
|
|
||||||
return getOuterContext() != null && getOuterContext().isUiContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSystemServiceName(Class<?> serviceClass) {
|
public String getSystemServiceName(Class<?> serviceClass) {
|
||||||
return SystemServiceRegistry.getSystemServiceName(serviceClass);
|
return SystemServiceRegistry.getSystemServiceName(serviceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(b/149463653): check if we still need this method after migrating IMS to WindowContext.
|
||||||
|
private boolean isSelfOrOuterUiContext() {
|
||||||
|
// We may override outer context's isUiContext
|
||||||
|
return isUiContext() || getOuterContext() != null && getOuterContext().isUiContext();
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@Override
|
@Override
|
||||||
public boolean isUiContext() {
|
public boolean isUiContext() {
|
||||||
@@ -2389,7 +2389,7 @@ class ContextImpl extends Context {
|
|||||||
context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId,
|
context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId,
|
||||||
overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo(),
|
overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo(),
|
||||||
mResources.getLoaders()));
|
mResources.getLoaders()));
|
||||||
context.mIsUiContext = isUiContext() || isOuterUiContext();
|
context.mIsUiContext = isSelfOrOuterUiContext();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2494,7 +2494,7 @@ class ContextImpl extends Context {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Display getDisplay() {
|
public Display getDisplay() {
|
||||||
if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay) {
|
if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay && !isSelfOrOuterUiContext()) {
|
||||||
throw new UnsupportedOperationException("Tried to obtain display from a Context not "
|
throw new UnsupportedOperationException("Tried to obtain display from a Context not "
|
||||||
+ "associated with one. Only visual Contexts (such as Activity or one created "
|
+ "associated with one. Only visual Contexts (such as Activity or one created "
|
||||||
+ "with Context#createWindowContext) or ones created with "
|
+ "with Context#createWindowContext) or ones created with "
|
||||||
|
|||||||
Reference in New Issue
Block a user