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
This commit is contained in:
Bruno Martins
2020-10-01 14:39:59 +01:00
parent 4b568b121c
commit 5d877cde9c

View File

@@ -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(