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

Commit 019d2caf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Switch to a SystemApi to get service info."

parents e636cf31 f705f3a1
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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());
            }
        }

+10 −6
Original line number Diff line number Diff line
@@ -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);
        }