From 2d55b23e7dec99a7f9e5d3e6872810b5da5013ce Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Sat, 29 Oct 2022 14:35:16 -0700 Subject: Logspam: Properly handle optional app widgets service If a service is not present and an exeception is thrown in the SystemServiceRegistry, we log a message and proceed with the null service. Optional feature services, like app widgets, are expected to be missing if not supported. Properly handle the lookup, so no exception that pollutes the logs is emitted for what is normal operation. Test: No exception logged with the app widgets feature disabled Upstream from Meta Change-Id: I1cae4f9188ec47b55d68d7c8208f0da1c6c263b4 --- core/java/android/app/SystemServiceRegistry.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index bdecca379b20..277a24f65413 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -1020,9 +1020,10 @@ public final class SystemServiceRegistry { registerService(Context.APPWIDGET_SERVICE, AppWidgetManager.class, new CachedServiceFetcher() { @Override - public AppWidgetManager createService(ContextImpl ctx) throws ServiceNotFoundException { - IBinder b = ServiceManager.getServiceOrThrow(Context.APPWIDGET_SERVICE); - return new AppWidgetManager(ctx, IAppWidgetService.Stub.asInterface(b)); + public AppWidgetManager createService(ContextImpl ctx) { + IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE); + return b == null ? null : new AppWidgetManager(ctx, + IAppWidgetService.Stub.asInterface(b)); }}); registerService(Context.MIDI_SERVICE, MidiManager.class, -- cgit v1.2.3-59-g8ed1b