diff --git a/api/current.txt b/api/current.txt index 1ffba87773ace..09260af23b90d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6493,7 +6493,6 @@ package android.app.admin { method public boolean isNetworkLoggingEnabled(android.content.ComponentName); method public boolean isOverrideApnEnabled(android.content.ComponentName); method public boolean isPackageSuspended(android.content.ComponentName, java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException; - method public boolean isPrintingEnabled(); method public boolean isProfileOwnerApp(java.lang.String); method public boolean isProvisioningAllowed(java.lang.String); method public boolean isResetPasswordTokenActive(android.content.ComponentName); @@ -6566,7 +6565,6 @@ package android.app.admin { method public boolean setPermittedAccessibilityServices(android.content.ComponentName, java.util.List); method public boolean setPermittedCrossProfileNotificationListeners(android.content.ComponentName, java.util.List); method public boolean setPermittedInputMethods(android.content.ComponentName, java.util.List); - method public void setPrintingEnabled(android.content.ComponentName, boolean); method public void setProfileEnabled(android.content.ComponentName); method public void setProfileName(android.content.ComponentName, java.lang.String); method public void setRecommendedGlobalProxy(android.content.ComponentName, android.net.ProxyInfo); @@ -33140,6 +33138,7 @@ package android.os { field public static final java.lang.String DISALLOW_NETWORK_RESET = "no_network_reset"; field public static final java.lang.String DISALLOW_OUTGOING_BEAM = "no_outgoing_beam"; field public static final java.lang.String DISALLOW_OUTGOING_CALLS = "no_outgoing_calls"; + field public static final java.lang.String DISALLOW_PRINTING = "no_printing"; field public static final java.lang.String DISALLOW_REMOVE_MANAGED_PROFILE = "no_remove_managed_profile"; field public static final java.lang.String DISALLOW_REMOVE_USER = "no_remove_user"; field public static final java.lang.String DISALLOW_SAFE_BOOT = "no_safe_boot"; diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 8d161006be763..77e118ccb1bf2 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -9403,41 +9403,6 @@ public class DevicePolicyManager { } } - /** - * Allows/disallows printing. - * - * Called by a device owner or a profile owner. - * Device owner changes policy for all users. Profile owner can override it if present. - * Printing is enabled by default. If {@code FEATURE_PRINTING} is absent, the call is ignored. - * - * @param admin which {@link DeviceAdminReceiver} this request is associated with. - * @param enabled whether printing should be allowed or not. - * @throws SecurityException if {@code admin} is neither device, nor profile owner. - */ - public void setPrintingEnabled(@NonNull ComponentName admin, boolean enabled) { - try { - mService.setPrintingEnabled(admin, enabled); - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); - } - } - - /** - * Returns whether printing is enabled for this user. - * - * Always {@code false} if {@code FEATURE_PRINTING} is absent. - * Otherwise, {@code true} by default. - * - * @return {@code true} iff printing is enabled. - */ - public boolean isPrintingEnabled() { - try { - return mService.isPrintingEnabled(); - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); - } - } - /** * Called by device owner to add an override APN. * diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index ef990071dbfd8..5218a7340ec93 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -402,9 +402,6 @@ interface IDevicePolicyManager { CharSequence getStartUserSessionMessage(in ComponentName admin); CharSequence getEndUserSessionMessage(in ComponentName admin); - void setPrintingEnabled(in ComponentName admin, boolean enabled); - boolean isPrintingEnabled(); - List setMeteredDataDisabled(in ComponentName admin, in List packageNames); List getMeteredDataDisabled(in ComponentName admin); diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 2093cec769da4..7e7af1a122999 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -943,6 +943,20 @@ public class UserManager { * @see #getUserRestrictions() */ public static final String DISALLOW_SHARE_INTO_MANAGED_PROFILE = "no_sharing_into_profile"; + + /** + * Specifies whether the user is allowed to print. + * + * This restriction can be set by device or profile owner. + * + * The default value is {@code false}. + * + * @see DevicePolicyManager#addUserRestriction(ComponentName, String) + * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) + * @see #getUserRestrictions() + */ + public static final String DISALLOW_PRINTING = "no_printing"; + /** * Application restriction key that is used to indicate the pending arrival * of real restrictions for the app. diff --git a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java index 842f8d0a42f57..23185d7fb5ab1 100644 --- a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java +++ b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java @@ -122,7 +122,8 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_CONFIG_BRIGHTNESS, UserManager.DISALLOW_SHARE_INTO_MANAGED_PROFILE, UserManager.DISALLOW_AMBIENT_DISPLAY, - UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT + UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT, + UserManager.DISALLOW_PRINTING }); /** diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java index c4e485c1523a7..3557dc90a5035 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java @@ -121,16 +121,6 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub { return null; } - @Override - public void setPrintingEnabled(ComponentName admin, boolean enabled) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isPrintingEnabled() { - return true; - } - @Override public List setMeteredDataDisabled(ComponentName admin, List packageNames) { return packageNames; diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 4afe1c7847010..953a79f625e6e 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -305,8 +305,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private static final String TAG_PASSWORD_VALIDITY = "password-validity"; - private static final String TAG_PRINTING_ENABLED = "printing-enabled"; - private static final String TAG_TRANSFER_OWNERSHIP_BUNDLE = "transfer-ownership-bundle"; private static final int REQUEST_EXPIRE_PASSWORD = 5571; @@ -615,8 +613,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { long mPasswordTokenHandle = 0; - boolean mPrintingEnabled = true; - public DevicePolicyData(int userHandle) { mUserHandle = userHandle; } @@ -2948,12 +2944,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { out.endTag(null, TAG_CURRENT_INPUT_METHOD_SET); } - if (!policy.mPrintingEnabled) { - out.startTag(null, TAG_PRINTING_ENABLED); - out.attribute(null, ATTR_VALUE, Boolean.toString(policy.mPrintingEnabled)); - out.endTag(null, TAG_PRINTING_ENABLED); - } - for (final String cert : policy.mOwnerInstalledCaCerts) { out.startTag(null, TAG_OWNER_INSTALLED_CA_CERT); out.attribute(null, ATTR_ALIAS, cert); @@ -3172,9 +3162,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { policy.mCurrentInputMethodSet = true; } else if (TAG_OWNER_INSTALLED_CA_CERT.equals(tag)) { policy.mOwnerInstalledCaCerts.add(parser.getAttributeValue(null, ATTR_ALIAS)); - } else if (TAG_PRINTING_ENABLED.equals(tag)) { - String enabled = parser.getAttributeValue(null, ATTR_VALUE); - policy.mPrintingEnabled = Boolean.toString(true).equals(enabled); } else { Slog.w(LOG_TAG, "Unknown tag: " + tag); XmlUtils.skipCurrentTag(parser); @@ -10417,7 +10404,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { public CharSequence getPrintingDisabledReasonForUser(@UserIdInt int userId) { synchronized (DevicePolicyManagerService.this) { DevicePolicyData policy = getUserData(userId); - if (policy.mPrintingEnabled) { + if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_PRINTING)) { Log.e(LOG_TAG, "printing is enabled"); return null; } @@ -12789,27 +12776,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } - private boolean hasPrinting() { - return mInjector.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING); - } - - @Override - public void setPrintingEnabled(ComponentName admin, boolean enabled) { - if (!mHasFeature || !hasPrinting()) { - return; - } - Preconditions.checkNotNull(admin, "Admin cannot be null."); - enforceProfileOrDeviceOwner(admin); - synchronized (this) { - final int userHandle = mInjector.userHandleGetCallingUserId(); - DevicePolicyData policy = getUserData(userHandle); - if (policy.mPrintingEnabled != enabled) { - policy.mPrintingEnabled = enabled; - saveSettingsLocked(userHandle); - } - } - } - private void deleteTransferOwnershipMetadataFileLocked() { mTransferOwnershipMetadataManager.deleteMetadataFile(); } @@ -12839,25 +12805,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } - /** - * Returns whether printing is enabled for current user. - * @hide - */ - @Override - public boolean isPrintingEnabled() { - if (!hasPrinting()) { - return false; - } - if (!mHasFeature) { - return true; - } - synchronized (this) { - final int userHandle = mInjector.userHandleGetCallingUserId(); - DevicePolicyData policy = getUserData(userHandle); - return policy.mPrintingEnabled; - } - } - @Override public int addOverrideApn(@NonNull ComponentName who, @NonNull ApnSetting apnSetting) { if (!mHasFeature) { diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java index e1c1eb298e31c..e8620edc9d5e6 100644 --- a/services/print/java/com/android/server/print/PrintManagerService.java +++ b/services/print/java/com/android/server/print/PrintManagerService.java @@ -21,7 +21,6 @@ import static android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING; import android.annotation.NonNull; import android.app.ActivityManager; -import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManagerInternal; import android.content.ComponentName; import android.content.Context; @@ -115,12 +114,9 @@ public final class PrintManagerService extends SystemService { private final SparseArray mUserStates = new SparseArray<>(); - private final DevicePolicyManager mDpm; - PrintManagerImpl(Context context) { mContext = context; mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); - mDpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); registerContentObservers(); registerBroadcastReceivers(); } @@ -722,7 +718,7 @@ public final class PrintManagerService extends SystemService { } private boolean isPrintingEnabled() { - return mDpm == null || mDpm.isPrintingEnabled(); + return !mUserManager.hasUserRestriction(UserManager.DISALLOW_PRINTING); } private void dump(@NonNull DualDumpOutputStream dumpStream,