Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Fixed app crash when no root is given or available.
Browse files Browse the repository at this point in the history
Minor refactoring.
  • Loading branch information
ViRb3 committed Jun 5, 2016
1 parent 4ff61df commit 3c6563d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nMAC/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace nMAC
{
internal class Logger
{
private TextView _txtLog;
private readonly TextView _txtLog;

internal Logger(Context context)
{
Expand Down
8 changes: 4 additions & 4 deletions nMAC/MACFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace nMAC
{
internal static class MACFunctions
{
private const string UnsupportedDeviceMessage = @"Sorry, this device not supported.
Please contact me if you want to make it work!";
internal static string MACFile;
internal static string LocalMACFile;
internal static string BackupMACFile;
Expand All @@ -23,8 +25,7 @@ internal static async Task AssignPaths(Context context)

if (device == null)
{
Helpers.ShowCriticalError(context, @"Sorry, this device not supported.
Please contact me if you want to make it work!");
Helpers.ShowCriticalError(context, UnsupportedDeviceMessage);
return;
}

Expand Down Expand Up @@ -76,8 +77,7 @@ internal static string ReadMAC(Context context)

if (!Device.CheckFile(content))
{
Helpers.ShowCriticalError(context, @"Sorry, this device not supported.
Please contact me if you want to make it work!");
Helpers.ShowCriticalError(context, UnsupportedDeviceMessage);
return null;
}

Expand Down
28 changes: 14 additions & 14 deletions nMAC/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

SetContentView(Resource.Layout.Main);
this.SetContentView(Resource.Layout.Main);
ToggleViews(false);

Button btnRandomize = FindViewById<Button>(Resource.Id.btnRandomize);
Button btnRandomize = this.FindViewById<Button>(Resource.Id.btnRandomize);
btnRandomize.Click += BtnRandomize_Click;
Button btnChange = FindViewById<Button>(Resource.Id.btnChange);
Button btnChange = this.FindViewById<Button>(Resource.Id.btnChange);
btnChange.Click += BtnChange_Click;
Button btnRestore = FindViewById<Button>(Resource.Id.btnRestore);
Button btnRestore = this.FindViewById<Button>(Resource.Id.btnRestore);
btnRestore.Click += BtnRestore_Click;

InitializeLogger(this);
await AssignPaths(this);
Log("Checking SU availability...");

if (MACFile == null) // device not supported
if (!await CheckSUStrict(this))
{
Log("Device not supported!");
Log("Error confirming SU access!");
return;
}

Log("Checking SU availability...");
await AssignPaths(this);

if (!await CheckSUStrict(this))
if (MACFile == null) // device not supported
{
Log("Error confirming SU access!");
Log("Device not supported!");
return;
}

Expand Down Expand Up @@ -112,12 +112,12 @@ private void BtnRandomize_Click(object sender, EventArgs e)

private void ToggleViews(bool state)
{
RelativeLayout layoutMAC = FindViewById<RelativeLayout>(Resource.Id.layoutMAC);
RelativeLayout layoutMAC = this.FindViewById<RelativeLayout>(Resource.Id.layoutMAC);

for (int i = 0; i < layoutMAC.ChildCount; i++)
layoutMAC.GetChildAt(i).Enabled = state;

RelativeLayout layoutButtons = FindViewById<RelativeLayout>(Resource.Id.layoutButtons);
RelativeLayout layoutButtons = this.FindViewById<RelativeLayout>(Resource.Id.layoutButtons);

for (int i = 0; i < layoutButtons.ChildCount; i++)
layoutButtons.GetChildAt(i).Enabled = state;
Expand Down Expand Up @@ -196,7 +196,7 @@ private void SetMACViews(string MAC, bool excludeFirst = false)
}
}

RelativeLayout layoutMAC = FindViewById<RelativeLayout>(Resource.Id.layoutMAC);
RelativeLayout layoutMAC = this.FindViewById<RelativeLayout>(Resource.Id.layoutMAC);

for (int i = excludeFirst ? 1 : 0; i < layoutMAC.ChildCount; i++)
{
Expand All @@ -213,7 +213,7 @@ private void SetMACViewsForRandom(string MAC)

private string GetMACFromViews()
{
RelativeLayout layoutMAC = FindViewById<RelativeLayout>(Resource.Id.layoutMAC);
RelativeLayout layoutMAC = this.FindViewById<RelativeLayout>(Resource.Id.layoutMAC);
StringWriter stringWriter = new StringWriter();

for (int i = 0; i < layoutMAC.ChildCount; i++)
Expand Down
2 changes: 1 addition & 1 deletion nMAC/ProgressDialogFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace nMAC
{
internal class ProgressDialogFragment : Android.App.DialogFragment
internal class ProgressDialogFragment : DialogFragment
{
private static string _message, _title;
private static ProgressDialog _progressDialog;
Expand Down
2 changes: 1 addition & 1 deletion nMAC/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="virb3e.nMAC" android:versionCode="4" android:versionName="1.1" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="virb3e.nMAC" android:versionCode="5" android:versionName="1.101" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down

0 comments on commit 3c6563d

Please sign in to comment.