From 56354a961e004dc540ec9525ed0afb62cc68a1bd Mon Sep 17 00:00:00 2001 From: Kangping Dong Date: Fri, 5 Jan 2024 15:25:30 +0800 Subject: [PATCH] [Thread] start / initialize Thread service early We need to do initialization work and start OT daemon when system_server boots. But the initialize() is called at the phase PHASE_BOOT_COMPLETED which is too late as Apps (e.g. Google Play Services) can be started before this phase. This commit changes to start the Thread service earlier at the phase PHASE_SYSTEM_SERVICES_READY. Other services such as Wi-Fi, Bluetooth, Ethernet and Nearby all starts / initializes at this phase. This commit resolves comment aosp/2737373/comment/d65b9446_8a08117c Bug: 318787467 Test: atest CtsThreadNetworkTestCases Change-Id: I7b7b8551b9114cbf07f995b64316c7b420d868b6 --- .../com/android/server/thread/ThreadNetworkService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkService.java b/thread/service/java/com/android/server/thread/ThreadNetworkService.java index a3cf278c0f..53f2d4f4b3 100644 --- a/thread/service/java/com/android/server/thread/ThreadNetworkService.java +++ b/thread/service/java/com/android/server/thread/ThreadNetworkService.java @@ -48,17 +48,20 @@ public class ThreadNetworkService extends IThreadNetworkManager.Stub { } /** - * Called by the service initializer. + * Called by {@link com.android.server.ConnectivityServiceInitializer}. * * @see com.android.server.SystemService#onBootPhase */ public void onBootPhase(int phase) { - if (phase == SystemService.PHASE_BOOT_COMPLETED) { + if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { mControllerService = ThreadNetworkControllerService.newInstance(mContext); mControllerService.initialize(); + } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { + // Country code initialization is delayed to the BOOT_COMPLETED phase because it will + // call into Wi-Fi and Telephony service whose country code module is ready after + // PHASE_ACTIVITY_MANAGER_READY and PHASE_THIRD_PARTY_APPS_CAN_START mCountryCode = ThreadNetworkCountryCode.newInstance(mContext, mControllerService); mCountryCode.initialize(); - mShellCommand = new ThreadNetworkShellCommand(mCountryCode); } }