issue with CONNECTIVITY_CHANGE - android

Is it necessary to use "ACCESS_NETWORK_STATE" permission to work "CONNECTIVITY_CHANGE" reciver?
When I test it with "INTERNET" permission and not "ACCESS_NETWORK_STATE" works like a charm.
Any idea or comment will be appreciated.

android.permission.INTERNET
Allows applications to open network sockets
&&
android.permission.ACCESS_NETWORK_STATE
Allows applications to access information about networks
It do requires the caller to hold the permission ACCESS_NETWORK_STATE

Related

Permission regarding Android EMM

I am making an EMM application. This application will only be installed in firm's devices only. Is there any way to grant below permissions programmatically through DevicePolicyManager.
android.permission.SYSTEM_ALERT_WINDOW (Display over other apps)
android.permission.BIND_ACCESSIBILITY_SERVICE (Accessibility service)
android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS (Ignore battery optimization)
I want to grant above permissions through DevicePolicyManager as my app is a system owner app. But, I can't grant them through devicePolicyManager.setPermissionGrantState. As I have also tried devicePolicyManager.setPermittedAccessibilityServices for granting ACCESSIBILY_SERVICE programmatically, but it also didn't work. So, is there is any way I can grant above all permissions programmatically without navigating to that screen and turn in on manually. Or Is there is a way so that user cannot be able to disable the above features anyway. Like when I enable location and other permissions through DevicePolicyManager user is unable to turn it off.
So reviewing: https://developers.google.com/android/work/requirements#4.2.-runtime-permission-grant-state-management_1
and https://developers.google.com/android/management/reference/rest/v1/enterprises.policies#permissionpolicy
seem to indicate at you can create a policy which will automatically grant permissions.
I do see:
PERMISSION_POLICY_AUTO_GRANT
Permission policy to always grant new permission requests for runtime permissions. Already granted or denied permissions are not affected by this.
and
PERMISSION_GRANT_STATE_GRANTED
Runtime permission state: The permission is granted to the app and the user cannot manage the permission through the UI.
which sounds like what you want.

I am confused by android permission

I want to get the location from Android, so I set a permission. But I got confused when I found another article saying:
android.permission.INTERNET is needed.
Why is it so? Does ACCESS_FINE_LOCATION include INTERNET?
INTERNET permission allows you to connect to the internet. Without it, all attempts will fail or throw an exception. FINE_LOCATION allows you to use GPS. It does not include INTERNET.

ConnectivityManager.requestNetwork in Android 6.0

I'm trying to get the new ConnectivityManager.bindProcessToNetwork(Network) using ConnectivityManager.requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)
The reason is to force the app to call the future request in some specific network, which doesn't have a internet connectivity (it's a local hardware communication network). At this point, the system is sending the requests over 3G/4G network and never reach the desired Wifi network, because this network doesn't respond the connectivity check that android call.
When I call the requestNetwork method, I receive the following error:
java.lang.SecurityException: com.xyz.app was not granted either of these permissions: android.permission.CHANGE_NETWORK_STATE, android.permission.WRITE_SETTINGS.
I try to call the new method to request permission available in Android 6.0:
requestPermissions(new String[]{Manifest.permission.CHANGE_NETWORK_STATE, Manifest.permission.WRITE_SETTINGS}, PERMISSIONS_REQUEST_WIFI);
But the callback is always PackageManager.PERMISSION_DENIED.
I put both of these permissions in the AndroidManifest.xml, without success.
Notice: The Manifest.permission.WRITE_SETTINGS is not in the Permissions Groups.
I'm not sure if this was intended by Google, but the following is the behavior I'm seeing:
CHANGE_NETWORK_STATE seems to always be denied (as noted in the comments, its a signature permission) but it also doesn't seem to matter. My ConnectivityManager network requests all seem to be gated by WRITE_SETTINGS only - so if you have WRITE_SETTINGS you don't need CHANGE_NETWORK_STATE.
As noted in comments, you do this differently than other permissions, using:
Intent goToSettings = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
goToSettings.setData(Uri.parse("package:" + Context.getPackageName()));
startActivity(goToSettings);
And after that, my ConnectivityManager network requests were peachy.
To check if the permission is already granted before calling the ACTION_MANAGE_WRITE_SETTINGS activity, this answer has the solution using
Settings.System.canWrite(Context)
Can't get WRITE_SETTINGS permission
UPDATE: as of Android 6.0.1, CHANGE_NETWORK_STATE is auto granted when requested in your manifest file. The above WRITE_SETTINGS checks are only required for 6.0
This was an Android 6.0 bug. It's fixed in Android 6.0.1, requestNetwork() can be called if you request CHANGE_NETWORK_STATE in the manifest. No need to call requestPermissions(), it's a normal permission.

Do I need android.permission.WRITE_SETTINGS to enable/disable Wifi?

I have a (FOSS) app out there which can, among other features, enable and disable Wifi.
AndroidManifest.xml contains android.permission.CHANGE_WIFI_STATE, unit tests on the emulator pass and the feature works on a real device, a HTC Desire running 2.2.2.
The SDK versions are android:minSdkVersion="7" and android:targetSdkVersion="10", so I can't say about newer releases of Android.
I have received one single crash report:
java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider
uri content://settings/secure from pid=6191,
uid=10114 requires android.permission.WRITE_SETTINGS
Is android.permission.WRITE_SETTINGS possibly required on recent versions of Android? The reference says the permission exists since API 1, so I'd be surprised why it wasn't on older releases.
The user message is weird, it just says "lies", so I am unsure if I should just follow this report and add android.permission.WRITE_SETTINGS.
Any thoughts?
Cheers,
Torsten
That's weird, cause I needed to check exactly the same issue, so i just wrote a few lines of code doing exactly just that : enable/disable wifi and bluetooth.
My conclusion: you dont need the WRITE_SETTINGS permission to toggle the wifi, nor the bluetooth for that matter.
wifi = access_wifi_state + change_wifi_state
BT = bluetooth + bluetooth_admin
(with 4.2.2)
Check whether you were trying something else too, which may trigger the exception ?

where is the android.permission.INTERNET permission check point in Android?

Most of the permission checking will happened in checkPermission or checkUidPermission in current Android permission framework.
But the android.permission.INTERNET permission will not be checked in these two methods. So I wondering about the exactly checking function/method of this permission in Android.
I've checked the code.
The system permission like INTERNET or file operations will be controlled by gids with the user id. The uid without the net gid will not be able to create the socket and will return EACCES(permission denied) by linux kernel.

Categories

Resources