Merge "Make device wide DO features available if all users affiliated"

This commit is contained in:
TreeHugger Robot
2017-01-16 18:09:47 +00:00
committed by Android (Google) Code Review
8 changed files with 452 additions and 176 deletions

View File

@@ -768,6 +768,10 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
/**
* Called when a new batch of security logs can be retrieved.
*
* <p>If a secondary user or profile is created, this callback won't be received until all users
* become affiliated again (even if security logging is enabled).
* See {@link DevicePolicyManager#setAffiliationIds}
*
* <p>This callback is only applicable to device owners.
*
* @param context The running context as per {@link #onReceive}.
@@ -782,13 +786,18 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
* ever be called when network logging is enabled. The logs can only be retrieved while network
* logging is enabled.
*
* <p>If a secondary user or profile is created, this callback won't be received until all users
* become affiliated again (even if network logging is enabled). It will also no longer be
* possible to retrieve the network logs batch with the most recent {@code batchToken} provided
* by this callback. See {@link DevicePolicyManager#setAffiliationIds}.
*
* <p>This callback is only applicable to device owners.
*
* @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}.
* @param batchToken The token representing the current batch of network logs.
* @param networkLogsCount The total count of events in the current batch of network logs.
* @see DevicePolicyManager#retrieveNetworkLogs(ComponentName)
* @see DevicePolicyManager#retrieveNetworkLogs
*/
public void onNetworkLogsAvailable(Context context, Intent intent, long batchToken,
int networkLogsCount) {

View File

@@ -3651,15 +3651,16 @@ public class DevicePolicyManager {
/**
* Called by a device owner to request a bugreport.
* <p>
* There must be only one user on the device, managed by the device owner. Otherwise a
* {@link SecurityException} will be thrown.
* If the device contains secondary users or profiles, they must be affiliated with the device
* owner user. Otherwise a {@link SecurityException} will be thrown. See
* {@link #setAffiliationIds}.
*
* @param admin Which {@link DeviceAdminReceiver} this request is associated with.
* @return {@code true} if the bugreport collection started successfully, or {@code false} if it
* wasn't triggered because a previous bugreport operation is still active (either the
* bugreport is still running or waiting for the user to share or decline)
* @throws SecurityException if {@code admin} is not a device owner, or if there are users other
* than the one managed by the device owner.
* @throws SecurityException if {@code admin} is not a device owner, or there is at least one
* profile or secondary user that is not affiliated with the device owner user.
*/
public boolean requestBugreport(@NonNull ComponentName admin) {
throwIfParentInstance("requestBugreport");
@@ -6631,14 +6632,16 @@ public class DevicePolicyManager {
}
/**
* Called by device owner to control the security logging feature. Logging can only be
* enabled on single user devices where the sole user is managed by the device owner.
* Called by device owner to control the security logging feature.
*
* <p> Security logs contain various information intended for security auditing purposes.
* See {@link SecurityEvent} for details.
*
* <p>There must be only one user on the device, managed by the device owner.
* Otherwise a {@link SecurityException} will be thrown.
* <p><strong>Note:</strong> The device owner won't be able to retrieve security logs if there
* are unaffiliated secondary users or profiles on the device, regardless of whether the
* feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
* all users to become affiliated. Therefore it's recommended that affiliation ids are set for
* new users as soon as possible after provisioning via {@link #setAffiliationIds}.
*
* @param admin Which device owner this request is associated with.
* @param enabled whether security logging should be enabled or not.
@@ -6680,13 +6683,16 @@ public class DevicePolicyManager {
* <p> Access to the logs is rate limited and it will only return new logs after the device
* owner has been notified via {@link DeviceAdminReceiver#onSecurityLogsAvailable}.
*
* <p>There must be only one user on the device, managed by the device owner.
* Otherwise a {@link SecurityException} will be thrown.
* <p>If there is any other user or profile on the device, it must be affiliated with the
* device owner. Otherwise a {@link SecurityException} will be thrown. See
* {@link #setAffiliationIds}
*
* @param admin Which device owner this request is associated with.
* @return the new batch of security logs which is a list of {@link SecurityEvent},
* or {@code null} if rate limitation is exceeded or if logging is currently disabled.
* @throws SecurityException if {@code admin} is not a device owner.
* @throws SecurityException if {@code admin} is not a device owner, or there is at least one
* profile or secondary user that is not affiliated with the device owner user.
* @see DeviceAdminReceiver#onSecurityLogsAvailable
*/
public @Nullable List<SecurityEvent> retrieveSecurityLogs(@NonNull ComponentName admin) {
throwIfParentInstance("retrieveSecurityLogs");
@@ -6726,14 +6732,17 @@ public class DevicePolicyManager {
* will result in {@code null} being returned. The device logs are retrieved from a RAM region
* which is not guaranteed to be corruption-free during power cycles, as a result be cautious
* about data corruption when parsing. </strong>
* <p>
* There must be only one user on the device, managed by the device owner. Otherwise a
* {@link SecurityException} will be thrown.
*
* <p>If there is any other user or profile on the device, it must be affiliated with the
* device owner. Otherwise a {@link SecurityException} will be thrown. See
* {@link #setAffiliationIds}
*
* @param admin Which device owner this request is associated with.
* @return Device logs from before the latest reboot of the system, or {@code null} if this API
* is not supported on the device.
* @throws SecurityException if {@code admin} is not a device owner.
* @throws SecurityException if {@code admin} is not a device owner, or there is at least one
* profile or secondary user that is not affiliated with the device owner user.
* @see #retrieveSecurityLogs
*/
public @Nullable List<SecurityEvent> retrievePreRebootSecurityLogs(
@NonNull ComponentName admin) {
@@ -6939,6 +6948,12 @@ public class DevicePolicyManager {
* Indicates the entity that controls the device or profile owner. Two users/profiles are
* affiliated if the set of ids set by their device or profile owners intersect.
*
* <p><strong>Note:</strong> Features that depend on user affiliation (such as security logging
* or {@link #bindDeviceAdminServiceAsUser}) won't be available when a secondary user or profile
* is created, until it becomes affiliated. Therefore it is recommended that the appropriate
* affiliation ids are set by its profile owner as soon as possible after the user/profile is
* created.
*
* @param admin Which profile or device owner this request is associated with.
* @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
*
@@ -7138,15 +7153,19 @@ public class DevicePolicyManager {
}
/**
* Called by a device owner to control the network logging feature. Logging can only be
* enabled on single user devices where the sole user is managed by the device owner. If a new
* user is added on the device, logging is disabled.
* Called by a device owner to control the network logging feature.
*
* <p> Network logs contain DNS lookup and connect() library call events.
*
* <p><strong>Note:</strong> The device owner won't be able to retrieve network logs if there
* are unaffiliated secondary users or profiles on the device, regardless of whether the
* feature is enabled. Logs will be discarded if the internal buffer fills up while waiting for
* all users to become affiliated. Therefore it's recommended that affiliation ids are set for
* new users as soon as possible after provisioning via {@link #setAffiliationIds}.
*
* @param admin Which {@link DeviceAdminReceiver} this request is associated with.
* @param enabled whether network logging should be enabled or not.
* @throws {@link SecurityException} if {@code admin} is not a device owner.
* @throws SecurityException if {@code admin} is not a device owner.
* @see #retrieveNetworkLogs
*/
public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
@@ -7164,7 +7183,7 @@ public class DevicePolicyManager {
* @param admin Which {@link DeviceAdminReceiver} this request is associated with. Can only
* be {@code null} if the caller has MANAGE_USERS permission.
* @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
* @throws {@link SecurityException} if {@code admin} is not a device owner and caller has
* @throws SecurityException if {@code admin} is not a device owner and caller has
* no MANAGE_USERS permission
*/
public boolean isNetworkLoggingEnabled(@Nullable ComponentName admin) {
@@ -7190,12 +7209,19 @@ public class DevicePolicyManager {
* after the device device owner has been notified via
* {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
*
* <p>If a secondary user or profile is created, calling this method will throw a
* {@link SecurityException} until all users become affiliated again. It will also no longer be
* possible to retrieve the network logs batch with the most recent batchToken provided
* by {@link DeviceAdminReceiver#onNetworkLogsAvailable}. See
* {@link DevicePolicyManager#setAffiliationIds}.
*
* @param admin Which {@link DeviceAdminReceiver} this request is associated with.
* @param batchToken A token of the batch to retrieve
* @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
* {@code null} if the batch represented by batchToken is no longer available or if
* logging is disabled.
* @throws {@link SecurityException} if {@code admin} is not a device owner.
* @throws SecurityException if {@code admin} is not a device owner, or there is at least one
* profile or secondary user that is not affiliated with the device owner user.
* @see DeviceAdminReceiver#onNetworkLogsAvailable
*/
public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,