Switch to a SystemApi to get service info.
The mechanism we were using was through a hidden API. Switching to a SystemApi as part of the mainline effort. Bug: 142281756 Test: atest com.android.server.job.controllers.ConnectivityControllerTest Test: atest com.android.server.job.controllers.JobStatusTest Test: atest com.android.server.job.controllers.QuotaControllerTest Test: atest com.android.server.job.JobSchedulerServiceTest Test: atest com.android.server.job.JobStoreTest Test: atest CtsJobSchedulerTestCases Change-Id: Idac1833329b81a7f7d986767f241f27a0a1cf6ca
This commit is contained in:
@@ -2590,13 +2590,14 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
// job that runs one of the app's services, as well as verifying that the
|
||||
// named service properly requires the BIND_JOB_SERVICE permission
|
||||
private void enforceValidJobRequest(int uid, JobInfo job) {
|
||||
final IPackageManager pm = AppGlobals.getPackageManager();
|
||||
final PackageManager pm = getContext()
|
||||
.createContextAsUser(UserHandle.getUserHandleForUid(uid), 0)
|
||||
.getPackageManager();
|
||||
final ComponentName service = job.getService();
|
||||
try {
|
||||
ServiceInfo si = pm.getServiceInfo(service,
|
||||
PackageManager.MATCH_DIRECT_BOOT_AWARE
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
|
||||
UserHandle.getUserId(uid));
|
||||
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
|
||||
if (si == null) {
|
||||
throw new IllegalArgumentException("No such service " + service);
|
||||
}
|
||||
@@ -2608,8 +2609,10 @@ public class JobSchedulerService extends com.android.server.SystemService
|
||||
throw new IllegalArgumentException("Scheduled service " + service
|
||||
+ " does not require android.permission.BIND_JOB_SERVICE permission");
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// Can't happen; the Package Manager is in this same process
|
||||
} catch (NameNotFoundException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Tried to schedule job for non-existent package: "
|
||||
+ service.getPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,16 +18,15 @@ package com.android.server.job.controllers;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.AppGlobals;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Log;
|
||||
@@ -116,10 +115,15 @@ public class ComponentController extends StateController {
|
||||
ServiceInfo si = mServiceInfoCache.get(userId, service);
|
||||
if (si == null) {
|
||||
try {
|
||||
si = AppGlobals.getPackageManager().getServiceInfo(
|
||||
service, PackageManager.MATCH_DIRECT_BOOT_AUTO, userId);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
// createContextAsUser may potentially be expensive
|
||||
// TODO: cache user context or improve ContextImpl implementation if this becomes
|
||||
// a problem
|
||||
si = mContext.createContextAsUser(UserHandle.of(userId), 0)
|
||||
.getPackageManager()
|
||||
.getServiceInfo(service, PackageManager.MATCH_DIRECT_BOOT_AUTO);
|
||||
} catch (NameNotFoundException e) {
|
||||
Slog.e(TAG, "Job exists for non-existent package: " + service.getPackageName());
|
||||
return null;
|
||||
}
|
||||
mServiceInfoCache.add(userId, service, si);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user