Prevent NetD from Destroying Sockets when Android Device is Not Charging

Users of Android Marshmallow and Nougat sometimes report that Netd destroys sockets when their device is not charging. Often the Logcat will display something like this:

06-23 12:38:17.576   522  2676 I Netd    : Destroyed 3 sockets for UidRanges{ 10000-2147483647 } skip={1001 1027 10010 10013 10018 10021 10035 10037 10064 10081} in 1.2 ms

This is actually incredibly simple to fix, so simple in fact that it falls under “inattention blindness” – performing deep-method troubleshooting while missing something in plain sight. The truth is, the culprit for this problem is the Android Doze feature introduced in Marshmallow 6.0, and updated in Nougat.

Doze mode activates when a device is left untouched for a period of time. When Doze activates, your device does the following:

  • Network access is suspended.
  • The system ignores wake locks.
  • Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.
  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire.
  • The system does not perform Wi-Fi scans.
  • The system does not allow sync adapters to run.
  • The system does not allow JobScheduler to run

So here, you have two options:

Option 1: Adapt your apps to Doze via whitelisting permissions

You can manually configure the whitelist in Settings > Battery > Battery Optimization. Alternatively, the system provides ways for apps to ask users to whitelist them.

An app can fire the ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS intent to take the user directly to the Battery Optimization, where they can add the app.

An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog.

Option 2: Disable Doze completely on your device – not recommended but it’s your phone

Download the app “Doze Settings Editor” onto your device, launch it, and set the following parametres:

  1. dumpsys deviceidle disable
  2. idle_to 1
  3. max_idle_to 1

A complete explanation of the Doze Settings Editor parameters:

Inactive Timeout – inactive_to
This is the time, after becoming inactive, at which we start looking at the motion sensor to determine if the device is being left alone. We don’t do this immediately after going inactive just because we don’t want to be continually running the significant motion sensor whenever the screen is off.
Sensing Timeout – sensing_to
If we don’t receive a callback from AnyMotion in this amount of time + locating_to, we will change from STATE_SENSING to STATE_INACTIVE, and any AnyMotion callbacks while not in STATE_SENSING will be ignored.
Locating Timeout – locating_to
This is how long we will wait to try to get a good location fix before going in to idle mode.
Location Accuracy – location_accuracy
The desired maximum accuracy (in meters) we consider the location to be good enough to go on to idle. We will be trying to get an accuracy fix at least this good or until locating_to expires.
Motion Inactive Timeout – motion_inactive_to
This is the time, after seeing motion, that we wait after becoming inactive from that until we start looking for motion again.
Idle After Inactive Timeout – idle_after_inactive_to
This is the time, after the inactive timeout elapses, that we will wait looking for significant motion until we truly consider the device to be idle.
Idle Pending Timeout – idle_pending_to
This is the initial time, after being idle, that we will allow ourself to be back in the IDLE_PENDING state allowing the system to run normally until we return to idle.
Max Idle Pending Timeout – max_idle_pending_to
Maximum pending idle timeout (time spent running) we will be allowed to use.
Idle Pending Factor – idle_pending_factor
Scaling factor to apply to current pending idle timeout each time we cycle through that state.
Idle Timeout – idle_to
This is the initial time that we want to sit in the idle state before waking up again to return to pending idle and allowing normal work to run.
Max Idle Timeout – max_idle_to
Maximum idle duration we will be allowed to use.
Idle Factor – idle_factor
Scaling factor to apply to current idle timeout each time we cycle through that state.
Min Time to Alarm – min_time_to_alarm
This is the minimum time we will allow until the next upcoming alarm for us to actually go in to idle mode.
Max Temp App Whitelist Duration – max_temp_app_whitelist_duration
Max amount of time to temporarily whitelist an app when it receives a high tickle.
MMS Temp App Whitelist Duration – mms_temp_app_whitelist_duration
Amount of time we would like to whitelist an app that is receiving an MMS.
SMS Temp App Whitelist Duration – sms_temp_app_whitelist_duration
Amount of time we would like to whitelist an app that is receiving an SMS.

Kevin Arrows
Kevin is a dynamic and self-motivated information technology professional, with a Thorough knowledge of all facets pertaining to network infrastructure design, implementation and administration. Superior record of delivering simultaneous large-scale mission critical projects on time and under budget.

Expert Tip

Prevent NetD from Destroying Sockets when Android Device is Not Charging

If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Restoro by clicking the Download button below.

Download Now

I'm not interested