[Miscellaneous Android Development] Dib Membrane:
Successfully recovered my R2 thanks to QFIL timing tip; now have root via Magisk 16.7

Thank you so much, [MENTION=3540215]FEGuy[/MENTION]!!! I've now successfully recovered my original R2!!

No problem, I figured you were probably busy with other things for awhile and didn't think you were intentionally ignoring my pleas. :D Since I couldn't be without a phone right now, in the meantime I joined the "had to order a second R2" club. ;) Thank goodness they're so ridiculously cheap; money is beyond tight for me right now, but I was able to scrape together $20.48. I was worried it might go up to the $99 list price after having bought the first one and activated service, but thankfully not.

BTW, for anyone else needing to order a second R2, I need to digress from my first R2 recovery for a minute so others can benefit from my experience on that. I first ordering my second R2 from Visible's website on my PC, but when trying to add the R2 to my cart, it said I couldn't because I already had a device assigned to my account. I searched and found someone else that had this happen, and they said they had to get a support rep to close their original phone out of their account before it would let them buy a new one. I chatted with support from the Visible app on a family member's R2 to ask for them to do this, but the rep kept ignoring my suggestion. Instead, she had me borrow yet another family member's R2 to try ordering from within the Visible app. I first tried while logged in by default as my family member, but got the same error about already having an active device. The rep suggested I log out and then back in to the app using my own account, which I couldn't imagine would make a difference, but amazingly, it worked.

There were still some snafus; the shipping notice appeared on my family member's phone, even though I'd logged back into the Visible app as them, and weirdly, I received an email saying they were a few days behind in shipping, and I wouldn't receive my replacement R2 next-day as promised. Thankfully, that email turned out to be in error. Couldn't check a tracking number from the notification on my family member's phone, as the message was abbreviated, and when you tap on Visible messages from the notifications, it just dismisses them and goes to the app but doesn't show you the full (nor even the truncated) message there. Visible really needs to add a Notifications tab to the app to allow reading them in full, and to go back to re-read past ones.

Thank you!! That was the missing piece of the puzzle. I feel stupid, because as I was searching around for solutions, I did find both of those points that are missing from most of the unbrick guides:

that you have to close the DFU tool before hitting Download in QFIL, and

that you only a have a few seconds after the bricked phone connects in EDL mode to start the flashing.

I did try both of those things, but I'm not positive I tried them at the same time, and if I did, I guess I didn't start the flash fast enough. I was pretty burned out from trying a million things at that point, so I don't think I tried that technique more than once. Also, I misunderstood where the time-critical window was. I thought it was after the phone connected to the PC in EDL mode, and so I tried running the DFU tool to switch the phone into EDL mode, then leisurely quit the tool, unplugged the USB cable, and then eventually plugged it back in and tried to immediately QFIL-flash (also tried with MiFlash). But now I see that the critical window apparently starts after the phone switches from DFU to EDL, and you don't restart the timer by replugging the USB. Strange that it was designed this way, and that it doesn't just continue to sit there in Sahara mode until something talks to it.

Another thing I screwed up on previously is that the COM port numbers are different when the R2 connects in DFU mode vs. EDL mode. If you use "Select Port" while the phone is connected in DFU mode, it'll be the wrong port for EDL mode and you'll be forced to reselect the correct port during that critical time window after the EDL switch. Therefore, it's better to do a preliminary run where you get the phone into EDL mode, then do Select Port in QFIL to get that ready to go. Then reboot the phone into DFU mode and leave Select Port alone. Then do the switch into EDL using the DFU tool, and QFIL will automatically reselect the appropriate EDL-mode port. One other minor note is that the DFU tool doesn't exit immediately upon Alt + F4 or hitting the close button; you need to be ready to also hit yes on the exit confirmation dialog.

Interestingly, I still could not get QFIL to reflash the stock images. I tried both with B10 and B12, but in both cases, though I now got through the Sahara part and to the firehose successfully thanks to your timing advice, I got:

{ERROR: Didn't properly read the sparse_header!
[i][…][/i]
Download Fail:FireHose Fail:FHLoader Fail:Process fail

Dunno what's up with that (are there sparse files in the ZIPs that need to be extracted using a program like 7-Zip rather than Windows Explorer's default ZIP handling or something?). However, I figured TWRP would probably be able to successfully reflash the original firmware, so I tried to just reflash TWRP with QFIL, and that worked!

Then, as it turned out, I didn't need to reflash the original firmware, as the R2 was now able to successfully boot both into TWRP and into the initial Android setup. So apparently that culprit install of Magisk 16.7 only screwed up the boot image/partition, and reflashing TWRP fixed that bit.

Yeah, I was leery about proceeding with initial setup before doing the Magisk install the first time, seemingly with good reason. This time I rebooted the phone before doing the first step of initial setup, went back into TWRP, flashed Magisk 16.7, rebooted, did initial setup, then installed one of my root apps and confirmed that I had root. Yay! :victory:

Interestingly, this time, I skipped part 2 of your guide, thinking that if I hadn't set any passcodes yet, the data partition wouldn't yet be encrypted. I got this notification in the Magisk install log again:

Encrypted data detected, keep forceencrypt

but this time I didn't get the

Removing dm(avb)-verity in dtb

so I'm thinking my concern about that message appearing (since you warned not to flash anything that'd remove dm-verity) was correct, and that's the step that borked the boot code the first time.

Yeah, the TWRP message definitely says it will only offer to root your device if you have it mount the system partition read-write, but I couldn't find any documentation of its supposed rooting process. I even delved into the TWRP source code a bit, but didn't find anything further on that. Perhaps it was a planned feature they didn't get to, and they failed to take out the reference to it in that message? Or maybe TWRP only supports rooting certain specific devices?

Anyway, doesn't matter, as I have successfully tested most of my root applications at this point, and everything is working. So happy I can finally finish setting up my R2 properly, and thank you again so much for your help! :D

---------- Post added at 06:22 AM ---------- Previous post was at 06:00 AM ----------

Is this just a case of needing to go into TWRP's Settings → Time Zone (clock icon) and setting your correct TZ? In my case, at least, the timezone was incorrect (though it was set correctly in Android) until I went into that menu and manually set it.