Android 3.2 and WifiManager.setWifiEnabled - java

I updated to Android 3.2 and now when I call WifiManager.setWifiEnabled I get an error in the log saying WRITE_SECURE_SETTINGS permission needed.
Is this something that has changed with 3.2?
(Is this change documented somewhere?)
I would like to be able to disable Wifi from my app (most of the time) as its not needed and will only use more battery than necessary.
Is there a way to do disable Wifi from 3.2 onwards?
Regards
Jerry

WiFi power management is a system-wide setting and not the responsibility of your application. As long as you don't grab an explicit WifiLock or power-hungry WakeLock (such as FULL_WAKE_LOCK), then Android will respect the users power management choices and so should you.
If you still want to turn WiFi on and off, you need to make sure you have the CHANGE_WIFI_STATE permission.
I'm not sure why the log mentions WRITE_SECURE_SETTINGS, but unless you are explicitly catching an exception thrown by setWifiEnabled that complains about it, then the message isn't for you.

Related

How can I disable the Android 11's auto-reset permissions in android application?

Since Android 11, there has been a system feature where it resets app permissions after a certain amount of time has passed and you haven't used the app.
I know you can turn it off on most apps, by the user itself like the screenshot below :
and also it seems to turn back on when there are app or system updates.
How can I disable this function in my app by code or sth else?
Well, I doubt there is an easy way.
If your app is a device policy controller, it will not be set to hibernation (System exemptions from hibernation) or, if your app is a default handler for messages, phone, browser etc.
What you can do, is to ask the user to disable auto revoke for your app. But you might have to do that after updates as well, if the system resets this privilege on your app (so your problem won't be solved).
The permissions you request in your app manifest (android:required="true") should never be revoked. But of course you cannot request every kind of permission that way. Some need to be requested explicitly.
Apps using background services are whitelisted automatically as stated here. So you can declare a background service, if this is appropriate for you. But if there is nothing to be done, I could imagine, that the system removes your app from whitelist. (I didn't test all of it)
If you see this post you can also try
PackageManager pm = getPackageManager();
pm.setAutoRevokeWhitelisted(getPackageName(), true);
boolean result = pm.isAutoRevokeWhitelisted(); // result should be true
and this in your manifest:
<uses-permission android:name="android.permission.WHITELIST_AUTO_REVOKE_PERMISSIONS" />
But I actually doubt it works.
i found article for your subject. It's says,
"The toggle is disabled for some apps that perform a background
service, including device admin apps Whenever the toggle is
hidden/disabled the app is already exempted from auto revoke"
Link to the article
You can examine this if you want. I hope it helps you.

React Native Publishing APP on Play Store Rejected (permissions)

I have just completed my app which I have React Native using Expo. It is my first time uploading an APP to Play Store. After I got finished uploading my APP and all the requirements I got an Email from Google that my APP got Rejected, and I have no idea how to fix the issues they have listed.
=====================================================================
Here are the reasons:
The declared function DEVICE_AUTOMATION is allowed, but not approved for the specific permissions that are listed in your manifestREAD_SMS . These excess permissions READ_SMS must be removed from your app manifest
The declared functionality DEVICE_AUTOMATION is determined to be unnecessary or not aligned with the core functionality of your app.
=====================================================================
Any help would be grateful.
Best Regards
Musayyab
Starting from Jan 9, 2019, Google starts restricts the use of high risk or sensitive permission including SMS or Call Log.
According to mail, you can't use READ_SMS permission in your application. (It does not matter what application make by whatever language) Indeed, Google just judge 'Your application doesn't need READ_SMS function'.
If you tried to use READ_SMS as OTP(or Phone Authentication), You can use SMS Retriever API to achieve almost same feature.
In other cases, there are no alternatives available at this time.
Android apps have something called Permissions which the app tell s the phone what it would like to do. The purpose of these is to protect the privacy of the Android User.
Google Play has recently got stricter in what apps it will allow to use some of these permissions, as they are often used by abusive apps. One of these permissions is READ_SMS. If an app is granted this permission it is allowed to read all of the users SMS messages.
It sounds from your comment like you don't want your app to read the users SMS messages. So in this case the check worked - your app was asking for a permission it didn't need. You should remove the request for the READ_SMS permission from your app.
There are instructions on editing the permissions in a react native app here. So possibly you added this permission to your AndroidManifest.xml file. If you did, then you should remove it.
If you didn't add it yourself, it is a possible a bad third-party library you added to your app added the permission. If so you should stop using that library.

Controlling a device hardware via device admin or root

I need to have control over some admin features of android device.
Is it possible to acquire control over hardware not specified in android.app.admin.DevicePolicyManager like disabling access to microphone?
Also it will be good to find ability to track network connections or attempts to use network adapters by apps.
Maybe some command for root console or other way exist - how I can search for?
As far as i know there is no way to block any other hardware except camera with device manager. I believe that if your app takes control of microphone it will be unavailable to other apps, but i am not sure. Note that from android 8.0 no app is allowed to take control of microphone while in background.
About tracking network activity you could open vpn to monitor all packets that are sent and received.
Please keep in mind that i am not familiar with root methods so you should do some more research on this.

How to set a static IP for new WiFi configuration?

Again stuck on the same problem.
I have found around that we can set static system settings like this:
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_USE_STATIC_IP, "1"); // to define it use static ip's
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_IP,"192.168.1.15");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_NETMASK,"255.255.255.0");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_DNS1,"192.168.1.1");
System.putString(getContentResolver(), android.provider.Settings.System.WIFI_STATIC_GATEWAY,"192.168.1.1");
But No Success!
I don't understand that when to set these settings?
Should I do it before the wifi configuration creation or after saving the wifi configuration or even before activating it or after it?
However, I have tried the all possible cases from my side and when I check Android WiFi settings, I see it's still on DHCP.
A previous question i.e. How to configue a static IP address, netmask, gateway programmatically on Android 3.x or 4.x has completely ruined my android device and now it can't switch
ON its WiFi anymore.
I also tried static IP on my HTC phone and no success, its always in DHCP mode!
Do I need to call a "reconnect" command? If yes, then in which way?
I think you it should look like:
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_IP,"192.168.1.15");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_DNS1, "192.168.1.1");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.1.1");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
android.provider.Settings.System.putString(getContentResolver(),android.provider.Settings.System.WIFI_USE_STATIC_IP, "1");
And don't forget the manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
Regarding the WiFi problem that your device had, you can try switching the WIFI on programmatically. This post might be helpful:
How to programmatically turn off WiFi on Android device?
After more than a year, I give up with setting a static IP (or DHCP, DNS, ...). Simply it's not possible, or, better, it's not allowed (from an arbitrary application).
Someone says:
"You could use NDK - this gives you low-level access to Linux under Android. Warning: don't expect this to be documented or supported. They might even ban you from Android Market (I know I would)"
For those who want to have some expriences with NDK, here is the a link:
http://developer.android.com/tools/sdk/ndk/index.html
Good luck, and give some feedback if you find something interesting!

check billing (and blobstore) enabled from app

I was wondering if there was a way to check if billing/blobstore was available from within an app. I have tried to use the capabilities api for blobstore being enabled but it cannot tell if billing/blobstore is available.
Basically I want to know if the app place I'm delpoying to is setup for free or billing (and subsequently blobstore) from within a java app.
P.S. I have tried catching the exception com.google.apphosting.api.ApiProxy$FeatureNotEnabledException which appears to be thrown in app's logs but it does not catch it (or any exception), but simply shows a error page.
Thanks,
Steven
Fixed by adding a filter which just tries to access the blobstore service in any way and catch exceptions.
sorry, i don't believe there's currently any way to programmatically determine if the current app has enabled billing or not. the capabilities api is intended to handle when services are down for maintenance system-wide, not available per app.
the one thing you could try is programmatically authenticating to the admin console, using either ClientLogin or OAuth, and fetching its billing page.

Categories