Ejemplo n.º 1
0
        /// <summary>
        /// Gets the information of the running applications including subapp asynchronously.
        /// </summary>
        /// <returns>The application running context list.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static async Task <IEnumerable <ApplicationRunningContext> > GetAllRunningApplicationsAsync()
        {
            return(await Task.Run(() =>
            {
                Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
                List <ApplicationRunningContext> result = new List <ApplicationRunningContext>();

                Interop.ApplicationManager.AppManagerAppContextCallback cb = (IntPtr contextHandle, IntPtr userData) =>
                {
                    if (contextHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        err = Interop.ApplicationManager.AppContextClone(out clonedHandle, contextHandle);
                        if (err != Interop.ApplicationManager.ErrorCode.None)
                        {
                            Log.Warn(LogTag, "Failed to clone the app context. err = " + err);
                            return false;
                        }
                        ApplicationRunningContext context = new ApplicationRunningContext(clonedHandle);
                        result.Add(context);
                        return true;
                    }
                    return false;
                };

                err = Interop.ApplicationManager.AppManagerForeachRunningAppContext(cb, IntPtr.Zero);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to foreach appcontext.");
                }
                return result;
            }).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        private static IntPtr MakeNativeAppMetadataFilter(IDictionary <string, string> filter)
        {
            if (filter == null || filter.Count == 0)
            {
                throw ApplicationManagerErrorFactory.FilterIsInvalid();
            }

            IntPtr infoHandle = IntPtr.Zero;

            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppInfoMetadataFilterCreate(out infoHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to create the filter for searching with metadata.");
            }
            foreach (var item in filter)
            {
                err = Interop.ApplicationManager.AppInfoMetadataFilterAdd(infoHandle, item.Key, item.Value);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    Interop.ApplicationManager.AppInfoMetadataFilterDestroy(infoHandle);
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to add the item to the filter.");
                }
            }
            return(infoHandle);
        }
