Sharing a Surface between two applications

3,013 views
Skip to first unread message

space

unread,
Jun 29, 2010, 7:06:45 AM6/29/10
to android-platform
Hi!

I try to share a surface between two applications.

First I created a single android project/application, with a service
and activity. Activity creates a SurfaceView, sends the surface via
aidl to the service, which keeps updating it. So far so good. Then I
tried to split it into two separate android projects/applications. The
activity<->service connection is working (I call a test method which
simply returns a number) but when I send the Surface to the service,
the Surface becomes invalid (Surface.isValid is true on the activity
side, but false in the service side).

I tried also sharing a process, but still the same problem :-(

I started to debug it, and when the Surface_writeToParcel function is
called, it tries to get a SurfaceControl instance, which is NULL.

In the sourcecode (android_view_Surface.cpp) I found the following
comment:

/*
* if this method is called from the WindowManager's process,
it means
* the client is is not remote, and therefore is allowed to
have
* a Surface (data), so we create it here.
* If we don't have a SurfaceControl, it means we're in a
different
* process.
*/

Does this mean that a Surface can be sent ONLY from the
WindowManager's process to a client process and the client cannot
forward it?

Anyway, my main question: what is the best way to share a surface
between two processes?

Thank you in advance!
/Pal
Message has been deleted

Dianne Hackborn

unread,
Jun 29, 2010, 1:11:26 PM6/29/10
to android-...@googlegroups.com
Sorry, you can't do this.  What are you trying to accomplish?  The design is that the window manager generates and supplies surfaces for specific client processes.  If another process wants its own surface, it should talk with the window manager to make its own window and use the surface from that.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?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.

Karthik Ravi Shankar

unread,
Jun 29, 2010, 1:15:01 PM6/29/10
to android-...@googlegroups.com
Hi Dianne,

Does this mean we can have multiple windows and multiple surfaces visible to the user at the same time? I'm asking this coz I have been trying to figure this out for one of my apps for quite sometime and any advice would be useful!!

Thanks, Karthik.
Karthik R
Graduate Student
Computer Science Department
UCLA

Dianne Hackborn

unread,
Jun 29, 2010, 2:32:12 PM6/29/10
to android-...@googlegroups.com
Um the status bar, the application window, the IME, the wallpaper, each dialog, the menu pane...  these are all separate windows, running in a variety of different processes.

Dianne Hackborn

unread,
Jun 29, 2010, 2:32:29 PM6/29/10
to android-...@googlegroups.com
Oh yeah and let's not forget SurfaceView that is also, of course, a separate surface.

Ajala Xavier

unread,
Jul 14, 2015, 5:24:14 PM7/14/15
to android-...@googlegroups.com
Hello ,

After going through this thread I understood the following

Case 1:
Single application( Apk) with Activity and Service( set to run in a different process in the AndroidManifest.xml): 
Activity can create a SurfaceView and send it to the service through AIDL Serivce can  update the Surface.

Case 2:
Multiple applications: Activity( one APK) and Serivce( Another APK)
- Activity can't share the SurfaceView that it created to the Service. The only way for the Service to update the UI is by creating its own surface view.

Can any one confirm my understanding. 
Appreciate if you can point me to the sample code that does Case 1 and Case 2.
Ajala

Андрей Суворов

unread,
Feb 13, 2017, 11:34:52 AM2/13/17
to android-platform
Mybe someone still looking for info.

Multiple application (from services or activities) can share SurfaceView. Another app can draw inside one app SurfaceView transmitted via aidl.
See this topic for one use case 



среда, 15 июля 2015 г., 0:24:14 UTC+3 пользователь Ajala Xavier написал:
Reply all
Reply to author
Forward
0 new messages