Skip to content

Commit

Permalink
Enable better ui flow for bl unlocking/locking
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Jun 23, 2024
1 parent 0f10eb6 commit 0437b27
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 60 deletions.
108 changes: 80 additions & 28 deletions WOA Device Manager/Helpers/FastbootProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using WOADeviceManager.Managers;
Expand Down Expand Up @@ -59,32 +60,59 @@ public static bool CanUnlock()
return canUnlock;
}

public static bool FlashUnlock(Control frameHost = null)
public static async void FlashUnlock(Control frameHost = null)
{
if (CanUnlock())
if (DeviceManager.Device.CanUnlock)
{
ContentDialog dialog = new()
{
Title = "⚠️ EVERYTHING WILL BE FORMATTED",
Content = "Flash unlocking requires everything to be formatted. MAKE SURE YOU HAVE MADE A COPY OF EVERYTHING. We're not responsible for data loss.",
PrimaryButtonText = "⚠️ Proceed"
PrimaryButtonText = "⚠️ Proceed",
CloseButtonText = "Cancel"
};

dialog.PrimaryButtonClick += (ContentDialog dialog, ContentDialogButtonClickEventArgs args) =>
{
DeviceManager.Device.FastBootTransport.FlashingUnlock();
dialog.Hide();
};

dialog.CloseButtonText = "Cancel";

if (frameHost != null)
{
dialog.XamlRoot = frameHost.XamlRoot;
}
_ = dialog.ShowAsync();

return true;
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
{
new Task(async () =>
{
MainPage.SetStatus("Initializing...", Emoji: "🔓", Title: "Unlocking Bootloader", SubTitle: "WOA Device Manager is preparing to unlock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
while (DeviceManager.Device.State != DeviceState.BOOTLOADER)
{
MainPage.SetStatus("Rebooting phone to Bootloader mode...", Emoji: "🔓", Title: "Unlocking Bootloader", SubTitle: "WOA Device Manager is preparing to unlock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
try
{
await DeviceRebootHelper.RebootToBootloaderAndWait();
}
catch { }
}
MainPage.SetStatus("Waiting for User to accept the prompt on the phone.", Emoji: "🔓", Title: "Unlocking Bootloader", SubTitle: "WOA Device Manager is preparing to unlock your phone bootloader", SubMessage: "Use your volume buttons to go up and down, and your power button to confirm.");
bool result = DeviceManager.Device.FastBootTransport.FlashingUnlock();
while (DeviceManager.Device.State == DeviceState.BOOTLOADER)
{
Thread.Sleep(300);
}
MainPage.SetStatus("Device is going to reboot in a moment...", Emoji: "🔓", Title: "Unlocking Bootloader", SubTitle: "WOA Device Manager is preparing to unlock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
while (DeviceManager.Device.State == DeviceState.DISCONNECTED)
{
Thread.Sleep(300);
}
MainPage.SetStatus();
}).Start();
}
}
else
{
Expand All @@ -100,38 +128,62 @@ public static bool FlashUnlock(Control frameHost = null)
dialog.XamlRoot = frameHost.XamlRoot;
}

_ = dialog.ShowAsync();

return false;
await dialog.ShowAsync();
}
}

public static bool FlashLock(Control frameHost = null)
public static async void FlashLock(Control frameHost = null)
{
// TODO: Check that the device doesn't have Windows installed
ContentDialog dialog = new()
{
Title = "⚠️ Your bootloader will be locked",
Content = "This procedure will lock your bootloader. You usually don't want to do this unless you have to sell your device.",
PrimaryButtonText = "⚠️ Proceed"
};

dialog.PrimaryButtonClick += (ContentDialog dialog, ContentDialogButtonClickEventArgs args) =>
{
DeviceManager.Device.FastBootTransport.FlashingLock();
dialog.Hide();
PrimaryButtonText = "⚠️ Proceed",
CloseButtonText = "Cancel"
};

dialog.CloseButtonText = "Cancel";

if (frameHost != null)
{
dialog.XamlRoot = frameHost.XamlRoot;
}

_ = dialog.ShowAsync();
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
{
new Task(async () =>
{
MainPage.SetStatus("Initializing...", Emoji: "🔒", Title: "Locking Bootloader", SubTitle: "WOA Device Manager is preparing to lock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
while (DeviceManager.Device.State != DeviceState.BOOTLOADER)
{
MainPage.SetStatus("Rebooting phone to Bootloader mode...", Emoji: "🔒", Title: "Locking Bootloader", SubTitle: "WOA Device Manager is preparing to lock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
return true;
try
{
await DeviceRebootHelper.RebootToBootloaderAndWait();
}
catch { }
}
MainPage.SetStatus("Waiting for User to accept the prompt on the phone.", Emoji: "🔒", Title: "Locking Bootloader", SubTitle: "WOA Device Manager is preparing to lock your phone bootloader", SubMessage: "Use your volume buttons to go up and down, and your power button to confirm.");
bool result = DeviceManager.Device.FastBootTransport.FlashingLock();
while (DeviceManager.Device.State == DeviceState.BOOTLOADER)
{
Thread.Sleep(300);
}
MainPage.SetStatus("Device is going to reboot in a moment...", Emoji: "🔒", Title: "Locking Bootloader", SubTitle: "WOA Device Manager is preparing to lock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");
while (DeviceManager.Device.State == DeviceState.DISCONNECTED)
{
Thread.Sleep(300);
}
MainPage.SetStatus();
}).Start();
}
}

public static async Task<bool> BootTWRP()
Expand Down
17 changes: 2 additions & 15 deletions WOA Device Manager/Pages/LockBootloaderPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,9 @@ private void RefreshButton_Click(object sender, RoutedEventArgs e)
Bindings.Update();
}

private async void LockBootloaderButton_Click(object sender, RoutedEventArgs e)
private void LockBootloaderButton_Click(object sender, RoutedEventArgs e)
{
while (DeviceManager.Device.State != DeviceState.BOOTLOADER)
{
MainPage.SetStatus("Rebooting phone to Bootloader mode...", Emoji: "🔒", Title: "Locking Bootloader", SubTitle: "WOA Device Manager is preparing to lock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");

try
{
await DeviceRebootHelper.RebootToBootloaderAndWait();
}
catch { }

MainPage.ToggleLoadingScreen(false);
}

if (FastBootProcedures.CanUnlock())
if (DeviceManager.Device.CanUnlock)
{
FastBootProcedures.FlashLock(this);
}
Expand Down
17 changes: 2 additions & 15 deletions WOA Device Manager/Pages/UnlockBootloaderPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,9 @@ private void RefreshButton_Click(object sender, RoutedEventArgs e)
Bindings.Update();
}

private async void UnlockBootloaderButton_Click(object sender, RoutedEventArgs e)
private void UnlockBootloaderButton_Click(object sender, RoutedEventArgs e)
{
while (DeviceManager.Device.State != DeviceState.BOOTLOADER)
{
MainPage.SetStatus("Rebooting phone to Bootloader mode...", Emoji: "🔓", Title: "Unlocking Bootloader", SubTitle: "WOA Device Manager is preparing to unlock your phone bootloader", SubMessage: "Your phone may reboot into different operating modes. This is expected behavior. Do not interfere with this process.");

try
{
await DeviceRebootHelper.RebootToBootloaderAndWait();
}
catch { }

MainPage.ToggleLoadingScreen(false);
}

if (FastBootProcedures.CanUnlock())
if (DeviceManager.Device.CanUnlock)
{
FastBootProcedures.FlashUnlock(this);
}
Expand Down
4 changes: 2 additions & 2 deletions WOA Device Manager/Pages/zDebugPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ private void RebootToAndroid_Click(object sender, RoutedEventArgs e)

private void FlashUnlock_Click(object sender, RoutedEventArgs e)
{
_ = FastBootProcedures.FlashUnlock(this);
FastBootProcedures.FlashUnlock(this);
}

private void FlashLock_Click(object sender, RoutedEventArgs e)
{
_ = FastBootProcedures.FlashLock(this);
FastBootProcedures.FlashLock(this);
}

private async void BootTWRP_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 0437b27

Please sign in to comment.