Added a H264 availability check.
authorArmin Novak <armin.novak@thincast.com>
Thu, 23 Feb 2017 11:31:08 +0000 (12:31 +0100)
committerArmin Novak <armin.novak@thincast.com>
Thu, 23 Feb 2017 11:31:08 +0000 (12:31 +0100)
client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/presentation/BookmarkActivity.java
client/Android/Studio/freeRDPCore/src/main/java/com/freerdp/freerdpcore/services/LibFreeRDP.java
client/Android/Studio/freeRDPCore/src/main/res/values/strings.xml
client/Android/Studio/freeRDPCore/src/main/res/xml/performance_flags.xml
client/Android/Studio/freeRDPCore/src/main/res/xml/performance_flags_3g.xml

index 873ef52..6cc26fc 100644 (file)
@@ -18,7 +18,10 @@ import android.os.Bundle;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
 import android.util.Log;
+import android.view.View;
 
 import com.freerdp.freerdpcore.R;
 import com.freerdp.freerdpcore.application.GlobalApp;
@@ -26,6 +29,7 @@ import com.freerdp.freerdpcore.domain.BookmarkBase;
 import com.freerdp.freerdpcore.domain.ConnectionReference;
 import com.freerdp.freerdpcore.domain.ManualBookmark;
 import com.freerdp.freerdpcore.services.BookmarkBaseGateway;
+import com.freerdp.freerdpcore.services.LibFreeRDP;
 import com.freerdp.freerdpcore.utils.RDPFileParser;
 
 import java.io.File;
@@ -55,14 +59,15 @@ public class BookmarkActivity extends PreferenceActivity implements
     private static boolean settings_changed = false;
     private static boolean new_bookmark = false;
     private int current_preferences;
-
+    
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        PreferenceManager mgr = getPreferenceManager();
         // init shared preferences for activity
-        getPreferenceManager().setSharedPreferencesName("TEMP");
-        getPreferenceManager().setSharedPreferencesMode(MODE_PRIVATE);
+        mgr.setSharedPreferencesName("TEMP");
+        mgr.setSharedPreferencesMode(MODE_PRIVATE);
 
         if (bookmark == null) {
             // if we have a bookmark id set in the extras we are in edit mode
@@ -112,15 +117,15 @@ public class BookmarkActivity extends PreferenceActivity implements
             // hide gateway settings if we edit a non-manual bookmark
             if (current_preferences == PREFERENCES_ADVANCED
                     && bookmark.getType() != ManualBookmark.TYPE_MANUAL) {
-                getPreferenceScreen().removePreference(
-                        findPreference("bookmark.enable_gateway"));
-                getPreferenceScreen().removePreference(
-                        findPreference("bookmark.gateway"));
+                PreferenceScreen screen = getPreferenceScreen();
+                screen.removePreference(findPreference("bookmark.enable_gateway"));
+                screen.removePreference(findPreference("bookmark.gateway"));
             }
 
+            updateH264Preferences();
+
             // update preferences from bookmark
-            bookmark.writeToSharedPreferences(getPreferenceManager()
-                    .getSharedPreferences());
+            bookmark.writeToSharedPreferences(mgr.getSharedPreferences());
 
             // no settings changed yet
             settings_changed = false;
@@ -168,15 +173,34 @@ public class BookmarkActivity extends PreferenceActivity implements
         }
 
         // update UI with bookmark data
-        SharedPreferences spref = getPreferenceManager().getSharedPreferences();
+        SharedPreferences spref = mgr.getSharedPreferences();
         initSettings(spref);
 
         // register for preferences changed notification
-        getPreferenceManager().getSharedPreferences()
-                .registerOnSharedPreferenceChangeListener(this);
+        mgr.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
 
         // set the correct component names in our preferencescreen settings
         setIntentComponentNames();