Ejemplo n.º 3
0
        internal static void Fetch(this ApplicationInfoFilter filter, Interop.ApplicationManager.AppInfoFilterCallback callback)
        {
            if (filter is ApplicationInfoMetadataFilter)
            {
                ApplicationInfoMetadataFilter metaFilter = (ApplicationInfoMetadataFilter)filter;
                metaFilter.Fetch(callback);
                return;
            }

            IntPtr nativeHandle = MakeNativeAppInfoFilter(filter.Filter);

            if (nativeHandle == IntPtr.Zero)
            {
                throw ApplicationManagerErrorFactory.NativeFilterHandleIsInvalid();
            }
            try
            {
                Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppInfoFilterForeachAppinfo(nativeHandle, callback, IntPtr.Zero);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to get application information list with filter.");
                }
            }
            finally
            {
                Interop.ApplicationManager.AppInfoFilterDestroy(nativeHandle);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the information of the installed applications asynchronously.
        /// </summary>
        /// <returns>The installed application info list.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static async Task <IEnumerable <ApplicationInfo> > GetInstalledApplicationsAsync()
        {
            return(await Task.Run(() =>
            {
                Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
                List <ApplicationInfo> result = new List <ApplicationInfo>();

                Interop.ApplicationManager.AppManagerAppInfoCallback cb = (IntPtr infoHandle, IntPtr userData) =>
                {
                    if (infoHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        err = Interop.ApplicationManager.AppInfoClone(out clonedHandle, infoHandle);
                        if (err != Interop.ApplicationManager.ErrorCode.None)
                        {
                            Log.Warn(LogTag, "Failed to clone the appinfo. err = " + err);
                            return false;
                        }
                        ApplicationInfo app = new ApplicationInfo(clonedHandle);
                        result.Add(app);
                        return true;
                    }
                    return false;
                };
                err = Interop.ApplicationManager.AppManagerForeachAppInfo(cb, IntPtr.Zero);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to foreach the appinfo.");
                }
                return result;
            }).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Deletes all recent applications from the recent application list.
 /// </summary>
 /// <privlevel>platform</privlevel>
 /// <since_tizen> 3 </since_tizen>
 public static void DeleteAll()
 {
     Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
     err = Interop.ApplicationManager.RuaClearHistory();
     if (err != Interop.ApplicationManager.ErrorCode.None)
     {
         throw ApplicationManagerErrorFactory.GetException(err, "Failed to clear the recent application list.");
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Deletes the application from the recent application list.
 /// </summary>
 /// <privlevel>platform</privlevel>
 /// <since_tizen> 3 </since_tizen>
 public void Delete()
 {
     Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
     err = Interop.ApplicationManager.RuaDeleteHistoryWithPkgname(_pkgId);
     if (err != Interop.ApplicationManager.ErrorCode.None)
     {
         throw ApplicationManagerErrorFactory.GetException(err, "Failed to delete application from recent application list.");
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the application id.
        /// </summary>
        /// <param name="processId">The application pid.</param>
        /// <returns>Returns the application id.</returns>
        /// <exception cref="ArgumentException">Thrown when the given parameter is invalid.</exception>
        /// <since_tizen> 6 </since_tizen>
        public static string GetAppId(int processId)
        {
            string appid;

            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppManagerGetAppId(processId, out appid);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "fail to get appid(" + processId + ")");
            }
            return(appid);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns if the specified application is running or not.
        /// </summary>
        /// <param name="applicationId">The application ID.</param>
        /// <returns>Returns true if the given application is running, otherwise false.</returns>
        /// <exception cref="ArgumentException">Thrown when the given parameter is invalid.</exception>
        /// <since_tizen> 3 </since_tizen>
        public static bool IsRunning(string applicationId)
        {
            bool isRunning = false;

            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppManagerIsRunning(applicationId, out isRunning);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(Interop.ApplicationManager.ErrorCode.InvalidParameter, "Invalid parameter");
            }
            return(isRunning);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the information of the specified application with the application ID.
        /// </summary>
        /// <param name="applicationId">Application ID.</param>
        /// <returns>The application info.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static ApplicationInfo GetInstalledApplication(string applicationId)
        {
            IntPtr infoHandle = IntPtr.Zero;

            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppManagerGetAppInfo(applicationId, out infoHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to get the installed application information of " + applicationId + ".");
            }
            ApplicationInfo app = new ApplicationInfo(infoHandle);

            return(app);
        }
Ejemplo n.º 10
0
        private static IntPtr MakeNativeAppInfoFilter(IDictionary <string, string> filter)
        {
            if (filter == null || filter.Count == 0)
            {
                throw ApplicationManagerErrorFactory.FilterIsInvalid();
            }

            IntPtr infoHandle = IntPtr.Zero;

            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.AppInfoFilterCreate(out infoHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to create the filter handle.");
            }

            foreach (var item in filter)
            {
                if ((item.Key == ApplicationInfoFilter.Keys.Id) ||
                    (item.Key == ApplicationInfoFilter.Keys.Type) ||
                    (item.Key == ApplicationInfoFilter.Keys.Category) ||
                    (item.Key == ApplicationInfoFilter.Keys.InstalledStorage))
                {
                    err = Interop.ApplicationManager.AppInfoFilterAddString(infoHandle, item.Key, item.Value);
                }
                else if ((item.Key == ApplicationInfoFilter.Keys.NoDisplay) ||
                         (item.Key == ApplicationInfoFilter.Keys.TaskManage))
                {
                    err = Interop.ApplicationManager.AppInfoFilterAddBool(infoHandle, item.Key, Convert.ToBoolean(item.Value));
                }
                else
                {
                    Log.Warn(LogTag, string.Format("'{0}' is not supported key for the filter.", item.Key));
                }
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    Interop.ApplicationManager.AppInfoFilterDestroy(infoHandle);
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to add item to the filter.");
                }
            }
            return(infoHandle);
        }
Ejemplo n.º 11
0
        private static void RegisterApplicationChangedEvent()
        {
            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
            s_applicationChangedEventCallback = (IntPtr contextHandle, Interop.ApplicationManager.AppContextEvent state, IntPtr userData) =>
            {
                if (contextHandle == IntPtr.Zero)
                {
                    return;
                }

                IntPtr clonedHandle = IntPtr.Zero;
                err = Interop.ApplicationManager.AppContextClone(out clonedHandle, contextHandle);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to register the application context event.");
                }
                using (ApplicationRunningContext context = new ApplicationRunningContext(clonedHandle))
                {
                    lock (s_applicationChangedEventLock)
                    {
                        if (state == Interop.ApplicationManager.AppContextEvent.Launched)
                        {
                            s_launchedHandler?.Invoke(null, new ApplicationLaunchedEventArgs {
                                ApplicationRunningContext = context
                            });
                        }
                        else if (state == Interop.ApplicationManager.AppContextEvent.Terminated)
                        {
                            s_terminatedHandler?.Invoke(null, new ApplicationTerminatedEventArgs {
                                ApplicationRunningContext = context
                            });
                        }
                    }
                }
            };
            err = Interop.ApplicationManager.AppManagerSetAppContextEvent(s_applicationChangedEventCallback, IntPtr.Zero);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to register the application context event.");
            }
        }
Ejemplo n.º 12
0
        private static void RegisterApplicationEvent()
        {
            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
            err = Interop.ApplicationManager.AppManagerEventCreate(out _eventHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to create the application event handle");
            }

            err = Interop.ApplicationManager.AppManagerEventSetStatus(_eventHandle, Interop.ApplicationManager.AppManagerEventStatusType.All);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);
                _eventHandle = IntPtr.Zero;
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event");
            }

            s_eventCallback = (string appType, string appId, Interop.ApplicationManager.AppManagerEventType eventType, Interop.ApplicationManager.AppManagerEventState eventState, IntPtr eventHandle, IntPtr UserData) =>
            {
                lock (s_eventLock)
                {
                    if (eventType == Interop.ApplicationManager.AppManagerEventType.Enable)
                    {
                        s_enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState));
                    }
                    else if (eventType == Interop.ApplicationManager.AppManagerEventType.Disable)
                    {
                        s_disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState));
                    }
                }
            };
            err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, s_eventCallback, IntPtr.Zero);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);
                _eventHandle = IntPtr.Zero;
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to set the application event callback");
            }
        }
Ejemplo n.º 13
0
        public static IEnumerable <RecentApplicationInfo> GetRecentApplications()
        {
            Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;

            List <RecentApplicationInfo> result = new List <RecentApplicationInfo>();
            IntPtr table;
            int    nrows, ncols;

            err = Interop.ApplicationManager.RuaHistoryLoadDb(out table, out nrows, out ncols);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to load a table for the recent application list.");
            }

            for (int row = 0; row < nrows; ++row)
            {
                Interop.ApplicationManager.RuaRec record;

                err = Interop.ApplicationManager.RuaHistoryGetRecord(out record, table, nrows, ncols, row);
                if (err != Interop.ApplicationManager.ErrorCode.None)
                {
                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to get record.");
                }

                RecentApplicationInfo info = new RecentApplicationInfo(record);
                result.Add(info);
            }

            err = Interop.ApplicationManager.RuaHistoryUnLoadDb(ref table);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                throw ApplicationManagerErrorFactory.GetException(err, "Failed to unload a table for the recent application list.");
            }

            return(result);
        }