From: WonYoung Choi Date: Tue, 26 Apr 2016 10:11:09 +0000 (+0900) Subject: Fix alarms of Code Analyzer X-Git-Tag: submit/trunk/20170823.075128~121^2~162 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da45806a91ffcb8c859f692ab88e250ac94e79ce;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Fix alarms of Code Analyzer Change-Id: I4c2fe5113e5d3c9b0d4c8683ba1547e9c6b71c20 --- diff --git a/Tizen.Applications/CustomDictionary.xml b/Tizen.Applications/CustomDictionary.xml index ca9eb94..958b6fe 100755 --- a/Tizen.Applications/CustomDictionary.xml +++ b/Tizen.Applications/CustomDictionary.xml @@ -1,7 +1,17 @@ - - - Tizen - - + + + Tizen + ApplicationInfo + LaunchMode + AppControl + Wifi + Nfc + + + applicationinfo + launchmode + appcontrol + + diff --git a/Tizen.Applications/GlobalSuppressions.cs b/Tizen.Applications/GlobalSuppressions.cs index aef5e44..767e006 100755 Binary files a/Tizen.Applications/GlobalSuppressions.cs and b/Tizen.Applications/GlobalSuppressions.cs differ diff --git a/Tizen.Applications/Interop/Interop.AppEvent.cs b/Tizen.Applications/Interop/Interop.AppEvent.cs index 4fc04e0..a6b0d98 100755 --- a/Tizen.Applications/Interop/Interop.AppEvent.cs +++ b/Tizen.Applications/Interop/Interop.AppEvent.cs @@ -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"; } } } diff --git a/Tizen.Applications/Tizen.Applications.Messages/MessagePort.cs b/Tizen.Applications/Tizen.Applications.Messages/MessagePort.cs index 7c77e6a..48b6cf1 100755 --- a/Tizen.Applications/Tizen.Applications.Messages/MessagePort.cs +++ b/Tizen.Applications/Tizen.Applications.Messages/MessagePort.cs @@ -174,17 +174,32 @@ namespace Tizen.Applications.Messages } /// + /// Sends a untrusted message to the message port of a remote application. + /// + /// The message to be passed to the remote application, the recommended message size is under 4KB + /// The ID of the remote application + /// The name of the remote message port + public void Send(Bundle message, string remoteAppId, string remotePortName) + { + Send(message, remoteAppId, remotePortName, false); + } + + /// /// Sends a message to the message port of a remote application. /// /// The message to be passed to the remote application, the recommended message size is under 4KB /// The ID of the remote application /// The name of the remote message port /// If true the trusted message port of remote application otherwise false - 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) : diff --git a/Tizen.Applications/Tizen.Applications.csproj.user b/Tizen.Applications/Tizen.Applications.csproj.user index 55f44b9..07dbd5b 100755 --- a/Tizen.Applications/Tizen.Applications.csproj.user +++ b/Tizen.Applications/Tizen.Applications.csproj.user @@ -1,6 +1,6 @@  - ShowAllFiles + ProjectFiles \ No newline at end of file diff --git a/Tizen.Applications/Tizen.Applications/AppControl.cs b/Tizen.Applications/Tizen.Applications/AppControl.cs index 8783a70..df71e2d 100755 --- a/Tizen.Applications/Tizen.Applications/AppControl.cs +++ b/Tizen.Applications/Tizen.Applications/AppControl.cs @@ -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 /// public static IEnumerable GetMatchedApplicationIds(AppControl control) { + if (control == null) + { + throw new ArgumentNullException("control"); + } + List ids = new List(); 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. /// /// The AppControl - /// The callback function to be called when the reply is delivered /// Thrown when failed because of a null arguament /// Thrown when failed because of invalid operation /// Thrown when failed because of timeout @@ -424,13 +430,47 @@ namespace Tizen.Applications /// /// AppControl appControl = new AppControl(); /// appControl.ApplicationId = "org.tizen.calculator"; + /// AppControl.SendLaunchRequest(appControl); + /// + /// + public static void SendLaunchRequest(AppControl launchRequest) + { + SendLaunchRequest(launchRequest, null); + } + + /// + /// Sends the launch request. + /// + /// + /// 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. + /// + /// The AppControl + /// The callback function to be called when the reply is delivered + /// Thrown when failed because of arguament is invalid + /// Thrown when failed because of invalid operation + /// Thrown when failed because of timeout + /// http://tizen.org/privilege/appmanager.launch + /// + /// + /// AppControl appControl = new AppControl(); + /// appControl.ApplicationId = "org.tizen.calculator"; /// AppControl.SendLaunchRequest(appControl, (launchRequest, replyRequest, result) => { /// // ... /// }); /// /// - 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 /// 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 /// public void Add(string key, IEnumerable 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 /// 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 /// public bool TryGet(string key, out IEnumerable 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 /// 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 /// The name of the extra data /// If true the extra data is of array data type, otherwise false /// Thrown when the key is a zero-length string + /// Thrown when failed to check the key /// /// /// AppControl appControl = new AppControl(); @@ -796,50 +877,70 @@ namespace Tizen.Applications /// 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 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; diff --git a/Tizen.Applications/Tizen.Applications/ApplicationInfo.cs b/Tizen.Applications/Tizen.Applications/ApplicationInfo.cs index f512ee2..4b99bc0 100755 --- a/Tizen.Applications/Tizen.Applications/ApplicationInfo.cs +++ b/Tizen.Applications/Tizen.Applications/ApplicationInfo.cs @@ -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; } diff --git a/Tizen.Applications/Tizen.Applications/Bundle.cs b/Tizen.Applications/Tizen.Applications/Bundle.cs old mode 100644 new mode 100755 diff --git a/Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs b/Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs index 2d83114..70c06f0 100755 --- a/Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs +++ b/Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs @@ -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 /// 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); } } }