Skip to content

Commit 31a6f03

Browse files
authored
[Applications.Common][Non-ACR] Add internal apis (#7480)
Adds: - AppControl.SetDefaultApplication() - AppControl.UnsetDefaultApplication() - AppControl.ExportAsBundle() - ApplicationManager.GetRuaStatTags() Signed-off-by: Changgyu Choi <uppletaste@gmail.com>
1 parent 39e903d commit 31a6f03

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

src/Tizen.Applications.Common/Interop/Interop.AppControl.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,14 @@ internal enum ErrorCode
178178

179179
[DllImport(Libraries.AppControl, EntryPoint = "app_control_get_screen_name")]
180180
internal static extern ErrorCode GetScreenName(SafeAppControlHandle handle, out string screen_name);
181+
182+
[DllImport(Libraries.AppControl, EntryPoint = "app_control_set_defapp")]
183+
internal static extern ErrorCode SetDefaultApplication(SafeAppControlHandle handle, string appId);
184+
185+
[DllImport(Libraries.AppControl, EntryPoint = "app_control_unset_defapp")]
186+
internal static extern ErrorCode UnsetDefaultApplication(string appId);
187+
188+
[DllImport(Libraries.AppControl, EntryPoint = "app_control_export_as_bundle")]
189+
internal static extern ErrorCode ExportAsBundle(SafeAppControlHandle handle, out IntPtr bundle);
181190
}
182191
}

src/Tizen.Applications.Common/Interop/Interop.ApplicationManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,16 @@ internal struct RuaRec
453453
[DllImport(Libraries.Rua, EntryPoint = "rua_unregister_update_cb")]
454454
internal static extern ErrorCode RuaUnSetUpdateCallback(int id);
455455
//int rua_unregister_update_cb(int callback_id);
456+
457+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
458+
internal delegate int RuaStatTagIterCallback([MarshalAs(UnmanagedType.LPStr)] string ruaStatTag,
459+
IntPtr userData);
460+
// int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data)
461+
462+
[DllImport(Libraries.Rua, EntryPoint = "rua_stat_get_stat_tags")]
463+
internal static extern ErrorCode RuaStatGetStatTags(string caller, RuaStatTagIterCallback callback,
464+
IntPtr userData);
465+
// int rua_stat_get_stat_tags(char *caller, int (*rua_stat_tag_iter_fn)(const char *rua_stat_tag, void *data),
466+
// void *data);
456467
}
457468
}

src/Tizen.Applications.Common/Tizen.Applications/AppControl.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,113 @@ public static void UnsetAutoRestart()
10311031
}
10321032
}
10331033

