USB/RS232 communcation security exception android.permission.sec.MDM_APP_MGMT - android

I have created an Android app that runs on a Samsung Galaxy Tab Pro (SM-T900). The main feature of this app is RS232/USB communication using the USB host mode and the USB-to-Serial library.
This app has been working perfectly without the need for any code updates for over a year. However, since the latest Samsung/Android update to Android 5.1, I get a security error and I am no longer able to communicate with USB/RS232 devices. Apart from that, my app runs fine without any crashing. I am simply no longer able to perform USB/RS232 communication.
Here's the logcat:
03-24 17:03:09.015 2798-3149/? D/UsbSettingsManager: requestPermission:/dev/bus/usb/002/008 ,packageName com.example.pumpconnector ,pi PendingIntent{338f59ea: PendingIntentRecord{1fd58866 com.example.pumpconnector broadcastIntent}}
03-24 17:03:09.020 2798-3149/? D/ApplicationPolicy: isUsbDevicePermittedForPackage vendorId: 1027, productId: 24577, package: com.example.pumpconnector
03-24 17:03:09.020 13313-13332/com.example.pumpconnector V/MainActivity: java.lang.SecurityException: Admin does not have android.permission.sec.MDM_APP_MGMT
The app has been configured to start whenever a USB device is attached to the device, which still works on the Samsung tablet. The app works perfectly fine on other (non-Samsung) devices. It's fully functioning on a LG Nexus 5 with Android 6.0.1. installed and also on a Moto G with Android 5.1. A little Google search on the exception quickly points to Samsung specific update/bug that prevent USB communication (check this thread).
I tried to put the following line in the Manifest (without result):
<uses-permission android:name="android.permission.sec.MDM_APP_MGMT"/>
Is there any way to get my app to get the android.permission.sec.MDM_APP_MGMT without having to wait for Samsung to fix it? All help is appreciated.

Check Knox version on device (maybe have been upgraded between) and follow migration guide in knox web site.
Also be sure you'r validating KLM license using KnoxEnterpriseLicenseManager and using EnterpriseLicenseManager For Basic License. Ofc you should check for license in receiver with convenient manager.

Related

Nearby Connections API: Android 12 fails to advertise and discover devices with unknown status codes (8037, 8038, 8039)

