Merge changes I10ab56a8,I7e437c3d,I0413c52f am: bece59741a am: 3979981b2d am: 70d4f9abc9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1425270 Change-Id: I87e9f3a8e69bb69ce6d67986bba92f7f0ac4e757
This commit is contained in:
@@ -5465,6 +5465,10 @@
|
|||||||
android:permission="android.permission.BIND_JOB_SERVICE" >
|
android:permission="android.permission.BIND_JOB_SERVICE" >
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service android:name="com.android.server.profcollect.ProfcollectForwardingService$ProfcollectBGJobService"
|
||||||
|
android:permission="android.permission.BIND_JOB_SERVICE" >
|
||||||
|
</service>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="com.android.server.autofill.AutofillCompatAccessibilityService"
|
android:name="com.android.server.autofill.AutofillCompatAccessibilityService"
|
||||||
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package com.android.server.profcollect;
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -34,6 +39,7 @@ import com.android.server.wm.ActivityMetricsLaunchObserverRegistry;
|
|||||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System-server-local proxy into the {@code IProfcollectd} native service.
|
* 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 final class ProfcollectForwardingService extends SystemService {
|
||||||
public static final String LOG_TAG = "ProfcollectForwardingService";
|
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 IProfCollectd mIProfcollect;
|
||||||
private ProfcollectForwardingService mSelfService;
|
private static ProfcollectForwardingService sSelfService;
|
||||||
private final Handler mHandler = new ProfcollectdHandler(IoThread.getHandler().getLooper());
|
private final Handler mHandler = new ProfcollectdHandler(IoThread.getHandler().getLooper());
|
||||||
|
|
||||||
public ProfcollectForwardingService(Context context) {
|
public ProfcollectForwardingService(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
if (mSelfService != null) {
|
if (sSelfService != null) {
|
||||||
throw new AssertionError("only one service instance allowed");
|
throw new AssertionError("only one service instance allowed");
|
||||||
}
|
}
|
||||||
mSelfService = this;
|
sSelfService = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
Log.i(LOG_TAG, "Profcollect forwarding service start");
|
if (DEBUG) {
|
||||||
connectNativeService();
|
Log.d(LOG_TAG, "Profcollect forwarding service start");
|
||||||
if (mIProfcollect == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (serviceHasSupportedTraceProvider()) {
|
connectNativeService();
|
||||||
registerObservers();
|
}
|
||||||
|
|
||||||
|
@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
|
// Event observers
|
||||||
private void registerObservers() {
|
private void registerObservers() {
|
||||||
registerAppLaunchObserver();
|
registerAppLaunchObserver();
|
||||||
@@ -155,7 +220,9 @@ public final class ProfcollectForwardingService extends SystemService {
|
|||||||
int randomNum = ThreadLocalRandom.current().nextInt(100);
|
int randomNum = ThreadLocalRandom.current().nextInt(100);
|
||||||
if (randomNum < traceFrequency) {
|
if (randomNum < traceFrequency) {
|
||||||
try {
|
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");
|
mIProfcollect.TraceOnce("applaunch");
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage());
|
Log.e(LOG_TAG, e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user