コード例 #1
0
        /// <summary>
        /// Gets the information of the installed applications with the ApplicationInfoMetadataFilter asynchronously.
        /// </summary>
        /// <param name="filter">Key-value pairs for filtering.</param>
        /// <since_tizen> 3 </since_tizen>
        public static async Task <IEnumerable <ApplicationInfo> > GetInstalledApplicationsAsync(ApplicationInfoMetadataFilter filter)
        {
            return(await Task.Run(() =>
            {
                List <ApplicationInfo> result = new List <ApplicationInfo>();

                Interop.ApplicationManager.AppInfoFilterCallback cb = (IntPtr infoHandle, IntPtr userData) =>
                {
                    if (infoHandle != IntPtr.Zero)
                    {
                        IntPtr clonedHandle = IntPtr.Zero;
                        Interop.ApplicationManager.ErrorCode 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;
                };
                filter.Fetch(cb);
                return result;
            }));
        }
コード例 #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);
        }
コード例 #3
0
        public ApplicationRunningContext(string applicationId, string instanceId)
        {
            IntPtr contextHandle = IntPtr.Zero;

            err = Interop.ApplicationManager.AppManagerGetAppContextByInstanceId(applicationId, instanceId, out contextHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Log.Warn(LogTag, "Failed to get the handle of the ApplicationRunningContext. err = " + err);
                switch (err)
                {
                case Interop.ApplicationManager.ErrorCode.InvalidParameter:
                    throw new ArgumentException("Invalid Parameter.");

                case Interop.ApplicationManager.ErrorCode.NoSuchApp:
                    throw new InvalidOperationException("No such application.");

                case Interop.ApplicationManager.ErrorCode.OutOfMemory:
                    throw new OutOfMemoryException("Out of memory");

                default:
                    throw new InvalidOperationException("Invalid Operation.");
                }
            }
            _contextHandle = contextHandle;
        }
コード例 #4
0
        /// <summary>
        /// Gets the information of the running applications including subapp asynchronously.
        /// </summary>
        /// <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;
            }));
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the information of the installed applications asynchronously.
        /// </summary>
        /// <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;
            }));
        }
コード例 #7
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.");
     }
 }
コード例 #8
0
 internal ApplicationInfo(IntPtr infoHandle)
 {
     err = Interop.ApplicationManager.AppInfoGetAppId(infoHandle, out _applicationId);
     if (err != Interop.ApplicationManager.ErrorCode.None)
     {
         throw new ArgumentException("Invalid native handle.");
     }
     _infoHandle = infoHandle;
 }
コード例 #9
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.");
     }
 }
コード例 #10
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);
        }
コード例 #11
0
        /// <summary>
        /// Gets the localized label of the application for the given locale.
        /// </summary>
        /// <param name="locale">Locale.</param>
        /// <returns>The localized label.</returns>
        /// <since_tizen> 3 </since_tizen>
        public string GetLocalizedLabel(string locale)
        {
            string label = string.Empty;

            err = Interop.ApplicationManager.AppInfoGetLocaledLabel(ApplicationId, locale, out label);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _applicationId + ". err = " + err);
                label = Label;
            }
            return(label);
        }
コード例 #12
0
        /// <summary>
        /// Gets the information of the specified application with the application ID.
        /// </summary>
        /// <param name="applicationId">Application ID.</param>
        /// <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);
        }
コード例 #13
0
        internal static Exception GetException(Interop.ApplicationManager.ErrorCode err, string message)
        {
            string errMessage = String.Format("{0} err = {1}", message, err);

            switch (err)
            {
            case Interop.ApplicationManager.ErrorCode.InvalidParameter:
                return(new ArgumentException(errMessage));

            default:
                return(new InvalidOperationException(errMessage));
            }
        }
コード例 #14
0
 private IntPtr GetInfoHandle()
 {
     if (_infoHandle == IntPtr.Zero)
     {
         IntPtr infoHandle = IntPtr.Zero;
         err = Interop.ApplicationManager.AppManagerGetAppInfo(_applicationId, out infoHandle);
         if (err != Interop.ApplicationManager.ErrorCode.None)
         {
             Log.Warn(LogTag, "Failed to get the handle of the ApplicationInfo. err = " + err);
         }
         _infoHandle = infoHandle;
     }
     return(_infoHandle);
 }
コード例 #15
0
        /// <summary>
        /// Resumes the running application.
        /// </summary>
        /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when failed because of permission denied.</exception>
        /// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 4 </since_tizen>
        public void Resume()
        {
            err = Interop.ApplicationManager.AppManagerResumeApp(_contextHandle);
            if (err != Interop.ApplicationManager.ErrorCode.None)
            {
                switch (err)
                {
                case Interop.ApplicationManager.ErrorCode.InvalidParameter:
                    throw new ArgumentException("Invalid argument.");

                case Interop.ApplicationManager.ErrorCode.PermissionDenied:
                    throw new UnauthorizedAccessException("Permission denied.");

                default:
                    throw new InvalidOperationException("Invalid Operation.");
                }
            }
        }
コード例 #16
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);
        }
コード例 #17
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))
                {
                    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.");
            }
        }
コード例 #18
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) =>
            {
                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");
            }
        }
コード例 #19
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);
        }