New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapped primary/secondary public storage breaks storage access framework mapping #493

Closed
d4rken opened this Issue Sep 13, 2016 · 1 comment

Comments

1 participant
@d4rken
Owner

d4rken commented Sep 13, 2016

Another uri mapping issue, similar to #312. Also see #492

Detect storages and mounts

Storage(location=SDCARD, path=/storage/sdcard0, userHandle=0, flags=[PRIMARY], safUri=null, mount=Mountpoint(path=/storage/sdcard0, blockDevice=/dev/fuse, fileSystemType=FUSE, options=[nodev, group_id=1023, relatime, rw, nosuid, default_permissions, allow_other, user_id=1023, noexec]))
Storage(location=SDCARD, path=/storage/emulated/0, userHandle=-1, flags=[EMULATED, SECONDARY], safUri=null, mount=Mountpoint(path=/storage/emulated/0, blockDevice=/dev/fuse, fileSystemType=FUSE, options=[nodev, group_id=1023, relatime, rw, nosuid, default_permissions, allow_other, user_id=1023, noexec]))
Storage(location=SDCARD, path=/storage/emulated/legacy, userHandle=-1, flags=[SECONDARY], safUri=null, mount=Mountpoint(path=/storage/emulated/legacy, blockDevice=/dev/fuse, fileSystemType=FUSE, options=[nodev, group_id=1023, relatime, rw, nosuid, default_permissions, allow_other, user_id=1023, noexec]))

Uri mapper in action, we are trying to get a match for /storage/emulated/0 (the internal emulated storage) which is now the secondary public storage due to being swapped.
Try 1, user selects actual removable (external) sdcard in the documents activity.