+
+        updateH264Preferences();
+    }
+
+    private void updateH264Preferences() {
+        if (!LibFreeRDP.hasH264Support()) {
+            final int preferenceIdList[] = {
+                    R.string.preference_key_h264,
+                    R.string.preference_key_h264_3g
+            };
+
+            PreferenceManager mgr = getPreferenceManager();
+            for (int id : preferenceIdList) {
+                final String key = getString(id);
+                Preference preference = mgr.findPreference(key);
+                if (preference != null) {
+                    preference.setEnabled(false);
+                }
+            }
+        }
     }
 
     private void updateBookmarkFromFile(ManualBookmark bookmark,
@@ -672,5 +696,4 @@ public class BookmarkActivity extends PreferenceActivity implements
             }
         }
     }
-
 }
index 69620bd..ba6902a 100644 (file)
@@ -26,10 +26,12 @@ import java.util.ArrayList;
 public class LibFreeRDP {
     private static final String TAG = "LibFreeRDP";
     private static EventListener listener;
+    private static boolean mHasH264 = true;
 
     static {
+        final String h264 = "openh264";
         final String[] libraries = {
-                "openh264", "freerdp-openssl", "jpeg", "winpr2",
+                h264, "freerdp-openssl", "jpeg", "winpr2",
                 "freerdp2", "freerdp-client2", "freerdp-android2"};
         final String LD_PATH = System.getProperty("java.library.path");
 
@@ -39,10 +41,17 @@ public class LibFreeRDP {
                 System.loadLibrary(lib);
             } catch (UnsatisfiedLinkError e) {
                 Log.e(TAG, "Failed to load library " + lib + ": " + e.toString());
+                if (lib.equals(h264)) {
+                    mHasH264 = false;
+                }
             }
         }
     }
 
+    public static boolean hasH264Support() {
+        return mHasH264;
+    }
+
     private static native String freerdp_get_jni_version();
 
     private static native String freerdp_get_version();
@@ -118,7 +127,7 @@ public class LibFreeRDP {
 
         final String clientName = ApplicationSettingsActivity.getClientName(context);
         if (!clientName.isEmpty()) {
-            args.add("/client-hostname:\""+clientName+"\"");
+            args.add("/client-hostname:\"" + clientName + "\"");
         }
         String certName = "";
         if (bookmark.getType() != BookmarkBase.TYPE_MANUAL) {
@@ -260,7 +269,7 @@ public class LibFreeRDP {
 
         final String clientName = ApplicationSettingsActivity.getClientName(context);
         if (!clientName.isEmpty()) {
-            args.add("/client-hostname:\""+clientName+"\"");
+            args.add("/client-hostname:\"" + clientName + "\"");
         }
 
         // Parse hostname and port. Set to 'v' argument
index 342b089..300c38f 100644 (file)
     <string name="pref_ringtone_silent">Silent</string>
 
     <string name="pref_title_vibrate">Vibrate</string>
+    <string name="preference_key_h264_3g" translatable="false">bookmark.perf_gfx_h264</string>
+    <string name="preference_key_h264" translatable="false">bookmark.perf_gfx_h264</string>
 </resources>
index 214b0c3..4973364 100644 (file)
@@ -18,7 +18,7 @@
             android:title="@string/settings_perf_gfx" />
         <CheckBoxPreference
             android:dependency="bookmark.perf_gfx"
-            android:key="bookmark.perf_gfx_h264"
+            android:key="@string/preference_key_h264"
             android:title="@string/settings_perf_gfx_h264" />
         <CheckBoxPreference
             android:key="bookmark.perf_wallpaper"
index d8bfa11..c1e2e50 100644 (file)
             android:key="bookmark.perf_remotefx_3g"
             android:title="@string/settings_perf_remotefx" />
         <CheckBoxPreference
+            android:key="bookmark.perf_gfx_3g"
+            android:title="@string/settings_perf_gfx" />
+        <CheckBoxPreference
+            android:dependency="bookmark.perf_gfx_3g"
+            android:key="@string/preference_key_h264_3g"
+            android:title="@string/settings_perf_gfx_h264" />
+        <CheckBoxPreference
             android:key="bookmark.perf_wallpaper_3g"
             android:title="@string/settings_perf_wallpaper" />
         <CheckBoxPreference