Explicitly Managing WiFi Power Consumption in Android - android

Background
I'm developing a research application that runs on Android phones. In short, the application runs so long as the phone is on and periodically takes information from many components and sensors on the phone. The application is to disturb the user as little as possible. That being said, it's draining the battery far too quickly and forces the user to recharge every day. This simply won't do.
To try and figure out how to improve the situation, a colleague also working on the application let the application run for a long period of time and noticed that the biggest battery hog is WiFi. My current idea is to manually shut off WiFi when it's not in use in an attempt to save power. AFAIK, Android uses PSM for WiFi to accomplish this to some end, but it doesn't seem to be enough.
Problem
Is there a way to "ramp up" Android's PSM? Or, if there is not as this question suggests, is there any way that I can safely turn WiFi on and off without adversely affecting the user? I.e., is there a way to tell which applications are using WiFi and turn it off when none are? Do standard applications - such as the web browser and email clients - use WiFi locks to prevent WiFi from being turned off when they are working?
Any advice on where to start in solving this problem are greatly appreciated. Information on how Android's PSM works, how long it takes for it to take effect, or any information relevant to the problem are very welcome.
Thanks for your time!

Is there a way to "ramp up" Android's PSM?
Not via the Android SDK.
I.e., is there a way to tell which applications are using WiFi and turn it off when none are?
The OS does this already.
Do standard applications - such as the web browser and email clients - use WiFi locks to prevent WiFi from being turned off when they are working?
Some probably do. You are welcome to search the Android source code and find out. Of course, bear in mind that there are no "standard applications" -- I presume you are thinking of the ones that are part of the Android open source project.
Any advice on where to start in solving this problem are greatly appreciated.
Find out where in your own code you are being inefficient, specifically here:
the application runs so long as the phone is on and periodically takes information from many components and sensors on the phone.
If the device behaves fine when your code is not running, and the device does not behave fine when your code is running, then the problem lies in your code. Conversely, if the device does not behave fine even when your code is not running, then something else is afoot (device defect, firmware defect, rogue application, etc.), but it probably has nothing to do with StackOverflow.

Related

Endless foreground service never works as expected

I am creating application that has endless ForegroundService for new android versions.
Problem is that ForegroundService always dies after some time no matter what.
Tried to do Battery optimization, Wake lock, creating new process for service, even creating JobScheduler that checks if Service still working, but that one also stops working after some time.
Tried to follow Google samples, Stackoverflow solutions and many others, nothing seems to work.
I also made some research on my banking app and some other apps that relies on services for notifying the user or tracking some activities, they also not working flawlessly like old times.
At the end I figure out that for some Vendor phones doing some extra setting Vendor specific setting helps, this link one of many examples to understand Slack Known issues with Android .
After this reading, I don't think that simple user should go somewhere in to deep phone setting to make app that he likes to work... In fact I think it is the worst practice....
Made some conclusion after researching that because of saving few battery percents Google and poorly made Vendors battery saving strategies on top making phones dump and not reliable....
Also these background restrictions making not possible to develop awesome pocket portable device features...
I mean I agree with ForegroundService idea for long running task instead of simple Service in background that might be malware, spying or whatever that user does know nothing about it. Also agree that User is notified about high power usage, but randomly killing everything is same as killing the idea of smart device.
Please tell me that I am wrong about everything and give me a solution :)

Detect if a cell phone device is reachable or not (switched on/off) programmatically

I am assigned an absurd task, which is to detect if a cell phone is reachable or not by typing in their numbers.
So its basic use is say I am handling a telephonic service which has around 10,000 agents. By running a program through web or which ever way possible i'll know if a number is switched on/off, since the numbers need to be available 24x7 for the company.(It has other uses as well, telling those would be waste of time for all).
I tried searching on internet but could not get a single hint if it can be achieved or not.
Currently I am going through basics of how a call is established and network in cell phone devices.
For any help,I would highly appreciate since this complete question might sound stupid.
Even if some can point me to the right direction, do answer.
NOTE : I have to build an stand-alone application to do the work. Cannot install my own application in devices to send a ping or so, since most of the cell phones a basic low-end devices.
Thanks

Restart radio programmatically

