Merge "Reset the delay time to refresh the periodic job." into main

This commit is contained in:
Xinyi Mao
2024-01-03 09:28:08 +00:00
committed by Android (Google) Code Review

View File

@@ -26,7 +26,6 @@ import android.util.Log;
import com.android.settings.core.instrumentation.ElapsedTimeUtils; import com.android.settings.core.instrumentation.ElapsedTimeUtils;
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action; import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils; import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.BatteryUtils; import com.android.settingslib.fuelgauge.BatteryUtils;
import java.time.Duration; import java.time.Duration;
@@ -34,9 +33,7 @@ import java.time.Duration;
/** Receives broadcasts to start or stop the periodic fetching job. */ /** Receives broadcasts to start or stop the periodic fetching job. */
public final class BootBroadcastReceiver extends BroadcastReceiver { public final class BootBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "BootBroadcastReceiver"; private static final String TAG = "BootBroadcastReceiver";
private static final long RESCHEDULE_FOR_BOOT_ACTION_WITH_DELAY = private static final long RESCHEDULE_FOR_BOOT_ACTION_DELAY_MILLIS =
Duration.ofMinutes(40).toMillis();
private static final long RESCHEDULE_FOR_BOOT_ACTION_WITHOUT_DELAY =
Duration.ofSeconds(6).toMillis(); Duration.ofSeconds(6).toMillis();
private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Handler mHandler = new Handler(Looper.getMainLooper());
@@ -81,7 +78,7 @@ public final class BootBroadcastReceiver extends BroadcastReceiver {
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
final Intent recheckIntent = new Intent(ACTION_PERIODIC_JOB_RECHECK); final Intent recheckIntent = new Intent(ACTION_PERIODIC_JOB_RECHECK);
recheckIntent.setClass(context, BootBroadcastReceiver.class); recheckIntent.setClass(context, BootBroadcastReceiver.class);
final long delayedTime = getRescheduleTimeForBootAction(context); final long delayedTime = RESCHEDULE_FOR_BOOT_ACTION_DELAY_MILLIS;
mHandler.postDelayed(() -> context.sendBroadcast(recheckIntent), delayedTime); mHandler.postDelayed(() -> context.sendBroadcast(recheckIntent), delayedTime);
// Refreshes the usage source from UsageStatsManager when booting. // Refreshes the usage source from UsageStatsManager when booting.
@@ -93,16 +90,6 @@ public final class BootBroadcastReceiver extends BroadcastReceiver {
} }
} }
private long getRescheduleTimeForBootAction(Context context) {
final boolean delayHourlyJobWhenBooting =
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()
.delayHourlyJobWhenBooting();
return delayHourlyJobWhenBooting
? RESCHEDULE_FOR_BOOT_ACTION_WITH_DELAY
: RESCHEDULE_FOR_BOOT_ACTION_WITHOUT_DELAY;
}
private static void refreshJobs(Context context) { private static void refreshJobs(Context context) {
PeriodicJobManager.getInstance(context).refreshJob(/* fromBoot= */ true); PeriodicJobManager.getInstance(context).refreshJob(/* fromBoot= */ true);
} }