* [ComponentManager] Add new APIs to handle components of the component-based application
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* Change property name
Type is changed to ComponentType.
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* Fix typo
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* Update ComponentState
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class ComponentManager
+ {
+ internal enum ErrorCode
+ {
+ None = Tizen.Internals.Errors.ErrorCode.None,
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+ IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+ NoSuchComponent = -0x03040000 | 0x01,
+ DbFailed = -0x03040000 | 0x03,
+ InvalidApplication = -0x03040000 | 0x04,
+ NotRunning = -0x03040000 | 0x05,
+ LabelNotFound = -0x03040000 | 0x06,
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied
+ }
+
+ internal enum ComponentInfoComponentType
+ {
+ Frame = 0,
+ Service = 1
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ComponentManagerComponentContextCallback(IntPtr handle, IntPtr userData);
+ // bool (*component_manager_component_context_cb)(component_context_h handle, void *user_data);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ComponentManagerComponentInfoCallback(IntPtr handle, IntPtr userData);
+ // bool (*component_manager_component_info_cb)(component_info_h handle, void *user_data);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_foreach_component_context")]
+ internal static extern ErrorCode ComponentManagerForeachComponentContext(ComponentManagerComponentContextCallback callback, IntPtr userData);
+ // int component_manager_foreach_component_context(component_manager_component_context_cb callback, void *user_data)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_foreach_component_info")]
+ internal static extern ErrorCode ComponentManagerForeachComponentInfo(ComponentManagerComponentInfoCallback callback, IntPtr userData);
+ // int component_manager_foreach_component_info(component_manager_component_info_cb callback, void *user_data)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_get_component_context")]
+ internal static extern ErrorCode ComponentManagerGetComponentContext(string componentId, out IntPtr handle);
+ // int component_manager_get_component_context(const char *comp_id, component_context_h *handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_get_component_info")]
+ internal static extern ErrorCode ComponentManagerGetComponentInfo(string componentId, out IntPtr handle);
+ // int component_manager_get_component_info(const char *comp_id, component_info_h *handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_is_running")]
+ internal static extern ErrorCode ComponentManagerIsRunning(string componentId, out bool running);
+ // int component_manager_is_running(const char *appid, bool *running);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_resume_component")]
+ internal static extern ErrorCode ComponentManagerResumeComponent(IntPtr handle);
+ // int component_manager_resume_component(component_context_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_terminate_bg_component")]
+ internal static extern ErrorCode ComponentManagerTerminateBgComponent(IntPtr handle);
+ // int component_manager_terminate_bg_component (component_context_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_pause_component")]
+ internal static extern ErrorCode ComponentManagerPauseComponent(IntPtr handle);
+ // int component_manager_pause_component(component_context_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_manager_terminate_component")]
+ internal static extern ErrorCode ComponentManagerTerminateComponent(IntPtr handle);
+ // int component_manager_terminate_component(component_context_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_destroy")]
+ internal static extern ErrorCode ComponentContextDestroy(IntPtr handle);
+ // int component_context_destroy(component_context_h handle)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_get_app_id")]
+ internal static extern ErrorCode ComponentContextGetAppId(IntPtr handle, out string applicationId);
+ // int component_context_get_app_id(component_context_h handle, char **app_id)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_get_component_id")]
+ internal static extern ErrorCode ComponentContextGetComponentId(IntPtr handle, out string componentId);
+ // int component_context_get_component_id(component_context_h handle, char **component_id)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_get_instance_id")]
+ internal static extern ErrorCode ComponentContextGetInstanceId(IntPtr handle, out string instanceId);
+ // int component_context_get_instance_id(component_context_h handle, char **instance_id)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_get_component_state")]
+ internal static extern ErrorCode ComponentContextGetComponentState(IntPtr handle, out int state);
+ // int component_context_get_component_state(component_context_h handle, component_state_e *state)
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_is_terminated")]
+ internal static extern ErrorCode ComponentContextIsTerminated(IntPtr handle, out bool terminated);
+ // int component_context_is_terminated(component_context_h handle, bool *terminated);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_is_subcomponent")]
+ internal static extern ErrorCode ComponentContextIsSubComponent(IntPtr handle, out bool is_subcomponent);
+ // int component_context_is_subcomponent(component_context_h handle, bool *is_subcomponent);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_context_clone")]
+ internal static extern ErrorCode ComponentContextClone(out IntPtr destination, IntPtr source);
+ // int component_context_clone(component_context_h *clone, component_context_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_create")]
+ internal static extern ErrorCode ComponentInfoCreate(string componentId, out IntPtr handle);
+ // int component_info_create(const char *component_id, component_info_h *handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_destroy")]
+ internal static extern ErrorCode ComponentInfoDestroy(IntPtr handle);
+ // int component_info_destroy(component_info_h handle);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_app_id")]
+ internal static extern ErrorCode ComponentInfoGetAppId(IntPtr handle, out string applicationId);
+ // int component_info_get_app_id(component_info_h handle, char **app_id);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_component_id")]
+ internal static extern ErrorCode ComponentInfoGetComponentId(IntPtr handle, out string componentId);
+ // int component_info_get_component_id(component_info_h handle, char **component_id);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_component_type")]
+ internal static extern ErrorCode ComponentInfoGetComponentType(IntPtr handle, out ComponentInfoComponentType type);
+ // int component_info_get_component_type(component_info_h handle, component_info_component_type_e *type);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_is_icon_display")]
+ internal static extern ErrorCode ComponentInfoIsIconDisplay(IntPtr handle, out bool iconDisplay);
+ // int component_info_is_icon_display(component_info_h handle, bool *icon_display);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_is_managed_by_task_manager")]
+ internal static extern ErrorCode ComponentInfoIsManagedByTaskManager(IntPtr handle, out bool managed);
+ // int component_info_is_managed_by_task_manager(component_info_h handle, bool *managed);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_icon")]
+ internal static extern ErrorCode ComponentInfoGetIcon(IntPtr handle, out string icon);
+ // int component_info_get_icon(component_info_h handle, char **icon);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_label")]
+ internal static extern ErrorCode ComponentInfoGetLabel(IntPtr handle, out string label);
+ // int component_info_get_label(component_info_h handle, char **label);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_get_localized_label")]
+ internal static extern ErrorCode ComponentInfoGetLocalizedLabel(IntPtr handle, string locale, out string label);
+ // int component_info_get_localized_label(component_info_h handle, const char *locale, char **label);
+
+ [DllImport(Libraries.ComponentManager, EntryPoint = "component_info_clone")]
+ internal static extern ErrorCode ComponentInfoClone(out IntPtr destination, IntPtr source);
+ // int component_info_clone(component_info_h *clone, component_info_h handle);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string ComponentManager = "libcapi-appfw-component-manager.so.1";
+ }
+}
\ No newline at end of file
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <!-- Property Group for Tizen Project -->
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ <TizenCreateTpkOnBuild>false</TizenCreateTpkOnBuild>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>portable</DebugType>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>None</DebugType>
+ </PropertyGroup>
+
+ <!-- Include Nuget Package for Tizen Project building -->
+ <ItemGroup>
+ <PackageReference Include="Tizen.NET" Version="5.0.0.14562">
+ <ExcludeAssets>Runtime</ExcludeAssets>
+ </PackageReference>
+ <PackageReference Include="Tizen.NET.Sdk" Version="1.0.1" />
+ </ItemGroup>
+
+</Project>
\ No newline at end of file
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.271
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.ComponentManager", "Tizen.Applications.ComponentManager.csproj", "{0C733CDC-EE90-42CE-9083-87FC55EF91DA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0C733CDC-EE90-42CE-9083-87FC55EF91DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C733CDC-EE90-42CE-9083-87FC55EF91DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0C733CDC-EE90-42CE-9083-87FC55EF91DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0C733CDC-EE90-42CE-9083-87FC55EF91DA}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {7166CBA3-05BB-413B-9DA4-5F0A408AFA36}
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// This class provides methods and properties to get information of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public class ComponentInfo : IDisposable
+ {
+ private const string LogTag = "Tizen.Applications";
+ private bool _disposed = false;
+ private IntPtr _infoHandle = IntPtr.Zero;
+ private string _componentId = string.Empty;
+
+ internal ComponentInfo(IntPtr infoHandle)
+ {
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentId(infoHandle, out _componentId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Invalid native handle.");
+ }
+ _infoHandle = infoHandle;
+ }
+
+ /// <summary>
+ /// A constructor of ComponentInfo that takes the component ID.
+ /// </summary>
+ /// <param name="componentId">Component ID.</param>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of 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 ComponentInfo(string componentId)
+ {
+ _componentId = componentId;
+ IntPtr infoHandle = IntPtr.Zero;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoCreate(_componentId, out infoHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to create the ComponentInfo.");
+ }
+ _infoHandle = infoHandle;
+ }
+
+ /// <summary>
+ /// Destructor of the class.
+ /// </summary>
+ ~ComponentInfo()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets the component ID.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string ComponentId
+ {
+ get
+ {
+ if (!string.IsNullOrEmpty(_componentId))
+ return _componentId;
+
+ string compId = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentId(_infoHandle, out compId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the ComponentId. err = " + err);
+ }
+ _componentId = compId;
+
+ return _componentId;
+ }
+ }
+
+ /// <summary>
+ /// Gets the application ID of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string ApplicationId
+ {
+ get
+ {
+ string appId = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetAppId(_infoHandle, out appId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the ApplicationId of " + _componentId + ". err = " + err);
+ }
+
+ return appId;
+ }
+ }
+
+ /// <summary>
+ /// Gets the type of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public ComponentType ComponentType
+ {
+ get
+ {
+ Interop.ComponentManager.ComponentInfoComponentType type = 0;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetComponentType(_infoHandle, out type);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the Type of " + _componentId + ". err = " + err);
+ }
+
+ return (ComponentType)type;
+ }
+ }
+
+ /// <summary>
+ /// Checks whether the icon of the component should be displayed or not.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsIconDisplayed
+ {
+ get
+ {
+ bool iconDisplay = false;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoIsIconDisplay(_infoHandle, out iconDisplay);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the IsIconDisplay of " + _componentId + ". err = " + err);
+ }
+
+ return iconDisplay;
+ }
+ }
+
+ /// <summary>
+ /// Checks whether the component should be managed by task-manager or not.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsManagedByTaskManager
+ {
+ get
+ {
+ bool managed = false;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoIsManagedByTaskManager(_infoHandle, out managed);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the IsManagedByTaskManager of " + _componentId + ". err = " + err);
+ }
+
+ return managed;
+ }
+ }
+
+ /// <summary>
+ /// Gets the absolute path of the icon image.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string IconPath
+ {
+ get
+ {
+ string path = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetIcon(_infoHandle, out path);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the IconPath of " + _componentId + ". err = " + err);
+ }
+
+ return path;
+ }
+ }
+
+ /// <summary>
+ /// Gets the label of the component.
+ /// </summary>
+ public string Label
+ {
+ get
+ {
+ string label = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetLabel(_infoHandle, out label);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the Label of " + _componentId + ". err = " + err);
+ }
+
+ return label;
+ }
+ }
+
+ /// <summary>
+ /// Gets the localized label of the component for the given locale.
+ /// </summary>
+ /// <param name="locale">Locale.</param>
+ /// <remarks>The format of locale is language and country code. (available value: "[2-letter lowercase language code (ISO 639-1)]-[2-letter lowercase country code (ISO 3166-alpha-2)]")</remarks>
+ /// <returns>The localized label.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public string GetLocalizedLabel(string locale)
+ {
+ string label = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentInfoGetLocalizedLabel(_infoHandle, locale, out label);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the GetLocalizedLabel of " + _componentId + ". err = " + err);
+ label = Label;
+ }
+ return label;
+ }
+
+ /// <summary>
+ /// Releases all resources used by the ComponentInfo class.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases all resources used by the ComponentInfo class.
+ /// </summary>
+ /// <param name="disposing">Disposing</param>
+ /// <since_tizen> 6 </since_tizen>
+ private void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (disposing)
+ {
+ }
+
+ if (_infoHandle != IntPtr.Zero)
+ {
+ Interop.ComponentManager.ComponentInfoDestroy(_infoHandle);
+ _infoHandle = IntPtr.Zero;
+ }
+ _disposed = true;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// This class has the methods and events of the ComponentManager.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public static class ComponentManager
+ {
+ private const string LogTag = "Tizen.Applications";
+
+ /// <summary>
+ /// Gets the information of the installed components asynchronously.
+ /// </summary>
+ /// <returns>The installed component info 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<ComponentInfo>> GetInstalledComponentsAsync()
+ {
+ return await Task.Run(() =>
+ {
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ErrorCode.None;
+ List<ComponentInfo> result = new List<ComponentInfo>();
+
+ Interop.ComponentManager.ComponentManagerComponentInfoCallback cb = (IntPtr infoHandle, IntPtr userData) =>
+ {
+ if (infoHandle != IntPtr.Zero)
+ {
+ IntPtr clonedHandle = IntPtr.Zero;
+ err = Interop.ComponentManager.ComponentInfoClone(out clonedHandle, infoHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to clone the ComponentInfo. err = " + err);
+ return false;
+ }
+ ComponentInfo info = new ComponentInfo(clonedHandle);
+ result.Add(info);
+ return true;
+ }
+ return false;
+ };
+ err = Interop.ComponentManager.ComponentManagerForeachComponentInfo(cb, IntPtr.Zero);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManagerErrorFactory.GetException(err, "Failed to retrieve the component info.");
+ }
+ return result;
+ }).ConfigureAwait(false);
+ }
+
+ /// <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);
+ }
+
+ /// <summary>
+ /// Checks whether the component is running or not.
+ /// </summary>
+ /// <param name="componentId">Component ID.</param>
+ /// <returns>Returns true if the component is running, otherwise false.</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 bool IsRunning(string componentId)
+ {
+ bool isRunning = false;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerIsRunning(componentId, out isRunning);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManagerErrorFactory.GetException(err, "Failed to check the IsRunning of " + componentId + ".");
+ }
+ return isRunning;
+ }
+
+ /// <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.");
+ }
+ }
+
+ internal static class ComponentManagerErrorFactory
+ {
+ internal static Exception GetException(Interop.ComponentManager.ErrorCode err, string message)
+ {
+ string errMessage = string.Format("{0} err = {1}", message, err);
+ switch (err)
+ {
+ case Interop.ComponentManager.ErrorCode.InvalidParameter:
+ case Interop.ComponentManager.ErrorCode.NoSuchComponent:
+ return new ArgumentException(errMessage);
+ case Interop.ComponentManager.ErrorCode.PermissionDenied:
+ return new UnauthorizedAccessException(errMessage);
+ case Interop.ComponentManager.ErrorCode.IoError:
+ return new global::System.IO.IOException(errMessage);
+ case Interop.ComponentManager.ErrorCode.OutOfMemory:
+ return new OutOfMemoryException(errMessage);
+ default:
+ return new InvalidOperationException(errMessage);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// This class provides methods and properties to get information of the running component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public class ComponentRunningContext : IDisposable
+ {
+ private const string LogTag = "Tizen.Applications";
+ private bool _disposed = false;
+ internal IntPtr _contextHandle = IntPtr.Zero;
+ private string _componentId = string.Empty;
+
+ internal ComponentRunningContext(IntPtr contextHandle)
+ {
+ _contextHandle = contextHandle;
+ }
+
+ /// <summary>
+ /// A constructor of ComponentRunningContext that takes the component ID.
+ /// </summary>
+ /// <param name="componentId">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/packagemanager.info</privilege>
+ /// <since_tizen> 6 </since_tizen>
+ public ComponentRunningContext(string componentId)
+ {
+ _componentId = componentId;
+ IntPtr contextHandle = IntPtr.Zero;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerGetComponentContext(_componentId, out contextHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to create the ComponentRunningContext of " + _componentId + ".");
+ }
+ _contextHandle = contextHandle;
+ }
+
+ /// <summary>
+ /// Destructor of the class.
+ /// </summary>
+ ~ComponentRunningContext()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Enumeration for the component state.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public enum ComponentState
+ {
+ /// <summary>
+ /// The Initialized state. This is the state when the component is constructed but OnCreate() is not called yet.
+ /// </summary>
+ Initialized = 0,
+
+ /// <summary>
+ /// The created state. This state is reached after OnCreate() is called.
+ /// </summary>
+ Created,
+
+ /// <summary>
+ /// The started state. This state is reached after OnStart() or OnStartCommand() is called.
+ /// </summary>
+ Started,
+
+ /// <summary>
+ /// The resumed state. This state is reached after OnResume() is called.
+ /// </summary>
+ Resumed,
+
+ /// <summary>
+ /// The paused state. This state is reached after OnPause() is called.
+ /// </summary>
+ Paused,
+
+ /// <summary>
+ /// The destroyed state. This state is reached right before OnDestroy() call.
+ /// </summary>
+ Destroyed
+ }
+
+ /// <summary>
+ /// Gets the ID of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string ComponentId
+ {
+ get
+ {
+ if (!string.IsNullOrEmpty(_componentId))
+ return _componentId;
+
+ string componentId = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextGetComponentId(_contextHandle, out componentId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the ComponentId. err = " + err);
+ }
+ _componentId = componentId;
+
+ return _componentId;
+ }
+ }
+
+ /// <summary>
+ /// Gets the application ID of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string ApplicationId
+ {
+ get
+ {
+ string appId = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextGetAppId(_contextHandle, out appId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the ApplicationId of " + _componentId + ". err = " + err);
+ }
+
+ return appId;
+ }
+ }
+
+ /// <summary>
+ /// Gets the instance ID of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public string InstanceId
+ {
+ get
+ {
+ string instanceId = string.Empty;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextGetInstanceId(_contextHandle, out instanceId);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the InstanceId of " + _componentId + ". err = " + err);
+ }
+
+ return instanceId;
+ }
+ }
+
+ /// <summary>
+ /// Gets the state of the component.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public ComponentState State
+ {
+ get
+ {
+ int state = 0;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextGetComponentState(_contextHandle, out state);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the State of " + _componentId + ". err = " + err);
+ }
+
+ return (ComponentState)state;
+ }
+ }
+
+ /// <summary>
+ /// Checks whether the component is terminated or not.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsTerminated
+ {
+ get
+ {
+ bool isTerminated = false;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextIsTerminated(_contextHandle, out isTerminated);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the IsTerminated of " + _componentId + ". err = " + err);
+ }
+
+ return isTerminated;
+ }
+ }
+
+ /// <summary>
+ /// Checks whether the component is running as sub component of the group.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public bool IsSubComponent
+ {
+ get
+ {
+ bool isSubComponent = false;
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentContextIsSubComponent(_contextHandle, out isSubComponent);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ Log.Warn(LogTag, "Failed to get the IsSubComponent of " + _componentId + ". err = " + err);
+ }
+
+ return isSubComponent;
+ }
+ }
+
+ /// <summary>
+ /// Resumes the running component.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of 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.launch</privilege>
+ /// <since_tizen> 6 </since_tizen>
+ public void Resume()
+ {
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerResumeComponent(_contextHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to Send the resume request.");
+ }
+ }
+
+ /// <summary>
+ /// Pauses the running component.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of 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.launch</privilege>
+ /// <since_tizen> 6 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Pause()
+ {
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerPauseComponent(_contextHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to Send the pause request.");
+ }
+ }
+
+ /// <summary>
+ /// Terminates the running component.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed because of 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.launch</privilege>
+ /// <since_tizen> 6 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Terminate()
+ {
+ Interop.ComponentManager.ErrorCode err = Interop.ComponentManager.ComponentManagerTerminateComponent(_contextHandle);
+ if (err != Interop.ComponentManager.ErrorCode.None)
+ {
+ throw ComponentManager.ComponentManagerErrorFactory.GetException(err, "Failed to Send the terminate request.");
+ }
+ }
+
+ /// <summary>
+ /// Releases all resources used by the ComponentInfo class.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases all resources used by the ComponentInfo class.
+ /// </summary>
+ /// <param name="disposing">Disposing</param>
+ /// <since_tizen> 6 </since_tizen>
+ private void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+
+ if (disposing)
+ {
+ }
+
+ if (_contextHandle != IntPtr.Zero)
+ {
+ Interop.ComponentManager.ComponentContextDestroy(_contextHandle);
+ _contextHandle = IntPtr.Zero;
+ }
+ _disposed = true;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Enumeration for component type.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public enum ComponentType
+ {
+ /// <summary>
+ /// Frame component
+ /// </summary>
+ Frame = 0,
+
+ /// <summary>
+ /// Service component
+ /// </summary>
+ Service = 1
+ }
+}