Accessing FrameBuffer through IOCTL

4,710 views
Skip to first unread message

Rohit

unread,
Jun 10, 2011, 4:28:32 AM6/10/11
to andro...@googlegroups.com
I tried to use ioctl on the framebuffer to access it, but i got the error "not a typewriter" ..Any help

-thanks in advance

Peter Xu

unread,
Jun 10, 2011, 9:01:13 AM6/10/11
to andro...@googlegroups.com, Rohit
On 2011年06月10日 16:28, Rohit wrote:
> I tried to use ioctl on the framebuffer to access it, but i got the
> error "not a typewriter" ..Any help
Hi,

I can use ioctl() to access the framebuffer (whose device file is
/dev/graphics/fb0 in android).
Maybe you can describe your steps in detail.

Peter
>
> -thanks in advance
> --
> You received this message because you are subscribed to the Google
> Groups "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/XnOcp4a0bWAJ.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.

Dianne Hackborn

unread,
Jun 12, 2011, 6:23:48 PM6/12/11
to andro...@googlegroups.com
In a proper secure Android build the frame buffer is not directly accessible from the NDK, so this question belongs on another group like android-porting.

On Fri, Jun 10, 2011 at 1:28 AM, Rohit <rjl0...@gmail.com> wrote:
I tried to use ioctl on the framebuffer to access it, but i got the error "not a typewriter" ..Any help

-thanks in advance

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/XnOcp4a0bWAJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Peter Teoh

unread,
Jun 12, 2011, 9:36:36 PM6/12/11
to andro...@googlegroups.com
An example showing ioctl():

http://www.pocketmagic.net/?p=1473

Another showing direct access via commandline:

http://my.opera.com/otaku_2r/blog/grab-a-frame-in-android-frame-buffer

And according to this:

http://code.google.com/p/android-x86/issues/detail?id=75

your "not a typerwriter" issue may be related to:

a. Not using "root" on the Android device. (rooted device needed).
b. QEMU emulator problem. Try using the direct device?
c. Driver related problem? Eg, see this for similar error:

http://acassis.wordpress.com/2010/03/31/debugging-keypad-on-android/

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/android-ndk/-/XnOcp4a0bWAJ.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.
>

--
Regards,
Peter Teoh

Rohit

unread,
Jun 12, 2011, 11:50:18 PM6/12/11
to andro...@googlegroups.com
I knew that I need a rooted android device for accessing the framebuffer....so what I did was I used some pull and push commands and copied the fb0 file to the mnt/sdcard/ and after that I was able to open the fb0 file from my C code..Earlier when I tried to open the file from the dev/graphics folder It was giving an error like Permission Denied.So This one worked.. But when I tried to use the ioctl(fb,FBIOGET_FSCREENINFO,&fi) or ioctl(fb,FBIOGET_VSCREENINFO,&vi) then it gave the error "not a typewriter" . I am wondering whether this is the right way to do this thing.

Kevin Galligan

unread,
Jun 12, 2011, 11:59:07 PM6/12/11
to andro...@googlegroups.com
How are you calling your C code?

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/android-ndk/-/IN8GkTkcm7QJ.

Rohit

unread,
Jun 13, 2011, 12:23:45 AM6/13/11
to andro...@googlegroups.com
This is the line in my java code which calls the native code:  
      String str = stringFromJNI();

and in my C code This is my stringFromJNI function:

jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
     int fb;
     fb=open("/mnt/sdcard/fb0",O_RDWR);
     if (fb==-1){
           LOGE("JNILOG",strerror(errno));
     }

     if( ioctl(fb,  FBIOGET_VSCREENINFO,&vi)==-1) {
           LOGE("JNILOG",strerror(errno));
      }

This second log gives the error "not a typewriter"

Kevin Galligan

unread,
Jun 13, 2011, 12:38:09 AM6/13/11
to andro...@googlegroups.com
You need to start a process and call your C code on the command line,
something like ...

java.lang.Process sh = Runtime.getRuntime().exec("su -c sh");
OutputStream os = sh.getOutputStream();

then pass in all your commands to the process output stream. this
will run them as root. You could probably make it one line and
replace 'sh' with whatever your process name is, but I'm just
cutting/pasting right now.

Just because your phone is rooted, it doesn't mean that everything
automatically runs as root. You need to force it.

As a consequence, you can't use JNI, or at least I'm not sure how you
would. You'll also need to set up the make file to produce an
executable rather than a library file. If you figure out a way to do
JNI, please let me know. We just released a video recording product
for rooted phones, but we have another non-rooted jni version in the
making, baked into apps, and I wouldn't mind bringing the code bases
closer together.

http://touchtrack.co/home.seam

Sorry for the shameless plug ;)

-Kevin

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/android-ndk/-/MLIx_dsjD4wJ.

