Difference between system files charging_enabled vs battery_charging_enabled


Question

I have a oneplus2 and I need to know the difference between charging_enabled vs battery_charging_enabled files present in /sys/class/power_supply/battery



I am using an app called Battery Charge Limit that is currently using battery_charging_enabled file to toggle charging when the preset limit is reached but even though I can see my phone is discharging (the app stop phone's charging even though the cable is plugged in), the discharging current is unusually very small as compared to "normal" discharging (without the app). Why is this happening? From where is it getting the extra power (if not from the battery) to keep up with the activities done on the phone.



I was wondering if the full charge condition (the ability of the phone to run directly on plugged power source instead of battery after it charges to 100%) was being applied at 90% (which I have set as the max charge limit in the app).



Also I checked the status of charging_enabled while the app was activated and it was 1, which means that it was not affected by the app (which is obvious as the control file used by the app is different).



Edit: I just changed the control file of the app from battery_charging_enabled to charging_enabled and now the battery drain seems normal.



Can anyone explain the difference between these control files ?



Edit: Adding device codes snippets from the file /android/lineage/kernel/oneplus/msm8994/drivers/power/qpnp-smbcharger.c . Hope it helps.



case POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED:
smbchg_battchg_en(chip, val->intval,
REASON_BATTCHG_USER, &unused);
pr_err("chg_en form userspace battery charging enable: %d\n",val->intval);
break;
case POWER_SUPPLY_PROP_CHARGING_ENABLED:
smbchg_usb_en(chip, val->intval, REASON_USER);
smbchg_dc_en(chip, val->intval, REASON_USER);
chip->chg_enabled = val->intval;
pr_err("chg_en form userspace charging enable: %d\n",chip->chg_enabled);
schedule_work(&chip->usb_set_online_work);
break;
------------------------------------------------------------------------
case POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED:
val->intval = smcghg_is_battchg_en(chip, REASON_BATTCHG_USER);
break;
case POWER_SUPPLY_PROP_CHARGING_ENABLED:
val->intval = chip->chg_enabled;

Answer

I had mailed this to developer requesting to answer here , instead he answered on mail to me. Quoting verbatim



You are right. Different control files behave differently. battery_charging_enabled tries to maintain the charge. It takes required power from charger, and it didn't charge/discharge battery. This behaviour is ideal, and if it works, then you should be using it.


charging_enabled completely cuts off power supply from cable. This case we need the threshold limit to start charging again


I have a OnePlus 3, I have both files, but the former doesn't work. I have no choice but to use the latter.



Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes