Android Apps and Root Access [duplicate] - android

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" />

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.

Android permissions for pinging network

I'm working on android app which do some pings on LAN, using C# System.Net.NetworkInformation.Ping class. What kind of android manifest permission do I need? For now I have only android.permission.INTERNET, but it seems not enought.
Many thanks for any help.
add these two permissions :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Android Oreo 8.0+ Disable Network Permissions Problems

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

<uses feature> tan in android

<uses-permission android:name="android.permission.PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
I have basically declares this in the manifest. I want to know what exactly uses feature does.
From my understanding, if i declared permission access_coarse_location and all that, this means my app uses feature android.hardware.location ..and for that automatically thats set for true.
By specifying that feature to false, am telling android store..that a user can download this app even if he doesn't have location hardware..because this thing is handled inside code?
Is my understanding right? Because i find it funny there is feature android.hardware.wifi ..
what phone, mobile device doesn't have a wifi?
yup your understanding is correct.
From https://developer.android.com/guide/topics/manifest/uses-feature-element:
Google Play uses the elements declared in your app
manifest to filter your app from devices that do not meet it's
hardware and software feature requirements. By specifying the features
that your application requires, you enable Google Play to present your
application only to users whose devices meet the application's feature
requirements, rather than presenting it to all users
I want to know what exactly uses feature does
Quoting the documentation:
The purpose of a declaration is to inform any external entity of the set of hardware and software features on which your application depends. The element offers a required attribute that lets you specify whether your application requires and cannot function without the declared feature, or whether it prefers to have the feature but can function without it. Because feature support can vary across Android devices, the element serves an important role in letting an application describe the device-variable features that it uses.
Here, "external entity" usually means an app distribution channel, like the Play Store.
Is my understanding right?
Yes. One role of <uses-feature> is to indicate that some feature is not required, where a permission would imply that it is required.
Because i find it funny there is feature android.hardware.wifi .. what phone, mobile device doesn't have a wifi?
There is no requirement that Android devices support WiFi. For example, Android is used in vehicles, from cars to the Boeing 787 Dreamliner, and those environments may not offer WiFi.
You are correct in your understanding. The uses tag is mainly for filtering on the play store. Which means that users who may have a device that doesn't support a required feature that your app depends on, will not see your app in the listings.
As an aside. There are plenty of Android devices which don't feature a wireless chipset. I've been working with Android based Barcode scanners that don't have Wifi, nor GPS services. It's always best to handle things in code, depending on what the device is capable of.
Hope this helps.

Android device connection with localhost server [duplicate]

This question already has answers here:
How can I access my localhost from my Android device?
(44 answers)
Closed 9 years ago.
I am new at android. I am devloping an app that uses MySQL. The application runs well in the emulator. But now I need to run the app in a android device. What can I do.
As stated in the first comment, you should check your file AndroidManifest.xml.
In order to access the network, it should contain the following instructions :
<uses-permission android:name="android.permission.INTERNET" />
You may also add the following, which enable your application to know the actual state of the network connection.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Categories

Resources