From 4218524124eb053f79afcb28eb5c56eba3e8a173 Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Thu, 1 Oct 2020 15:53:17 +0100 Subject: [PATCH] TrustInterfaceService: Do the needful at a later stage According to the lifecycle of a SystemService, onStart() is called to get the service running and the service should publish its binder interface at that point. First of all, ensure to do that and then do the real work once boot is completed. This was actually the root cause of the issue that commit c06e32d addressed (not entirely correctly). Although the crash was no longer observed after that commit, the proper fix is actually this one. Change-Id: I42dc7182ba3d0db5413709de229ab9c0c4926df6 --- .../internal/TrustInterfaceService.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java index dc8e53bd..9b2f83c9 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java @@ -69,13 +69,6 @@ public class TrustInterfaceService extends LineageSystemService { public TrustInterfaceService(Context context) { super(context); mContext = context; - mNotificationManager = context.getSystemService(NotificationManager.class); - if (context.getPackageManager().hasSystemFeature(LineageContextConstants.Features.TRUST)) { - publishBinderService(LineageContextConstants.LINEAGE_TRUST_INTERFACE, mService); - } else { - Log.wtf(TAG, "Lineage Trust service started by system server but feature xml not" + - " declared. Not publishing binder service!"); - } } @Override @@ -85,20 +78,34 @@ public class TrustInterfaceService extends LineageSystemService { @Override public void onStart() { - try { - mUsbRestrictor = IUsbRestrict.getService(); - } catch (NoSuchElementException | RemoteException e) { - // ignore, the hal is not available + if (mContext.getPackageManager().hasSystemFeature(LineageContextConstants.Features.TRUST)) { + publishBinderService(LineageContextConstants.LINEAGE_TRUST_INTERFACE, mService); + } else { + Log.wtf(TAG, "Lineage Trust service started by system server but feature xml not" + + " declared. Not publishing binder service!"); } + } - // Onboard - if (!hasOnboardedUser()) { - postOnBoardingNotification(); - registerLocaleChangedReceiver(); - return; + @Override + public void onBootPhase(int phase) { + if (phase == PHASE_BOOT_COMPLETED) { + mNotificationManager = mContext.getSystemService(NotificationManager.class); + + try { + mUsbRestrictor = IUsbRestrict.getService(); + } catch (NoSuchElementException | RemoteException e) { + // ignore, the hal is not available + } + + // Onboard + if (!hasOnboardedUser()) { + postOnBoardingNotification(); + registerLocaleChangedReceiver(); + return; + } + + runTestInternal(); } - - runTestInternal(); } /* Public methods implementation */