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

Commit 1b7792fc authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Show class name in error message" into rvc-dev am: dee20d12 am: c98cd1ab am: 8c0711b6

Change-Id: I7f524b2d223ffd76860a71524821214ee12a9046
parents a66ea600 8c0711b6
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -1899,7 +1899,8 @@ class ContextImpl extends Context {
    public Object getSystemService(String name) {
    public Object getSystemService(String name) {
        // Check incorrect Context usage.
        // Check incorrect Context usage.
        if (isUiComponent(name) && !isUiContext() && vmIncorrectContextUseEnabled()) {
        if (isUiComponent(name) && !isUiContext() && vmIncorrectContextUseEnabled()) {
            final String errorMessage = "Tried to access visual service " + name
            final String errorMessage = "Tried to access visual service "
                    + SystemServiceRegistry.getSystemServiceClassName(name)
                    + " from a non-visual Context. ";
                    + " from a non-visual Context. ";
            final String message = "Visual services, such as WindowManager, WallpaperService or "
            final String message = "Visual services, such as WindowManager, WallpaperService or "
                    + "LayoutInflater should be accessed from Activity or other visual Context. "
                    + "LayoutInflater should be accessed from Activity or other visual Context. "
+16 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.accounts.AccountManager;
import android.accounts.AccountManager;
import android.accounts.IAccountManager;
import android.accounts.IAccountManager;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.app.ContextImpl.ServiceInitializationState;
import android.app.ContextImpl.ServiceInitializationState;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager;
@@ -227,6 +228,8 @@ public final class SystemServiceRegistry {
            new ArrayMap<Class<?>, String>();
            new ArrayMap<Class<?>, String>();
    private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS =
    private static final Map<String, ServiceFetcher<?>> SYSTEM_SERVICE_FETCHERS =
            new ArrayMap<String, ServiceFetcher<?>>();
            new ArrayMap<String, ServiceFetcher<?>>();
    private static final Map<String, String> SYSTEM_SERVICE_CLASS_NAMES = new ArrayMap<>();

    private static int sServiceCacheSize;
    private static int sServiceCacheSize;


    private static volatile boolean sInitializing;
    private static volatile boolean sInitializing;
@@ -1389,6 +1392,19 @@ public final class SystemServiceRegistry {
            @NonNull Class<T> serviceClass, @NonNull ServiceFetcher<T> serviceFetcher) {
            @NonNull Class<T> serviceClass, @NonNull ServiceFetcher<T> serviceFetcher) {
        SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName);
        SYSTEM_SERVICE_NAMES.put(serviceClass, serviceName);
        SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher);
        SYSTEM_SERVICE_FETCHERS.put(serviceName, serviceFetcher);
        SYSTEM_SERVICE_CLASS_NAMES.put(serviceName, serviceClass.getSimpleName());
    }

    /**
     * Returns system service class name by system service name. This method is mostly an inverse of
     * {@link #getSystemServiceName(Class)}
     *
     * @return system service class name. {@code null} if service name is invalid.
     * @hide
     */
    @Nullable
    public static String getSystemServiceClassName(@NonNull String name) {
        return SYSTEM_SERVICE_CLASS_NAMES.get(name);
    }
    }


    /**
    /**