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

Commit ec7daa59 authored by Svet Ganov's avatar Svet Ganov
Browse files

Avoid stale caching of print and companion system services

Test: manual

bug:62297669

Change-Id: I2029ec292a80aefcaf9f0aab27a0564c68486fe9
parent 75b7712f
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.IRestrictionsManager;
import android.content.RestrictionsManager;
import android.content.pm.IShortcutService;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.hardware.ConsumerIrManager;
@@ -651,9 +652,12 @@ final class SystemServiceRegistry {
                new CachedServiceFetcher<PrintManager>() {
            @Override
            public PrintManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                // Get the services without throwing as this is an optional feature
                IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
                IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
                IPrintManager service = null;
                // If the feature not present, don't try to look up every time
                if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
                    service = IPrintManager.Stub.asInterface(ServiceManager
                            .getServiceOrThrow(Context.PRINT_SERVICE));
                }
                return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
                        UserHandle.getAppId(Process.myUid()));
            }});
@@ -663,11 +667,13 @@ final class SystemServiceRegistry {
            @Override
            public CompanionDeviceManager createService(ContextImpl ctx)
                    throws ServiceNotFoundException {
                        // Get the services without throwing as this is an optional feature
                        IBinder iBinder =
                                ServiceManager.getService(Context.COMPANION_DEVICE_SERVICE);
                        ICompanionDeviceManager service =
                                ICompanionDeviceManager.Stub.asInterface(iBinder);
                ICompanionDeviceManager service = null;
                // If the feature not present, don't try to look up every time
                if (ctx.getPackageManager().hasSystemFeature(
                        PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) {
                    service = ICompanionDeviceManager.Stub.asInterface(
                            ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE));
                }
                return new CompanionDeviceManager(service, ctx.getOuterContext());
            }});