1034+
/// <summary>
1035+
/// Sets the default application for the app control.
1036+
/// </summary>
1037+
/// <remarks>
1038+
/// This method sets the specified application as the default handler
1039+
/// for the given app control's operation, MIME type, and URI combination.
1040+
/// This method is only available for platform level signed applications.
1041+
/// </remarks>
1042+
/// <param name="appControl">The AppControl.</param>
1043+
/// <param name="applicationId">The application ID to set as default.</param>
1044+
/// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
1045+
/// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
1046+
/// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
1047+
/// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
1048+
/// <since_tizen> 14 </since_tizen>
1049+
[EditorBrowsable(EditorBrowsableState.Never)]
1050+
public static void SetDefaultApplication(AppControl appControl, string applicationId)
1051+
{
1052+
if (appControl == null)
1053+
{
1054+
throw new ArgumentNullException(nameof(appControl));
1055+
}
1056+
1057+
if (string.IsNullOrEmpty(applicationId))
1058+
{
1059+
throw new ArgumentNullException(nameof(applicationId));
1060+
}
1061+
1062+
Interop.AppControl.ErrorCode err =
1063+
Interop.AppControl.SetDefaultApplication(appControl._handle, applicationId);
1064+
if (err != Interop.AppControl.ErrorCode.None)
1065+
{
1066+
switch (err)
1067+
{
1068+
case Interop.AppControl.ErrorCode.InvalidParameter:
1069+
throw new ArgumentException("Invalid arguments");
1070+
case Interop.AppControl.ErrorCode.PermissionDenied:
1071+
throw new Exceptions.PermissionDeniedException("Permission denied");
1072+
case Interop.AppControl.ErrorCode.OutOfMemory:
1073+
throw new Exceptions.OutOfMemoryException("Out of memory");
1074+
default:
1075+
throw new InvalidOperationException("err = " + err);
1076+
}
1077+
}
1078+
}
1079+
1080+
/// <summary>
1081+
/// Unsets the default application.
1082+
/// </summary>
1083+
/// <remarks>
1084+
/// This method removes the default application setting for the specified application ID.
1085+
/// This method is only available for platform level signed applications.
1086+
/// </remarks>
1087+
/// <param name="applicationId">The application ID to unset as default.</param>
1088+
/// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
1089+
/// <exception cref="ArgumentException">Thrown when the argument is invalid.</exception>
1090+
/// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
1091+
/// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
1092+
/// <since_tizen> 14 </since_tizen>
1093+
[EditorBrowsable(EditorBrowsableState.Never)]
1094+
public static void UnsetDefaultApplication(string applicationId)
1095+
{
1096+
if (string.IsNullOrEmpty(applicationId))
1097+
{
1098+
throw new ArgumentNullException(nameof(applicationId));
1099+
}
1100+
1101+
Interop.AppControl.ErrorCode err = Interop.AppControl.UnsetDefaultApplication(applicationId);
1102+
if (err != Interop.AppControl.ErrorCode.None)
1103+
{
1104+
switch (err)
1105+
{
1106+
case Interop.AppControl.ErrorCode.InvalidParameter:
1107+
throw new ArgumentException("Invalid arguments");
1108+
case Interop.AppControl.ErrorCode.PermissionDenied:
1109+
throw new Exceptions.PermissionDeniedException("Permission denied");
1110+
default:
1111+
throw new InvalidOperationException("err = " + err);
1112+
}
1113+
}
1114+
}
1115+
1116+
/// <summary>
1117+
/// Exports the app control data as a bundle.
1118+
/// </summary>
1119+
/// <remarks>
1120+
/// This method exports the internal data of the app control as a Bundle object.
1121+
/// The exported bundle contains all the information of the app control, including
1122+
/// the operation, URI, MIME type, extra data, and internal AUL data.
1123+
/// This method is only available for platform level signed applications.
1124+
/// </remarks>
1125+
/// <returns>The exported Bundle object.</returns>
1126+
/// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
1127+
/// <since_tizen> 14 </since_tizen>
1128+
[EditorBrowsable(EditorBrowsableState.Never)]
1129+
public Bundle ExportAsBundle()
1130+
{
1131+
Interop.AppControl.ErrorCode err = Interop.AppControl.ExportAsBundle(_handle, out IntPtr bundleHandle);
1132+
if (err != Interop.AppControl.ErrorCode.None)
1133+
{
1134+
throw new InvalidOperationException("Failed to export app control as bundle. err = " + err);
1135+
}
1136+
1137+
SafeBundleHandle safeBundleHandle = new SafeBundleHandle(bundleHandle, true);
1138+
return new Bundle(safeBundleHandle);
1139+
}
1140+
10341141
/// <summary>
10351142
/// Gets all default applications.
10361143
/// </summary>

src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,48 @@ public static IEnumerable<RecentApplicationInfo> GetRecentApplications()
863863
return result;
864864
}
865865

866+
/// <summary>
867+
/// Gets the RUA (Recently Used Applications) stat tags for the specified caller.
868+
/// </summary>
869+
/// <remarks>
870+
/// This method retrieves the list of application IDs that have been launched
871+
/// by the specified caller application, as recorded in the RUA statistics.
872+
/// This method is only available for platform level signed applications.
873+
/// </remarks>
874+
/// <param name="caller">The caller application identifier.</param>
875+
/// <returns>An enumerable collection of application IDs (stat tags).</returns>
876+
/// <exception cref="ArgumentNullException">Thrown when the caller argument is null.</exception>
877+
/// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
878+
/// <since_tizen> 14 </since_tizen>
879+
[EditorBrowsable(EditorBrowsableState.Never)]
880+
public static IEnumerable<string> GetRuaStatTags(string caller)
881+
{
882+
if (caller == null)
883+
{
884+
throw new ArgumentNullException(nameof(caller));
885+
}
886+
887+
List<string> tags = new List<string>();
888+
Interop.ApplicationManager.RuaStatTagIterCallback callback = (string ruaStatTag, IntPtr userData) =>
889+
{
890+
if (!string.IsNullOrEmpty(ruaStatTag))
891+
{
892+
tags.Add(ruaStatTag);
893+
}
894+
return 0;
895+
};
896+
897+
Interop.ApplicationManager.ErrorCode err =
898+
Interop.ApplicationManager.RuaStatGetStatTags(caller, callback, IntPtr.Zero);
899+
if (err != Interop.ApplicationManager.ErrorCode.None)
900+
{
901+
throw ApplicationManagerErrorFactory.GetException(err, "Failed to get RUA stat tags.");
902+
}
903+
GC.KeepAlive(callback);
904+
905+
return tags;
906+
}
907+
866908
/// <summary>
867909
/// Attaches the window of the child application to the window of the parent application.
868910
/// </summary>

0 commit comments

Comments
 (0)