Ejemplo n.º 1
0
        /// <summary>
        /// Gets the information of the running components asynchronously.
        /// </summary>
        /// <returns>The component running context list.</returns>
        /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
        /// <exception cref="InvalidOperationException">Thrown when failed because of the "component not exist" error or the system error.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when failed because of permission denied.</exception>
        /// <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
        /// <since_tizen> 6 </since_tizen>
        public static async Task <IEnumerable <ComponentRunningContext> > GetRunningComponentsAsync()
        {
            return(await Task.Run(() =>
            {
                Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ErrorCode.None;
                List <ComponentRunningContext> result = new List <ComponentRunningContext>();

                Interop.ComponentManager.ComponentManagerComponentContextCallback cb = (IntPtr contextHandle, IntPtr userData) =>
                {
                    if (contextHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        err = Interop.ComponentManager.ComponentContextClone(out clonedHandle, contextHandle);
                        if (err != Interop.ComponentManager.ErrorCode.None)
                        {
                            Log.Warn(LogTag, "Failed to clone the ComponentInfo. err = " + err);
                            return false;
                        }
                        ComponentRunningContext context = new ComponentRunningContext(clonedHandle);
                        result.Add(context);
                        return true;
                    }
                    return false;
                };
                err = Interop.ComponentManager.ComponentManagerForeachComponentContext(cb, IntPtr.Zero);
                if (err != Interop.ComponentManager.ErrorCode.None)
                {
                    throw ComponentManagerErrorFactory.GetException(err, "Failed to retrieve the running component context.");
                }
                return result;
            }).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Terminates the component if it is running in the background.
 /// </summary>
 /// <param name="context">Component ID</param>
 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
 /// <exception cref="InvalidOperationException">Thrown when failed because of the "component not exist" error or the system error.</exception>
 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
 /// <exception cref="UnauthorizedAccessException">Thrown when failed because of permission denied.</exception>
 /// <privilege>http://tizen.org/privilege/appmanager.kill.bgapp</privilege>
 /// <remarks>
 /// This function returns after it just sends a request for terminating a background component.
 /// Platform will decide if the target component could be terminated or not according to the state of the target component.
 /// </remarks>
 /// <since_tizen> 6 </since_tizen>
 public static void TerminateBackgroundComponent(ComponentRunningContext context)
 {
     Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerTerminateBgComponent(context._contextHandle);
     if (err != Interop.ComponentManager.ErrorCode.None)
     {
         throw ComponentManagerErrorFactory.GetException(err, "Failed to send the terminate request.");
     }
 }