[Information] Sync with API4 branch (#266)
authorkichankwon <35328573+kichankwon@users.noreply.github.com>
Fri, 25 May 2018 01:26:04 +0000 (10:26 +0900)
committerGitHub <noreply@github.com>
Fri, 25 May 2018 01:26:04 +0000 (10:26 +0900)
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs [changed mode: 0644->0755]
src/Tizen.System.Information/RuntimeInfo/TvProductHelper.cs [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 973957d..8dde55d
@@ -29,13 +29,33 @@ namespace Tizen.System
             Handler = null;
         }
 
+        private static Interop.RuntimeInfo.RuntimeInformationChangedCallback __callback;
+
         internal event EventHandler<RuntimeFeatureStatusChangedEventArgs> EventHandler
         {
             add
             {
                 if (Handler == null)
                 {
-                    InformationError ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(TvProductHelper.ConvertKeyIfTvProduct(Key), RuntimeInformationChangedCallback, IntPtr.Zero);
+                    __callback = (RuntimeInfoKey num, IntPtr userData) =>
+                    {
+                        string strKey = "Invalid";
+                        RuntimeInfoKey key = TvProductHelper.ReconvertKeyIfTvProduct(num);
+
+                        if (key > 0 && Information.EnumStringMapping.ContainsKey(key))
+                        {
+                            strKey = Information.EnumStringMapping[key];
+                        }
+
+                        RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs()
+                        {
+                            Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + strKey
+                        };
+
+                        Handler?.Invoke(null, eventArgs);
+                    };
+
+                    InformationError ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(TvProductHelper.ConvertKeyIfTvProduct(Key), __callback, IntPtr.Zero);
                     if (ret != InformationError.None)
                     {
                         Log.Error(InformationErrorFactory.LogTag, "Interop failed to add event handler");
@@ -58,15 +78,5 @@ namespace Tizen.System
                 }
             }
         }
-
-        private void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData)
-        {
-            RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs()
-            {
-                Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + (Information.EnumStringMapping.ContainsKey(key) ? Information.EnumStringMapping[key] : "Invalid")
-            };
-
-            Handler?.Invoke(null, eventArgs);
-        }
     }
 }
old mode 100644 (file)
new mode 100755 (executable)
index ef5f846..5454f25
@@ -19,6 +19,7 @@ using System.Collections.Generic;
 
 namespace Tizen.System
 {
+    /// This class is for a TV product. It will be removed.
     internal static class TvProductHelper
     {
         private static int is_TV_product = -1;
@@ -41,40 +42,67 @@ namespace Tizen.System
             [RuntimeInfoKey.AudioJackConnector] = 20
         };
 
-        /// This function is for a TV product. It will be removed.
-        internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
+        private static void CheckTvProduct()
         {
             bool is_key_existed = false;
             string profile;
-            int key_TV = -1;
 
-            if (is_TV_product == -1)
-            {
 #pragma warning disable CS0618 // Type or member is obsolete
-                is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
+            is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
 #pragma warning restore CS0618 // Type or member is obsolete
-                if (is_key_existed && String.Compare(profile, "TV") == 0)
-                {
-                    is_TV_product = 1;
-                }
-                else
-                {
-                    is_TV_product = 0;
-                }
+            if (is_key_existed && String.Compare(profile, "TV") == 0)
+            {
+                is_TV_product = 1;
             }
+            else
+            {
+                is_TV_product = 0;
+            }
+        }
 
-            if (is_TV_product == 0)
+        internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
+        {
+            if (is_TV_product == -1)
             {
-                return key;
+                CheckTvProduct();
             }
-            else
+
+            if (is_TV_product == 1)
             {
-                if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV))
+                if (!s_keyTVkeyMapping.TryGetValue(key, out int key_TV))
                 {
                     InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
                 }
                 return (RuntimeInfoKey)key_TV;
             }
+            else
+            {
+                return key;
+            }
+        }
+
+        internal static RuntimeInfoKey ReconvertKeyIfTvProduct(RuntimeInfoKey key)
+        {
+            if (is_TV_product == -1)
+            {
+                CheckTvProduct();
+            }
+
+            if (is_TV_product == 1)
+            {
+                foreach (KeyValuePair<RuntimeInfoKey, int> kvp in s_keyTVkeyMapping)
+                {
+                    if (kvp.Value == (int)key)
+                        return kvp.Key;
+                }
+
+                Log.Error(InformationErrorFactory.LogTag, "Key mapping failed");
+                return 0;
+            }
+            else
+            {
+                return key;
+            }
         }
     }
 }