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

Commit 90ea8e34 authored by Makoto Onuki's avatar Makoto Onuki Committed by Automerger Merge Worker
Browse files

Merge "Add WTF when a system server wrapper can't be found" into rvc-dev am: bea34c40

Change-Id: I12f037d475120da06aac8203ccc009fff6df74fc
parents 1c0cc0fe bea34c40
Loading
Loading
Loading
Loading
+40 −4
Original line number Original line Diff line number Diff line
@@ -186,6 +186,7 @@ import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyRegistryManager;
import android.telephony.TelephonyRegistryManager;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.view.ContextThemeWrapper;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.view.WindowManager;
@@ -222,6 +223,9 @@ import java.util.Objects;
public final class SystemServiceRegistry {
public final class SystemServiceRegistry {
    private static final String TAG = "SystemServiceRegistry";
    private static final String TAG = "SystemServiceRegistry";


    /** @hide */
    public static boolean sEnableServiceNotFoundWtf = false;

    // Service registry information.
    // Service registry information.
    // This information is never changed once static initialization has completed.
    // This information is never changed once static initialization has completed.
    private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES =
    private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES =
@@ -1364,8 +1368,30 @@ public final class SystemServiceRegistry {
     * @hide
     * @hide
     */
     */
    public static Object getSystemService(ContextImpl ctx, String name) {
    public static Object getSystemService(ContextImpl ctx, String name) {
        ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);
        if (name == null) {
        return fetcher != null ? fetcher.getService(ctx) : null;
            return null;
        }
        final ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);
        if (fetcher == null) {
            if (sEnableServiceNotFoundWtf) {
                Slog.wtf(TAG, "Unknown manager requested: " + name);
            }
            return null;
        }

        final Object ret = fetcher.getService(ctx);
        if (sEnableServiceNotFoundWtf && ret == null) {
            // Some services do return null in certain situations, so don't do WTF for them.
            switch (name) {
                case Context.CONTENT_CAPTURE_MANAGER_SERVICE:
                case Context.APP_PREDICTION_SERVICE:
                case Context.INCREMENTAL_SERVICE:
                    return null;
            }
            Slog.wtf(TAG, "Manager wrapper not available: " + name);
            return null;
        }
        return ret;
    }
    }


    /**
    /**
@@ -1373,7 +1399,15 @@ public final class SystemServiceRegistry {
     * @hide
     * @hide
     */
     */
    public static String getSystemServiceName(Class<?> serviceClass) {
    public static String getSystemServiceName(Class<?> serviceClass) {
        return SYSTEM_SERVICE_NAMES.get(serviceClass);
        if (serviceClass == null) {
            return null;
        }
        final String serviceName = SYSTEM_SERVICE_NAMES.get(serviceClass);
        if (sEnableServiceNotFoundWtf && serviceName == null) {
            // This should be a caller bug.
            Slog.wtf(TAG, "Unknown manager requested: " + serviceClass.getCanonicalName());
        }
        return serviceName;
    }
    }


    /**
    /**
@@ -1683,7 +1717,9 @@ public final class SystemServiceRegistry {
                        try {
                        try {
                            cache.wait();
                            cache.wait();
                        } catch (InterruptedException e) {
                        } catch (InterruptedException e) {
                            Log.w(TAG, "getService() interrupted");
                            // This shouldn't normally happen, but if someone interrupts the
                            // thread, it will.
                            Slog.wtf(TAG, "getService() interrupted");
                            Thread.currentThread().interrupt();
                            Thread.currentThread().interrupt();
                            return null;
                            return null;
                        }
                        }
+3 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.StringRes;
import android.app.ActivityThread;
import android.app.ActivityThread;
import android.app.AppCompatCallbacks;
import android.app.AppCompatCallbacks;
import android.app.INotificationManager;
import android.app.INotificationManager;
import android.app.SystemServiceRegistry;
import android.app.usage.UsageStatsManagerInternal;
import android.app.usage.UsageStatsManagerInternal;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
@@ -513,6 +514,8 @@ public final class SystemServer {
            Looper.getMainLooper().setSlowLogThresholdMs(
            Looper.getMainLooper().setSlowLogThresholdMs(
                    SLOW_DISPATCH_THRESHOLD_MS, SLOW_DELIVERY_THRESHOLD_MS);
                    SLOW_DISPATCH_THRESHOLD_MS, SLOW_DELIVERY_THRESHOLD_MS);


            SystemServiceRegistry.sEnableServiceNotFoundWtf = true;

            // Initialize native services.
            // Initialize native services.
            System.loadLibrary("android_servers");
            System.loadLibrary("android_servers");