Skip to content
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

Add support for Xiaomi (with OrangeFox) #188

Closed
wants to merge 6 commits into from

Conversation

anon1892
Copy link
Member

@anon1892 anon1892 commented Jul 27, 2023

Some modifications to the code, so OrangeFox recovery can be supported (especially useful for Xiaomi devices)

To start, I just created two devices files, I have to test for others, but should be roughly the same, a lot of Xiaomi devices follow the same installation process (and will not have need to update code like this time)

Also added two devices metadata :

  • recovery for OAI to know which recovery handle (optional, TWRP by default)
  • notes for showing device specific notes on the OS chooser screen (optional too)

That's about it, what do you think?

EDIT : This PR is now split into many little ones : #218 #220 #221 #222 #223 #224 #225 #226

@tsterbak tsterbak self-requested a review July 27, 2023 14:41
@tsterbak tsterbak added the device Request to add or improve a specific device. label Jul 27, 2023
@tsterbak tsterbak added this to the Release Beta-Version 0.4.5 milestone Jul 27, 2023
@tsterbak
Copy link
Member

Thanks a lot for the contribution! ☺️ Great to see support for Xiaomi devices coming! 🥳

Why would you require OrangeFox for these devices? There are also TWRP version available.
At this point support for OrangeFox would be great, but I think I would prefer to do both those things (support for the Xiaomi devices) and extending recovery support to OrangeFox separately. If there is no blocker from your side, the Xiaomi support could be merged really fast while there might be more work necessary for the OrangeFox support. One option could be to split the two things in separate PRs and move them forward independently. What do you think?

Great work!

@tsterbak tsterbak added the enhancement New feature or request label Jul 27, 2023
@anon1892
Copy link
Member Author

Depends of the device : there is no Android 12 & 13 support by TWRP for lavender (Remi Note 7)
Should OAI recommand unofficial TWRP for A12/13 but official for A10/11 until OrangeFox is supported ?

@Heus-Sueh
Copy link
Contributor

if this PR is merged, will i just need to create a .yaml file to add support for a new xiaomi device?

I believe that the whole process is similar except that the bootloader can be unlocked using fastboot oem unlock.

@MagicLike
Copy link
Member

MagicLike commented Jul 27, 2023

if this PR is merged, will i just need to create a .yaml file to add support for a new xiaomi device?

Yep, therefore I refer to the contribute section in the README: https://github.com/openandroidinstaller-dev/openandroidinstaller/#how-to-contribute-your-own-installation-configurations

I believe that the whole process is similar except that the bootloader can be unlocked using fastboot oem unlock.

Xiaomi devices are a bit more locked down afaik. You need to create a Mi account, which has to be connected to your SIM and phone number and then request an unlock for your device. (can you confirm @anon1892?)

Sources:

@MagicLike
Copy link
Member

Thanks a lot for the contribution! relaxed Great to see support for Xiaomi devices coming! partying_face

Why would you require OrangeFox for these devices? There are also TWRP version available. At this point support for OrangeFox would be great, but I think I would prefer to do both those things (support for the Xiaomi devices) and extending recovery support to OrangeFox separately. If there is no blocker from your side, the Xiaomi support could be merged really fast while there might be more work necessary for the OrangeFox support. One option could be to split the two things in separate PRs and move them forward independently. What do you think?

Great work!

Sidenote: I would move this PR on to 0.5, as it is a massive amount of new features and therefore needs a larger amount of testing. Or what do you think?

@tsterbak
Copy link
Member

Depends of the device : there is no Android 12 & 13 support by TWRP for lavender (Remi Note 7)
Should OAI recommand unofficial TWRP for A12/13 but official for A10/11 until OrangeFox is supported ?

I see, so it makes sense to move forward with these changes together. I will see that I get some testing for OrangeFox started and see how these changes work. I might need to streamline or refactor some code to make it work smoothly. :)

@tsterbak
Copy link
Member

if this PR is merged, will i just need to create a .yaml file to add support for a new xiaomi device?
I believe that the whole process is similar except that the bootloader can be unlocked using fastboot oem unlock.

Yes, in theory this is true. But for some devices there are steps necessary that are not supported yet. Also some Xiaomi devices are affected by this. (For example flashing a vb_meta partition).
But this will be addressed in some later release.

@tsterbak
Copy link
Member

