Commit 01c6b80d authored by Geoffrey Métais's avatar Geoffrey Métais

Update API for remote browsing

parent 89f47cff
......@@ -5,6 +5,7 @@ import android.net.Uri;
interface IExtensionHost {
// Protocol version 1
oneway void updateList(in List<VLCExtensionItem> items);
oneway void updateList(in String title, in List<VLCExtensionItem> items, boolean showParams);
oneway void playUri(in Uri uri, String title);
oneway void unBind(int index);
}
......@@ -5,6 +5,7 @@ import org.videolan.vlc.plugin.api.VLCExtensionItem;
interface IExtensionService {
// Protocol version 1
oneway void onInitialize(in IExtensionHost host);
oneway void browse(int intId, String stringId);
oneway void onInitialize(int index, in IExtensionHost host);
oneway void browse(int intId, String stringId); // longId?
oneway void refresh();
}
......@@ -35,20 +35,24 @@ public class VLCExtensionItem implements Parcelable {
public static final int TYPE_SUBTITLE = 4;
public static final int TYPE_OTHER_FILE = 5;
String id;
String path;
String title;
String subTitle;
public String stringId;
public int intId;
public String link;
public String title;
public String subTitle;
//TODO choose how to deal with icons
String iconUri; // for content provider
int iconType; // Using VLC icons. maybe with iconRes?
public String imageLink; // for content provider
public int iconType; // Using VLC icons. maybe with iconRes?
public VLCExtensionItem(String id, String path, String title, String subTitle, String mimeType, int iconType) {
this.id = id;
this.path = path;
public VLCExtensionItem(String stringId, int intId, String link, String title, String subTitle, String imageLink, int iconType) {
this.stringId = stringId;
this.intId = intId;
this.link = link;
this.title = title;
this.subTitle = subTitle;
this.imageLink = imageLink;
this.iconType = iconType;
}
......@@ -76,20 +80,22 @@ public class VLCExtensionItem implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(path);
dest.writeString(stringId);
dest.writeInt(intId);
dest.writeString(link);
dest.writeString(title);
dest.writeString(subTitle);
dest.writeString(iconUri);
dest.writeString(imageLink);
dest.writeInt(iconType);
}
public void readFromParcel(Parcel in) {
id = in.readString();
path = in.readString();
stringId = in.readString();
intId = in.readInt();
link = in.readString();
title = in.readString();
subTitle = in.readString();
iconUri = in.readString();
imageLink = in.readString();
iconType = in.readInt();
}
}
......@@ -17,6 +17,7 @@ import java.util.List;
public abstract class VLCExtensionService extends Service{
private static final String TAG = "VLC/ExtensionService";
private int mIndex = -1;
private static final ComponentName VLC_HOST_SERVICE =
new ComponentName("org.videolan.vlc",
......@@ -26,10 +27,10 @@ public abstract class VLCExtensionService extends Service{
Context mContext = this;
private volatile Looper mServiceLooper;
private volatile Handler mServiceHandler;
protected volatile Handler mServiceHandler;
protected abstract void browse(int intId, String stringId);
protected abstract void updateList(List<VLCExtensionItem> items);
protected abstract void refresh();
@Override
public void onCreate() {
......@@ -51,6 +52,9 @@ public abstract class VLCExtensionService extends Service{
@Override
public void onDestroy() {
super.onDestroy();
try {
mHost.unBind(mIndex);
} catch (RemoteException e) {}
mServiceHandler.removeCallbacksAndMessages(null); // remove all callbacks
mServiceLooper.quit();
}
......@@ -62,11 +66,27 @@ public abstract class VLCExtensionService extends Service{
e.printStackTrace();
}
}
protected void updateList(String title, List<VLCExtensionItem> items, boolean showParams){
try {
mHost.updateList(title, items, showParams);
} catch (RemoteException e) {
e.printStackTrace();
}
}
protected void onInitialize() {};
private final IExtensionService.Stub mBinder = new IExtensionService.Stub() {
@Override
public void onInitialize(IExtensionHost host) throws RemoteException {
public void onInitialize(int index, IExtensionHost host) throws RemoteException {
mIndex = index;
mHost = host;
mServiceHandler.post(new Runnable() {
@Override
public void run() {
VLCExtensionService.this.onInitialize();
}
});
}
@Override
......@@ -78,5 +98,15 @@ public abstract class VLCExtensionService extends Service{
}
});
}
@Override
public void refresh() {
mServiceHandler.post(new Runnable() {
@Override
public void run() {
VLCExtensionService.this.refresh();
}
});
}
};
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
<item name="android:windowContentOverlay">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:color/transparent</item>
</style>
</resources>
\ No newline at end of file
......@@ -30,13 +30,11 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.text.TextUtils;
......@@ -59,30 +57,40 @@ public class PluginService extends Service {
public static final String ACTION_EXTENSION = "org.videolan.vlc.Extension";
public static final int PROTOCOLE_VERSION = 1;
private static final int PLAY_MEDIA = 42;
private final IBinder mBinder = new LocalBinder();
private ExtensionManagerActivity mExtensionManagerActivity;
public interface ExtensionManagerActivity {
void displayExtensionItems(String title, List<VLCExtensionItem> items, boolean showParams);
}
public void setExtensionManagerActivity(ExtensionManagerActivity activity) {
mExtensionManagerActivity = activity;
}
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "service onCreate");
getAvailableExtensions();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
return START_NOT_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
Log.d(TAG, "service onBind");
return mBinder;
}
@Override
public boolean onUnbind(Intent intent) {
setExtensionManagerActivity(null);
return false;
}
public class LocalBinder extends Binder {
public PluginService getService() {
return PluginService.this;
......@@ -119,7 +127,15 @@ public class PluginService extends Service {
private List<ExtensionListing> mPlugins = new LinkedList<>();
int mCurrentIndex = -1;
public void connectService(int index) {
public void openExtension(int index) {
if (index == mCurrentIndex)
browse(0, null);
else
connectService(index);
}
public void connectService(final int index) {
ExtensionListing info = mPlugins.get(index);
if (mCurrentIndex != -1) {
......@@ -129,7 +145,7 @@ public class PluginService extends Service {
final Connection conn = new Connection();
ComponentName cn = info.componentName();
conn.componentName = cn;
conn.hostInterface = makeHostInterface(conn);
conn.hostInterface = makeHostInterface();
conn.serviceConnection = new ServiceConnection() {
@Override
......@@ -137,7 +153,7 @@ public class PluginService extends Service {
conn.ready = true;
conn.binder = IExtensionService.Stub.asInterface(service);
try {
conn.binder.onInitialize(conn.hostInterface);
conn.binder.onInitialize(index, conn.hostInterface);
} catch (RemoteException e) {
e.printStackTrace();
}
......@@ -145,6 +161,7 @@ public class PluginService extends Service {
@Override
public void onServiceDisconnected(ComponentName name) {
mCurrentIndex = -1;
}
};
......@@ -155,37 +172,81 @@ public class PluginService extends Service {
Context.BIND_AUTO_CREATE)) {
Log.e(TAG, "Error binding to extension " + cn.flattenToShortString());
info.setConnection(null);
// return null;
}
} else
mCurrentIndex = index;
} catch (SecurityException e) {
Log.e(TAG, "Error binding to extension " + cn.flattenToShortString(), e);
info.setConnection(null);
// return null;
info.setConnection(null);
}
}
private void disconnect() {
public void refresh() {
try {
ExtensionListing plugin = mPlugins.get(mCurrentIndex);
if (plugin == null)
return;
IExtensionService service = plugin.getConnection().binder;
if (service == null)
return;
service.refresh();
} catch (RemoteException e) {}
}
public void browse(int intId, String stringId) {
try {
ExtensionListing plugin = mPlugins.get(mCurrentIndex);
if (plugin == null)
return;
IExtensionService service = plugin.getConnection().binder;
if (service == null)
return;
service.browse(intId, stringId);
} catch (RemoteException e) {}
}
public void disconnect() {
if (mCurrentIndex == -1)
return;
ExtensionListing plugin = mPlugins.get(mCurrentIndex);
Connection conn = plugin.getConnection();
if (conn != null)
unbindService(conn.serviceConnection);
if (conn != null) {
try {
unbindService(conn.serviceConnection);
} catch (Exception e) {} // In case of extension service crashed
}
plugin.setConnection(null);
}
private IExtensionHost makeHostInterface(Connection conn) {
private IExtensionHost makeHostInterface() {
return new IExtensionHost.Stub(){
@Override
public void updateList(List<VLCExtensionItem> items) throws RemoteException {
//TODO
public void updateList(final String title, final List<VLCExtensionItem> items, final boolean showParams) throws RemoteException {
mHandler.post(new Runnable() {
@Override
public void run() {
if (mExtensionManagerActivity != null)
mExtensionManagerActivity.displayExtensionItems(title, items, showParams);
}
});
}
@Override
public void playUri(Uri uri, String title) throws RemoteException {
Log.d(TAG, "play media "+title);
Log.d(TAG, " - uri is: "+uri);
MediaWrapper media = new MediaWrapper(uri);
final MediaWrapper media = new MediaWrapper(uri);
media.setTitle(title);
mHandler.obtainMessage(PLAY_MEDIA, media).sendToTarget();
mHandler.post(new Runnable() {
@Override
public void run() {
MediaUtils.openMediaNoUi(PluginService.this, media);
}
});
}
@Override
public void unBind(int index) throws RemoteException {
if (mCurrentIndex == index)
mCurrentIndex = -1;
}
};
}
......@@ -196,7 +257,6 @@ public class PluginService extends Service {
ServiceConnection serviceConnection;
IExtensionService binder;
IExtensionHost hostInterface;
ContentObserver contentObserver;
/**
* Only access on the async thread. The pair is (collapse token, operation)
......@@ -205,15 +265,5 @@ public class PluginService extends Service {
// = new LinkedList<Pair<Object, Operation>>();
}
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case PLAY_MEDIA:
MediaWrapper media = (MediaWrapper) msg.obj;
MediaUtils.openMediaNoUi(PluginService.this, media);
break;
}
}
};
private final Handler mHandler = new Handler();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment