78741eb2149241c0cf178c8337a5f59f3f4e8a4b
[platform/core/csapi/tizenfx.git] / src / Tizen.System.Information / RuntimeInfo / TvProductHelper.cs
1 /*
2 * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace Tizen.System
21 {
22     /// This class is for a TV product. It will be removed.
23     internal static class TvProductHelper
24     {
25         private static int is_TV_product = -1;
26
27         private static readonly Dictionary<RuntimeInfoKey, int> s_keyTVkeyMapping = new Dictionary<RuntimeInfoKey, int>
28         {
29             [RuntimeInfoKey.Bluetooth] = 5,
30             [RuntimeInfoKey.WifiHotspot] = 6,
31             [RuntimeInfoKey.BluetoothTethering] = 7,
32             [RuntimeInfoKey.UsbTethering] = 8,
33             [RuntimeInfoKey.PacketData] = 13,
34             [RuntimeInfoKey.DataRoaming] = 14,
35             [RuntimeInfoKey.Vibration] = 16,
36             [RuntimeInfoKey.AudioJack] = 20,
37             [RuntimeInfoKey.BatteryIsCharging] = 22,
38             [RuntimeInfoKey.TvOut] = 18,
39             [RuntimeInfoKey.Charger] = 26,
40             [RuntimeInfoKey.AutoRotation] = 28,
41             [RuntimeInfoKey.Gps] = 21,
42             [RuntimeInfoKey.AudioJackConnector] = 20
43         };
44
45         private static void CheckTvProduct()
46         {
47             bool is_key_existed = false;
48             string profile;
49
50 #pragma warning disable CS0618 // Type or member is obsolete
51             is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
52 #pragma warning restore CS0618 // Type or member is obsolete
53             if (is_key_existed && (String.Compare(profile, "TV") == 0 || String.Compare(profile, "AV") == 0))
54             {
55                 is_TV_product = 1;
56             }
57             else
58             {
59                 is_TV_product = 0;
60             }
61         }
62
63         internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
64         {
65             if (is_TV_product == -1)
66             {
67                 CheckTvProduct();
68             }
69
70             if (is_TV_product == 1)
71             {
72                 if (!s_keyTVkeyMapping.TryGetValue(key, out int key_TV))
73                 {
74                     InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
75                 }
76                 return (RuntimeInfoKey)key_TV;
77             }
78             else
79             {
80                 return key;
81             }
82         }
83
84         internal static RuntimeInfoKey ReconvertKeyIfTvProduct(RuntimeInfoKey key)
85         {
86             if (is_TV_product == -1)
87             {
88                 CheckTvProduct();
89             }
90
91             if (is_TV_product == 1)
92             {
93                 foreach (KeyValuePair<RuntimeInfoKey, int> kvp in s_keyTVkeyMapping)
94                 {
95                     if (kvp.Value == (int)key)
96                         return kvp.Key;
97                 }
98
99                 Log.Error(InformationErrorFactory.LogTag, "Key mapping failed");
100                 return 0;
101             }
102             else
103             {
104                 return key;
105             }
106         }
107     }
108 }