Sidenote: I would move this PR on to 0.5, as it is a massive amount of new features and therefore needs a larger amount of testing. Or what do you think?

I'm not sure yet. We will see :D

@@ -497,3 +518,24 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
except CalledProcessError:
logger.error("Failed to detect a device.")
return None

@add_logging("Flash custom recovery with fastboot.")
def fastboot_flash_recovery(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to flash the recovery here, or could we just boot it?
I would prefer that, since if something goes wrong, the recovery of the device is still intact. This reduces the risk for users (I would say).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - that is the same reason I initially brought this feature forward

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't flash the recovery, you will not be able to install OTA.
In addition, the Xiaomi recovery is very poor... And if something goes wrong, as I mentioned in notes metadata for lavender & ginkgo, you can flash MIUI and all partitions with a script.
For Xiaomi devices, I never saw a documentation recommanding not to flash the recovery (it's even a mandatory step)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OTA is a very good point. Should be fine. 👍
Maybe we should even consider moving more phones to flashing the recovery.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one - I'd still vote for only flashing if necessary, like on Samsung or Xiaomi devices, as it is easier to revert back and as seen on the OnePlus One - the bootloader can't interact with any non stock recovery. So backwards compatibility would be another issue...

@anon1892
Copy link
Member Author

anon1892 commented Jul 27, 2023

the bootloader can be unlocked using fastboot oem unlock.

Sadly, not on Xiaomi devices. @MagicLike got the point.

I might need to streamline or refactor some code to make it work smoothly. :)

Yes, go ahead! The code can certainly be improved

@MagicLike
Copy link
Member

the bootloader can be unlocked using fastboot oem unlock.

Sadly, not on Xiaomi devices. @MagicLike got the point.

Sidequestion: Does the SIM card need a internet connection, or could I just use a prepaid card without internet and use Wifi instead? (Having a Xiaomi myself, but don't want to give them all my data...)

@tsterbak
Copy link
Member

Sidequestion: Does the SIM card need a internet connection, or could I just use a prepaid card without internet and use Wifi instead? (Having a Xiaomi myself, but don't want to give them all my data...)

You have to give them everything... I have a MI 9 Lite and they needed internet connection to unlock it.

@anon1892
Copy link
Member Author

Sidequestion: Does the SIM card need a internet connection, or could I just use a prepaid card without internet and use Wifi instead? (Having a Xiaomi myself, but don't want to give them all my data...)

It needs internet connection, but very few (less than 1Mo for sure, but I didn't measure how many)

@Heus-Sueh
Copy link
Contributor

Xiaomi devices are a bit more locked down afaik. You need to create a Mi account, which has to be connected to your SIM and phone number and then request an unlock for your device. (can you confirm @anon1892?)

Sources:

* https://en.miui.com/unlock/index.html

* https://new.c.mi.com/global/post/101245

mine is the Mi A2 Lite (daisy) it doesn't come with MIUI it comes with pure android so only the fastboot oem unlock command solves it

README.md Outdated
Xiaomi | Redmi Note 7 | [lavender](https://wiki.lineageos.org/devices/lavender) | lavender | tested
Xiaomi | Redmi Note 8 / 8T | [ginkgo](https://wiki.lineageos.org/devices/ginkgo) | ginkgo / willow | untested
Xiaomi | Redmi Note 10S / 11SE / Poco M5S | [rosemary](https://wiki.lineageos.org/devices/rosemary) | rosemary / maltose / secret / rosemary_p | untested
Xiaomi | Redmi 9A / 9C / 9AT / 9i / 9A Sport / 10A / 10A Sport | [garden](https://wiki.lineageos.org/devices/garden) | garden / dandelion / blossom / angelican | tested
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This url does not exist

Copy link
Member Author

@anon1892 anon1892 Jul 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups... Copy - paste ! garden was never officially supported by Lineage. Which URL should I replace it with?
EDIT : No link at all, like some others phones on the readme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer, to have one config file per device code (if they are not very similar) and treat them as separate devices.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dandelion and angelican are official Xiaomi namecodes.
garden and blossom are names of unified groups of codenames, given by ROM developers.
A garden ROM will fit for dandelion device, for example. So as far I understand, we cannot divide config files per device code, isn't it ?

Copy link
Member

@MagicLike MagicLike Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by that? - Do you mean having an extra device code for 2 configs or multiple device codes for one config? (Sorry, I am just a bit confused)

Copy link
Member Author

@anon1892 anon1892 Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may forgot some (it's a mess), but globally :

Official Xiaomi codenames :

  • Redmi 9C : angelica
  • Redmi 9C NFC : angelican
  • Redmi 9A/10A/10A Sport/9i/9A Sport : dandelion
  • Poco C3/C31 : angelicain

Community names :

  • Redmi 9A/9C/9i/9 India : garden
  • All of the above + Redmi 9 Active/9AT/9I Sport : blossom

So, a garden ROM will work on dandelion and angelica phones for example
And I forgot some codenames...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, thats confusing 😀

Then it might be a good idea, to start displaying multiple device codes (or the actually found one) as well as multiple possible names for devices (or based on the code) to the user. I could see this causing confusion for users (we recently also saw this for Samsung devices :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is !
I agree, we could display device code + group name, it may be more clear?

@tsterbak tsterbak changed the base branch from main to dev July 29, 2023 18:02
@anon1892
Copy link
Member Author

Also, some questions :

  • Should we rename functions whose name contain "twrp" and replace it for "recovery" ?
    It would imply changing call to these functions in all devices files, or create a "legacy" function (in step_views.py, could be very simple)

  • It can be related to create a wiki page #192 , should we create (directly on the app, on GitHub or on the website) a little tutorial to show how to come back to stock MiUI in case of something goes wrong (something more precise than the notes in Xiaomi devices files I created)

  • Generally, instructions in device files are always the same. Should we create a separate file with all possibles texts that an be showed to users, and link these texts to device files ? It could also be a good starting point for allowing translations. (It's off topic, should I create an issue for that ?)

@MagicLike
Copy link
Member

  • Should we rename functions whose name contain "twrp" and replace it for "recovery" ?
    It would imply changing call to these functions in all devices files, or create a "legacy" function (in step_views.py, could be very simple)

Maybe, but then the whole system would need a rewrite afaik, as then the different recoveries would need to be detected and then OAI would need to adapt it's commands to it. But yes it would make more sence instead of spaghetti coding another recovery in addition to twrp.

  • It can be related to create a wiki page #192 , should we create (directly on the app, on GitHub or on the website) a little tutorial to show how to come back to stock MiUI in case of something goes wrong (something more precise than the notes in Xiaomi devices files I created)

Yes, documentation is needed indeed - but I would want to use mkdocs(-material) for its higher capabilities -> #192 (comment). I also would set it up for you @tsterbak - if needed.

  • Generally, instructions in device files are always the same. Should we create a separate file with all possibles texts that an be showed to users, and link these texts to device files ? It could also be a good starting point for allowing translations. (It's off topic, should I create an issue for that ?)

#72

@anon1892
Copy link
Member Author

Maybe, but then the whole system would need a rewrite afaik, as then the different recoveries would need to be detected and then OAI would need to adapt it's commands to it. But yes it would make more sence instead of spaghetti coding another recovery in addition to twrp.

Ok. Will do it then. Yes, see 0fd5f35, I started to allow several recoveries to be used for the same device, and OAI to behave differently depending on the selected recovery. (need more work, I pursue)

@tsterbak
Copy link
Member

I need up my mind about if and how to integrate different recoveries at this point. As @MagicLike pointed out, there would be a substantial amount of refactoring and generalization necessary to make it work smoothly. And testing these things is horrible 😅
On the other hand OF is pretty close to TWRP, so the actual flashing code would not need to change much (if at all). It has been a while since I last used it, but the scripting basically works the same way.

So if have to think about if and how I can maintain this puppy (https://textual.textualize.io/blog/2023/07/29/pull-requests-are-cake-or-puppies/). ☺️ Once I have more free time (presumably on Friday), I will give this a closer look and see how it can fit in the current state of the installer and what changes are necessary to maintain this properly.

@RaptaG
Copy link
Contributor

RaptaG commented Jul 31, 2023

Does this support Xiaomi Redmi Note 9 Pro?

@anon1892
Copy link
Member Author

anon1892 commented Jul 31, 2023

You can just run make test in your repository and that will run the tests with pytest. Let me know if I can support you :)

Ok. I will start by making different pull requests, then that. Thank you !

Does this support Xiaomi Redmi Note 9 Pro?

Just looked, it's simple (sames steps as lavender, in this PR).
I will not be able to test, but I can make the device config file (during this week I think, after doing what I said before)

@MagicLike
Copy link
Member

Does this support Xiaomi Redmi Note 9 Pro?

Just looked, it's simple (sames steps as lavender, in this PR). I will not be able to test, but I can make the device config file (during this week I think, after doing what I said before)

If it is that simple, I will maybe also try to look into creating a config for begonia, but as it is currently my main device I will probably not be able to test it for now. (Would mark it as untested in the README and add a warning in the config itself...)

@anon1892
Copy link
Member Author

If it is that simple, I will maybe also try to look into creating a config for begonia, but as it is currently my main device I will probably not be able to test it for now. (Would mark it as untested in the README and add a warning in the config itself...)

Just looked at https://forum.xda-developers.com/t/rom-12-0-begonia-lineageos-19-0-unofficial.4381391/
It seems to be same steps, so it's easy too 👍

@tsterbak
Copy link
Member

tsterbak commented Aug 2, 2023

Thanks a lot for splitting it up!
Should this PR be closed for now, since it is split up?

@anon1892
Copy link
Member Author

anon1892 commented Aug 2, 2023

Yes!

@anon1892 anon1892 closed this Aug 2, 2023
@RaptaG
Copy link
Contributor

RaptaG commented Aug 2, 2023

so no redmi note 9 pro support :C

@MagicLike
Copy link
Member

so no redmi note 9 pro support :C

That is not true - this pr was split up into multiple ones. You can even write a config yourself and tak inspiration from the others already created. Or either I or @anon1892 can write one, which then you need to test.
Example at #222

@RaptaG
Copy link
Contributor

RaptaG commented Aug 2, 2023

If does not work, what will happen with my phone?

@MagicLike
Copy link
Member

If does not work, what will happen with my phone?

That is pretty difficult to say in my perspective. But there defenetly is a way back afaik. But @anon1892 probably knows it better, as they flashed multiple xiaomi phones already.

@anon1892
Copy link
Member Author

anon1892 commented Aug 2, 2023

If does not work, what will happen with my phone?

You will have to follow steps, which are easy : https://wiki.lineageos.org/devices/miatoll/install/variant3
And if something is broken, re-flash MiUI in fastboot mode (very easy, just start a script) : https://xiaomifirmwareupdater.com/miui/joyeuse/

@RaptaG
Copy link
Contributor

RaptaG commented Aug 2, 2023

@anon1892 btw, does mi unlock work for you?

It doesn't on my end

@anon1892
Copy link
Member Author

anon1892 commented Aug 2, 2023

@RaptaG Yes, but sometimes it's annoying.
Last time I had to use it, it worked when I created a new Xiaomi account WITH GOOGLE (social connection) AND specifying USA when they asked for a country. I've seen this on a Xiaomi forum and it worked.

tsterbak added a commit that referenced this pull request Aug 4, 2023
Some modifications to the code, so OrangeFox recovery can be supported
(especially useful for Xiaomi devices)

Work started in #188 

It works, but I don't like the fix line 267 of `tooling.py`
tsterbak added a commit that referenced this pull request Aug 16, 2023
Work started and tested in #188 : working

Requirements : 
- #218 for OrangeFox support (especially `fastboot_flash_recovery` and
`fastboot_reboot_recovery`)
- #220 for additional partitions support
- #221 for device specific notes (optional)
tsterbak added a commit that referenced this pull request Sep 27, 2023
Work started and tested in #188 : works fine

Requirements : 
- #218 for OrangeFox support (especially `fastboot_flash_recovery` and
`fastboot_reboot_recovery`
- #221 for device specific notes (optional)
tsterbak added a commit that referenced this pull request Sep 27, 2023
Work started in #188 

Untested but should work (same steps as #222 )

Requirements : 
- #218 for OrangeFox support (especially `fastboot_flash_recovery` and
`fastboot_reboot_recovery`
- #221 for device specific notes (optional)
tsterbak added a commit that referenced this pull request Sep 27, 2023
Work started and tested in #188 : working

Requirements : 
- #218 for OrangeFox support (especially `fastboot_flash_recovery` and
`fastboot_reboot_recovery`
- #221 for device specific notes (optional)
tsterbak added a commit that referenced this pull request Sep 27, 2023
Work started in #188 

Untested but should work

Requirements : 
- #218 for OrangeFox support (optional)
- #221 for device specific notes (optional)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
device Request to add or improve a specific device. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants