How to pass view instance via aidl
I am trying to get a notification expanded view from statusbarService.java and pass it via aidl service to another application.
-frameworks/base/services/java/com/android/server/status/StatusBarService.java
private void makeStatusBarView(Context context) {
Resources res = context.ge开发者_如何学PythontResources();
mRightIconSlots = res.getStringArray(com.android.internal.R.array.status_bar_icon_order);
mRightIcons = new StatusBarIcon[mRightIconSlots.length];
**ExpandedView expanded** = (ExpandedView)View.inflate(context,
com.android.internal.R.layout.status_bar_expanded, null);
}
I want this "expanded" view instance to be stored through a service and pass it to anybody who binds to the service via aidl.
I wrote a service class. But i am not sure how to pass this view to the service instance. To bind to a service, it must be either an activity or service. StatusBarService.java is not either of both. So I don't know how to pass this view instance to a service.
Assuming if somehow view instance is passed to the service, I need to pass the view instance via aidl to anyone who binds to it. So I know that I need to write a parcelabale class which takes View as member and return the parcelable class instance.
I am not sure how to write a view instance via parcel. Any suggestions? I think something to play around with byte Arrays. Anybody know how to convert a view instance and write as byte arrays?
I think what Nikola meant to say was that instead of passing an actual View instance you can always pass its state instead. The complexity of this depends on the complexity of the view. For example, if you have a database connection then you will need to pass its state as well. The same is true for any and all data members of the View class that are not Parcelable themselves.
Once you receive the state at the other end of the AIDL interface, yiu can simply rebuild a new instance of the View class.
This is just an idea but you could create an AIDL interface to wrap your View instance. So lets say the view has the below public methods. You can't do much about the private ones.
int getWidth()
int getHeight()
String getFoo()
Make an aidl interface with basically the same methods. Then you can new up an implementation of that aidl interface. When you do that you will have to implement the methods of that aidl interface. For each of those you just call the corresponding method on your actual view. So ...
something like this
new view_interface(){
int getWidth(){
return view.getWidth();
}
// and so on ...
};
You can then pass this instance over aidl to your service or other process or whatever your building.
Just another option...
精彩评论