using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
+using static Interop.ApplicationManager;
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()
{
}
/// <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)
{
/// 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)
{
/// <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()
{
/// <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()
{
/// 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)
{
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;
{
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)
}
/// <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>
/// <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
{
/// 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)
{
/// 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)
{
/// 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)
{
/// 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)
{
/// 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)
{