Clean up debug logging
PiperOrigin-RevId: 314707946
This commit is contained in:
parent
fb73a9dfc8
commit
c77e300249
@ -60,7 +60,6 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public final class JobDispatcherScheduler implements Scheduler {
|
public final class JobDispatcherScheduler implements Scheduler {
|
||||||
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final String TAG = "JobDispatcherScheduler";
|
private static final String TAG = "JobDispatcherScheduler";
|
||||||
private static final String KEY_SERVICE_ACTION = "service_action";
|
private static final String KEY_SERVICE_ACTION = "service_action";
|
||||||
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
||||||
@ -90,14 +89,12 @@ public final class JobDispatcherScheduler implements Scheduler {
|
|||||||
public boolean schedule(Requirements requirements, String servicePackage, String serviceAction) {
|
public boolean schedule(Requirements requirements, String servicePackage, String serviceAction) {
|
||||||
Job job = buildJob(jobDispatcher, requirements, jobTag, servicePackage, serviceAction);
|
Job job = buildJob(jobDispatcher, requirements, jobTag, servicePackage, serviceAction);
|
||||||
int result = jobDispatcher.schedule(job);
|
int result = jobDispatcher.schedule(job);
|
||||||
logd("Scheduling job: " + jobTag + " result: " + result);
|
|
||||||
return result == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS;
|
return result == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
int result = jobDispatcher.cancel(jobTag);
|
int result = jobDispatcher.cancel(jobTag);
|
||||||
logd("Canceling job: " + jobTag + " result: " + result);
|
|
||||||
return result == FirebaseJobDispatcher.CANCEL_RESULT_SUCCESS;
|
return result == FirebaseJobDispatcher.CANCEL_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,31 +144,20 @@ public final class JobDispatcherScheduler implements Scheduler {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logd(String message) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A {@link JobService} that starts the target service if the requirements are met. */
|
/** A {@link JobService} that starts the target service if the requirements are met. */
|
||||||
public static final class JobDispatcherSchedulerService extends JobService {
|
public static final class JobDispatcherSchedulerService extends JobService {
|
||||||
@Override
|
@Override
|
||||||
public boolean onStartJob(JobParameters params) {
|
public boolean onStartJob(JobParameters params) {
|
||||||
logd("JobDispatcherSchedulerService is started");
|
Bundle extras = Assertions.checkNotNull(params.getExtras());
|
||||||
Bundle extras = params.getExtras();
|
|
||||||
Assertions.checkNotNull(extras, "Service started without extras.");
|
|
||||||
Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
|
Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
|
||||||
if (requirements.checkRequirements(this)) {
|
int notMetRequirements = requirements.getNotMetRequirements(this);
|
||||||
logd("Requirements are met");
|
if (notMetRequirements == 0) {
|
||||||
String serviceAction = extras.getString(KEY_SERVICE_ACTION);
|
String serviceAction = Assertions.checkNotNull(extras.getString(KEY_SERVICE_ACTION));
|
||||||
String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
|
String servicePackage = Assertions.checkNotNull(extras.getString(KEY_SERVICE_PACKAGE));
|
||||||
Assertions.checkNotNull(serviceAction, "Service action missing.");
|
|
||||||
Assertions.checkNotNull(servicePackage, "Service package missing.");
|
|
||||||
Intent intent = new Intent(serviceAction).setPackage(servicePackage);
|
Intent intent = new Intent(serviceAction).setPackage(servicePackage);
|
||||||
logd("Starting service action: " + serviceAction + " package: " + servicePackage);
|
|
||||||
Util.startForegroundService(this, intent);
|
Util.startForegroundService(this, intent);
|
||||||
} else {
|
} else {
|
||||||
logd("Requirements are not met");
|
Log.w(TAG, "Requirements not met: " + notMetRequirements);
|
||||||
jobFinished(params, /* needsReschedule */ true);
|
jobFinished(params, /* needsReschedule */ true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -35,7 +35,6 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
/** A {@link Scheduler} that uses {@link WorkManager}. */
|
/** A {@link Scheduler} that uses {@link WorkManager}. */
|
||||||
public final class WorkManagerScheduler implements Scheduler {
|
public final class WorkManagerScheduler implements Scheduler {
|
||||||
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final String TAG = "WorkManagerScheduler";
|
private static final String TAG = "WorkManagerScheduler";
|
||||||
private static final String KEY_SERVICE_ACTION = "service_action";
|
private static final String KEY_SERVICE_ACTION = "service_action";
|
||||||
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
||||||
@ -64,14 +63,12 @@ public final class WorkManagerScheduler implements Scheduler {
|
|||||||
Constraints constraints = buildConstraints(requirements);
|
Constraints constraints = buildConstraints(requirements);
|
||||||
Data inputData = buildInputData(requirements, servicePackage, serviceAction);
|
Data inputData = buildInputData(requirements, servicePackage, serviceAction);
|
||||||
OneTimeWorkRequest workRequest = buildWorkRequest(constraints, inputData);
|
OneTimeWorkRequest workRequest = buildWorkRequest(constraints, inputData);
|
||||||
logd("Scheduling work: " + workName);
|
|
||||||
WorkManager.getInstance().enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest);
|
WorkManager.getInstance().enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
logd("Canceling work: " + workName);
|
|
||||||
WorkManager.getInstance().cancelUniqueWork(workName);
|
WorkManager.getInstance().cancelUniqueWork(workName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -136,12 +133,6 @@ public final class WorkManagerScheduler implements Scheduler {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logd(String message) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A {@link Worker} that starts the target service if the requirements are met. */
|
/** A {@link Worker} that starts the target service if the requirements are met. */
|
||||||
// This class needs to be public so that WorkManager can instantiate it.
|
// This class needs to be public so that WorkManager can instantiate it.
|
||||||
public static final class SchedulerWorker extends Worker {
|
public static final class SchedulerWorker extends Worker {
|
||||||
@ -157,22 +148,17 @@ public final class WorkManagerScheduler implements Scheduler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result doWork() {
|
public Result doWork() {
|
||||||
logd("SchedulerWorker is started");
|
Data inputData = Assertions.checkNotNull(workerParams.getInputData());
|
||||||
Data inputData = workerParams.getInputData();
|
|
||||||
Assertions.checkNotNull(inputData, "Work started without input data.");
|
|
||||||
Requirements requirements = new Requirements(inputData.getInt(KEY_REQUIREMENTS, 0));
|
Requirements requirements = new Requirements(inputData.getInt(KEY_REQUIREMENTS, 0));
|
||||||
if (requirements.checkRequirements(context)) {
|
int notMetRequirements = requirements.getNotMetRequirements(context);
|
||||||
logd("Requirements are met");
|
if (notMetRequirements == 0) {
|
||||||
String serviceAction = inputData.getString(KEY_SERVICE_ACTION);
|
String serviceAction = Assertions.checkNotNull(inputData.getString(KEY_SERVICE_ACTION));
|
||||||
String servicePackage = inputData.getString(KEY_SERVICE_PACKAGE);
|
String servicePackage = Assertions.checkNotNull(inputData.getString(KEY_SERVICE_PACKAGE));
|
||||||
Assertions.checkNotNull(serviceAction, "Service action missing.");
|
|
||||||
Assertions.checkNotNull(servicePackage, "Service package missing.");
|
|
||||||
Intent intent = new Intent(serviceAction).setPackage(servicePackage);
|
Intent intent = new Intent(serviceAction).setPackage(servicePackage);
|
||||||
logd("Starting service action: " + serviceAction + " package: " + servicePackage);
|
|
||||||
Util.startForegroundService(context, intent);
|
Util.startForegroundService(context, intent);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
} else {
|
} else {
|
||||||
logd("Requirements are not met");
|
Log.w(TAG, "Requirements not met: " + notMetRequirements);
|
||||||
return Result.retry();
|
return Result.retry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
@RequiresApi(21)
|
@RequiresApi(21)
|
||||||
public final class PlatformScheduler implements Scheduler {
|
public final class PlatformScheduler implements Scheduler {
|
||||||
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final String TAG = "PlatformScheduler";
|
private static final String TAG = "PlatformScheduler";
|
||||||
private static final String KEY_SERVICE_ACTION = "service_action";
|
private static final String KEY_SERVICE_ACTION = "service_action";
|
||||||
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
private static final String KEY_SERVICE_PACKAGE = "service_package";
|
||||||
@ -81,13 +80,11 @@ public final class PlatformScheduler implements Scheduler {
|
|||||||
JobInfo jobInfo =
|
JobInfo jobInfo =
|
||||||
buildJobInfo(jobId, jobServiceComponentName, requirements, serviceAction, servicePackage);
|
buildJobInfo(jobId, jobServiceComponentName, requirements, serviceAction, servicePackage);
|
||||||
int result = jobScheduler.schedule(jobInfo);
|
int result = jobScheduler.schedule(jobInfo);
|
||||||
logd("Scheduling job: " + jobId + " result: " + result);
|
|
||||||
return result == JobScheduler.RESULT_SUCCESS;
|
return result == JobScheduler.RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel() {
|
public boolean cancel() {
|
||||||
logd("Canceling job: " + jobId);
|
|
||||||
jobScheduler.cancel(jobId);
|
jobScheduler.cancel(jobId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -135,30 +132,21 @@ public final class PlatformScheduler implements Scheduler {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logd(String message) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A {@link JobService} that starts the target service if the requirements are met. */
|
/** A {@link JobService} that starts the target service if the requirements are met. */
|
||||||
public static final class PlatformSchedulerService extends JobService {
|
public static final class PlatformSchedulerService extends JobService {
|
||||||
@Override
|
@Override
|
||||||
public boolean onStartJob(JobParameters params) {
|
public boolean onStartJob(JobParameters params) {
|
||||||
logd("PlatformSchedulerService started");
|
|
||||||
PersistableBundle extras = params.getExtras();
|
PersistableBundle extras = params.getExtras();
|
||||||
Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
|
Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
|
||||||
if (requirements.checkRequirements(this)) {
|
int notMetRequirements = requirements.getNotMetRequirements(this);
|
||||||
logd("Requirements are met");
|
if (notMetRequirements == 0) {
|
||||||
String serviceAction = extras.getString(KEY_SERVICE_ACTION);
|
String serviceAction = Assertions.checkNotNull(extras.getString(KEY_SERVICE_ACTION));
|
||||||
String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
|
String servicePackage = Assertions.checkNotNull(extras.getString(KEY_SERVICE_PACKAGE));
|
||||||
Intent intent =
|
Intent intent = new Intent(serviceAction).setPackage(servicePackage);
|
||||||
new Intent(Assertions.checkNotNull(serviceAction)).setPackage(servicePackage);
|
|
||||||
logd("Starting service action: " + serviceAction + " package: " + servicePackage);
|
|
||||||
Util.startForegroundService(this, intent);
|
Util.startForegroundService(this, intent);
|
||||||
} else {
|
} else {
|
||||||
logd("Requirements are not met");
|
Log.w(TAG, "Requirements not met: " + notMetRequirements);
|
||||||
jobFinished(params, /* needsReschedule */ true);
|
jobFinished(params, /* wantsReschedule= */ true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user