Merge changes I10ab56a8,I7e437c3d,I0413c52f am: bece59741a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1425270 Change-Id: Id057c7c99c55afc5a1117729b2f50e0f16e3b466
This commit is contained in:
@@ -5465,6 +5465,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"
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
@@ -41,28 +47,43 @@ 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");
|
||||
connectNativeService();
|
||||
if (mIProfcollect == null) {
|
||||
return;
|
||||
if (DEBUG) {
|
||||
Log.d(LOG_TAG, "Profcollect forwarding service start");
|
||||
}
|
||||
if (serviceHasSupportedTraceProvider()) {
|
||||
registerObservers();
|
||||
connectNativeService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBootPhase(int phase) {
|
||||
if (phase == PHASE_BOOT_COMPLETED) {
|
||||
if (mIProfcollect == null) {
|
||||
return;
|
||||
}
|
||||
if (serviceHasSupportedTraceProvider()) {
|
||||
registerObservers();
|
||||
}
|
||||
ProfcollectBGJobService.schedule(getContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user