Fix alarms of Code Analyzer
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 26 Apr 2016 10:11:09 +0000 (19:11 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 26 Apr 2016 10:11:09 +0000 (19:11 +0900)
Change-Id: I4c2fe5113e5d3c9b0d4c8683ba1547e9c6b71c20

Tizen.Applications/CustomDictionary.xml
Tizen.Applications/GlobalSuppressions.cs
Tizen.Applications/Interop/Interop.AppEvent.cs
Tizen.Applications/Tizen.Applications.Messages/MessagePort.cs
Tizen.Applications/Tizen.Applications.csproj.user
Tizen.Applications/Tizen.Applications/AppControl.cs
Tizen.Applications/Tizen.Applications/ApplicationInfo.cs
Tizen.Applications/Tizen.Applications/Bundle.cs [changed mode: 0644->0755]
Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs

index ca9eb94..958b6fe 100755 (executable)
@@ -1,7 +1,17 @@
 <Dictionary>
-       <Words>
-               <Recognized>
-                       <Word>Tizen</Word>
-               </Recognized>
-       </Words>
+  <Words>
+    <Recognized>
+      <Word>Tizen</Word>
+      <Word>ApplicationInfo</Word>
+      <Word>LaunchMode</Word>
+      <Word>AppControl</Word>
+      <Word>Wifi</Word>
+      <Word>Nfc</Word>
+    </Recognized>
+    <Compound>
+      <Term CompoundAlternate="ApplicationInfo">applicationinfo</Term>
+      <Term CompoundAlternate="LaunchMode">launchmode</Term>
+      <Term CompoundAlternate="AppControl">appcontrol</Term>
+    </Compound>
+  </Words>
 </Dictionary>
index aef5e44..767e006 100755 (executable)
Binary files a/Tizen.Applications/GlobalSuppressions.cs and b/Tizen.Applications/GlobalSuppressions.cs differ
index 4fc04e0..a6b0d98 100755 (executable)
@@ -48,23 +48,23 @@ internal static partial class Interop
             }
         }
 
-        internal class EventNames
+        internal static class EventNames
         {
-            internal const string LowMemory = "tizen.system.event.low_memory";
-            internal const string LanguageSet = "tizen.system.event.language_set";
+            public const string LowMemory = "tizen.system.event.low_memory";
+            public const string LanguageSet = "tizen.system.event.language_set";
         }
 
-        internal class EventKeys
+        internal static class EventKeys
         {
-            internal const string LowMemory = "low_memory";
-            internal const string LanguageSet = "language_set";
+            public const string LowMemory = "low_memory";
+            public const string LanguageSet = "language_set";
         }
 
-        internal class EventValues
+        internal static class EventValues
         {
-            internal const string MemoryNormal = "normal";
-            internal const string MemorySoftWarning = "soft_warning";
-            internal const string MemoryHardWarning = "hard_warning";
+            public const string MemoryNormal = "normal";
+            public const string MemorySoftWarning = "soft_warning";
+            public const string MemoryHardWarning = "hard_warning";
         }
     }
 }
index 7c77e6a..48b6cf1 100755 (executable)
@@ -174,17 +174,32 @@ namespace Tizen.Applications.Messages
         }
 
         /// <summary>
+        /// Sends a untrusted message to the message port of a remote application.
+        /// </summary>
+        /// <param name="message">The message to be passed to the remote application, the recommended message size is under 4KB</param>
+        /// <param name="remoteAppId">The ID of the remote application</param>
+        /// <param name="remotePortName">The name of the remote message port</param>
+        public void Send(Bundle message, string remoteAppId, string remotePortName)
+        {
+            Send(message, remoteAppId, remotePortName, false);
+        }
+
+        /// <summary>
         /// Sends a message to the message port of a remote application.
         /// </summary>
         /// <param name="message">The message to be passed to the remote application, the recommended message size is under 4KB</param>
         /// <param name="remoteAppId">The ID of the remote application</param>
         /// <param name="remotePortName">The name of the remote message port</param>
         /// <param name="trusted">If true the trusted message port of remote application otherwise false</param>
