My App has a background service which keeps running as foreground service. This service controls the device WiFi/Bluetooth programmatically on certain conditions. Everything works fine BUT on few devices (specifically the devices with custom ROMs) this is failing with the permission error. For example on OppoF9, I am getting below messages in the logcat:
D OppoPermissionInterceptPolicy: not foreground app, reject it! <My App Package>
W ServiceManager: Permission failure: android.permission.CHANGE_WIFI_STATE from uid=10424 pid=8894
E CheckPermission: Permission Denial: can't change wifi state pid=8894, uid=10424
I am not sure weather this issue is related with "adding the app under white listed categories" in few devices(again for devices with custom ROMs).
So,
Is this device specific issue (Which I predict as "YES")?
Is there any possible solution (Programatically possible solution OR manual settings before trying my service on these phone)?
Any suggestions how to fix it? TIA.
Related
I have an app which records videos, it has about 80K current installations (more than 100K downloads), Crashlytics statistics seems to be good - Crash-free users 99.66% and rating on Google Play is also OK - 4.5
But still for some of my users can happen the next errors (it may happened for such user once or a couple of times by now, so not often, but still happens from time to time):
android.hardware.camera2.CameraAccessException: CAMERA_DISABLED (1): connectHelper:1578: Camera "0" disabled by policy
android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): Camera service is currently unavailable
java.lang.IllegalArgumentException: supportsCameraApi:2096: Unknown camera ID 0
android.hardware.camera2.CameraAccessException: CAMERA_DISABLED (1): validateClientPermissionsLocked:1066: Caller "com.MY_APP_PACKAGE" (PID 10237, UID 21433) cannot open camera "1" when sensor privacy is enabled
on opening camera using camera2 API:
...
cameraManager.openCamera(cameraId, stateCallback, mainHandler)`
} catch (e: Exception) {
e.printStackTrace()
openReportErrorDialog(e) // so a user could report this issue
...
Reported devices:
Vivo 1906
Wheatek BV5500Plus
Samsung SM-N975F
Samsung SM-G988W
Samsung SM-A520F
Motorola REVVLRY
HUAWEI VOG-L09
HUAWEI STK-LX1
HUAWEI MRD-LX1
HUAWEI FIG-LX1
Coolpad CP3669AS
Infinix X655C
Android versions: from 8 to 11 (app min SDK is 6)
So basically it can work fine for a specific user for some time, no issues when opening camera, but from time to time this exception can occur for such user
I don't have any idea why it happens. I can't reproduce this issue on my own devices (two Samsung, one Lenovo, one Huawei and one Xiaomi devices), only users can report such issue from time to time...
The most nonsense exception here is Unknown camera ID 0, because before opening camera I get list of available cameras, so it's not hardcoded, it's not possible that such camera id doesn't exist, and a user said that before this error that camera was working ok
UPDATE
Found this
https://developer.android.com/guide/components/foreground-services#bg-access-restrictions
So it seems if a foreground service was started by system (on BOOT_COMPLETED broadcast, declared in manifest) and not by app (if a user launch app) then it can't access camera and microphone.
So basically after rebooting a device we can't automatically start camera anymore without user interaction.
Really bad for dashboard camera applications for car drivers...
They added ACCESS_BACKGROUND_LOCATION, but there is no ACCESS_BACKGROUND_CAMERA and ACCESS_BACKGROUND_RECORD_AUDIO...
android.hardware.camera2.CameraAccessException: CAMERA_DISABLED (1): connectHelper:1578: Camera "0" disabled by policy
That either means the device has an enterprise policy installed that disables cameras for example (employers that don't want employees photographing stuff at work), or your app is trying to open the camera in the background, on more recent Android releases.
If it's the policy, there's nothing you can do besides to tell the user that there's a policy in place and to complain to their admins.
android.hardware.camera2.CameraAccessException: CAMERA_DISCONNECTED (2): Camera service is currently unavailable
java.lang.IllegalArgumentException: supportsCameraApi:2096: Unknown camera ID 0
These usually mean something has crashed in the camera stack - until things restart (takes a few seconds usually), all cameras will be reported as unknown.
Ideally that'll never happen, but bugs unfortunately exist even on the best devices. A retry a few seconds later will probably work, unless the camera hardware on the phone is failing in some way that leads to a persistent crash.
android.hardware.camera2.CameraAccessException: CAMERA_DISABLED (1): validateClientPermissionsLocked:1066: Caller "com.MY_APP_PACKAGE" (PID 10237, UID 21433) cannot open camera "1" when sensor privacy is enabled
This means the OEM has some kind of 'shut off all cameras' feature like airplane mode is for radios. Like the enterprise policy above, this is something out of your control - the user needs to re-enable camera access, so all you can do is put up a dialog saying "cameras are disabled, sorry".
If your app targets Android 10 (API level 29) or higher and accesses location information in a foreground service, declare the location foreground service type as an attribute of your component.
<manifest>
...
<service ... android:foregroundServiceType="location|camera" />
At runtime, if the foreground service only needs access to a subset of the types declared in the manifest, you can limit the service's access using the logic in the following code snippet:
Notification notification = ...;
Service.startForeground(notification, FOREGROUND_SERVICE_TYPE_LOCATION| FOREGROUND_SERVICE_TYPE_CAMERA);
This is how you will be able to use camera in the background.
Sorry, that questions sound stupid but drives me crazy.
I'm about implementing an app very similar to the Bluetooth App described in Developer Android.
I don't get required permissions, though.
Yes, I ask for permission twice
a) in my manifest
b) and I check before using BT with
ActivityCompat.requestPermissions(..)
In logcat, see belove, I learn that my app doesn't get Bluetooth permission.
It isn't the first time I write a BT app. LAst time it was fine. But was a while ago.
My mobile (Nexus 5) told me something about Development Mode Active and apps would be routed to Developer Manager to be started as instant app.
I also learned that Bluetooth access is not granted to instant apps at all.
(I understand that.).
Could that be the problem? Does Android Studio produce different apps now. Does it interact in a different manager with the test hardware?
If so, how do I pursuade Android Studio to not produce an instant app?
Thank you so much in advance.
my manifest code
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Log output:
android.permission.BLUETOOTH: denied
and some lines earlier
I/ActivityManager: START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.android.packageinstaller cmp=com.google.android.instantapps.supervisor/.permissions.GrantPermissionsTrampoline (has extras)} from uid 10029 on display 0
W/Isotope: UID: [10029] PID: [14812] GrantPermissionsTrampoline : Permission not allowed: android.permission.BLUETOOTH
Sorry for bothering you... It was so easy. I have just deactivated that instant apps dev manager on my Android phone.
Voila, my app is an app again and no instant app. It gets all
permissions it need. Anything is fine.
I'm sorry again.
I am working on an android app and from last 2 weeks i am facing a issue in MI Phones that they don't receive Push Notification when application is in Background State or Inactive State. This is working great in other devices like samsung, micromax etc.
At last i solve it by Moving My application in Auto Start Mode through Device Permission Section
Security -> Permission Section -> Auto Start -> MY_APP -> Mark Toggle to On.
When i follow above steps i found that Facebook and whatsapp are already in AutoStart List, means it is possible to move an android application in AutoStart by code.
So can anybody please help me with some piece of code or Tutorials which i can follow to solve this issue.
You can use cordova-plugin-autostart by enabling autostart after boot
cordova.plugins.autoStart.enable();
If enabled is not called, then by default it will be disabled
cordova.plugins.autoStart.disable();
In the config.xml the following needs to be added
<gap:plugin platform="android" name="cordova-plugin-autostart" version="2.0.1" source="npm"/>
NOTE: Installation to the SD card will prevent the automatic start of your app after the boot
I have same issue with mi 3 but bro its not possible from lollipop and marshmallow cause of security reason. But if your phone is rooted then you can change it to allow.
I have seen some Android apps on my phone require this android.permission.READ_PHONE_STATE permission. I don't know if I could trust them. I know this permission will give the app access to many information. I'm particularly interested in what functionality in an Android app normally require the information like DeviceId , SimSerialNumber, SubscriberId?
Phone state provides access to a lot of information about the phone. Usual usages will be for reading the IMEI of your phone and your phone number. This can be useful to identify you in their systems.
It can also be needed if the application is made compatible for Android 1.5 or lower, because this permission didn't exist back then and is added automatically by the play store to those apps
See also: https://android.stackexchange.com/questions/605/why-do-so-many-applications-require-permission-to-read-the-phone-state-and-ident
Another possible reason is so they can mute audio events if you're in the middle of a call. This is why apps like Pandora, Spotify, etc need the permission - so they can mute themselves when you get a call.
Not long ago I discovered that for some devices you should add android.permission.READ_PHONE_STATE if your application sends SMS. Probably in some cases SmsManager tries to retrieve some information about phone state before sending sms.
For example getting exception for HUAWEI GRA-L09:
java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10174 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1543)
at android.os.Parcel.readException(Parcel.java:1496)
at com.android.internal.telephony.ISms$Stub$Proxy.s! endMultipartTextForSubscriber(ISms.java:1224)
at android.telephony.SmsManager.sendMultipartTextMessage(SmsManager.java:404)
We are trying to build a custom build of Android ICS (4.0.4 version) for our own hardware board. On this environment, we are currently observing that when we start the GPRS through PPP in the COMMAND LINE, it is connected successfully and we are able to browse the internet also successfully.
But however, when we try to enable the same in "Mobile Networks" menu option of the "Settings" menu in our Android build (through our touch screen), we find that the GPRS connectivity is not starting.
On debugging, we find that the logcat output when we go in for this screen in our custom Android build for the same is as follows (some parts of relevant section):
i am able to get my log messages till AsyncChannel send(msg) in AsyncChannel.java class but after sendmessage not getting into the callback mechanism and onSetUserDataEnabled(enabled)
Is it a permission related issue?
the logcat snippet when i turn on mobile data is:
D/ConnectivityService( 2467): setMobileDataEnabled(true)
D/ConnectivityService( 2467): Data enabled: user=false, policy=true
W/BackupManagerService( 2467): dataChanged but no participant pkg='com.android.providers.settings' uid=1001
complete locat o/p is here
We would highly be obliged if anyone had faced the same issue before and if so how we can get this resolved. Thanks in advance for your help.
thanks