Bug 8572 - On try make a Ndef ReadOnly throws exeption
Summary: On try make a Ndef ReadOnly throws exeption
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-11-23 11:54 UTC by Marco A. (Gh0stman)
Modified: 2012-11-29 12:28 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marco A. (Gh0stman) 2012-11-23 11:54:07 UTC
Ndef ndef = Ndef.Get(tag);
                if (ndef != null)

                    if (!ndef.IsWritable)
                        //displayMessage("Read-only tag.");
                        return false;

                    // work out how much space we need for the data
                    int size = message.ToByteArray().Length;
                    if (ndef.MaxSize < size)
                        //displayMessage("Tag doesn't have enough free space.");
                        return false;

                        bool vReadyOnly = ndef.MakeReadOnly();
                    catch (Exception ex)
                        string ret = ex.Message;
                    RunOnUiThread(() => Toast.MakeText(this, "Crédito gravado com sucesso!", ToastLength.Short));
                    //displayMessage("Tag written successfully.");
                    return true;
{Java.IO.IOException: Exception of type 'Java.IO.IOException' was thrown.
  at Android.Runtime.JNIEnv.CallBooleanMethod (IntPtr jobject, IntPtr jmethod) [0x00023] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.7-branch/0e9eea34/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:156 
  at Android.Nfc.Tech.Ndef.MakeReadOnly () [0x0002d] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.7-branch/0e9eea34/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Nfc.Tech.Ndef.cs:155 
  at BusTravelCard.Activities.FinishCard.writeTag (Android.Nfc.Tag tag) [0x00405] in C:\Trabalho\Sistemas\Bus\MonoDroid\BusTravelCard\BusTravelCard\Activities\FinishCard.cs:202 
  --- End of managed exception stack trace ---
	at android.nfc.tech.Ndef.makeReadOnly(Ndef.java:375)
	at bustravelcard.activities.FinishCard.n_onNewIntent(Native Method)
	at bustravelcard.activities.FinishCard.onNewIntent(FinishCard.java:55)
	at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1127)
	at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2056)
	at android.app.ActivityThread.performNewIntents(ActivityThread.java:2069)
	at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2078)
	at android.app.ActivityThread.access$1400(ActivityThread.java:128)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4517)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
	at dalvik.system.NativeStart.main(Native Method)
Comment 1 Marco A. (Gh0stman) 2012-11-23 12:18:09 UTC
Today I write a NDEF message on the card/tag with no problems.
But now I want to protect the NDEF message from be overwriten by someone else (other app).
Looking on the docs I see two options FormatReadOnly(message); or WriteNdefMessage(message); MakeReadOnly();

On this test I was trying to write/protect and re-write with the new variant of the text.

The app is a credit card for a store. User fill with credits (get some bonus and stuff for use the card) and when he/she use the credit the new value is put in the card. The tag is a AES encripted text.

If you guys have any ideas I would love to hear.
Comment 2 Jonathan Pryor 2012-11-29 12:28:54 UTC
This does not appear to be a bug in Mono for Android.

> On try make a Ndef ReadOnly throws exeption

The IOException is a documented error condition:


One interesting note from the documentation:

> It must not be called from the main application thread.

Based on the stack trace, it looks like you're calling it from the main application thread (based on the android.app.ActivityThread.main() entry). If that's the case, Don't Do That™.