Loading core/res/AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -5496,6 +5496,10 @@ android:permission="android.permission.BIND_JOB_SERVICE" > </service> <service android:name="com.android.server.profcollect.ProfcollectForwardingService$ProfcollectBGJobService" android:permission="android.permission.BIND_JOB_SERVICE" > </service> <service android:name="com.android.server.autofill.AutofillCompatAccessibilityService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" Loading services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +77 −10 Original line number Diff line number Diff line Loading @@ -16,6 +16,11 @@ package com.android.server.profcollect; import android.app.job.JobInfo; import android.app.job.JobParameters; import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -34,6 +39,7 @@ import com.android.server.wm.ActivityMetricsLaunchObserverRegistry; import com.android.server.wm.ActivityTaskManagerInternal; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; /** * System-server-local proxy into the {@code IProfcollectd} native service. Loading @@ -41,29 +47,44 @@ import java.util.concurrent.ThreadLocalRandom; public final class ProfcollectForwardingService extends SystemService { public static final String LOG_TAG = "ProfcollectForwardingService"; private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG); private static final long BG_PROCESS_PERIOD = DEBUG ? TimeUnit.MINUTES.toMillis(1) : TimeUnit.DAYS.toMillis(1); private IProfCollectd mIProfcollect; private ProfcollectForwardingService mSelfService; private static ProfcollectForwardingService sSelfService; private final Handler mHandler = new ProfcollectdHandler(IoThread.getHandler().getLooper()); public ProfcollectForwardingService(Context context) { super(context); if (mSelfService != null) { if (sSelfService != null) { throw new AssertionError("only one service instance allowed"); } mSelfService = this; sSelfService = this; } @Override public void onStart() { Log.i(LOG_TAG, "Profcollect forwarding service start"); if (DEBUG) { Log.d(LOG_TAG, "Profcollect forwarding service start"); } connectNativeService(); } @Override public void onBootPhase(int phase) { if (phase == PHASE_BOOT_COMPLETED) { if (mIProfcollect == null) { return; } if (serviceHasSupportedTraceProvider()) { registerObservers(); } ProfcollectBGJobService.schedule(getContext()); } } private boolean serviceHasSupportedTraceProvider() { Loading Loading @@ -130,6 +151,50 @@ public final class ProfcollectForwardingService extends SystemService { } } /** * Background trace process service. */ public static class ProfcollectBGJobService extends JobService { // Unique ID in system service private static final int JOB_IDLE_PROCESS = 260817; private static final ComponentName JOB_SERVICE_NAME = new ComponentName( "android", ProfcollectBGJobService.class.getName()); /** * Attach the service to the system job scheduler. */ public static void schedule(Context context) { JobScheduler js = context.getSystemService(JobScheduler.class); js.schedule(new JobInfo.Builder(JOB_IDLE_PROCESS, JOB_SERVICE_NAME) .setRequiresDeviceIdle(true) .setRequiresCharging(true) .setPeriodic(BG_PROCESS_PERIOD) .build()); } @Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(LOG_TAG, "Starting background process job"); } try { sSelfService.mIProfcollect.ProcessProfile(); } catch (RemoteException e) { Log.e(LOG_TAG, e.getMessage()); } return true; } @Override public boolean onStopJob(JobParameters params) { // TODO: Handle this? return false; } } // Event observers private void registerObservers() { registerAppLaunchObserver(); Loading @@ -155,7 +220,9 @@ public final class ProfcollectForwardingService extends SystemService { int randomNum = ThreadLocalRandom.current().nextInt(100); if (randomNum < traceFrequency) { try { Log.i(LOG_TAG, "Tracing on app launch event: " + packageName); if (DEBUG) { Log.d(LOG_TAG, "Tracing on app launch event: " + packageName); } mIProfcollect.TraceOnce("applaunch"); } catch (RemoteException e) { Log.e(LOG_TAG, e.getMessage()); Loading Loading
core/res/AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -5496,6 +5496,10 @@ android:permission="android.permission.BIND_JOB_SERVICE" > </service> <service android:name="com.android.server.profcollect.ProfcollectForwardingService$ProfcollectBGJobService" android:permission="android.permission.BIND_JOB_SERVICE" > </service> <service android:name="com.android.server.autofill.AutofillCompatAccessibilityService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" Loading
services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +77 −10 Original line number Diff line number Diff line Loading @@ -16,6 +16,11 @@ package com.android.server.profcollect; import android.app.job.JobInfo; import android.app.job.JobParameters; import android.app.job.JobScheduler; import android.app.job.JobService; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -34,6 +39,7 @@ import com.android.server.wm.ActivityMetricsLaunchObserverRegistry; import com.android.server.wm.ActivityTaskManagerInternal; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; /** * System-server-local proxy into the {@code IProfcollectd} native service. Loading @@ -41,29 +47,44 @@ import java.util.concurrent.ThreadLocalRandom; public final class ProfcollectForwardingService extends SystemService { public static final String LOG_TAG = "ProfcollectForwardingService"; private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG); private static final long BG_PROCESS_PERIOD = DEBUG ? TimeUnit.MINUTES.toMillis(1) : TimeUnit.DAYS.toMillis(1); private IProfCollectd mIProfcollect; private ProfcollectForwardingService mSelfService; private static ProfcollectForwardingService sSelfService; private final Handler mHandler = new ProfcollectdHandler(IoThread.getHandler().getLooper()); public ProfcollectForwardingService(Context context) { super(context); if (mSelfService != null) { if (sSelfService != null) { throw new AssertionError("only one service instance allowed"); } mSelfService = this; sSelfService = this; } @Override public void onStart() { Log.i(LOG_TAG, "Profcollect forwarding service start"); if (DEBUG) { Log.d(LOG_TAG, "Profcollect forwarding service start"); } connectNativeService(); } @Override public void onBootPhase(int phase) { if (phase == PHASE_BOOT_COMPLETED) { if (mIProfcollect == null) { return; } if (serviceHasSupportedTraceProvider()) { registerObservers(); } ProfcollectBGJobService.schedule(getContext()); } } private boolean serviceHasSupportedTraceProvider() { Loading Loading @@ -130,6 +151,50 @@ public final class ProfcollectForwardingService extends SystemService { } } /** * Background trace process service. */ public static class ProfcollectBGJobService extends JobService { // Unique ID in system service private static final int JOB_IDLE_PROCESS = 260817; private static final ComponentName JOB_SERVICE_NAME = new ComponentName( "android", ProfcollectBGJobService.class.getName()); /** * Attach the service to the system job scheduler. */ public static void schedule(Context context) { JobScheduler js = context.getSystemService(JobScheduler.class); js.schedule(new JobInfo.Builder(JOB_IDLE_PROCESS, JOB_SERVICE_NAME) .setRequiresDeviceIdle(true) .setRequiresCharging(true) .setPeriodic(BG_PROCESS_PERIOD) .build()); } @Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(LOG_TAG, "Starting background process job"); } try { sSelfService.mIProfcollect.ProcessProfile(); } catch (RemoteException e) { Log.e(LOG_TAG, e.getMessage()); } return true; } @Override public boolean onStopJob(JobParameters params) { // TODO: Handle this? return false; } } // Event observers private void registerObservers() { registerAppLaunchObserver(); Loading @@ -155,7 +220,9 @@ public final class ProfcollectForwardingService extends SystemService { int randomNum = ThreadLocalRandom.current().nextInt(100); if (randomNum < traceFrequency) { try { Log.i(LOG_TAG, "Tracing on app launch event: " + packageName); if (DEBUG) { Log.d(LOG_TAG, "Tracing on app launch event: " + packageName); } mIProfcollect.TraceOnce("applaunch"); } catch (RemoteException e) { Log.e(LOG_TAG, e.getMessage()); Loading