diff options
author | 2024-06-06 07:52:30 +0000 | |
---|---|---|
committer | 2024-06-06 18:01:49 +0000 | |
commit | 6b36e0587bdd56f5f11eb69cface5a959cb56a78 (patch) | |
tree | 7648e505d418107a67713944e36b39862d122311 /services/profcollect | |
parent | dc2cfc8a10b8b74ec2c70f3b2d32aa9bf765de87 (diff) |
profcollect: Trace on camera open events
This allows us to collect traces for camera related libraries, like
libg3a. For the initial experiment, we collect the traces one second
after the camera opens. We can fine tune this or switch to other
triggers once we have the benchmark numbers.
Test: manual
Bug: 319394981
Change-Id: Ia65694602af1054dd261f4e72c1c3f82056eb1e3
Diffstat (limited to 'services/profcollect')
-rw-r--r-- | services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java index 33bf4bd1cc02..c0259135132b 100644 --- a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +++ b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java @@ -25,6 +25,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.hardware.camera2.CameraManager; import android.os.Handler; import android.os.IBinder.DeathRecipient; import android.os.Looper; @@ -258,6 +259,7 @@ public final class ProfcollectForwardingService extends SystemService { BackgroundThread.get().getThreadHandler().post( () -> { registerAppLaunchObserver(); + registerCameraOpenObserver(); registerDex2oatObserver(); registerOTAObserver(); }); @@ -371,4 +373,37 @@ public final class ProfcollectForwardingService extends SystemService { pfs.getContext().sendBroadcast(intent); }); } + + private void registerCameraOpenObserver() { + CameraManager cm = getContext().getSystemService(CameraManager.class); + cm.registerAvailabilityCallback(new CameraManager.AvailabilityCallback() { + @Override + public void onCameraOpened(String cameraId, String packageId) { + Log.d(LOG_TAG, "Received camera open event from: " + packageId); + // Skip face auth and Android System Intelligence, since they trigger way too + // often. + if (packageId.startsWith("client.pid") + || packageId.equals("com.google.android.as")) { + return; + } + // Sample for a fraction of camera events. + final int traceFrequency = + DeviceConfig.getInt(DeviceConfig.NAMESPACE_PROFCOLLECT_NATIVE_BOOT, + "camera_trace_freq", 10); + int randomNum = ThreadLocalRandom.current().nextInt(100); + if (randomNum >= traceFrequency) { + return; + } + BackgroundThread.get().getThreadHandler().post(() -> { + try { + // Wait for a short time before starting tracing. + Thread.sleep(1000); + mIProfcollect.trace_once("camera"); + } catch (RemoteException | InterruptedException e) { + Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); + } + }); + } + }, null); + } } |