peemes
peemes

Reputation: 195

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...

Upvotes: 11

Views: 3116

Answers (3)

3c71
3c71

Reputation: 4511

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());

Upvotes: 7

Jyoti JK
Jyoti JK

Reputation: 2171

I think the application Info of each package has Storage Volume UUID on which this application is being hosted.

You can get it by ,

ApplicationInfo ai = context.getPackageManager().getApplicationInfo(packagename, 0);
StorageStats storageStats = storageStatsManager.queryStatsForUid(ai.storageUuid, uid);

This is introduced in Oreo Version

Upvotes: 2

peemes
peemes

Reputation: 195

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

Upvotes: 2

Related Questions