[Android] Nicer unbind, and some cleaning

Geoffrey Métais git at videolan.org
Mon Dec 21 17:21:55 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 11 17:28:12 2015 +0100| [89f47cffaaad0ea64a7455022c8bb21c023d8877] | committer: Geoffrey Métais

Nicer unbind, and some cleaning

> https://code.videolan.org/videolan/vlc-android/commit/89f47cffaaad0ea64a7455022c8bb21c023d8877
---

 .../src/org/videolan/vlc/gui/MainActivity.java     | 11 ++++--
 .../org/videolan/vlc/plugin/ExtensionListing.java  | 46 ++--------------------
 .../src/org/videolan/vlc/plugin/PluginService.java | 14 ++-----
 3 files changed, 15 insertions(+), 56 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 6db3ed3..2bfd0c4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -221,8 +221,9 @@ public class MainActivity extends AudioPlayerContainerActivity implements Search
         reloadPreferences();
 
         // Bind service which discoverves au connects toplugins
-        bindService(new Intent(MainActivity.this,
-                PluginService.class), mPluginServiceConnection, Context.BIND_AUTO_CREATE);
+        if (!bindService(new Intent(MainActivity.this,
+                PluginService.class), mPluginServiceConnection, Context.BIND_AUTO_CREATE))
+            mPluginServiceConnection = null;
     }
 
     private void setupNavigationView() {
@@ -275,13 +276,17 @@ public class MainActivity extends AudioPlayerContainerActivity implements Search
     @Override
     protected void onStop() {
         super.onStop();
-        unbindService(mPluginServiceConnection);
+        if (mPluginServiceConnection != null) {
+            unbindService(mPluginServiceConnection);
+            mPluginServiceConnection = null;
+        }
     }
 
     private void loadPlugins() {
         List<ExtensionListing> plugins = mPluginService.getAvailableExtensions();
         if (plugins.isEmpty()) {
             unbindService(mPluginServiceConnection);
+            mPluginServiceConnection = null;
             mPluginService.stopSelf();
             return;
         }
diff --git a/vlc-android/src/org/videolan/vlc/plugin/ExtensionListing.java b/vlc-android/src/org/videolan/vlc/plugin/ExtensionListing.java
index bc82b1d..bbb332a 100644
--- a/vlc-android/src/org/videolan/vlc/plugin/ExtensionListing.java
+++ b/vlc-android/src/org/videolan/vlc/plugin/ExtensionListing.java
@@ -34,10 +34,8 @@ public class ExtensionListing implements Parcelable {
     private ComponentName mComponentName;
     private int mProtocolVersion;
     private boolean mCompatible;
-    private boolean mWorldReadable;
     private String mTitle;
     private String mDescription;
-    private int mIcon;
     private ComponentName mSettingsActivity;
 
     private PluginService.Connection connection;
@@ -65,7 +63,7 @@ public class ExtensionListing implements Parcelable {
     }
 
     /**
-     * Returns the version of the {@link com.google.android.apps.dashclock.api.DashClockExtension}
+     * Returns the version of the {@link org.videolan.vlc.plugin.api.VLCExtensionService}
      * protocol used by the extension.
      */
     public int protocolVersion() {
@@ -73,7 +71,7 @@ public class ExtensionListing implements Parcelable {
     }
 
     /**
-     * Sets the version of the {@link com.google.android.apps.dashclock.api.DashClockExtension}
+     * Sets the version of the {@link org.videolan.vlc.plugin.api.VLCExtensionService}
      * protocol used by the extension.
      */
     public ExtensionListing protocolVersion(int protocolVersion) {
@@ -83,7 +81,7 @@ public class ExtensionListing implements Parcelable {
 
     /**
      * Returns whether this extension is compatible to the host application; that is whether
-     * the version of the {@link com.google.android.apps.dashclock.api.DashClockExtension}
+     * the version of the {@link org.videolan.vlc.plugin.api.VLCExtensionService}
      * protocol used by the extension matches what is used by the host application.
      */
     public boolean compatible() {
@@ -99,23 +97,6 @@ public class ExtensionListing implements Parcelable {
     }
 
     /**
-     * Returns if the data of the ExtensionInfo is available to all hosts or only for the
-     * DashClock app.
-     */
-    public boolean worldReadable() {
-        return mWorldReadable;
-    }
-
-    /**
-     * Sets if the data of the ExtensionInfo is available to all hosts or only for the
-     * DashClock app.
-     */
-    public ExtensionListing worldReadable(boolean worldReadable) {
-        mWorldReadable = worldReadable;
-        return this;
-    }
-
-    /**
      * Returns the label of the extension.
      */
     public String title() {
@@ -146,23 +127,6 @@ public class ExtensionListing implements Parcelable {
     }
 
     /**
-     * Returns the ID of the drawable resource within the extension's package that represents this
-     * data. Default 0.
-     */
-    public int icon() {
-        return mIcon;
-    }
-
-    /**
-     * Sets the ID of the drawable resource within the extension's package that represents this
-     * data. Default 0.
-     */
-    public ExtensionListing icon(int icon) {
-        mIcon = icon;
-        return this;
-    }
-
-    /**
      * Returns the full qualified component name of the settings class to configure
      * the extension.
      */
@@ -209,10 +173,8 @@ public class ExtensionListing implements Parcelable {
             mComponentName = ComponentName.readFromParcel(in);
             mProtocolVersion = in.readInt();
             mCompatible = in.readInt() == 1;
-            mWorldReadable = in.readInt() == 1;
             mTitle = in.readString();
             mDescription = in.readString();
-            mIcon = in.readInt();
             boolean hasSettings = in.readInt() == 1;
             if (hasSettings) {
                 mSettingsActivity = ComponentName.readFromParcel(in);
@@ -232,10 +194,8 @@ public class ExtensionListing implements Parcelable {
         mComponentName.writeToParcel(parcel, 0);
         parcel.writeInt(mProtocolVersion);
         parcel.writeInt(mCompatible ? 1 : 0);
-        parcel.writeInt(mWorldReadable ? 1 : 0);
         parcel.writeString(mTitle);
         parcel.writeString(mDescription);
-        parcel.writeInt(mIcon);
         parcel.writeInt(mSettingsActivity != null ? 1 : 0);
         if (mSettingsActivity != null) {
             mSettingsActivity.writeToParcel(parcel, 0);
diff --git a/vlc-android/src/org/videolan/vlc/plugin/PluginService.java b/vlc-android/src/org/videolan/vlc/plugin/PluginService.java
index fd2c1ee..d76ae9d 100644
--- a/vlc-android/src/org/videolan/vlc/plugin/PluginService.java
+++ b/vlc-android/src/org/videolan/vlc/plugin/PluginService.java
@@ -94,6 +94,7 @@ public class PluginService extends Service {
         List<ResolveInfo> resolveInfos = pm.queryIntentServices(
                 new Intent(ACTION_EXTENSION), PackageManager.GET_META_DATA);
 
+        mPlugins.clear();
         for (ResolveInfo resolveInfo : resolveInfos) {
             ExtensionListing info = new ExtensionListing();
             info.componentName(new ComponentName(resolveInfo.serviceInfo.packageName,
@@ -102,7 +103,8 @@ public class PluginService extends Service {
             Bundle metaData = resolveInfo.serviceInfo.metaData;
             if (metaData != null) {
                 info.compatible(metaData.getInt("protocolVersion") == PROTOCOLE_VERSION);
-                info.worldReadable(metaData.getBoolean("worldReadable", false));
+                if (!info.compatible())
+                    continue;
                 info.description(metaData.getString("description"));
                 String settingsActivity = metaData.getString("settingsActivity");
                 if (!TextUtils.isEmpty(settingsActivity)) {
@@ -111,16 +113,8 @@ public class PluginService extends Service {
                 }
                 mPlugins.add(info);
             }
-            info.icon(resolveInfo.getIconResource());
-            //availableExtensions.add(info); TODO
-            Log.d(TAG, "componentName "+info.componentName().toString());
-            Log.d(TAG, " - title "+info.title());
-            Log.d(TAG, " - protocolVersion "+info.protocolVersion());
-            Log.d(TAG, " - settingsActivity " + info.settingsActivity());
-
-//            connectService(info);
         }
-        return plugins;
+        return mPlugins;
     }
 
     private List<ExtensionListing> mPlugins = new LinkedList<>();



More information about the Android mailing list