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

Commit 79cb3c52 authored by Charles Chen's avatar Charles Chen
Browse files

Move IME log to WindowTokenClient

IMF has the requirement to debug if the configuration is dispatched
to InputMethodService. Since we migrated InputMethodService to
WindowProviderService, we should also move the debug logic to
WindowContext module because config updates will be no longer from
ActivityThread.

Test: build & run
Bug: 135719017
Change-Id: I248c90f36249a6a4537228f7b0204f0d4466ebc7
parent fc7a1b5b
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ import android.graphics.Canvas;
import android.graphics.HardwareRenderer;
import android.graphics.Typeface;
import android.hardware.display.DisplayManagerGlobal;
import android.inputmethodservice.InputMethodService;
import android.media.MediaFrameworkInitializer;
import android.media.MediaFrameworkPlatformInitializer;
import android.media.MediaServiceManager;
@@ -5779,9 +5778,6 @@ public final class ActivityThread extends ClientTransactionHandler
            final int NSVC = mServices.size();
            for (int i=0; i<NSVC; i++) {
                final Service service = mServices.valueAt(i);
                if (service instanceof InputMethodService) {
                    mHasImeComponent = true;
                }
                // If {@code includeUiContext} is set to false, WindowProviderService should not be
                // collected because WindowProviderService is a UI Context.
                if (includeUiContexts || !(service instanceof WindowProviderService)) {
@@ -7524,12 +7520,6 @@ public final class ActivityThread extends ClientTransactionHandler

        ViewRootImpl.ConfigChangedCallback configChangedCallback = (Configuration globalConfig) -> {
            synchronized (mResourcesManager) {
                // TODO (b/135719017): Temporary log for debugging IME service.
                if (Build.IS_DEBUGGABLE && mHasImeComponent) {
                    Log.d(TAG, "ViewRootImpl.ConfigChangedCallback for IME, "
                            + "config=" + globalConfig);
                }

                // We need to apply this change to the resources immediately, because upon returning
                // the view hierarchy will be informed about it.
                if (mResourcesManager.applyConfigurationToResources(globalConfig,
@@ -7884,11 +7874,6 @@ public final class ActivityThread extends ClientTransactionHandler
        return mDensityCompatMode;
    }

    @Override
    public boolean hasImeComponent() {
        return mHasImeComponent;
    }

    // ------------------ Regular JNI ------------------------
    private native void nPurgePendingResources();
    private native void nDumpGraphicsInfo(FileDescriptor fd);
+0 −2
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ interface ActivityThreadInternal {

    boolean isInDensityCompatMode();

    boolean hasImeComponent();

    boolean isCachedProcessState();

    Application getApplication();
+0 −21
Original line number Diff line number Diff line
@@ -28,12 +28,9 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.HardwareRenderer;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.os.LocaleList;
import android.os.Trace;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Slog;
import android.view.ContextThemeWrapper;
import android.view.WindowManagerGlobal;
@@ -168,12 +165,7 @@ class ConfigurationController {
                mPendingConfiguration = null;
            }

            final boolean hasIme = mActivityThread.hasImeComponent();
            if (config == null) {
                // TODO (b/135719017): Temporary log for debugging IME service.
                if (Build.IS_DEBUGGABLE && hasIme) {
                    Log.w(TAG, "handleConfigurationChanged for IME app but config is null");
                }
                return;
            }

@@ -204,12 +196,6 @@ class ConfigurationController {
                mConfiguration = new Configuration();
            }
            if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
                // TODO (b/135719017): Temporary log for debugging IME service.
                if (Build.IS_DEBUGGABLE && hasIme) {
                    Log.w(TAG, "handleConfigurationChanged for IME app but config seq is obsolete "
                            + ", config=" + config
                            + ", mConfiguration=" + mConfiguration);
                }
                return;
            }

@@ -237,13 +223,6 @@ class ConfigurationController {
                ComponentCallbacks2 cb = callbacks.get(i);
                if (!equivalent) {
                    performConfigurationChanged(cb, config);
                } else {
                    // TODO (b/135719017): Temporary log for debugging IME service.
                    if (Build.IS_DEBUGGABLE && cb instanceof InputMethodService) {
                        Log.w(TAG, "performConfigurationChanged didn't callback to IME "
                                + ", configDiff=" + configDiff
                                + ", mConfiguration=" + mConfiguration);
                    }
                }
            }
        }
+23 −0
Original line number Diff line number Diff line
@@ -26,8 +26,11 @@ import android.app.IWindowToken;
import android.app.ResourcesManager;
import android.content.Context;
import android.content.res.Configuration;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import java.lang.ref.WeakReference;

@@ -43,6 +46,8 @@ import java.lang.ref.WeakReference;
 * @hide
 */
public class WindowTokenClient extends IWindowToken.Stub {
    private static final String TAG = WindowTokenClient.class.getSimpleName();

    /**
     * Attached {@link Context} for this window token to update configuration and resources.
     * Initialized by {@link #attachContext(Context)}.
@@ -53,6 +58,8 @@ public class WindowTokenClient extends IWindowToken.Stub {

    private final Configuration mConfiguration = new Configuration();

    private boolean mShouldDumpConfigForIme;

    /**
     * Attaches {@code context} to this {@link WindowTokenClient}. Each {@link WindowTokenClient}
     * can only attach one {@link Context}.
@@ -69,6 +76,8 @@ public class WindowTokenClient extends IWindowToken.Stub {
        }
        mContextRef = new WeakReference<>(context);
        mConfiguration.setTo(context.getResources().getConfiguration());
        mShouldDumpConfigForIme = Build.IS_DEBUGGABLE
                && context instanceof AbstractInputMethodService;
    }

    @Override
@@ -82,6 +91,13 @@ public class WindowTokenClient extends IWindowToken.Stub {
                newConfig, newConfig /* overrideConfig */, displayChanged,
                null /* configChanged */);

        if (!shouldUpdateResources && mShouldDumpConfigForIme) {
            Log.d(TAG, "Configuration not dispatch to IME because configuration is up"
                    + " to date. Current config=" + context.getResources().getConfiguration()
                    + ", reported config=" + mConfiguration
                    + ", updated config=" + newConfig);
        }

        if (shouldUpdateResources) {
            // TODO(ag/9789103): update resource manager logic to track non-activity tokens
            mResourcesManager.updateResourcesForActivity(this, newConfig, newDisplayId);
@@ -104,6 +120,13 @@ public class WindowTokenClient extends IWindowToken.Stub {
                        ((WindowProviderService) context).onConfigurationChanged(newConfig));
            }
            freeTextLayoutCachesIfNeeded(diff);
            if (diff == 0 && mShouldDumpConfigForIme) {
                Log.d(TAG, "Configuration not dispatch to IME because configuration has no "
                        + " public difference with updated config. "
                        + " Current config=" + context.getResources().getConfiguration()
                        + ", reported config=" + mConfiguration
                        + ", updated config=" + newConfig);
            }
            mConfiguration.setTo(newConfig);
        }
        if (displayChanged) {