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

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

Merge "Add method PrintManager#isPrintServiceEnabled(ComponentName)" into tm-dev

parents 9c196cec b7b88031
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33406,6 +33406,7 @@ package android.print {
  public final class PrintManager {
    method @NonNull public java.util.List<android.print.PrintJob> getPrintJobs();
    method public boolean isPrintServiceEnabled(@NonNull android.content.ComponentName);
    method @NonNull public android.print.PrintJob print(@NonNull String, @NonNull android.print.PrintDocumentAdapter, @Nullable android.print.PrintAttributes);
  }
+9 −0
Original line number Diff line number Diff line
@@ -90,6 +90,15 @@ interface IPrintManager {
     */
    void setPrintServiceEnabled(in ComponentName service, boolean isEnabled, int userId);

    /**
     * Checks whether the given print service is enabled.
     *
     * @param service the service to check
     * @param userId the id of the user requesting the check
     * @return whether the given print service is enabled
     */
    boolean isPrintServiceEnabled(in ComponentName service, int userId);

    /**
     * Listen for changes to the print service recommendations.
     *
+19 −0
Original line number Diff line number Diff line
@@ -784,6 +784,25 @@ public final class PrintManager {
        }
    }

    /**
     * Checks whether a given print service is enabled. The provided service must share UID
     * with the calling package, otherwise a {@link SecurityException} is thrown.
     *
     * @return true if the given print service is enabled
     */
    public boolean isPrintServiceEnabled(@NonNull ComponentName service) {
        if (mService == null) {
            Log.w(LOG_TAG, "Feature android.software.print not available");
            return false;
        }
        try {
            return mService.isPrintServiceEnabled(service, mUserId);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error sampling enabled/disabled " + service, re);
            return false;
        }
    }

    /**
     * @hide
     */
+14 −0
Original line number Diff line number Diff line
@@ -485,6 +485,20 @@ public class IPrintManagerParametersTest extends BasePrintTest {
        // Cannot test bad user Id as these tests are allowed to call across users
    }

    /**
     * test IPrintManager.isPrintServiceEnabled
     */
    @MediumTest
    @Test
    @NoActivity
    public void testIsPrintServiceEnabled() throws Throwable {
        assertException(() -> mIPrintManager.isPrintServiceEnabled(new ComponentName("bad", "name"),
                mUserId), SecurityException.class);

        assertException(() -> mIPrintManager.isPrintServiceEnabled(null, mUserId),
                SecurityException.class);
    }

    /**
     * test IPrintManager.addPrintServiceRecommendationsChangeListener
     */
+27 −0
Original line number Diff line number Diff line
@@ -369,6 +369,33 @@ public final class PrintManagerService extends SystemService {
            }
        }

        @Override
        public boolean isPrintServiceEnabled(ComponentName service, int userId) {
            final String[] packages = mContext.getPackageManager().getPackagesForUid(
                    Binder.getCallingUid());
            boolean matchCalling = false;
            for (int i = 0; i < packages.length; i++) {
                if (packages[i].equals(service.getPackageName())) {
                    matchCalling = true;
                    break;
                }
            }
            if (!matchCalling) {
                // Do not reveal any information about other package services.
                throw new SecurityException("PrintService does not share UID with caller.");
            }
            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
            final UserState userState;
            synchronized (mLock) {
                // Only the current group members can check print services.
                if (resolveCallingProfileParentLocked(resolvedUserId) != getCurrentUserId()) {
                    return false;
                }
                userState = getOrCreateUserStateLocked(resolvedUserId, false);
            }
            return userState.isPrintServiceEnabled(service);
        }

        @Override
        public List<RecommendationInfo> getPrintServiceRecommendations(int userId) {
            mContext.enforceCallingOrSelfPermission(
Loading