-        public void Send(Bundle message, string remoteAppId, string remotePortName, bool trusted = false)
+        public void Send(Bundle message, string remoteAppId, string remotePortName, bool trusted)
         {
             if (!_listening)
             {
-                throw new InvalidOperationException("Sould start listen before send");
+                throw new InvalidOperationException("Should start listen before send");
+            }
+            if (message == null)
+            {
+                throw new ArgumentNullException("message");
             }
             int ret = trusted ?
                         Interop.MessagePort.SendTrustedMessageWithLocalPort(remoteAppId, remotePortName, message.Handle, _portId) :
index 55f44b9..07dbd5b 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <ProjectView>ShowAllFiles</ProjectView>
+    <ProjectView>ProjectFiles</ProjectView>
   </PropertyGroup>
 </Project>
\ No newline at end of file
index 8783a70..df71e2d 100755 (executable)
@@ -66,7 +66,9 @@ namespace Tizen.Applications
         {
             Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle);
             if (err != Interop.AppControl.ErrorCode.None)
+            {
                 throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+            }
         }
 
         #region Public Properties
@@ -268,7 +270,7 @@ namespace Tizen.Applications
                     Interop.AppControl.ErrorCode err = Interop.AppControl.GetAppId(_handle, out _applicationId);
                     if (err != Interop.AppControl.ErrorCode.None)
                     {
-                        Log.Warn(LogTag, "Failed to get the appId from the appcontrol. Err = " + err);
+                        Log.Warn(LogTag, "Failed to get the application id from the AppControl. Err = " + err);
                     }
                 }
                 return _applicationId;
@@ -282,7 +284,7 @@ namespace Tizen.Applications
                 }
                 else
                 {
-                    Log.Warn(LogTag, "Failed to set the appId to the appcontrol. Err = " + err);
+                    Log.Warn(LogTag, "Failed to set the application id to the AppControl. Err = " + err);
                 }
             }
         }
@@ -313,7 +315,7 @@ namespace Tizen.Applications
                 Interop.AppControl.ErrorCode err = Interop.AppControl.GetLaunchMode(_handle, out value);
                 if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    Log.Warn(LogTag, "Failed to get the launchMode from the appcontrol. Err = " + err);
+                    Log.Warn(LogTag, "Failed to get the LaunchMode from the AppControl. Err = " + err);
                 }
                 return (AppControlLaunchMode)value;
             }
@@ -322,7 +324,7 @@ namespace Tizen.Applications
                 Interop.AppControl.ErrorCode err = Interop.AppControl.SetLaunchMode(_handle, (int)value);
                 if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    Log.Warn(LogTag, "Failed to set the launchMode to the appcontrol. Err = " + err);
+                    Log.Warn(LogTag, "Failed to set the LaunchMode to the AppControl. Err = " + err);
                 }
             }
         }
@@ -373,6 +375,11 @@ namespace Tizen.Applications
         /// </example>
         public static IEnumerable<string> GetMatchedApplicationIds(AppControl control)
         {
+            if (control == null)
+            {
+                throw new ArgumentNullException("control");
+            }
+
             List<string> ids = new List<string>();
             Interop.AppControl.AppMatchedCallback callback = new Interop.AppControl.AppMatchedCallback(
                 (handle, applicationId, userData) =>
@@ -395,7 +402,7 @@ namespace Tizen.Applications
                 Interop.AppControl.ErrorCode err = Interop.AppControl.ForeachAppMatched(control._handle, callback, pointerToApplicationIds);
                 if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    throw new InvalidOperationException("Failed to get matched appids. err = " + err);
+                    throw new InvalidOperationException("Failed to get matched application ids. err = " + err);
                 }
                 return ids;
             }
@@ -415,7 +422,6 @@ namespace Tizen.Applications
         /// To launch a service application, an explicit launch request with application ID given by property ApplicationId MUST be sent.
         /// </remarks>
         /// <param name="launchRequest">The AppControl</param>
-        /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered</param>
         /// <exception cref="ArgumentNullException">Thrown when failed because of a null arguament</exception>
         /// <exception cref="InvalidOperationException">Thrown when failed because of invalid operation</exception>
         /// <exception cref="TimeoutException">Thrown when failed because of timeout</exception>
@@ -424,13 +430,47 @@ namespace Tizen.Applications
         /// <code>
         /// AppControl appControl = new AppControl();
         /// appControl.ApplicationId = "org.tizen.calculator";
