Merge "Recheck the scedule job when the device is full charged and add more logs" into udc-qpr-dev

This commit is contained in:
YK Hung
2023-09-13 04:24:04 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 2 deletions

View File

@@ -120,6 +120,7 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
mFetchBatteryUsageData = true;
BatteryUsageDataLoader.enqueueWork(context, /*isFullChargeStart=*/ true);
BootBroadcastReceiver.invokeJobRecheck(context);
}
private void sendBatteryEventData(Context context, BatteryEventType batteryEventType) {

View File

@@ -68,6 +68,8 @@ public final class PeriodicJobManager {
/** Schedules the next alarm job if it is available. */
public void refreshJob(final boolean fromBoot) {
if (mAlarmManager == null) {
BatteryUsageLogUtils.writeLog(mContext, Action.SCHEDULE_JOB,
"cannot schedule next alarm job due to AlarmManager is null");
Log.e(TAG, "cannot schedule next alarm job");
return;
}
@@ -80,8 +82,8 @@ public final class PeriodicJobManager {
AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);
final String utcToLocalTime = ConvertUtils.utcToLocalTimeForLogging(triggerAtMillis);
BatteryUsageLogUtils.writeLog(
mContext, Action.SCHEDULE_JOB, "triggerTime=" + utcToLocalTime);
BatteryUsageLogUtils.writeLog(mContext, Action.SCHEDULE_JOB,
String.format("triggerTime=%s, fromBoot=%b", utcToLocalTime, fromBoot));
Log.d(TAG, "schedule next alarm job at " + utcToLocalTime);
}

View File

@@ -33,12 +33,23 @@ public final class PeriodicJobReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
loadDataAndRefreshJob(context, intent);
} catch (Exception e) {
BatteryUsageLogUtils.writeLog(context, Action.SCHEDULE_JOB,
String.format("loadDataAndRefreshJob() failed: %s", e));
}
}
private static void loadDataAndRefreshJob(Context context, Intent intent) {
final String action = intent == null ? "" : intent.getAction();
if (!ACTION_PERIODIC_JOB_UPDATE.equals(action)) {
Log.w(TAG, "receive unexpected action=" + action);
return;
}
if (DatabaseUtils.isWorkProfile(context)) {
BatteryUsageLogUtils.writeLog(context, Action.SCHEDULE_JOB,
"do not refresh job for work profile");
Log.w(TAG, "do not refresh job for work profile action=" + action);
return;
}