Search in sources :

Example 16 with JobParameters

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

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 17 with JobParameters

use of android.app.job.JobParameters in project android-priority-jobqueue by yigit.

the class FrameworkJobSchedulerServiceTest method onStartJobWithoutScheduler.

@Test
public void onStartJobWithoutScheduler() {
    when(mockJobManager.getScheduler()).thenReturn(null);
    JobParameters params = mock(JobParameters.class);
    service.onStartJob(params);
    // test sanity
    verify(mockScheduler, never()).onStartJob(params);
}
Also used : JobParameters(android.app.job.JobParameters) Test(org.junit.Test)

Example 18 with JobParameters

use of android.app.job.JobParameters in project android-priority-jobqueue by yigit.

the class FrameworkJobSchedulerServiceTest method onStartJob.

@Test
public void onStartJob() {
    JobParameters params = mock(JobParameters.class);
    service.onStartJob(params);
    verify(mockScheduler).onStartJob(params);
}
Also used : JobParameters(android.app.job.JobParameters) Test(org.junit.Test)

Example 19 with JobParameters

use of android.app.job.JobParameters in project android-priority-jobqueue by yigit.

the class FrameworkSchedulerTest method prepareJobParameters.

@NonNull
private JobParameters prepareJobParameters(SchedulerConstraint constraint) {
    JobInfo info = schedule(constraint);
    JobParameters params = mock(JobParameters.class);
    when(params.getExtras()).thenReturn(info.getExtras());
    when(params.getJobId()).thenReturn(info.getId());
    return params;
}
Also used : JobInfo(android.app.job.JobInfo) JobParameters(android.app.job.JobParameters) NonNull(android.support.annotation.NonNull)

Example 20 with JobParameters

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

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)

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