I'm developing an app that uses Nearby Connections API with basic P2P strategy. Suddenly, weirdly enough I'm not able to advertise and discover devices on my Pixel 3a with newest Android 12 and Play Services. OnFailureListeners throw these exceptions:
for discovering: 8037: unknown status code: 8037
for advertising: 8038: unknown status code: 8038
Indeed they cannot be found in docs and source code.
I also checked Google's "Rock Papers Scissors" official sample and it throws the same error codes.
Of course I reinstalled the app and restarted & updated my phone. EDIT: I also did the factory reset and it didn't help. But after I downgraded to latest Android 11 using Android Flash Tool, it started working again. Moreover, everything still works fine on Android 11, 10 and 9 using different phones.
Any ideas what causes this issue? It just worked fine for last two weeks and stopped working today. I believe it needs some deep investigation in source code (Xlythe if I may ask for your help, that would be really great).
After a while I finally managed to find a solution. It looks like Nearby Connections (all Nearbys?) have a critical bug on Android 12 that happens non-deterministically (API can work fine for few weeks then suddenly will throw these errors for another few weeks).
This bug is related to Android 12's feature change related to Bluetooth. Quoting:
Android 12 introduces the BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE, and BLUETOOTH_CONNECT permissions. These permissions make it easier for apps that target Android 12 to interact with Bluetooth devices, especially for apps that don't require access to device location.
In other words, some Bluetooth permissions are now legacy and there are some new permissions that are mandatory to make the API work. And you need to handle both scenarios in your code (before and after Android 12).
So here's a quick "mapper" from error codes to Manifest's permissions:
Error code 8037 while discovering - you haven't granted permission
for BLUETOOTH_SCAN
Error code 8038 while advertising - you haven't granted permission for BLUETOOTH_ADVERTISE
Error code 8039 (that's a new one as well) while onEndpointFound - you haven't granted permission for BLUETOOTH_CONNECT
More information how to implement new permissions properly can be found in documentation.
And I'm still waiting for Google to fix it in next Nearby API update as this is a little bit of workaround. Adding proper error messages to codes might be a little work to do but I would also revise if other permissions are still required after Android 12's update.

Build.GetSerial() returns unknown on API 29

I cant get serial on android 10 device.
I know about everything(permission, runtime permissions, I get serial only after the permission is granted) from here
android Build.GetSerial() throwing exception
My code works on all android versions, except 10
Do you have any ideas?
If you follow the official documentation here: https://developer.android.com/reference/android/os/Build.html#getSerial(), more info on Android 10 changes here
You will notice that starting from Android 10 this method is returning Build.UNKNOWN. You can't use it to uniquely identify a single device anymore
You need to switch to the "less" persistent version called Settings.Secure.ANDROID_ID
The only ways to bypass this restriction are:
Create a system app to be able to get the READ_PRIVILEGED_PHONE_STATE system permission (a normal app can't get this).
Be registered as a carrier (which requires you to have built the Android ROM)
Have a custom "work profile" to set your own policies in the device.
As you can imagine, all those options are not meant to be used by standard android app developers

hidraw set-report/send-report doesn't work with Android 6.x

I have a bluetooth hid device that I need to communicate with. Target platform is Android 5.x+. Currently testing on Nexus 7 2013 tablet.
My code works fine on android 5.x, I am able to receive, send and set reports on Android 5.x.
On Android 6.x, I am only able to receive reports sent by device, but I am not able to send or set reports. It looks like my set/send report requests are silently ignored by HID/BT stack.
The code that talks to /dev/hidraw* nodes runs as a native daemon as root.
Are there any new requirements to be able to set/send reports to Bluetooth hid devices on Android 6.x? Is there any changes I could make to AOSP to allow this to work?
[Update]
Logcat says:
05-17 11:22:56.085 2455-4061/com.android.bluetooth E/bt_btif: uhid_event: Invalid size read from uhid-dev: 4108 != 4
I do not understand how reading from uhid will return only 4 bytes! First 4 bytes are supposed to contain only the type of event. Is there any scenario that will result in a read() of less than sizeof(struct uhid_event) bytes?
Could this indicate a bug in uhid driver?
I checked available kernel sources and found that hidraw driver does not contain usable source to feed reports to /dev/hidraw* nodes
I also found that Bluedroid correctly receives and sends reports internally.
Simplest method to get/set/send reports I found was to modify bluedroid to communicate directly with my App for vendor-specific reports. I integrated my daemon into Bluedroid directly.

USB-Webcam on Android 4.4+

I am into a new project which requires me to use a USBconnected "Webcam".
The whole fun should run on Android 4.4.
my little story was:
I try multiple apps which do this - all work on both my testing devices
adapting some NDK lib that directly uses /dev/video0. This didnt work due to read-permission that was not granted in a new File("dev/video0").canRead() check. Although my unix permissions are correct, this seems to not work due to some new check on Android 4.4. (the whole thing was suggested here: Connect Android phone to a USB Web camera )
next: discover the UsbAccessory API that supposedly easens a lot of the above.
´find no documentation or anything about how to correctly handle a webcam
I still try, but don't come further than finding no device via
usbManager.getAccessory();
I've also tried to discover devices by filtering for a USB_ATTACHED broadcast but nothing triggers.
So I am starting to ask myself how the hell do others find the devices & communicate with them to get the pictures?
Anyone has sources from which i could learn, or a tutorial or something?
Little update from my side:
- I've gotten access by using the Android USB Host API e.g. UsbDevice instead of UsbAccessory.
- I have the connection and everything setup fine, and can now send binary data to my webcam and supposedly receive.
I can now send controlCommands via connection.controlTransfer(...) or use a "UsbRequest" in order to receive data.
However, I couldn't find any documentation to "make the camera submit pictures" to me. My Endpoint is of type XFER_INT (=interrupts).
I am continuing to try sending out various commands (e.g. binary values) but haven't had any success so far.

location manager issue for ice cream sandwhich

can anybody explain me what is this error ? I am getting only for android 4 + and not for below:
E/AndroidRuntime(891): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getaddress/com.example.getaddress.MainActivity}: java.lang.IllegalArgumentException: requested provider network doesn't exisit
It appears that the NETWORK_PROVIDER location provider is not accessible in Android 4+ emulators without Google APIs (well actually I have not tested on all of them ,see below). The real devices I have tested on are OK with it (but they all have Google services on them, it would be interesting to test with custom, clean Android versions, maybe with Kindles?).
It is not a question on enabling/disabling the provider in the device settings, it is simply not there in the emulator.
Symptom
Basically this code:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,mLocListener);
will cause the following exception:
java.lang.IllegalArgumentException: provider doesn't exisit: null
on all Android 4+ naked emulators (as opposed to Google-bound emulators)
note: the typo in "exisit" is in the actual log line.
Diagnostic
Getting a list of all location providers on the target device with the following:
List<String> providers = locationManager.getAllProviders();
I can see that the network provider is present on
physical devices
android 2.3.3 emulator (no Google APIs)
android level 17 (4.2) emulator (with Google APIs)
But not on
android level 15 (4.0.3) emulator with Google APIs
android 4.2 emulator (no Google APIs)
My guess is that for non-technical reasons, Google has not allowed the network location service in AOSP and limited its usage to the Google-bound versions of the OS from 4.2 (?).
What I don't know if whether or not there is a replacement network location service on non-Google devices (such as Kindle).
Probable impact on your app
I would not expect this to have any impact on most smartphones and tablets. However it can
somewhat impair your ability to test
be a compatibility issue for users that use custom/non-Google versions of Android (once again, Kindle?)
How to detect
A simple test such as:
locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)
can tell you painlessly if the network provider is present on the device. Note that if it is present, but the user has not activated it, your LocationListener will receive an onProviderDisabled callback following the location request.

Categories

Resources