Rohit

unread,
Jun 13, 2011, 1:27:21 AM6/13/11
to andro...@googlegroups.com
What I was trying to do is I am running all this on a EMULATOR I dont have a rooted device... but as my C code cannot access the /dev/graphics/fb0 directly because it needs root access I copied the fb0 to /mnt/sdcard/ so that I overcome the problem of having a root. the file was opening from this new location..if I try to access it from /dev/graphics/fb0 I was getting an error "permission denied" but if i access fb0 from /mnt/sdcard/fb0 I was able to open the file from my C code...so I was wondering whether it is possible to access the frame buffer in this way because I was getting an error "not a typewriter" when I used the function ioctl(fb,FBIOGET_FSCREENINFO,&fi)

Kevin Galligan

unread,
Jun 13, 2011, 1:52:09 AM6/13/11
to andro...@googlegroups.com
OK. I'm a little confused. Were you trying to run ioctl on the file
at '/mnt/sdcard/fb0'? That won't work. The file '/mnt/sdcard/fb0' is
a real file, with raw screen data in it. The file '/dev/graphics/fb0'
is a virtual file that gives you a window to the frame buffer device.
You can read it like a normal file, but its really streaming data from
memory rather than from a "file".

The emulator is a weird situation. If you adb shell into it, you have
more access than you normally would on a regular device. However,
your apps don't have access. Normally, if you did adb shell into a
non-rooted device, you wouldn't be able to read fb0 there either.
That's why on the emulator you could copy from /dev/graphics to the
sdcard. Otherwise you probably wouldn't be able to.

Just FYI, the file you copied into /mnt/sdcard/fb0 is raw pixel data.
Its a WxH array, probably 32 bit. You can read it in like that.

Now, if you want access from your app, you *may* be able to try my
method, but without the 'su -c' part. Just the 'sh', then try copying
the fb0 file from /dev/graphics to /mnt/sdcard. I've had some success
with that on the emulator.

I hate it when people do this, but I have to ask. Why are you trying
to do this?

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/android-ndk/-/M-4eNPzdBtIJ.

Rohit

unread,
Jun 13, 2011, 2:42:05 AM6/13/11
to andro...@googlegroups.com
yes I was trying to run ioctl on the file /mnt/sdcard/fb0  and that wasnt working ..thanx for telling the reason as to why it wasnt working :) ... So is there any way that my c code can open /dev/graphics/fb0 on the emulator with sufficient permissions to open the /dev/graphics/fb0 (basically I am trying to write a code for taking a screenshot programmatically ..I dont want to use any apps for that :P)

Dianne Hackborn

unread,
Jun 13, 2011, 3:41:59 PM6/13/11
to andro...@googlegroups.com
Again, could you please take this off android-ndk?  Thanks.

On Sun, Jun 12, 2011 at 11:42 PM, Rohit <rjl0...@gmail.com> wrote:
yes I was trying to run ioctl on the file /mnt/sdcard/fb0  and that wasnt working ..thanx for telling the reason as to why it wasnt working :) ... So is there any way that my c code can open /dev/graphics/fb0 on the emulator with sufficient permissions to open the /dev/graphics/fb0 (basically I am trying to write a code for taking a screenshot programmatically ..I dont want to use any apps for that :P)

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/2NXLR31vrJsJ.

To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
Mar 12, 2013, 11:23:18 PM3/12/13
to andro...@googlegroups.com


On Mon, Mar 11, 2013 at 11:16 PM, Stefan Welker <stefan...@gmail.com> wrote:
Why does Google provide such an error message?

"Google" doesn't provide this error message. It comes from the standard kernel, and this is typically what you get when using the wrong ioctl number on the wrong file descriptor.
 
For certain applications especially if low latency is the goal there should be a way to access the framebuffer.
This error message should read: I see what you are doing there, and we are going to make it available soon.

Getting the framebuffer data won't get you much. It is essentially unused in recent devices (except maybe at boot time or in recovery mode). Instead, the display comes from GPU or hardware composer memory which is not always directly accessible from the system. There are GL calls to retrieve the pixel data that are typically very slow, e.g. 50-100 ms / frame (so forget about "low latency").

Finally, letting applications grab the screen's content liberally is a serious security risk, which is why the platform prevents it (taking a snapshot requires either direct physical manipulation from the user, or using a debugging tool). I.e. nobody's going to "make it available soon" to applications, as already discussed several times.

Enough already, this is out of NDK territory. If you're interested in this sort of thing, go search the archives on android-platform instead.

Am Freitag, 10. Juni 2011 10:28:32 UTC+2 schrieb Rohit:
I tried to use ioctl on the framebuffer to access it, but i got the error "not a typewriter" ..Any help

-thanks in advance

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages