Merge "Show class name in error message" into rvc-dev am: dee20d12dc
Change-Id: I1e1b400b277a530635b2b7a480526c3f740b9bf2
This commit is contained in:
@@ -1899,8 +1899,9 @@ 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 "
|
||||||
+ " from a non-visual Context.";
|
+ SystemServiceRegistry.getSystemServiceClassName(name)
|
||||||
|
+ " 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. "
|
||||||
+ "Use an Activity or a Context created with "
|
+ "Use an Activity or a Context created with "
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user