Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid UUID of storage gained from Android StorageManager?

I lost whole day fighting with something trivial, but now I just give up and need your help.

In new Oreo API for reading app code/data/cache/ size we need storage UUID (StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid)).

The storage UUID is possible to fetch from StorageManager.getStorageVolumes() which returns list of all storages which contains also the UUIDs.

And there the problem begins: The UUID from returned list is in String format while StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid) requires UUID object - nothing simplier - there exist method UUID.fromString(String name) which converts it in a while.. but wait, the UUID value from StorageManager list is incompatibile with UUID parser - WHAT?! I've checked on 2 devices (one with Oreo and one with Nougat), both with external memory and for each device I get 2 storages:

  1. Internal device memory with UUID equals "null" - thats fine as this is described in documentation
  2. External card storage with UUID value in format like "4012-1A4B" what is invalid UUID format and causes UUID.fromString throws IllegalArgumentException.

Can anyone explain me what am I doing wrong and how should I get UUID for external storage? Or just new API StorageStatsManager.queryStatsForUid(UUID storageUuid, int uid) is useless as we are unable to get storage UUID?


FYI:

Whats more there is another StackOverflow question where usage of this API is marked as correct solution: https://stackoverflow.com/a/44708209/1946366 what makes me even more frustrated...

like image 725
peemes Avatar asked Feb 02 '18 18:02

peemes


People also ask

What is storage manager com Android StorageManager Android?

StorageManager is the interface to the systems storage service. The storage manager handles storage-related items such as Opaque Binary Blobs (OBBs). OBBs contain a filesystem that maybe be encrypted on disk and mounted on-demand from an application.


2 Answers

Actually the fromString(uuid_string) takes a "long" UUID (with like 4 or 8 parts can't remember exactly).

However the following works perfectly:

UUID.nameUUIDFromBytes(sv.getUuid().getBytes());
like image 80
3c71 Avatar answered Nov 05 '22 11:11

3c71


I found that this is raised already bug on Android: https://issuetracker.google.com/issues/62982912 so I think that my questions is unanswerable.

like image 35
peemes Avatar answered Nov 05 '22 12:11

peemes