Compartilhar via


DevicePolicyManager.SetNetworkLoggingEnabled(ComponentName, Boolean) Method

Definition

Called by a device owner, profile owner of a managed profile or delegated app with #DELEGATION_NETWORK_LOGGING to control the network logging feature.

[Android.Runtime.Register("setNetworkLoggingEnabled", "(Landroid/content/ComponentName;Z)V", "GetSetNetworkLoggingEnabled_Landroid_content_ComponentName_ZHandler", ApiSince=26)]
public virtual void SetNetworkLoggingEnabled (Android.Content.ComponentName? admin, bool enabled);
[<Android.Runtime.Register("setNetworkLoggingEnabled", "(Landroid/content/ComponentName;Z)V", "GetSetNetworkLoggingEnabled_Landroid_content_ComponentName_ZHandler", ApiSince=26)>]
abstract member SetNetworkLoggingEnabled : Android.Content.ComponentName * bool -> unit
override this.SetNetworkLoggingEnabled : Android.Content.ComponentName * bool -> unit

Parameters

admin
ComponentName

Which DeviceAdminReceiver this request is associated with, or null if called by a delegated app.

enabled
Boolean

whether network logging should be enabled or not.

Attributes

Remarks

Called by a device owner, profile owner of a managed profile or delegated app with #DELEGATION_NETWORK_LOGGING to control the network logging feature.

Supported for a device owner from Android 8 and a delegated app granted by a device owner from Android 10. Supported for a profile owner of a managed profile and a delegated app granted by a profile owner from Android 12. When network logging is enabled by a profile owner, the network logs will only include work profile network activity, not activity on the personal profile.

Network logs contain DNS lookup and connect() library call events. The following library functions are recorded while network logging is active: <ul> <li>getaddrinfo()</li> <li>gethostbyname()</li> <li>connect()</li> </ul>

Network logging is a low-overhead tool for forensics but it is not guaranteed to use full system call logging; event reporting is enabled by default for all processes but not strongly enforced. Events from applications using alternative implementations of libc, making direct kernel calls, or deliberately obfuscating traffic may not be recorded.

Some common network events may not be reported. For example: <ul> <li>Applications may hardcode IP addresses to reduce the number of DNS lookups, or use an alternative system for name resolution, and so avoid calling getaddrinfo() or gethostbyname.</li> <li>Applications may use datagram sockets for performance reasons, for example for a game client. Calling connect() is unnecessary for this kind of socket, so it will not trigger a network event.</li> </ul>

It is possible to directly intercept layer 3 traffic leaving the device using an always-on VPN service. See #setAlwaysOnVpnPackage(ComponentName, String, boolean) and android.net.VpnService for details.

<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 #setAffiliationIds.

Java documentation for android.app.admin.DevicePolicyManager.setNetworkLoggingEnabled(android.content.ComponentName, boolean).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to