+ /// Sends the launch request asynchronously.
+ /// </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/>
+ /// 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 the 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>
+ /// <returns>A task with the result of the launch request.</returns>
+ /// <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.LaunchRejectedException">Thrown when the launch request is rejected.</exception>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <since_tizen> 6 </since_tizen>
+ public static Task<AppControlResult> SendLaunchRequestAsync(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching)
+ {
+ if (launchRequest == null)
+ {
+ throw new ArgumentNullException(nameof(launchRequest));
+ }
+
+ var task = new TaskCompletionSource<AppControlResult>();
+ Interop.AppControl.ErrorCode err;
+ int requestId = 0;
+
+ lock (s_resultNativeCallbackMaps)
+ {
+ requestId = s_reaustId++;
+ s_resultNativeCallbackMaps[requestId] = (handle, result, userData) =>
+ {
+ task.SetResult((AppControlResult)result);
+ lock (s_resultNativeCallbackMaps)
+ {
+ s_resultNativeCallbackMaps.Remove((int)userData);
+ }
+ };
+ }
+
+ if (replyAfterLaunching != null)
+ {
+ lock (s_replyCallbackMaps)
+ {
+ s_replyCallbackMaps[requestId] = replyAfterLaunching;
+ }
+ err = Interop.AppControl.SendLaunchRequestAsync(launchRequest.SafeAppControlHandle, s_resultNativeCallbackMaps[requestId], s_replyNativeCallback, (IntPtr)requestId);
+ }
+ else
+ {
+ err = Interop.AppControl.SendLaunchRequestAsync(launchRequest.SafeAppControlHandle, s_resultNativeCallbackMaps[requestId], null, (IntPtr)requestId);
+ }
+
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ switch (err)
+ {
+ case Interop.AppControl.ErrorCode.InvalidParameter:
+ throw new ArgumentException("Invalid Arguments");
+ 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.PermissionDenied:
+ throw new Exceptions.PermissionDeniedException("Permission denied");
+
+ default:
+ throw new Exceptions.LaunchRejectedException("Launch rejected");
+ }
+ }
+
+ return task.Task;
+ }
+
+ /// <summary>
+ /// Sets the auto restart.
+ /// </summary>
+ /// <remarks>
+ /// The functionality of this method only applies to the caller application.
+ /// The auto restart cannot be applied to other applications. The application ID set in the AppControl is ignored.
+ /// This method is only available for platform level signed applications.
+ /// </remarks>
+ /// <param name="appControl">The AppControl.</param>
+ /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
+ /// <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 SetAutoRestart(AppControl appControl)
+ {
+ if (appControl == null)
+ {
+ throw new ArgumentNullException(nameof(appControl));
+ }
+
+ Interop.AppControl.ErrorCode err = Interop.AppControl.SetAutoRestart(appControl.SafeAppControlHandle);
+ if (err != Interop.AppControl.ErrorCode.None)
+ {
+ switch (err)
+ {
+ case Interop.AppControl.ErrorCode.InvalidParameter:
+ throw new ArgumentException("Invalid arguments");
+ 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>
+ /// 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>