Search in sources :

Example 11 with JobWorkItem

use of android.app.job.JobWorkItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AnomalyDetectionJobService method onStartJob.

@Override
public boolean onStartJob(JobParameters params) {
    synchronized (mLock) {
        mIsJobCanceled = false;
    }
    ThreadUtils.postOnBackgroundThread(() -> {
        final Context context = AnomalyDetectionJobService.this;
        final BatteryDatabaseManager batteryDatabaseManager = BatteryDatabaseManager.getInstance(this);
        final BatteryTipPolicy policy = new BatteryTipPolicy(this);
        final BatteryUtils batteryUtils = BatteryUtils.getInstance(this);
        final ContentResolver contentResolver = getContentResolver();
        final UserManager userManager = getSystemService(UserManager.class);
        final PowerWhitelistBackend powerWhitelistBackend = PowerWhitelistBackend.getInstance(context);
        final PowerUsageFeatureProvider powerUsageFeatureProvider = FeatureFactory.getFactory(this).getPowerUsageFeatureProvider(this);
        final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(this).getMetricsFeatureProvider();
        for (JobWorkItem item = dequeueWork(params); item != null; item = dequeueWork(params)) {
            saveAnomalyToDatabase(context, userManager, batteryDatabaseManager, batteryUtils, policy, powerWhitelistBackend, contentResolver, powerUsageFeatureProvider, metricsFeatureProvider, item.getIntent().getExtras());
            completeWork(params, item);
        }
    });
    return true;
}
Also used : Context(android.content.Context) MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) UserManager(android.os.UserManager) PowerUsageFeatureProvider(com.android.settings.fuelgauge.PowerUsageFeatureProvider) PowerWhitelistBackend(com.android.settingslib.fuelgauge.PowerWhitelistBackend) BatteryUtils(com.android.settings.fuelgauge.BatteryUtils) JobWorkItem(android.app.job.JobWorkItem) ContentResolver(android.content.ContentResolver)

Example 12 with JobWorkItem

use of android.app.job.JobWorkItem in project VirtualApp by asLody.

the class VJobSchedulerService method enqueue.

@TargetApi(26)
public int enqueue(JobInfo job, Parcelable workItem) {
    if (!(workItem instanceof JobWorkItem)) {
        Log.d("Q_M", "!(workItem instanceof JobWorkItem)");
        return -1;
    }
    Log.d("Q_M", "(workItem instanceof JobWorkItem)");
    int callingUid = VBinder.getCallingUid();
    int id = job.getId();
    ComponentName service = job.getService();
    JobId jobId = new JobId(callingUid, service.getPackageName(), id);
    JobConfig jobConfig = (JobConfig) this.mJobStore.get(jobId);
    if (jobConfig == null) {
        int i = this.mGlobalJobId;
        this.mGlobalJobId = i + 1;
        jobConfig = new JobConfig(i, service.getClassName(), job.getExtras());
        this.mJobStore.put(jobId, jobConfig);
    } else {
        jobConfig.serviceName = service.getClassName();
        jobConfig.extras = job.getExtras();
    }
    saveJobs();
    mirror.android.app.job.JobInfo.jobId.set(job, jobConfig.virtualJobId);
    mirror.android.app.job.JobInfo.service.set(job, this.mJobProxyComponent);
    return this.mScheduler.enqueue(job, (JobWorkItem) workItem);
}
Also used : ComponentName(android.content.ComponentName) JobWorkItem(android.app.job.JobWorkItem) TargetApi(android.annotation.TargetApi)

Example 13 with JobWorkItem

use of android.app.job.JobWorkItem in project android_packages_apps_Dialer by LineageOS.

the class DeviceProvisionedJobService method onStartJob.

