[Applications.Common] Add missing application APIs (#547)
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 4 Dec 2018 08:08:24 +0000 (17:08 +0900)
committersemun-lee <35090067+semun-lee@users.noreply.github.com>
Tue, 4 Dec 2018 08:08:24 +0000 (17:08 +0900)
* Add missing app_get* APIs

- app_get_device_orientation
- app_get_name
- app_get_version

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Fix typo

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Add eventsystem classes

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Add missing appmanger APIs

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Modify eventsystem to event

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Remove Event class

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Update file permission

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Update terminate bg method desc

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Modify terminate bg to static method

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Fix remark comment

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Add remarks for TerminateBackgroundApplication

Signed-off-by: hyunho <hhstark.kang@samsung.com>
* Add documentation about parameter and returns

Signed-off-by: hyunho <hhstark.kang@samsung.com>
36 files changed:
src/Tizen.Applications.Common/Interop/Interop.AppControl.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Interop/Interop.Bundle.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Interop/Interop.Glib.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Interop/Interop.Libc.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlData.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlLaunchMode.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlOperations.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlReceivedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlReplyCallback.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/AppControlReplyResult.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/Application.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs
src/Tizen.Applications.Common/Tizen.Applications/ApplicationInfoMetadataFilter.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationLaunchedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationRunningContext.cs [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationTerminatedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ApplicationType.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/Bundle.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs
src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/LocaleChangedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/LowBatteryEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/LowBatteryStatus.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/LowMemoryEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/LowMemoryStatus.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ReceivedAppControl.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationControl.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/RecentApplicationInfo.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/RegionFormatChangedEventArgs.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/SafeAppControlHandle.cs [changed mode: 0755->0644]
src/Tizen.Applications.Common/Tizen.Applications/SafeBundleHandle.cs [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index ab71a73..dd21e5b
@@ -83,6 +83,35 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets the name of current application.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Name
+        {
+            get
+            {
+                string name;
+                Interop.AppCommon.AppGetName(out name);
+                return name;
+            }
+        }
+
+        /// <summary>
+        /// Gets the version of current application.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public string Version
+        {
+            get
+            {
+                string version;
+                Interop.AppCommon.AppGetVersion(out version);
+                return version;
+            }
+        }
+
+
+        /// <summary>
         /// Runs the application's main loop.
         /// </summary>
         /// <param name="args">Arguments from commandline.</param>
index bb360b4..b26f480 100644 (file)
@@ -372,6 +372,7 @@ namespace Tizen.Applications
         /// 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)
         {
old mode 100755 (executable)
new mode 100644 (file)
index 41caa28..47aaa92
@@ -19,6 +19,7 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
+using static Interop.ApplicationManager;
 
 namespace Tizen.Applications
 {
@@ -166,6 +167,7 @@ namespace Tizen.Applications
         /// <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()
         {
@@ -201,9 +203,40 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Terminates the application if it is running on background.
+        /// </summary>
+        /// <param name="app">ApplicationRunningContext object</param>
+        /// <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.kill.bgapp</privilege>
+        /// <remarks>
+        /// This function returns after it just sends a request for terminating a background application.
+        /// Platform will decide if the target application could be terminated or not according to the state of the target application.
+        /// </remarks>
+        /// <since_tizen> 6 </since_tizen>
+        public static void TerminateBackgroundApplication(ApplicationRunningContext app)
+        {
+            ErrorCode err = Interop.ApplicationManager.AppManagerRequestTerminateBgApp(app._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.");
+                }
+            }
+        }
+
+        /// <summary>
         /// Gets the information of the installed applications with the ApplicationInfoFilter asynchronously.
         /// </summary>
         /// <param name="filter">Key-value pairs for filtering.</param>
+        /// <returns>The installed application info list.</returns>
         /// <since_tizen> 3 </since_tizen>
         public static async Task<IEnumerable<ApplicationInfo>> GetInstalledApplicationsAsync(ApplicationInfoFilter filter)
         {
@@ -237,6 +270,7 @@ namespace Tizen.Applications
         /// Gets the information of the installed applications with the ApplicationInfoMetadataFilter asynchronously.
         /// </summary>
         /// <param name="filter">Key-value pairs for filtering.</param>
+        /// <returns>The installed application info list.</returns>
         /// <since_tizen> 3 </since_tizen>
         public static async Task<IEnumerable<ApplicationInfo>> GetInstalledApplicationsAsync(ApplicationInfoMetadataFilter filter)
         {
@@ -269,6 +303,7 @@ namespace Tizen.Applications
         /// <summary>
         /// Gets the information of the running applications asynchronously.
         /// </summary>
+        /// <returns>The application running context list.</returns>
         /// <since_tizen> 3 </since_tizen>
         public static async Task<IEnumerable<ApplicationRunningContext>> GetRunningApplicationsAsync()
         {
@@ -307,6 +342,7 @@ namespace Tizen.Applications
         /// <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()
         {
@@ -346,6 +382,7 @@ namespace Tizen.Applications
         /// 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)
         {
@@ -377,6 +414,24 @@ namespace Tizen.Applications
             return isRunning;
         }
 
+        /// <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;
+        }
+
         private static void RegisterApplicationChangedEvent()
         {
             Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
old mode 100644 (file)
new mode 100755 (executable)
index b294259..c7196e7
@@ -28,7 +28,7 @@ namespace Tizen.Applications
     {
         private const string LogTag = "Tizen.Applications";
         private bool _disposed = false;
-        private IntPtr _contextHandle = IntPtr.Zero;
+        internal IntPtr _contextHandle = IntPtr.Zero;
         private Interop.ApplicationManager.ErrorCode err = Interop.ApplicationManager.ErrorCode.None;
 
         internal ApplicationRunningContext(IntPtr contextHandle)
@@ -157,6 +157,34 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Gets whether the application is terminated.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public bool IsTerminated
+        {
+            get
+            {
+                bool isRunning = false;
+                string appid = string.Empty;
+                err = Interop.ApplicationManager.AppContextGetAppId(_contextHandle, out appid);
+                if (err != Interop.ApplicationManager.ErrorCode.None)
+                {
+                    Log.Warn(LogTag, "Failed to get the application id. err = " + err);
+                }
+                else
+                {
+                    Interop.ApplicationManager.AppManagerIsRunning(appid, out isRunning);
+                    err = Interop.ApplicationManager.AppContextGetAppId(_contextHandle, out appid);
+                    if (err != Interop.ApplicationManager.ErrorCode.None)
+                    {
+                        Log.Warn(LogTag, "Failed to get is running. err = " + err);
+                    }
+                }
+                return !isRunning;
+            }
+        }
+
+        /// <summary>
         /// Gets the package ID of the application.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -195,6 +223,9 @@ namespace Tizen.Applications
         /// <summary>
         /// Gets the state of the application.
         /// </summary>
+        /// <remarks>
+        /// Note that application's state might be changed after you get app_context. This API just returns the state of application when you get the app_context.
+        /// </remarks>
         /// <since_tizen> 3 </since_tizen>
         public AppState State
         {
index 298f635..732c37c 100644 (file)
@@ -171,6 +171,7 @@ namespace Tizen.Applications
         /// Overrides this method if want to handle behavior when the system memory is low.
         /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
         /// </summary>
+        /// <param name="e">The low memory event argument</param>
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnLowMemory(LowMemoryEventArgs e)
         {
@@ -182,6 +183,7 @@ namespace Tizen.Applications
         /// Overrides this method if want to handle behavior when the system battery is low.
         /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
         /// </summary>
+        /// <param name="e">The low battery event argument</param>
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnLowBattery(LowBatteryEventArgs e)
         {
@@ -192,6 +194,7 @@ namespace Tizen.Applications
         /// Overrides this method if want to handle behavior when the system language is changed.
         /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
         /// </summary>
+        /// <param name="e">The locale changed event argument</param>
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
         {
@@ -203,6 +206,7 @@ namespace Tizen.Applications
         /// Overrides this method if want to handle behavior when the region format is changed.
         /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
         /// </summary>
+        /// <param name="e">The region format changed event argument</param>
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
         {
@@ -213,6 +217,7 @@ namespace Tizen.Applications
         /// Overrides this method if want to handle behavior when the device orientation is changed.
         /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
         /// </summary>
+        /// <param name="e">The device orientation changed event argument</param>
         /// <since_tizen> 3 </since_tizen>
         protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
         {
old mode 100755 (executable)
new mode 100644 (file)
index c35dadf..e137811
@@ -51,6 +51,7 @@ namespace Tizen.Applications
         /// <summary>
         /// Initializes a ReceivedAppControl class.
         /// </summary>
+        /// <param name="handle">App control handle</param>
         /// <since_tizen> 3 </since_tizen>
         public ReceivedAppControl(SafeAppControlHandle handle) : base(handle)
         {