Add metrics around scheduling failures.

Add metrics to track how often apps fail to schedule jobs.

Bug: 138239687
Bug: 279935506
Test: atest CtsJobSchedulerTestCases:JobSchedulingTest
Change-Id: I05fec96feb4ab8b78a0e896b84a31512b4f84fe5
This commit is contained in:
Kweku Adams
2023-05-08 19:07:47 +00:00
parent 22490466ca
commit 30cd1ec8ab

View File

@@ -1443,6 +1443,9 @@ public class JobSchedulerService extends com.android.server.SystemService
if (mActivityManagerInternal.isAppStartModeDisabled(uId, servicePkg)) {
Slog.w(TAG, "Not scheduling job " + uId + ":" + job.toString()
+ " -- package not allowed to start");
Counter.logIncrementWithUid(
"job_scheduler.value_cntr_w_uid_schedule_failure_app_start_mode_disabled",
uId);
return JobScheduler.RESULT_FAILURE;
}
@@ -1519,6 +1522,9 @@ public class JobSchedulerService extends com.android.server.SystemService
if ((mConstants.USE_TARE_POLICY && !mTareController.canScheduleEJ(jobStatus))
|| (!mConstants.USE_TARE_POLICY
&& !mQuotaController.isWithinEJQuotaLocked(jobStatus))) {
Counter.logIncrementWithUid(
"job_scheduler.value_cntr_w_uid_schedule_failure_ej_out_of_quota",
uId);
return JobScheduler.RESULT_FAILURE;
}
}
@@ -4083,6 +4089,9 @@ public class JobSchedulerService extends com.android.server.SystemService
if (!isInStateToScheduleUiJobSource && !isInStateToScheduleUiJobCalling) {
Slog.e(TAG, "Uid(s) " + sourceUid + "/" + callingUid
+ " not in a state to schedule user-initiated jobs");
Counter.logIncrementWithUid(
"job_scheduler.value_cntr_w_uid_schedule_failure_uij_invalid_state",
callingUid);
return JobScheduler.RESULT_FAILURE;
}
}
@@ -4132,10 +4141,14 @@ public class JobSchedulerService extends com.android.server.SystemService
private int validateRunUserInitiatedJobsPermission(int uid, String packageName) {
final int state = getRunUserInitiatedJobsPermissionState(uid, packageName);
if (state == PermissionChecker.PERMISSION_HARD_DENIED) {
Counter.logIncrementWithUid(
"job_scheduler.value_cntr_w_uid_schedule_failure_uij_no_permission", uid);
throw new SecurityException(android.Manifest.permission.RUN_USER_INITIATED_JOBS
+ " required to schedule user-initiated jobs.");
}
if (state == PermissionChecker.PERMISSION_SOFT_DENIED) {
Counter.logIncrementWithUid(
"job_scheduler.value_cntr_w_uid_schedule_failure_uij_no_permission", uid);
return JobScheduler.RESULT_FAILURE;
}
return JobScheduler.RESULT_SUCCESS;