<Compile Include="../Tizen.Applications.Common/Tizen.Applications/AppControlReplyCallback.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/AppControlReplyResult.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/Application.cs" />
+ <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationDisabledEventArgs.cs" />
+ <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationEnabledEventArgs.cs" />
+ <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationEventState.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfo.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfoFilter.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationInfoMetadataFilter.cs" />
Terminated = 1
}
+ internal enum AppManagerEventStatusType
+ {
+ All = 0x00,
+ Enable = 0x01,
+ Disable = 0x02
+ }
+
+ internal enum AppManagerEventType
+ {
+ Enable = 0,
+ Disable = 1
+ }
+
+ internal enum AppManagerEventState
+ {
+ Started = 0,
+ Completed = 1,
+ Failed = 2
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void AppManagerEventCallback(string appType, string appId, AppManagerEventType eventType, AppManagerEventState eventState, IntPtr eventHandle, IntPtr userData);
+ //void(* app_manager_event_cb)(const char *type, const char *app_id, app_manager_event_type_e event_type, app_manager_event_state_e event_state, app_manager_event_h handle, void *user_data)
+
+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void AppManagerAppContextEventCallback(IntPtr handle, AppContextEvent state, IntPtr userData);
//void(* app_manager_app_context_event_cb)(app_context_h app_context, app_context_event_e event, void *user_data)
internal static extern ErrorCode AppManagerGetExternalSharedDataPath(string applicationId, out string path);
//int app_manager_get_external_shared_data_path (const char *appid, char **path);
+ [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_create")]
+ internal static extern ErrorCode AppManagerEventCreate(out IntPtr handle);
+ //int app_manager_event_create (app_manager_event_h *handle);
+
+ [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_set_status")]
+ internal static extern ErrorCode AppManagerEventSetStatus(IntPtr handle, AppManagerEventStatusType statusType);
+ //int app_manager_event_set_status (app_manager_event_h handle, int status_type);
+
+ [DllImport(Libraries.AppManager, EntryPoint = "app_manager_set_event_cb")]
+ internal static extern ErrorCode AppManagerSetEventCallback(IntPtr handle, AppManagerEventCallback callback, IntPtr userData);
+ //int app_manager_set_event_cb (app_manager_event_h handle, app_manager_event_cb callback, void *user_data);
+
+ [DllImport(Libraries.AppManager, EntryPoint = "app_manager_unset_event_cb")]
+ internal static extern ErrorCode AppManagerUnSetEventCallback(IntPtr handle);
+ //int app_manager_unset_event_cb (app_manager_event_h handle);
+
+ [DllImport(Libraries.AppManager, EntryPoint = "app_manager_event_destroy")]
+ internal static extern ErrorCode AppManagerEventDestroy(IntPtr handle);
+ //int app_manager_event_destroy (app_manager_event_h handle);
+
[DllImport(Libraries.AppManager, EntryPoint = "app_context_destroy")]
internal static extern ErrorCode AppContextDestroy(IntPtr handle);
//int app_context_destroy(app_context_h app_context)
<Compile Include="Tizen.Applications.CoreBackend\EventType.cs" />
<Compile Include="Tizen.Applications.CoreBackend\DefaultCoreBackend.cs" />
<Compile Include="Tizen.Applications.CoreBackend\ICoreBackend.cs" />
+ <Compile Include="Tizen.Applications\ApplicationEnabledEventArgs.cs" />
+ <Compile Include="Tizen.Applications\ApplicationDisabledEventArgs.cs" />
+ <Compile Include="Tizen.Applications\ApplicationEventState.cs" />
<Compile Include="Tizen.Applications\ApplicationInfo.cs" />
<Compile Include="Tizen.Applications\ApplicationManager.cs" />
<Compile Include="Tizen.Applications\ApplicationInfoFilter.cs" />
--- /dev/null
+/*
+ * Copyright (c) 2017 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;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Arguments for the event that is raised when the application is disabled.
+ /// </summary>
+ public class ApplicationDisabledEventArgs : EventArgs
+ {
+ private readonly ApplicationEventState _eventState;
+ private readonly string _applicationId;
+
+ internal ApplicationDisabledEventArgs(string appId, ApplicationEventState eventState)
+ {
+ _applicationId = appId;
+ _eventState = eventState;
+ }
+
+ /// <summary>
+ /// The Id of the application
+ /// </summary>
+ public string ApplicationId { get { return _applicationId; } }
+
+ /// <summary>
+ /// The Event state of the application
+ /// </summary>
+ public ApplicationEventState EventState { get { return _eventState; } }
+ }
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2017 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;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Arguments for the event that is raised when the application is enabled.
+ /// </summary>
+ public class ApplicationEnabledEventArgs : EventArgs
+ {
+ private readonly ApplicationEventState _eventState;
+ private readonly string _applicationId;
+
+ internal ApplicationEnabledEventArgs(string appId, ApplicationEventState eventState)
+ {
+ _applicationId = appId;
+ _eventState = eventState;
+ }
+
+ /// <summary>
+ /// The Id of the application
+ /// </summary>
+ public string ApplicationId { get { return _applicationId; } }
+
+ /// <summary>
+ /// The Event state of the application
+ /// </summary>
+ public ApplicationEventState EventState { get { return _eventState; } }
+ }
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2017 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;
+
+namespace Tizen.Applications
+{
+ /// <summary>
+ /// Enumeration of the application event state
+ /// </summary>
+ public enum ApplicationEventState
+ {
+ /// <summary>
+ /// Processing Started.
+ /// </summary>
+ Started = Interop.ApplicationManager.AppManagerEventState.Started,
+ /// <summary>
+ /// Processing Completed.
+ /// </summary>
+ Completed = Interop.ApplicationManager.AppManagerEventState.Completed,
+ /// <summary>
+ /// Processing Failed.
+ /// </summary>
+ Failed = Interop.ApplicationManager.AppManagerEventState.Failed
+ }
+}
+
public static class ApplicationManager
{
private const string LogTag = "Tizen.Applications";
-
private static EventHandler<ApplicationLaunchedEventArgs> s_launchedHandler;
private static EventHandler<ApplicationTerminatedEventArgs> s_terminatedHandler;
-
private static Interop.ApplicationManager.AppManagerAppContextEventCallback s_applicationChangedEventCallback;
+ private static EventHandler<ApplicationEnabledEventArgs> _enabledHandler;
+ private static EventHandler<ApplicationDisabledEventArgs> _disabledHandler;
+ private static Interop.ApplicationManager.AppManagerEventCallback _eventCallback;
+ private static IntPtr _eventHandle = IntPtr.Zero;
+
+ /// <summary>
+ /// Occurs whenever the installed application is enabled.
+ /// </summary>
+ public static event EventHandler<ApplicationEnabledEventArgs> ApplicationEnabled
+ {
+ add
+ {
+ if (_enabledHandler == null && _disabledHandler == null)
+ {
+ RegisterApplicationEvent();
+ }
+ _enabledHandler += value;
+ }
+ remove
+ {
+ _enabledHandler -= value;
+ if (_enabledHandler == null && _disabledHandler == null)
+ {
+ UnRegisterApplicationEvent();
+ }
+ }
+ }
+
+ /// <summary>
+ /// Occurs whenever the installed application is disabled.
+ /// </summary>
+ public static event EventHandler<ApplicationDisabledEventArgs> ApplicationDisabled
+ {
+ add
+ {
+ if (_disabledHandler == null && _enabledHandler == null)
+ {
+ RegisterApplicationEvent();
+ }
+ _disabledHandler += value;
+ }
+ remove
+ {
+ _disabledHandler -= value;
+ if (_disabledHandler == null && _enabledHandler == null)
+ {
+ UnRegisterApplicationEvent();
+ }
+ }
+ }
/// <summary>
/// Occurs whenever the installed applications get launched.
{
Interop.ApplicationManager.AppManagerUnSetAppContextEvent();
}
+
+ 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");
+ }
+
+ _eventCallback = (string appType, string appId, Interop.ApplicationManager.AppManagerEventType eventType, Interop.ApplicationManager.AppManagerEventState eventState, IntPtr eventHandle, IntPtr UserData) =>
+ {
+ if (eventType == Interop.ApplicationManager.AppManagerEventType.Enable)
+ {
+ _enabledHandler?.Invoke(null, new ApplicationEnabledEventArgs(appId, (ApplicationEventState)eventState));
+ }
+ else if (eventType == Interop.ApplicationManager.AppManagerEventType.Disable)
+ {
+ _disabledHandler?.Invoke(null, new ApplicationDisabledEventArgs(appId, (ApplicationEventState)eventState));
+ }
+ };
+ err = Interop.ApplicationManager.AppManagerSetEventCallback(_eventHandle, _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");
+ }
+ }
+
+ private static void UnRegisterApplicationEvent()
+ {
+ if (_eventHandle != IntPtr.Zero)
+ {
+ Interop.ApplicationManager.AppManagerUnSetEventCallback(_eventHandle);
+ Interop.ApplicationManager.AppManagerEventDestroy(_eventHandle);
+ _eventHandle = IntPtr.Zero;
+ }
+ }
}
internal static class FilterExtension