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

Commit f2fd530d authored by Charles Chen's avatar Charles Chen Committed by Automerger Merge Worker
Browse files

Merge "Respect UI Context for getDisplay" into rvc-qpr-dev am: c5ba6230 am: 117b9ab1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12313930

Change-Id: Ib7ed054c9016abdc348b66e57635998cec91dca2
parents 3f6ed527 117b9ab1
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -1924,10 +1924,8 @@ class ContextImpl extends Context {
    @Override
    public Object getSystemService(String name) {
        if (vmIncorrectContextUseEnabled()) {
            // We may override this API from outer context.
            final boolean isUiContext = isUiContext() || isOuterUiContext();
            // Check incorrect Context usage.
            if (isUiComponent(name) && !isUiContext) {
            if (isUiComponent(name) && !isSelfOrOuterUiContext()) {
                final String errorMessage = "Tried to access visual service "
                        + SystemServiceRegistry.getSystemServiceClassName(name)
                        + " from a non-visual Context:" + getOuterContext();
@@ -1944,15 +1942,17 @@ class ContextImpl extends Context {
        return SystemServiceRegistry.getSystemService(this, name);
    }

    private boolean isOuterUiContext() {
        return getOuterContext() != null && getOuterContext().isUiContext();
    }

    @Override
    public String getSystemServiceName(Class<?> 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 */
    @Override
    public boolean isUiContext() {
@@ -2413,7 +2413,7 @@ class ContextImpl extends Context {
        context.setResources(createResources(mToken, mPackageInfo, mSplitName, overrideDisplayId,
                overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo(),
                mResources.getLoaders()));
        context.mIsUiContext = isUiContext() || isOuterUiContext();
        context.mIsUiContext = isSelfOrOuterUiContext();
        return context;
    }

@@ -2529,7 +2529,7 @@ class ContextImpl extends Context {

    @Override
    public Display getDisplay() {
        if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay) {
        if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay && !isSelfOrOuterUiContext()) {
            throw new UnsupportedOperationException("Tried to obtain display from a Context not "
                    + "associated with one. Only visual Contexts (such as Activity or one created "
                    + "with Context#createWindowContext) or ones created with "