Using ParceledListSlice to send large lists over Binder.

JobScheduler.getAllPendingJobs() and .getAllJobSnapshots() can
potentially contain enough data to exceed the Binder limit. Using a
ParceledListSlice will ensure the data can still be sent over Binder.

Bug: 70648761
Test: atest CtsJobSchedulerTestCases
Test: atest CtsBatterySavingTestCases
Change-Id: I79ea32eac56473ca996cc00312b30d0f72ce22c9
This commit is contained in:
Kweku Adams
2019-05-07 12:22:47 -07:00
parent 9192a430af
commit d1f4b90e28
3 changed files with 10 additions and 8 deletions

View File

@@ -83,7 +83,7 @@ public class JobSchedulerImpl extends JobScheduler {
@Override
public List<JobInfo> getAllPendingJobs() {
try {
return mBinder.getAllPendingJobs();
return mBinder.getAllPendingJobs().getList();
} catch (RemoteException e) {
return null;
}
@@ -110,7 +110,7 @@ public class JobSchedulerImpl extends JobScheduler {
@Override
public List<JobSnapshot> getAllJobSnapshots() {
try {
return mBinder.getAllJobSnapshots();
return mBinder.getAllJobSnapshots().getList();
} catch (RemoteException e) {
return null;
}

View File

@@ -19,6 +19,7 @@ package android.app.job;
import android.app.job.JobInfo;
import android.app.job.JobSnapshot;
import android.app.job.JobWorkItem;
import android.content.pm.ParceledListSlice;
/**
* IPC interface that supports the app-facing {@link #JobScheduler} api.
@@ -30,8 +31,8 @@ interface IJobScheduler {
int scheduleAsPackage(in JobInfo job, String packageName, int userId, String tag);
void cancel(int jobId);
void cancelAll();
List<JobInfo> getAllPendingJobs();
ParceledListSlice getAllPendingJobs();
JobInfo getPendingJob(int jobId);
List<JobInfo> getStartedJobs();
List<JobSnapshot> getAllJobSnapshots();
ParceledListSlice getAllJobSnapshots();
}

View File

@@ -49,6 +49,7 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.content.pm.ServiceInfo;
import android.database.ContentObserver;
import android.net.Uri;
@@ -2764,12 +2765,12 @@ public class JobSchedulerService extends com.android.server.SystemService
}
@Override
public List<JobInfo> getAllPendingJobs() throws RemoteException {
public ParceledListSlice<JobInfo> getAllPendingJobs() throws RemoteException {
final int uid = Binder.getCallingUid();
long ident = Binder.clearCallingIdentity();
try {
return JobSchedulerService.this.getPendingJobs(uid);
return new ParceledListSlice<>(JobSchedulerService.this.getPendingJobs(uid));
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -2905,7 +2906,7 @@ public class JobSchedulerService extends com.android.server.SystemService
* <p class="note">This is a slow operation, so it should be called sparingly.
*/
@Override
public List<JobSnapshot> getAllJobSnapshots() {
public ParceledListSlice<JobSnapshot> getAllJobSnapshots() {
final int uid = Binder.getCallingUid();
if (uid != Process.SYSTEM_UID) {
throw new SecurityException(
@@ -2916,7 +2917,7 @@ public class JobSchedulerService extends com.android.server.SystemService
mJobs.forEachJob((job) -> snapshots.add(
new JobSnapshot(job.getJob(), job.getSatisfiedConstraintFlags(),
isReadyToBeExecutedLocked(job))));
return snapshots;
return new ParceledListSlice<>(snapshots);
}
}
};