How to put Android phone into "deep sleep" using Tasker?


Question

I have a Sony Xperia Z running factory Android 5.1.1 I'd like to use in my car for navigation/ music.



I've installed Tasker & configured it to start Spotify playing on power & turn off Spotify when power is switched off.



However this still leaves the phone active & using it's battery while the car is not being used. We don't use our car that much so the battery runs flat over a couple of days.



What I'd really like to do is have Tasker shut down as much of the phone as possible - wireless, mobile data, location services. Ideally I'd like the phone doing absolutely nothing & waiting for power to start playing Spotify again.



Options for "Airplane Mode", "Mobile Data" & "Power Mode" are all unavailable/ red in Tasker. The phone is not rooted but am I correct that these aren't available in Android 5.1?



The Sony Xperia Z has got Ultra Stamina mode that would be perfect. But I can't work out how to activate Ultra Stamina via Tasker (I don't think it's possible) & the phone might need a reboot to come out of Ultra Stamina - which isn't great if I've just stopped the car/ turned off the phone for 5 minutes.



What is the best way to put the phone into "deep sleep" while the phone isn't receiving power where it uses as little services/ battery as possible in Tasker?


Answer


Options for "Airplane Mode", "Mobile Data" & "Power Mode" are all
unavailable/ red in Tasker. The phone is not rooted but am I correct
that these aren't available in Android 5.1?




On recent versions of Android, restrictions have been put in place that prevent lot of previously easily toggleable settings (e.g. location, mobile data, night mode, more) and are no longer available without root.



As expected there are workarounds to help toggle many settings without root.



Conventional methods employed involve circumventing Android's security policy on this permission (android.permission.WRITE_SECURE_SETTINGS) and declaring the appropriate permission for toggling secure settings explicitly on the target app/plugin that will be used to toggle these "secure settings" via Tasker.







  1. Using a plugin



It is possible to get most of the "power toggles" switched off using Tasker and an additional plugin Auto Tools.




  • Autools offers built-in options to toggle location mode (off, device only, battery saving, high accuracy), mobile-data (on/off), battery saver (enable/disable), notification listeners etc.


  • Additionally you can toggle flight mode using any of the methods listed here (without root).




Setup



In tasker create a new action:



Plugin >> Auto Tools >> Secure Settings







  1. Pseudo plugin







You will have to create an app using Tasker and declare the
appropriate permission for toggling secure settings. You will then
need to explicitly grant permission to that app.



This is to workaround Android's security policy on this permission.
Ordinarily, you wouldn't want to grant this level of permission to
other apps, but since this an app you're creating yourself, you don't
need to worry about it. The actual toggling is done with Java calls.





  • The app you created works as a sort of pseudo-plugin. In a task, use the Launch App action and choose your new app.


  • In the Data field, you will specify the setting to change and the value to change to. The format of the Data field should be as such: [setting name space]|[setting name]|[value]|[value type] .




Important!



In both cases remember to explicitly grant the app(s) two extra permissions added called



android.permission.WRITE_SECURE_SETTINGS and android.permission.WRITE_SETTINGS.




  • Connect your device to your computer, and open up a command prompt.


  • Run the command adb shell pm grant [your package name] android.permission.WRITE_SECURE_SETTINGS




E.g adb shell pm grant [com.joaomgcd.autotools] android.permission.WRITE_SECURE_SETTINGS



Acknowledgements




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