Make printing policy a restriction.
Use existing API instead of creating new method. Bug: 64140119 Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerTest#testPrintingPolicy Change-Id: I9ff94f4d73824e7bf9aedbb64811ad60fccf9779
This commit is contained in:
@@ -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<java.lang.String>);
|
||||
method public boolean setPermittedCrossProfileNotificationListeners(android.content.ComponentName, java.util.List<java.lang.String>);
|
||||
method public boolean setPermittedInputMethods(android.content.ComponentName, java.util.List<java.lang.String>);
|
||||
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";
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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<String> setMeteredDataDisabled(in ComponentName admin, in List<String> packageNames);
|
||||
List<String> getMeteredDataDisabled(in ComponentName admin);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<String> setMeteredDataDisabled(ComponentName admin, List<String> packageNames) {
|
||||
return packageNames;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<UserState> 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,
|
||||
|
||||
Reference in New Issue
Block a user