Android Oreo 8.0+ Disable Network Permissions Problems - android

I'm building a Cordova app that needs to access WiFi on Android and disable the currently connected network in order to prevent automatic disconnection from the network i'm having it connect to (since there is no internet).
The problem is that when testing on Android Oreo 8.0+ I am getting this error in adb logcat and I can't figure out what I need to do to fix this:
E/WifiConfigManager: UID 10315 does not have permission to update configuration "Test SSID"WPA_PSK
E/WifiStateMachine: Failed to disable network
These are the perms listed in manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
<uses-permission android:name="android.permission.INTERNET" />
The OVERRIDE_WIFI_CONFIG perm I found on this post, but that doesn't seem to help in my specific situation: Changing Android hotspot settings
I found this specific error located in this file:
https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#984
Which calls canModifyNetwork which I found here:
https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#651
Can anybody more experienced with Android help me to resolve this issue, and what needs to be done in order to allow my app to disable networks?
Does this mean that apps are not allowed to disable a network if it wasn't created by the app?? Please help I don't know where to go from here!
I did find this post as well, which references 6.0, but is this true that we're basically completely locked out of disabling networks we didn't create? Android 6.0 Cannot add WifiConfiguration if there is already another WifiConfiguration for that SSID

I am not able to answer your question per se, but I can answer this
Does this mean that apps are not allowed to disable a network if it
wasn't created by the app?
That's correct, as according the documentation of the method disableNetwork:
Disable a configured network. The specified network will not be a
candidate for associating. This may result in the asynchronous
delivery of state change events. Applications are not allowed to
disable networks created by other applications.
So if the user has already connected to this network using the Android system, in Oreo you won't be able to disable the network.
Though the method disableNetwork returns true or false in the case of success or failure

Related

Android 10 Bluetooth disconnecting background services

We're working on a project that includes connecting a sensor to an android device. The android device will send data to google cloud. We're facing a bit of a problem here, and we would appreciate help.
The problem statement is “The Bluetooth connection state is disconnected whenever the screen is switched off, while we need it to work in the background, and keep receiving data from a sensor and sending data to cloud”.
Implemented a background service that initializes the bluetooth connections
with all following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
It turned out that it also depends on the phone type itself. Some phone companies tries to extend the battery life of certain types of phones, so it was shutting down any background service that was not in use.
A work-around that can be done by creating a loop that sends a message every small period of time to maintain the connection.

Solved - Beacon Library - Unable to Obtain Bluetooth Permission on Xiaomi Phones + Only detects beacons when app is hidden in background

## How I solved it:
### For Permissions: Make sure to request Background location too:
```Java
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
For Verifying Permissions:
Copy the whole snippet from:
https://altbeacon.github.io/android-beacon-library/requesting_permission.html
to your on create method
BE PATIENT!!!!
Apparently, it takes about 1 minute for the first detection (both monitoring and ranging) to occur despite me setting the ranging time to 5 seconds (5000 ms). After that, the response time for out of range beacon should be less than half a second.
Please Advice if you can help with the long waiting time between starting the monitoring to receiving a list of beacons detected despite a change in beacon detection state already within 1 second of starting monitoring.
Original Question
Extra Detail:
The detection goes smoothly even if the 'Change Bluetooth Permission' mentioned above is set to 'notify' whenever I switch to another app despite the app not being a service. Why is that?
Original Question:
I am trying to scan for beacons around me using the android beacons library and it never works unless I manually go into settings -> manage apps and change the 'Change Bluetooth Connectivity (turn Bluetooth on or off)' permission from 'notify' -> to 'Accept'
However, I already requested bluetooth and bluetooth admin permissions
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
as well as other permissions like fine location/coarse location
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
The previous app that I created worked fine on my device but in that app, the beacon functions are built as a 'service' and I have heard that requesting Location permission when running beacon functions not as a service can spell disaster. However, removing the location permissions did not make a difference upon my experimentation. It is only manually changing the bluetooth permission in settings that made it work.
So the question is, how to I force the general bluetooth permission on a Xiaomi phone to ACCEPT through a prompt like requesting dangerous permissions for coarse location requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1234);
and is this the right way to solve the issue? Many thanks
Device:
Xiaomi Mi8 (MIUI11 Android 10 API29)```

Cordova Android app and user permissions

I have an Android Cordova app and I'm using GPS, check the network state, read/write on the Documents folder and taking camera pictures. Here my permissions on the manifest XML file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The manifest file is auto generated by the Cordova framework. For some reason I don't see camera permissions. Permissions are not asked at installation time anymore (that's since Android 6) but instead they should be asked before usage.
I correctly get the GPS access permission popup but not the read/write Documents folder permission. I also never get the camera permission albeit I'm able to use it without ever being asked for permission. Same story for the Network status permissions (never being asked).
I find Android permissions scheme extremely confusing, under application manager my app has got Location and Storage as expected, Camera and Network status are missing though.
To recap, inside the app, on the actual code, I'm using at least once those devices
GPS fine grained
GPS coarse (probably the Wifi SSID triangulation trick)
Write on Documents
Read on Documents
Read network status (Offline / Wifi / 3G etc..)
Take picture from the camera
Cordova framework wrote this manifest file:
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.hardware.location.gps (why is it not a .permission?)
android.permission.ACCESS_NETWORK_STATE
android.permission.WRITE_EXTERNAL_STORAGE
On application manager I get those options:
Location
Storage
So basically I get three different sets of permissions :-(
I found this in the this cordova plugin that you mentioned in comments.
So somehow this <uses-permission android:name="android.permission.CAMERA/> have to be in your code so as this plugin can use it.
Maybe you didn't check the right program to see its permissions, or if the camera permission is not shown in application permissions on device, you can't be able to use camera in this application. Please do a check again because I really want to know what is the situation.

Android Apps and Root Access [duplicate]

This question already has an answer here:
How to programmatically turn off WiFi on Android device? [duplicate]
(1 answer)
Closed 9 years ago.
From browsing StackOverflow I understand how an app gets root privileges (the "su" command) but does the app need root access to do the following commands?
Turn Bluetooth On/Off
Turn WiFi On/Off
Turn Mobile Data On/Off
The reason I ask is that for a unit of my studies, I am wanting to create a basic AI using either text input or the google api for speech recognition. I would like it to be able to control phone functions to make a true "assistant in your pocket". Code samples will be useful but a simple text explanation will be more than sufficient.
I apologize if this has been asked before but searching didn't find my question.
Many Thanks in Advance,
James
You don't need root for those operations, you just need to have the permissions for those actions in the application manifest.
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

Appcelerator Android app starts crashing when Internet is turned Off

I am working with Titanium Appcelerator 1.8.1 Android SDK. App is working perfect when Internet connectivity is on. But when I turn the connectivity is off, App crashes in the start. Nothing works as expected. I am supposed to develop offline feature, which enables app to be working as expected when it's offline and syncs data when it is online.
I had used following permission set:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Branch your logic like
if(Ti.Network.online){
//sync data
}else{
/fetch data from local persisitance
}
And FYI i guess Titanium takes care of adding these permissions to the manifest file by default.
That may be caused by the "Live view" option activated, it need the mobile to be in the same network as the PC where Appcelerator is running. If you are developing an offline app, you have to unselect that option, that way you can run your app without beeing in the same network as the PC.
Image of Live View option

Categories

Resources