+        /// AppControl.SendLaunchRequest(appControl);
+        /// </code>
+        /// </example>
+        public static void SendLaunchRequest(AppControl launchRequest)
+        {
+            SendLaunchRequest(launchRequest, null);
+        }
+
+        /// <summary>
+        /// Sends the launch request.
+        /// </summary>
+        /// <remarks>
+        /// The operation is mandatory information for the launch request. 
+        /// If the operation is not specified, AppControlOperations.Default is used by default.
+        /// If the operation is AppControlOperations.Default, the application ID is mandatory to explicitly launch the application. \n
+        /// Since Tizen 2.4, the launch request of the service application over out of packages is restricted by the platform. 
+        /// Also, implicit launch requests are NOT delivered to service applications since 2.4. 
+        /// To launch a service application, an explicit launch request with application ID given by property ApplicationId MUST be sent.
+        /// </remarks>
+        /// <param name="launchRequest">The AppControl</param>
+        /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered</param>
+        /// <exception cref="ArgumentException">Thrown when failed because of arguament is invalid</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of invalid operation</exception>
+        /// <exception cref="TimeoutException">Thrown when failed because of timeout</exception>
+        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+        /// <example>
+        /// <code>
+        /// AppControl appControl = new AppControl();
+        /// appControl.ApplicationId = "org.tizen.calculator";
         /// AppControl.SendLaunchRequest(appControl, (launchRequest, replyRequest, result) => {
         ///     // ...
         /// });
         /// </code>
         /// </example>
-        public static void SendLaunchRequest(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching = null)
+        public static void SendLaunchRequest(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching)
         {
+            if (launchRequest == null)
+            {
+                throw new ArgumentNullException("launchRequest");
+            }
+
             Interop.AppControl.ErrorCode err;
 
             err = Interop.AppControl.EnableAppStartedResultEvent(launchRequest._handle);
@@ -469,20 +509,17 @@ namespace Tizen.Applications
                 err = Interop.AppControl.SendLaunchRequest(launchRequest._handle, null, IntPtr.Zero);
             }
 
-            switch (err)
+            if (err != Interop.AppControl.ErrorCode.None)
             {
-                case Interop.AppControl.ErrorCode.InvalidParameter:
-                    throw new ArgumentNullException("Invalid parameter: key is a zero-length string");
-                case Interop.AppControl.ErrorCode.AppNotFound:
-                    throw new InvalidOperationException("App not found");
-                case Interop.AppControl.ErrorCode.LaunchRejected:
-                    throw new InvalidOperationException("Launch rejected");
-                case Interop.AppControl.ErrorCode.LaunchFailed:
-                    throw new InvalidOperationException("Launch failed");
-                case Interop.AppControl.ErrorCode.TimedOut:
-                    throw new TimeoutException("Timed out");
-                case Interop.AppControl.ErrorCode.PermissionDenied:
-                    throw new InvalidOperationException("Permission denied");
+                switch (err)
+                {
+                    case Interop.AppControl.ErrorCode.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.AppControl.ErrorCode.TimedOut:
+                        throw new TimeoutException("Timed out");
+                    default:
+                        throw new InvalidOperationException("Error = " + err);
+                }
             }
         }
 
@@ -516,13 +553,26 @@ namespace Tizen.Applications
             /// </example>
             public void Add(string key, string value)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
+                if (string.IsNullOrEmpty(value))
+                {
+                    throw new ArgumentNullException("value");
+                }
                 Interop.AppControl.ErrorCode err = Interop.AppControl.AddExtraData(_handle, key, value);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key or value is a zero-length string");
-                    case Interop.AppControl.ErrorCode.KeyRejected:
-                        throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                    switch (err)
+                    {
+                        case Interop.AppControl.ErrorCode.InvalidParameter:
+                            throw new ArgumentException("Invalid parameter: key or value is a zero-length string");
+                        case Interop.AppControl.ErrorCode.KeyRejected:
+                            throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                        default:
+                            throw new InvalidOperationException("Error = " + err);
+                    }
                 }
             }
 
@@ -545,14 +595,27 @@ namespace Tizen.Applications
             /// </example>
             public void Add(string key, IEnumerable<string> value)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