Every now and then, the radio of my android phone silently dies because of some network related issues.
On the Nexus 4, it shows the empty triangle as if there where no service available in this area. On other phones it does not even do that. It looks like signal is fine.
Anyway, after the radio died silently no phone call / text message / data is going through in any direction.
The only hint I get from the System is the android.net.conn.CONNECTIVITY_CHANGE broadcast fired when the signal dies and wifi is not connected.
The only thing, that fixes the problem is restarting the phone.
Finally my question:
Does anybody know how to restart the radio completely by code?
I mean, it is a separate image running on a separate CPU. There must be a way to reboot it without rebooting the phone.
Maybe there is something, I can path into the Android ROM. I'm running CM here and be happy to patch it (again).
I tried fixing it by launching a system app by pressing *#*#4636#*#* on the dailer and stopping the radio and starting it again. But it did not help at all.
I recently made an app that checks the radio every time the connection changes. It shows a simple notification that tells me, I should reboot my phone. [1]
Issues reproduced on:
LG Nexus 4
Samsung ACE 2
multiple Apple iPhone 4*
Issues not reproduced on:
Apple iPhone 5
All phones running in the Dialog.lk network.
[1] https://github.com/felixb/network-checker
On a rooted device, one can issue the pkill command for all processes running as the user radio. I tested this on a Oneplus 3. The system seems to immediately restart the service:
pkill -u radio
Yes it is possible, but it will be difficult to perform on device without a deep understanding of the modem communications code of which multiple versions exist and even that will be dependent on if the system will permit you to even perform the communications on device.
The only one I am aware of that you can fully manipulate on device at this time is Qualcomm's (Qualcomm is standard in the majority of devices, but Samsung has used VIA in some cases which is a whole different monster, and even still another chipset or two exist), but to even be able to perform what your asking with Qualcomm's chipset, the following must be true:
The device must be rooted.
The application must have root access.
The system ROM must have the ability to place the cellular radio into modem diagnostics mode.
The device must have the appropriate permissions to permit the access.
At this point most people would connect their computer to their device and manipulate the cellular radio using QPST, CDMAWare, or QXDM. Options available to those users include everything from manipulating cellular subscriber data to restarting the cellular modem.
But, this is where things get tricky, you need to be be able to access this from the device side, which depending on the device, the operating system, and the configuration of it...may very well not be possible.
Also your application must be able to communicate with the cellular radio using the special protocol that the applications above use to do their communications which will require you becoming intimately familiar with that specification. The whitepaper for the Qualcomm diagnostics protocol is floating around on the web if you look hard enough for it.
Also on the not so cool side, if your application has access to the radio...so does any other rooted application (or even non-rooted, if you don't set the device permissions correctly) thus enabling rouge applications the ability to change your radio's configuration data potentially even bricking your device (which I have seen people do using the applications named above).
So my answer is Yes, you can do it, although:
Depending on your device you may not be able to, you should be well prepared to study and develop the needed tools to perform what you are wanting to do
No quick-start guide exist to be followed
Remember that you do so in the knowledge that your device could potentially be bricked either by a mistake in your coding or by a rouge application.
Rebooting the radio, as you have done in the device menus, may not help your problem, you may still require a device reboot
My advice is to use a much easier method and include a timer with automatic reboot in your current application, it is much safer, won't brick your device, and you won't have to become a cellular engineer to figure out how to accomplish it.
Your timer could begin counting down when the radio dies, and provide you an option to stop the reboot if your doing something important, otherwise it would restart your device and all would be ready when you reached for it to make a call or check your email.
Hopefully I was able to help, even though I know this is not the answer that you wanted.
Side note, if you could hijack Android's system configuration menus from an outside application you could potentially manipulate the radio state using the same methods used in Android...but you already discovered that restarting the radio in this method does not help your situation. Plus Android is designed to prevent such manipulation to prevent malicious applications from overtaking the UI of other apps and the system.

How to reboot android device

How to shutdown and restart android device in my application.
please give me a suggestion if is possible or not.
I search a lot but no code work for me.
Based on what you said your intentions are, what you want to do is not possible in Android. If you are rooted, you can shut down your phone, but there's no way to wake it up at a future time.
What you might want to look into is to simply put the phone to sleep as much as possible -- place it in Airplane mode and turn off sound. ... and then re-enable all that at a given time.
If you don't want to code it all yourself, there are various scheduling apps out there, including Tasker (which can do much more).

App Idea Force Contact Pull Android

I have an idea for an but I am not sure if it's even possible. I ran into an issue the other day where a phones touch screen was barley working and I needed to get the contacts off of it. I have a cellbrite machine but anyone who has ever used one knows how finicky they can be.
I would love to develop an android app that will connect to any phone via bluetooth and force pull all the contact from it, this would be handy if you have a troublesome screen. My question is this even possible based on the different phone types, and the different level of bluetooth protocols supported on the phones. If anyone has any ideas on how this might be accomplished hat would be great.
Any app with the necessary permission can read a phone's contacts and send them over Bluetooth (or Wi-Fi).
I think the main problem would be that people don't think to install your app until they need it. Then, you can't install your app onto their broken phone unless the phone has a network connection, and if they have a network connection then there isn't really any need to use Bluetooth in the first place.
Actually, one of the basic ideas of Android is that everything on your phone is sync'ed - so you don't have to worry if your phone gets crushed.

Categories

Resources