Search in sources :

Example 11 with JobParameters

use of android.app.job.JobParameters in project android_frameworks_base by DirtyUnicorns.

the class TestJobService method callJobFinished.

public boolean callJobFinished() {
    if (jobParamsMap.size() == 0) {
        return false;
    }
    JobParameters params = jobParamsMap.valueAt(0);
    if (params == null) {
        return false;
    } else {
        jobFinished(params, false);
        jobParamsMap.removeAt(0);
        return true;
    }
}
Also used : JobParameters(android.app.job.JobParameters)

Example 12 with JobParameters

use of android.app.job.JobParameters in project android_frameworks_base by DirtyUnicorns.

the class JobServiceContext method executeRunnableJob.

/**
     * Give a job to this context for execution. Callers must first check {@link #getRunningJob()}
     * and ensure it is null to make sure this is a valid context.
     * @param job The status of the job that we are going to run.
     * @return True if the job is valid and is running. False if the job cannot be executed.
     */
boolean executeRunnableJob(JobStatus job) {
    synchronized (mLock) {
        if (!mAvailable) {
            Slog.e(TAG, "Starting new runnable but context is unavailable > Error.");
            return false;
        }
        mPreferredUid = NO_PREFERRED_UID;
        mRunningJob = job;
        final boolean isDeadlineExpired = job.hasDeadlineConstraint() && (job.getLatestRunTimeElapsed() < SystemClock.elapsedRealtime());
        Uri[] triggeredUris = null;
        if (job.changedUris != null) {
            triggeredUris = new Uri[job.changedUris.size()];
            job.changedUris.toArray(triggeredUris);
        }
        String[] triggeredAuthorities = null;
        if (job.changedAuthorities != null) {
            triggeredAuthorities = new String[job.changedAuthorities.size()];
            job.changedAuthorities.toArray(triggeredAuthorities);
        }
        mParams = new JobParameters(this, job.getJobId(), job.getExtras(), isDeadlineExpired, triggeredUris, triggeredAuthorities);
        mExecutionStartTimeElapsed = SystemClock.elapsedRealtime();
        mVerb = VERB_BINDING;
        scheduleOpTimeOut();
        final Intent intent = new Intent().setComponent(job.getServiceComponent());
        boolean binding = mContext.bindServiceAsUser(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND, new UserHandle(job.getUserId()));
        if (!binding) {
            if (DEBUG) {
                Slog.d(TAG, job.getServiceComponent().getShortClassName() + " unavailable.");
            }
            mRunningJob = null;
            mParams = null;
            mExecutionStartTimeElapsed = 0L;
            mVerb = VERB_FINISHED;
            removeOpTimeOut();
            return false;
        }
        try {
            mBatteryStats.noteJobStart(job.getBatteryName(), job.getSourceUid());
        } catch (RemoteException e) {
        // Whatever.
        }
        mJobPackageTracker.noteActive(job);
        mAvailable = false;
        return true;
    }
}
Also used : UserHandle(android.os.UserHandle) Intent(android.content.Intent) JobParameters(android.app.job.JobParameters) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 13 with JobParameters

use of android.app.job.JobParameters in project android_frameworks_base by crdroidandroid.

the class TestJobService method callJobFinished.

public boolean callJobFinished() {
    if (jobParamsMap.size() == 0) {
        return false;
    }
    JobParameters params = jobParamsMap.valueAt(0);
    if (params == null) {
        return false;
    } else {
        jobFinished(params, false);
        jobParamsMap.removeAt(0);
        return true;
    }
}
Also used : JobParameters(android.app.job.JobParameters)

Example 14 with JobParameters

use of android.app.job.JobParameters in project android_frameworks_base by AOSPA.

the class SyncJobService method callJobFinished.

public void callJobFinished(int jobId, boolean needsReschedule) {
    synchronized (jobParamsMap) {
        JobParameters params = jobParamsMap.get(jobId);
        if (params != null) {
            jobFinished(params, needsReschedule);
            jobParamsMap.remove(jobId);
        } else {
            Slog.e(TAG, "Job params not found for " + String.valueOf(jobId));
        }
    }
}
Also used : JobParameters(android.app.job.JobParameters)

Example 15 with JobParameters

use of android.app.job.JobParameters in project materialistic by hidroh.

the class ItemSyncJobServiceTest method testStartJob.

@Test
public void testStartJob() {
    JobParameters jobParameters = mock(JobParameters.class);
    when(jobParameters.getExtras()).thenReturn(new SyncDelegate.JobBuilder(service, "1").build().toPersistableBundle());
    when(jobParameters.getJobId()).thenReturn(2);
    service.onStartJob(jobParameters);
    verify(service.syncDelegate).subscribe(listenerCaptor.capture());
    verify(service.syncDelegate).performSync(any(SyncDelegate.Job.class));
    listenerCaptor.getValue().onDone("2");
}
Also used : JobParameters(android.app.job.JobParameters) Test(org.junit.Test)

Aggregations

JobParameters (android.app.job.JobParameters)24 Test (org.junit.Test)7 Intent (android.content.Intent)5 Uri (android.net.Uri)5 RemoteException (android.os.RemoteException)5 UserHandle (android.os.UserHandle)5 PersistableBundle (android.os.PersistableBundle)2 JobInfo (android.app.job.JobInfo)1 JobService (android.app.job.JobService)1 NonNull (android.support.annotation.NonNull)1