+                if (value == null)
+                {
+                    throw new ArgumentNullException("value");
+                }
                 string[] valueArray = value.ToArray();
                 Interop.AppControl.ErrorCode err = Interop.AppControl.AddExtraDataArray(_handle, key, valueArray, valueArray.Length);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key or value is a zero-length string");
-                    case Interop.AppControl.ErrorCode.KeyRejected:
-                        throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                    switch (err)
+                    {
+                        case Interop.AppControl.ErrorCode.InvalidParameter:
+                            throw new ArgumentException("Invalid parameter: key or value is a zero-length string");
+                        case Interop.AppControl.ErrorCode.KeyRejected:
+                            throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                        default:
+                            throw new InvalidOperationException("Error = " + err);
+                    }
                 }
             }
 
@@ -679,6 +742,10 @@ namespace Tizen.Applications
             /// </example>
             public bool TryGet(string key, out string value)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 Interop.AppControl.GetExtraData(_handle, key, out value);
                 if (value != null)
                 {
@@ -716,6 +783,10 @@ namespace Tizen.Applications
             /// </example>
             public bool TryGet(string key, out IEnumerable<string> value)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 IntPtr valuePtr = IntPtr.Zero;
                 int len = -1;
                 Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraDataArray(_handle, key, out valuePtr, out len);
@@ -754,15 +825,24 @@ namespace Tizen.Applications
             /// </example>
             public void Remove(string key)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 Interop.AppControl.ErrorCode err = Interop.AppControl.RemoveExtraData(_handle, key);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key is a zero-length string");
-                    case Interop.AppControl.ErrorCode.KeyNotFound:
-                        throw new KeyNotFoundException("Key is not found"); ;
-                    case Interop.AppControl.ErrorCode.KeyRejected:
-                        throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                    switch (err)
+                    {
+                        case Interop.AppControl.ErrorCode.InvalidParameter:
+                            throw new ArgumentException("Invalid parameter: key is a zero-length string");
+                        case Interop.AppControl.ErrorCode.KeyNotFound:
+                            throw new KeyNotFoundException("Key is not found"); ;
+                        case Interop.AppControl.ErrorCode.KeyRejected:
+                            throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                        default:
+                            throw new InvalidOperationException("Error = " + err);
+                    }
                 }
             }
 
@@ -788,6 +868,7 @@ namespace Tizen.Applications
             /// <param name="key">The name of the extra data</param>
             /// <returns>If true the extra data is of array data type, otherwise false</returns>
             /// <exception cref="ArgumentNullException">Thrown when the key is a zero-length string</exception>
+            /// <exception cref="InvalidOperationException">Thrown when failed to check the key</exception>
             /// <example>
             /// <code>
             /// AppControl appControl = new AppControl();
@@ -796,50 +877,70 @@ namespace Tizen.Applications
             /// </example>
             public bool IsCollection(string key)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 bool isArray = false;
                 Interop.AppControl.ErrorCode err = Interop.AppControl.IsExtraDataArray(_handle, key, out isArray);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key is a zero-length string");
+                    throw new InvalidOperationException("Error = " + err);
                 }
                 return isArray;
             }
 
             private string GetData(string key)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 string value = string.Empty;
                 Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraData(_handle, key, out value);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key is a zero-length string");
