{
if (handle == null)
{
- throw new ArgumentNullException("handle");
+ throw new ArgumentNullException(nameof(handle));
}
- Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
- if (err != Interop.AppControl.ErrorCode.None)
+ if (handle.IsInvalid)
{
- throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+ throw new ArgumentNullException(nameof(handle), "handle is invalid");
+ }
+
+ bool mustRelease = false;
+ try
+ {
+ handle.DangerousAddRef(ref mustRelease);
+ Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+ }
+ }
+ catch (ObjectDisposedException e)
+ {
+ throw new ArgumentNullException(nameof(handle), e.Message);
+ }
+ finally
+ {
+ if (mustRelease)
+ {
+ handle.DangerousRelease();
+ }
}
}
/// </code>
/// </example>
/// <since_tizen> 3 </since_tizen>
+#pragma warning disable CA1056
public string Uri
+#pragma warning restore CA1056
{
get
{
{
if (control == null)
{
- throw new ArgumentNullException("control");
+ throw new ArgumentNullException(nameof(control));
}
List<string> ids = new List<string>();
}
/// <summary>
+ /// Sends the launch request with setting timeout.
+ /// </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.<br/>
+ /// To launch a service application, an explicit launch request with the application ID given by property ApplicationId MUST be sent.<br/>
+ /// It can set receiving timeout interval using timeout parameter.
+ /// If there is an error that is not related to timeout, the error is returned immediately regardless of the timeout value.
+ /// </remarks>
+ /// <param name="launchRequest">The AppControl.</param>
+ /// <param name="timeout">The timeout in milliseconds, the timeout range is 5000 to 30000.</param>
+ /// <exception cref="ArgumentNullException">Thrown when failed because of a null argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of an 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, 10000);
+ /// </code>
+ /// </example>
+ /// <since_tizen> 7.5 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void SendLaunchRequest(AppControl launchRequest, uint timeout)
+ {
+ SendLaunchRequest(launchRequest, timeout, null);
+ }
+
+ /// <summary>
/// Sends the launch request.
/// </summary>
/// <remarks>
{
if (launchRequest == null)
{
- throw new ArgumentNullException("launchRequest");
+ throw new ArgumentNullException(nameof(launchRequest));
}
Interop.AppControl.ErrorCode err;
}
/// <summary>
+ /// Sends the launch request with setting timeout
+ /// </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.<br/>
+ /// To launch a service application, an explicit launch request with the application ID given by property ApplicationId MUST be sent.<br/>
+ /// It can set receiving timeout interval using timeout parameter.
+ /// If there is an error that is not related to timeout, the error is returned immediately regardless of the timeout value.
+ /// </remarks>
+ /// <param name="launchRequest">The AppControl.</param>
+ /// <param name="timeout">The timeout in milliseconds, the timeout range is 5000 to 30000.</param>
+ /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered.</param>
+ /// <exception cref="ArgumentException">Thrown when failed because of the argument is invalid.</exception>
+ /// <exception cref="Exceptions.AppNotFoundException">Thrown when the application to run is not found.</exception>
+ /// <exception cref="Exceptions.LaunchFailedException">Thrown when the request failed to launch the application.</exception>
+ /// <exception cref="Exceptions.LaunchRejectedException">Thrown when the launch request is rejected.</exception>
+ /// <exception cref="Exceptions.OutOfMemoryException">Thrown when the memory is insufficient.</exception>
+ /// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
+ /// <exception cref="TimeoutException">Thrown when failed because of timeout. The timeout interval is set by timeout parameter.</exception>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <example>
+ /// <code>
+ /// AppControl appControl = new AppControl();
+ /// appControl.ApplicationId = "org.tizen.calculator";
+ /// AppControl.SendLaunchRequest(appControl, 10000, (launchRequest, replyRequest, result) => {
+ /// // ...
+ /// });
+ /// </code>
+ /// </example>
+ /// <since_tizen> 7.5 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void SendLaunchRequest(AppControl launchRequest, uint timeout, AppControlReplyCallback replyAfterLaunching)
+ {
+ if (launchRequest == null)
+ {
+ throw new ArgumentNullException(nameof(launchRequest));
+ }
+
+ Interop.AppControl.ErrorCode err;
+
+ if (replyAfterLaunching != null)
+ {
+ int id = 0;
+ lock (s_replyCallbackMaps)
+ {
+ id = s_reaustId++;
+ s_replyCallbackMaps[id] = replyAfterLaunching;
+ }
+ err = Interop.AppControl.SendLaunchRequestWithTimeout(launchRequest._handle, timeout, s_replyNativeCallback, (IntPtr)id);
+ }
+ else
+ {
+ err = Interop.AppControl.SendLaunchRequestWithTimeout(launchRequest._handle, timeout, null, IntPtr.Zero);
+ }
+
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ switch (err)
+ {
+ case Interop.AppControl.ErrorCode.InvalidParameter:
+ throw new ArgumentException("Invalid Arguments");
+ case Interop.AppControl.ErrorCode.TimedOut:
+ throw new TimeoutException("Timed out");
+ case Interop.AppControl.ErrorCode.OutOfMemory:
+ throw new Exceptions.OutOfMemoryException("Out-of-memory");
+ case Interop.AppControl.ErrorCode.AppNotFound:
+ throw new Exceptions.AppNotFoundException("App(" + launchRequest.ApplicationId + ") not found. Operation(" + launchRequest.Operation + ")");
+ case Interop.AppControl.ErrorCode.LaunchRejected:
+ throw new Exceptions.LaunchRejectedException("Launch rejected");
+ case Interop.AppControl.ErrorCode.LaunchFailed:
+ throw new Exceptions.LaunchFailedException("Launch failed");
+ case Interop.AppControl.ErrorCode.PermissionDenied:
+ throw new Exceptions.PermissionDeniedException("Permission denied");
+
+ default:
+ throw new Exceptions.LaunchRejectedException("Launch rejected");
+ }
+ }
+ }
+
+ /// <summary>
/// Sends the terminate request to the application that is launched by AppControl.
/// </summary>
/// <remarks>
{
if (terminateRequest == null)
{
- throw new ArgumentNullException("terminateRequest");
+ throw new ArgumentNullException(nameof(terminateRequest));
}
Interop.AppControl.ErrorCode err;
}
/// <summary>
+ /// Unsets the auto restart.
+ /// </summary>
+ /// <remarks>
+ /// The functionality of this method only applies to the caller application.
+ /// This method is only available for platform level signed applications.
+ /// </remarks>
+ /// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
+ /// <exception cref="Exceptions.OutOfMemoryException">Thrown when the memory is insufficient.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the memory is insufficient.</exception>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static void UnsetAutoRestart()
+ {
+ Interop.AppControl.ErrorCode err = Interop.AppControl.UnsetAutoRestart();
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ switch (err)
+ {
+ case Interop.AppControl.ErrorCode.PermissionDenied:
+ throw new Exceptions.PermissionDeniedException("Permission denied");
+ case Interop.AppControl.ErrorCode.OutOfMemory:
+ throw new Exceptions.OutOfMemoryException("Out of memory");
+ default:
+ throw new InvalidOperationException("err = " + err);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets all default applications.
+ /// </summary>
+ /// <returns>ApplicationIds.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
+ /// <example>
+ /// <code>
+ /// IEnumerable<string> applicationIds = AppControl.GetDefaultApplicationIds();
+ /// if (applicationIds != null)
+ /// {
+ /// foreach (string id in applicationIds)
+ /// {
+ /// // ...
+ /// }
+ /// }
+ /// </code>
+ /// </example>
+ /// <since_tizen> 11 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static IEnumerable<string> GetDefaultApplicationIds()
+ {
+ List<string> ids = new List<string>();
+ Interop.AppControl.DefaultApplicationCallback callback = (applicationId, userData) =>
+ {
+ if (applicationId == null)
+ {
+ return false;
+ }
+
+ ids.Add(applicationId);
+ return true;
+ };
+
+ Interop.AppControl.ErrorCode err = Interop.AppControl.ForeachDefaultApplication(callback, IntPtr.Zero);
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ throw new InvalidOperationException("Failed to get default application Ids. err = " + err);
+ }
+
+ return ids;
+ }
+
+ /// <summary>
+ /// Sets the window position.
+ /// </summary>
+ /// <param name="windowPosition">The window position object.</param>
+ /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the invalid operation error occurs.</exception>
+ /// <since_tizen> 11 </since_tizen>
+ public void SetWindowPosition(WindowPosition windowPosition)
+ {
+ if (windowPosition == null)
+ {
+ throw new ArgumentNullException(nameof(windowPosition));
+ }
+
+ Interop.AppControl.ErrorCode err = Interop.AppControl.SetWindowPosition(this.SafeAppControlHandle, windowPosition.PositionX, windowPosition.PositionY, windowPosition.Width, windowPosition.Height);
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ if (err == Interop.AppControl.ErrorCode.InvalidParameter)
+ {
+ throw new ArgumentException("Invalid arguments");
+ }
+ else
+ {
+ throw new InvalidOperationException("err = " + err);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the window position.
+ /// </summary>
+ /// <returns>The window position.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when the invalid operation error occurs.</exception>
+ /// <since_tizen> 11 </since_tizen>
+ public WindowPosition GetWindowPosition()
+ {
+ Interop.AppControl.ErrorCode err = Interop.AppControl.GetWindowPosition(this.SafeAppControlHandle, out int x, out int y, out int w, out int h);
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ throw new InvalidOperationException("err = " + err);
+ }
+
+ return new WindowPosition(x, y, w, h);
+ }
+
+ /// <summary>
/// Class for extra data.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+#pragma warning disable CA1034
public class ExtraDataCollection
+#pragma warning restore CA1034
{
private readonly SafeAppControlHandle _handle;
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
if (string.IsNullOrEmpty(value))
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
Interop.AppControl.ErrorCode err = Interop.AppControl.AddExtraData(_handle, key, value);
if (err != Interop.AppControl.ErrorCode.None)
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
if (value == null)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
string[] valueArray = value.ToArray();
Interop.AppControl.ErrorCode err = Interop.AppControl.AddExtraDataArray(_handle, key, valueArray, valueArray.Length);
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
Interop.AppControl.GetExtraData(_handle, key, out value);
if (value != null)
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
IntPtr valuePtr = IntPtr.Zero;
int len = -1;
{
IntPtr charArr = Marshal.ReadIntPtr(valuePtr, IntPtr.Size * i);
stringList.Add(Marshal.PtrToStringAnsi(charArr));
- Interop.Libc.Free(charArr);
+ _ = Interop.Libc.Free(charArr);
}
- Interop.Libc.Free(valuePtr);
+ _ = Interop.Libc.Free(valuePtr);
value = stringList;
return true;
}
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
Interop.AppControl.ErrorCode err = Interop.AppControl.RemoveExtraData(_handle, key);
if (err != Interop.AppControl.ErrorCode.None)
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
bool isArray = false;
Interop.AppControl.ErrorCode err = Interop.AppControl.IsExtraDataArray(_handle, key, out isArray);
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
string value = string.Empty;
Interop.AppControl.ErrorCode err = Interop.AppControl.GetExtraData(_handle, key, out value);
{
if (string.IsNullOrEmpty(key))
{
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
}
IntPtr valuePtr = IntPtr.Zero;
int len = -1;
{
IntPtr charArr = Marshal.ReadIntPtr(valuePtr, IntPtr.Size * i);
valueArray.Add(Marshal.PtrToStringAnsi(charArr));
- Interop.Libc.Free(charArr);
+ _ = Interop.Libc.Free(charArr);
}
- Interop.Libc.Free(valuePtr);
+ _ = Interop.Libc.Free(valuePtr);
}
return valueArray;
}