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

Commit 074c1433 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

Avoid crashes for no WearableSensingManager in Wear

Wear intentionally removes the backing system service, so the absence of
the service class should not cause a crash/wtf error.

Bug: 340929916
Bug: 367193120
Test: manual, unit test
Flag: android.server.remove_wearable_sensing_service_from_wear
Change-Id: I919948a8d00336563e20d37503c03686433a004d
parent b9a7ac0a
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1657,11 +1657,20 @@ public final class SystemServiceRegistry {
                    @Override
                    public WearableSensingManager createService(ContextImpl ctx)
                            throws ServiceNotFoundException {
                        IBinder iBinder = ServiceManager.getServiceOrThrow(
                        IBinder iBinder = ServiceManager.getService(
                                Context.WEARABLE_SENSING_SERVICE);
                        if (iBinder != null) {
                            IWearableSensingManager manager =
                                    IWearableSensingManager.Stub.asInterface(iBinder);
                            return new WearableSensingManager(ctx.getOuterContext(), manager);
                        }
                        // Wear intentionally removes the service, so do not throw a
                        // ServiceNotFoundException when the service is not absent.
                        if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)
                                && android.server.Flags.removeWearableSensingServiceFromWear()) {
                            return null;
                        }
                        throw new ServiceNotFoundException(Context.WEARABLE_SENSING_SERVICE);
                    }});

        registerService(Context.ON_DEVICE_INTELLIGENCE_SERVICE, OnDeviceIntelligenceManager.class,