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