-                    case Interop.AppControl.ErrorCode.KeyNotFound:
-                        throw new KeyNotFoundException("Key is not found"); ;
-                    case Interop.AppControl.ErrorCode.InvalidDataType:
-                        throw new ArgumentException("Invalid data type: value is data collection type");
-                    case Interop.AppControl.ErrorCode.KeyRejected:
-                        throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                    switch (err)
+                    {
+                        case Interop.AppControl.ErrorCode.InvalidParameter:
+                            throw new ArgumentException("Invalid parameter: key is a zero-length string");
+                        case Interop.AppControl.ErrorCode.KeyNotFound:
+                            throw new KeyNotFoundException("Key is not found"); ;
+                        case Interop.AppControl.ErrorCode.InvalidDataType:
+                            throw new ArgumentException("Invalid data type: value is data collection type");
+                        case Interop.AppControl.ErrorCode.KeyRejected:
+                            throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                        default:
+                            throw new InvalidOperationException("Error = " + err);
+                    }
                 }
                 return value;
             }
 
             private IEnumerable<string> GetDataCollection(string key)
             {
+                if (string.IsNullOrEmpty(key))
+                {
+                    throw new ArgumentNullException("key");
+                }
                 IntPtr valuePtr = IntPtr.Zero;
                 int len = -1;
-
                 Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraDataArray(_handle, key, out valuePtr, out len);
-                switch (err)
+                if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    case Interop.AppControl.ErrorCode.InvalidParameter:
-                        throw new ArgumentNullException("Invalid parameter: key is a zero-length string");
-                    case Interop.AppControl.ErrorCode.KeyNotFound:
-                        throw new KeyNotFoundException("Key is not found"); ;
-                    case Interop.AppControl.ErrorCode.InvalidDataType:
-                        throw new ArgumentException("Invalid data type: value is data collection type");
-                    case Interop.AppControl.ErrorCode.KeyRejected:
-                        throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                    switch (err)
+                    {
+                        case Interop.AppControl.ErrorCode.InvalidParameter:
+                            throw new ArgumentException("Invalid parameter: key is a zero-length string");
+                        case Interop.AppControl.ErrorCode.KeyNotFound:
+                            throw new KeyNotFoundException("Key is not found"); ;
+                        case Interop.AppControl.ErrorCode.InvalidDataType:
+                            throw new ArgumentException("Invalid data type: value is data collection type");
+                        case Interop.AppControl.ErrorCode.KeyRejected:
+                            throw new ArgumentException("Key is rejected: the key is system-defined key.");
+                        default:
+                            throw new InvalidOperationException("Error = " + err);
+                    }
                 }
 
                 string[] valueArray = null;
index f512ee2..4b99bc0 100755 (executable)
@@ -51,7 +51,7 @@ namespace Tizen.Applications
         {
             get
             {
-                if (_applicationId != string.Empty)
+                if (!string.IsNullOrEmpty(_applicationId))
                     return _applicationId;
                 IntPtr infoHandle = GetInfoHandle();
                 string appid = string.Empty;
@@ -339,7 +339,7 @@ namespace Tizen.Applications
                 Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppManagerGetAppInfo(_applicationId, out infoHandle);
                 if (err != Interop.ApplicationManager.ErrorCode.None)
                 {
-                    Log.Warn(LogTag, "Failed to get ApplicationInfo handle.");
+                    Log.Warn(LogTag, "Failed to get the handle of the ApplicationInfo.");
                 }
                 _infoHandle = infoHandle;
             }
old mode 100644 (file)
new mode 100755 (executable)
index 2d83114..70c06f0 100755 (executable)
@@ -66,7 +66,7 @@ namespace Tizen.Applications
                 Interop.AppControl.ErrorCode err = Interop.AppControl.GetCaller(_handle, out value);
                 if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    Log.Warn(LogTag, "Failed to get the caller appId from the appcontrol. Err = " + err);
+                    Log.Warn(LogTag, "Failed to get the caller application id from the AppControl. Err = " + err);
                 }
                 return value;
             }
@@ -95,7 +95,7 @@ namespace Tizen.Applications
                 Interop.AppControl.ErrorCode err = Interop.AppControl.IsReplyRequested(_handle, out value);
                 if (err != Interop.AppControl.ErrorCode.None)
                 {
-                    Log.Warn(LogTag, "Failed to check the replyRequested of the appcontrol. Err = " + err);
+                    Log.Warn(LogTag, "Failed to check the reply  of the AppControl is requested. Err = " + err);
                 }
                 return value;
             }
@@ -123,9 +123,13 @@ namespace Tizen.Applications
         /// </example>
         public void ReplyToLaunchRequest(AppControl replyRequest, AppControlReplyResult result)
         {
+            if (replyRequest == null)
+            {
+                throw new ArgumentNullException("replyRequest");
+            }
             Interop.AppControl.ErrorCode err = Interop.AppControl.ReplyToLaunchRequest(replyRequest._handle, this._handle, (int)result);
-            if (err == Interop.AppControl.ErrorCode.InvalidParameter)
-                throw new ArgumentException("Invalid parameter of ReplyToLaunchRequest()");
+            if (err != Interop.AppControl.ErrorCode.None)
+                throw new InvalidOperationException("Failed to reply. Err = " + err);
         }
     }
 }