Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 968ac75c authored by Shreyas Basarge's avatar Shreyas Basarge
Browse files

Adds sourcePackageName field to JobStatus

Platform apps can schedule a job on behalf of
some other package. Battery stats and appIdleState
will be computed using sourcePackageName.

Change-Id: If52f6e1db3a563ef0854d1f59fbc6088a0c29ad1
parent 4bfa55d4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -45,6 +45,15 @@ public class JobSchedulerImpl extends JobScheduler {
        }
    }

    @Override
    public int scheduleAsPackage(JobInfo job, String packageName, int userId) {
        try {
            return mBinder.scheduleAsPackage(job, packageName, userId);
        } catch (RemoteException e) {
            return JobScheduler.RESULT_FAILURE;
        }
    }

    @Override
    public void cancel(int jobId) {
        try {
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.job.JobInfo;
  */
interface IJobScheduler {
    int schedule(in JobInfo job);
    int scheduleAsPackage(in JobInfo job, String packageName, int userId);
    void cancel(int jobId);
    void cancelAll();
    List<JobInfo> getAllPendingJobs();
+11 −0
Original line number Diff line number Diff line
@@ -62,6 +62,17 @@ public abstract class JobScheduler {
     */
    public abstract int schedule(JobInfo job);

    /**
     *
     * @param job The job to be scheduled.
     * @param packageName The package on behalf of which the job is to be scheduled. This will be
     *                    used to track battery usage and appIdleState.
     * @param userId    User on behalf of whom this job is to be scheduled.
     * @return {@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}
     * @hide
     */
    public abstract int scheduleAsPackage(JobInfo job, String packageName, int userId);

    /**
     * Cancel a job that is pending in the JobScheduler.
     * @param jobId unique identifier for this job. Obtain this value from the jobs returned by
+27 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.Process;
import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;
@@ -220,7 +221,14 @@ public class JobSchedulerService extends com.android.server.SystemService
     * @return Result of this operation. See <code>JobScheduler#RESULT_*</code> return codes.
     */
    public int schedule(JobInfo job, int uId) {
        return scheduleAsPackage(job, uId, null, -1);
    }

    public int scheduleAsPackage(JobInfo job, int uId, String packageName, int userId) {
        JobStatus jobStatus = new JobStatus(job, uId);
        if (packageName != null) {
            jobStatus.setSource(packageName, userId);
        }
        cancelJob(uId, job.getId());
        try {
            if (ActivityManagerNative.getDefault().getAppStartMode(uId,
@@ -1040,6 +1048,25 @@ public class JobSchedulerService extends com.android.server.SystemService
            }
        }

        @Override
        public int scheduleAsPackage(JobInfo job, String packageName, int userId)
                throws RemoteException {
            if (DEBUG) {
                Slog.d(TAG, "Scheduling job: " + job.toString() + " on behalf of " + packageName);
            }
            final int uid = Binder.getCallingUid();
            if (uid != Process.SYSTEM_UID) {
                throw new IllegalArgumentException("Only system process is allowed"
                        + "to set packageName");
            }
            long ident = Binder.clearCallingIdentity();
            try {
                return JobSchedulerService.this.scheduleAsPackage(job, uid, packageName, userId);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override
        public List<JobInfo> getAllPendingJobs() throws RemoteException {
            final int uid = Binder.getCallingUid();
+3 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -190,7 +191,7 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
                return false;
            }
            try {
                mBatteryStats.noteJobStart(job.getName(), job.getUid());
                mBatteryStats.noteJobStart(job.getName(), job.getSourceUid());
            } catch (RemoteException e) {
                // Whatever.
            }
@@ -566,7 +567,7 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
                }
                completedJob = mRunningJob;
                try {
                    mBatteryStats.noteJobFinish(mRunningJob.getName(), mRunningJob.getUid());
                    mBatteryStats.noteJobFinish(mRunningJob.getName(), mRunningJob.getSourceUid());
                } catch (RemoteException e) {
                    // Whatever.
                }
Loading