From 5d877cde9c76928020565bc1e988b2dc6eb23fbd Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Thu, 1 Oct 2020 14:39:59 +0100 Subject: [PATCH] ProfileManagerService: Fix initialization order 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 initialize the rest of the stuff only during PHASE_ACTIVITY_MANAGER_READY boot phase, because services can only broadcast intents after that phase. This fixes a particular issue, that was causing LineageParts to crash while starting System Profiles activity. Change-Id: I8a397523aec8b5008da3e596eee23463618c8489 --- .../internal/ProfileManagerService.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java index 7411412c..4e448d42 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2011-2015 CyanogenMod Project + * Copyright (C) 2011-2015 CyanogenMod Project + * 2017-2020 LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -231,13 +232,6 @@ public class ProfileManagerService extends LineageSystemService { super(context); mContext = context; mHandler = new Handler(mHandlerCallback); - if (context.getPackageManager().hasSystemFeature( - LineageContextConstants.Features.PROFILES)) { - publishBinderService(LineageContextConstants.LINEAGE_PROFILE_SERVICE, mService); - } else { - Log.wtf(TAG, "Lineage profile service started by system server but feature xml not" + - " declared. Not publishing binder service!"); - } } @Override @@ -259,12 +253,18 @@ public class ProfileManagerService extends LineageSystemService { org.lineageos.platform.internal.R.string.wildcardProfile, mWildcardUUID); - initialize(); - IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_LOCALE_CHANGED); filter.addAction(Intent.ACTION_SHUTDOWN); mContext.registerReceiver(mIntentReceiver, filter); + + if (mContext.getPackageManager().hasSystemFeature( + LineageContextConstants.Features.PROFILES)) { + publishBinderService(LineageContextConstants.LINEAGE_PROFILE_SERVICE, mService); + } else { + Log.wtf(TAG, "Lineage profile service started by system server but feature xml not" + + " declared. Not publishing binder service!"); + } } private void bindKeyguard() { @@ -281,6 +281,7 @@ public class ProfileManagerService extends LineageSystemService { @Override public void onBootPhase(int phase) { if (phase == PHASE_ACTIVITY_MANAGER_READY) { + initialize(); bindKeyguard(); } else if (phase == PHASE_BOOT_COMPLETED) { mContext.getContentResolver().registerContentObserver(