Updating mappings.
Trying to map: UriPermission {uri=content://com.android.externalstorage.documents/tree/CACB-623E%3A, modeFlags=3, persistedTime=1473659947518}
StorageVolumeX: StorageVolumeX(uuid=null, state=mounted, path=/storage/emulated/0, primary=false, emulated=true, owner=UserHandle{0}, userlabel=null)
MediaTek device (issue #312), faking UUID "primary" for /storage/emulated/0
StorageVolumeX: StorageVolumeX(uuid=CACB-623E, state=mounted, path=/storage/sdcard0, primary=true, emulated=false, owner=null, userlabel=null)
Mapped VolumeRoot(treeUri=/tree/CACB-623E:, rootId=CACB-623E, title=SD card, documentId=CACB-623E:, storagePath=/storage/sdcard0) to UriPermission {uri=content://com.android.externalstorage.documents/tree/CACB-623E%3A, modeFlags=3, persistedTime=1473659947518}
Invalid uri permission for Storage(location=SDCARD, path=/storage/emulated/0, userHandle=-1, flags=[EMULATED, SECONDARY], safUri=null, mount=Mountpoint(path=/storage/emulated/0, blockDevice=/dev/fuse, fileSystemType=FUSE, options=[nodev, group_id=1023, relatime, rw, nosuid, default_permissions, allow_other, user_id=1023, noexec])), releasing: content://com.android.externalstorage.documents/tree/CACB-623E%3A

This fails as expected. Note that we can see that SD Maid already detected the swapped public storages and notices something is up, but assuming this is the MediaTek issue from #312.

Try 2, user selects the internal emulated storage in the documents activity.

Updating mappings.
Trying to map: UriPermission {uri=content://com.android.externalstorage.documents/tree/emulated%3A, modeFlags=3, persistedTime=1473660004340}
StorageVolumeX: StorageVolumeX(uuid=null, state=mounted, path=/storage/emulated/0, primary=false, emulated=true, owner=UserHandle{0}, userlabel=null)
MediaTek device (issue #312), faking UUID "primary" for /storage/emulated/0
StorageVolumeX: StorageVolumeX(uuid=CACB-623E, state=mounted, path=/storage/sdcard0, primary=true, emulated=false, owner=null, userlabel=null)
Failed to build VolumeRoot via StorageVolume.
eu.thedarken.sdm.tools.storage.x.StorageAccessFrameworkException: No matching StorageVolume for: UriPermission {uri=content://com.android.externalstorage.documents/tree/emulated%3A, modeFlags=3, persistedTime=1473660004340}
    at eu.thedarken.sdm.tools.storage.x.c.a(StorageVolumeMapper.java:206)
    at eu.thedarken.sdm.tools.storage.x.c.a(StorageVolumeMapper.java:114)
    at eu.thedarken.sdm.setup.SAFSetupFragment.a(SAFSetupFragment.java:234)
    at android.support.v4.app.j.onActivityResult(FragmentActivity.java:165)
    at android.app.Activity.dispatchActivityResult(Activity.java:6232)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3642)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3689)
    at android.app.ActivityThread.access$1300(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)

eu.thedarken.sdm.tools.MissingVolumeRootException: No VolumeRoot for: /tree/emulated:
    at eu.thedarken.sdm.tools.storage.x.c.a(StorageVolumeMapper.java:140)
    at eu.thedarken.sdm.setup.SAFSetupFragment.a(SAFSetupFragment.java:234)
    at android.support.v4.app.j.onActivityResult(FragmentActivity.java:165)
    at android.app.Activity.dispatchActivityResult(Activity.java:6232)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:3642)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3689)
    at android.app.ActivityThread.access$1300(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)

Invalid uri permission for Storage(location=SDCARD, path=/storage/emulated/legacy, userHandle=-1, flags=[SECONDARY], safUri=null, mount=Mountpoint(path=/storage/emulated/legacy, blockDevice=/dev/fuse, fileSystemType=FUSE, options=[nodev, group_id=1023, relatime, rw, nosuid, default_permissions, allow_other, user_id=1023, noexec])), releasing: content://com.android.externalstorage.documents/tree/emulated%3A

Uh oh and violently fails. We want to get a match here. So why don't we?
The uri root for the internal emulated storage is /tree/emulated:, but we expect /tree/primary:.
Weird, because everytime I've encountered this so far primary is the identifier for internal emulated storage. This includes swapped storage cases like #312 where the internal emulated storage also had primary as identifier despite being swapped to act as "secondary" public storage.

Solutions? Try to detect this exact situation and expect either primary or emulated as identifier for emulated storage.

F: VERSIONNAME:4.3.2; VERSIONCODE:40303
P: VERSIONNAME:4.0.7; VERSIONCODE:40007
ro.build.id=LMY47D
ro.build.display.id=PSP3457DUO.20160303.1.0.19
ro.build.version.incremental=eng.ccadmin.20160303.165914
ro.build.ap.version=TBW961822_9871_V020136
ro.build.version.sdk=22
ro.build.version.codename=REL
ro.build.version.all_codenames=REL
ro.build.version.release=5.1
ro.build.date=Thu Mar 3 17:00:27 CST 2016
ro.build.date.utc=1456995627
ro.build.type=user
ro.build.user=ccadmin
ro.build.host=BUILD19
ro.build.tags=release-keys
ro.build.flavor=sp7731geaplus_dt_oversea-user
ro.product.model=PSP3457DUO
ro.product.brand=Prestigio
ro.product.name=PSP3457DUO
ro.product.device=KT45B01G
ro.product.board=sp7731gea
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.cpu.abilist=armeabi-v7a,armeabi
ro.product.cpu.abilist32=armeabi-v7a,armeabi
ro.product.cpu.abilist64=
ro.product.manufacturer=Prestigio
ro.product.locale.language=en
ro.product.locale.region=GB
ro.build.product=PSP3457DUO
ro.build.description=PSP3457DUO-user 5.1 LMY47D 03031659 release-keys
ro.build.fingerprint=Prestigio/PSP3457DUO/KT45B01G:5.1/LMY47D/10221943:user/release-keys
ro.build.characteristics=default
ro.product.hardware=SP7731GEA_V1.0.0
ro.product.partitionpath=/dev/block/platform/sdio_emmc/by-name/
ro.product.version=1.0.19

@d4rken d4rken added this to the Next Tasks milestone Sep 13, 2016

@d4rken

This comment has been minimized.

Owner

d4rken commented Sep 13, 2016

screenshot_2016-09-12-07-08-31
screenshot_2016-09-12-20-13-04

@d4rken d4rken modified the milestones: Next Tasks, v4.3.3 Sep 14, 2016

@d4rken d4rken closed this Sep 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment