Example #1
0
        /// <summary>
        /// Gets the string value of the feature.
        /// </summary>
        /// <param name="key">The name of the feature.</param>
        /// <param name="value">The value of the given feature.</param>
        /// <returns>Returns true on success, otherwise false.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static bool TryGetValue(string key, out string value)
        {
            Interop.SystemInfo.SystemInfoValueType valueType;
            Interop.SystemInfo.SystemInfoType      keyType = GetValueType(key, out valueType);

            InformationError err = InformationError.InvalidParameter;

            if (keyType == Interop.SystemInfo.SystemInfoType.platform)
            {
                err = Interop.SystemInfo.SystemInfoGetPlatformString(key, out value);
            }
            else if (keyType == Interop.SystemInfo.SystemInfoType.Custom)
            {
                err = Interop.SystemInfo.SystemInfoGetCustomString(key, out value);
            }
            else
            {
                value = string.Empty;
            }

            if (err != InformationError.None)
            {
                Log.Warn(InformationErrorFactory.LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err));
                return(false);
            }

            return(true);
        }
        internal static void ThrowException(InformationError err)
        {
            InformationError error = (InformationError)err;

            if (error == InformationError.InvalidParameter)
            {
                throw new ArgumentException("Invalid parameter");
            }
            else if (error == InformationError.OutOfMemory)
            {
                throw new OutOfMemoryException("Out of memory");
            }
            else if (error == InformationError.Io)
            {
                throw new IOException("I/O Error");
            }
            else if (error == InformationError.RemoteIo)
            {
                throw new IOException("Remote I/O Error");
            }
            else if (error == InformationError.PermissionDenied)
            {
                throw new UnauthorizedAccessException("Permission denied");
            }
            else if (error == InformationError.NotSupported)
            {
                throw new NotSupportedException("Not supported");
            }
            else if (error == InformationError.NoData)
            {
                throw new NotSupportedException("No data");
            }
        }
Example #3
0
        /// <summary>
        /// Update the system memory information to the latest.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
        public void Update()
        {
            InformationError ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out Info);

            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get System memory information");
                InformationErrorFactory.ThrowException(ret);
            }
        }
Example #4
0
        private static Interop.SystemInfo.SystemInfoType GetValueType(string key, out Interop.SystemInfo.SystemInfoValueType valueType)
        {
            InformationError err = Interop.SystemInfo.SystemInfoGetPlatformType(key, out valueType);

            if (err == InformationError.None)
            {
                return(Interop.SystemInfo.SystemInfoType.platform);
            }

            Log.Debug(InformationErrorFactory.LogTag, string.Format("Key {0} not in platform system info", key));
            err = Interop.SystemInfo.SystemInfoGetCustomType(key, out valueType);
            if (err == InformationError.None)
            {
                return(Interop.SystemInfo.SystemInfoType.Custom);
            }

            Log.Debug(InformationErrorFactory.LogTag, string.Format("Key {0} not in custom system info", key));
            return(Interop.SystemInfo.SystemInfoType.None);
        }
Example #5
0
        /// <summary>
        /// Gets the status of runtime key.
        /// Note that this is a generic method.
        /// </summary>
        /// <typeparam name="T">The generic type to return.</typeparam>
        /// <param name="key">The runtime information key for which the current should be read.</param>
        /// <param name="value">The value of the given feature.</param>
        /// <returns>Returns true on success, otherwise false.</returns>
        internal static bool TryGetValue <T>(RuntimeInfoKey key, out T value)
        {
            Type type;

            value = default(T);

            if (!s_keyDataTypeMapping.TryGetValue(key, out type))
            {
                Log.Error(InformationErrorFactory.LogTag, "Invalid key");
                return(false);
            }

            if (type == typeof(bool))
            {
                InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out bool val);

                if (ret != InformationError.None)
                {
                    Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
                    return(false);
                }

                value = (T)(object)val;
            }
            else if (type == typeof(int))
            {
                InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out int val);

                if (ret != InformationError.None)
                {
                    Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
                    return(false);
                }

                value = (T)(object)val;
            }

            return(true);
        }