From 36c8432f9cb9f9597512fedc5b15680982e05df0 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Tue, 20 Oct 2020 01:53:47 +0800 Subject: [PATCH] profcollectd: OTA Observer Pack any existing ETM profiles when an OTA is ready to install, which simplifies the workflow for reporting profcollectd profiles. Future work will use the same observer to upload profiles to a collection service. Bug: 79161490 Test: vendor/google/tools/fake-ota streaming on Change-Id: I106af19a3360b87d19ceafaa3ef3b97f1cf34244 --- .../ProfcollectForwardingService.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java index ddd1f7568224e..d14ed5a15cf91 100644 --- a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +++ b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java @@ -29,6 +29,8 @@ import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemProperties; +import android.os.UpdateEngine; +import android.os.UpdateEngineCallback; import android.util.Log; import com.android.server.IoThread; @@ -198,6 +200,7 @@ public final class ProfcollectForwardingService extends SystemService { // Event observers private void registerObservers() { registerAppLaunchObserver(); + registerOTAObserver(); } private final AppLaunchObserver mAppLaunchObserver = new AppLaunchObserver(); @@ -261,4 +264,33 @@ public final class ProfcollectForwardingService extends SystemService { // Ignored } } + + private void registerOTAObserver() { + UpdateEngine updateEngine = new UpdateEngine(); + updateEngine.bind(new UpdateEngineCallback() { + @Override + public void onStatusUpdate(int status, float percent) { + if (status == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT) { + packProfileReport(); + } + } + + @Override + public void onPayloadApplicationComplete(int errorCode) { + // Ignored + } + }); + } + + private void packProfileReport() { + if (mIProfcollect == null) { + return; + } + + try { + mIProfcollect.CreateProfileReport(); + } catch (RemoteException e) { + Log.e(LOG_TAG, e.getMessage()); + } + } }