@Override
public boolean onStartJob(JobParameters params) {
    if (!isDeviceProvisioned()) {
        VvmLog.i("DeviceProvisionedJobService.onStartJob", "device not provisioned, rescheduling");
        getSystemService(JobScheduler.class).schedule(createJobInfo(this));
        // job not running in background
        return false;
    }
    VvmLog.i("DeviceProvisionedJobService.onStartJob", "device provisioned");
    for (JobWorkItem item = params.dequeueWork(); item != null; item = params.dequeueWork()) {
        PhoneAccountHandle phoneAccountHandle = item.getIntent().getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE);
        VvmLog.i("DeviceProvisionedJobService.onStartJob", "restarting activation for " + phoneAccountHandle);
        ActivationTask.start(this, phoneAccountHandle, null);
    }
    // job not running in background
    return false;
}
Also used : JobScheduler(android.app.job.JobScheduler) PhoneAccountHandle(android.telecom.PhoneAccountHandle) JobWorkItem(android.app.job.JobWorkItem)

Example 14 with JobWorkItem

use of android.app.job.JobWorkItem in project android_packages_apps_Dialer by LineageOS.

the class TranscriptionService method scheduleNewVoicemailTranscriptionJob.

// Schedule a task to transcribe the indicated voicemail, return true if transcription task was
// scheduled.
@MainThread
public static boolean scheduleNewVoicemailTranscriptionJob(Context context, Uri voicemailUri, PhoneAccountHandle account, boolean highPriority) {
    Assert.isMainThread();
    if (!canTranscribeVoicemail(context, account)) {
        return false;
    }
    LogUtil.i("TranscriptionService.scheduleNewVoicemailTranscriptionJob", "scheduling transcription");
    Logger.get(context).logImpression(DialerImpression.Type.VVM_TRANSCRIPTION_VOICEMAIL_RECEIVED);
    ComponentName componentName = new ComponentName(context, TranscriptionService.class);
    JobInfo.Builder builder = new JobInfo.Builder(ScheduledJobIds.VVM_TRANSCRIPTION_JOB, componentName);
    if (highPriority) {
        builder.setMinimumLatency(0).setOverrideDeadline(0).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
    } else {
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
    }
    JobScheduler scheduler = context.getSystemService(JobScheduler.class);
    JobWorkItem workItem = makeWorkItem(voicemailUri, account);
    return scheduler.enqueue(builder.build(), workItem) == JobScheduler.RESULT_SUCCESS;
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName) JobWorkItem(android.app.job.JobWorkItem) MainThread(android.support.annotation.MainThread)

Example 15 with JobWorkItem

use of android.app.job.JobWorkItem in project android_packages_apps_Dialer by LineageOS.

the class TranscriptionService method checkForWork.

@MainThread
private boolean checkForWork() {
    Assert.isMainThread();
    if (stopped) {
        LogUtil.i("TranscriptionService.checkForWork", "stopped");
        return false;
    }
    JobWorkItem workItem = jobParameters.dequeueWork();
    if (workItem != null) {
        Assert.checkState(activeTask == null);
        activeTask = configProvider.shouldUseSyncApi() ? new TranscriptionTaskSync(this, new Callback(), workItem, getClientFactory(), configProvider) : new TranscriptionTaskAsync(this, new Callback(), workItem, getClientFactory(), configProvider);
        getExecutorService().execute(activeTask);
        return true;
    } else {
        return false;
    }
}
Also used : JobWorkItem(android.app.job.JobWorkItem) MainThread(android.support.annotation.MainThread)

Aggregations

JobWorkItem (android.app.job.JobWorkItem)16 ComponentName (android.content.ComponentName)7 Intent (android.content.Intent)7 JobInfo (android.app.job.JobInfo)6 JobScheduler (android.app.job.JobScheduler)6 ContentResolver (android.content.ContentResolver)2 Context (android.content.Context)2 UserManager (android.os.UserManager)2 MainThread (android.support.annotation.MainThread)2 BatteryUtils (com.android.settings.fuelgauge.BatteryUtils)2 PowerUsageFeatureProvider (com.android.settings.fuelgauge.PowerUsageFeatureProvider)2 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 TargetApi (android.annotation.TargetApi)1 PhoneAccountHandle (android.telecom.PhoneAccountHandle)1 PowerAllowlistBackend (com.android.settingslib.fuelgauge.PowerAllowlistBackend)1 PowerWhitelistBackend (com.android.settingslib.fuelgauge.PowerWhitelistBackend)1