Loading core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -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); } core/java/android/print/IPrintManager.aidl +9 −0 Original line number Diff line number Diff line Loading @@ -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. * Loading core/java/android/print/PrintManager.java +19 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading core/tests/coretests/src/android/print/IPrintManagerParametersTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading services/print/java/com/android/server/print/PrintManagerService.java +27 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -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); }
core/java/android/print/IPrintManager.aidl +9 −0 Original line number Diff line number Diff line Loading @@ -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. * Loading
core/java/android/print/PrintManager.java +19 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading
core/tests/coretests/src/android/print/IPrintManagerParametersTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading
services/print/java/com/android/server/print/PrintManagerService.java +27 −0 Original line number Diff line number Diff line Loading @@ -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