/// <summary> /// Create all provider elements /// </summary> private void CreateProvider(XElement manifest) { // Create services foreach (var tuple in FindProviders()) { var type = tuple.Item1; var xType = XBuilder.AsTypeDefinition(module, type); var attr = tuple.Item2; var provider = new XElement("provider"); manifest.Add(provider); provider.AddAttr("name", Namespace, FormatClassName(xType)); var authoritiesArr = (attr != null) ? attr.GetValue <string[]>("Authorities") : null; if (authoritiesArr != null && authoritiesArr.Any()) { //semicolon seperated list provider.AddAttr("authorities", Namespace, string.Join(";", authoritiesArr)); } provider.AddAttrIfFound("enabled", Namespace, attr, "Enabled"); provider.AddAttrIfFound("exported", Namespace, attr, "Exported"); provider.AddAttrIfFound("grantUriPermissions", Namespace, attr, "GrantUriPermissions"); provider.AddAttrIfNotEmpty("icon", Namespace, attr.GetValue <string>("Icon"), FormatDrawable); provider.AddAttrIfNotEmpty("label", Namespace, attr.GetValue <string>("Label"), FormatStringOrLiteral); provider.AddAttrIfFound("multiprocess", Namespace, attr, "MultiProcess"); provider.AddAttrIfNotEmpty("permission", Namespace, attr.GetValue <string>("Permission")); provider.AddAttrIfNotEmpty("process", Namespace, attr.GetValue <string>("Process")); provider.AddAttrIfNotEmpty("readPermission", Namespace, attr.GetValue <string>("ReadPermission")); provider.AddAttrIfFound("syncable", Namespace, attr, "Syncable"); provider.AddAttrIfNotEmpty("writePermission", Namespace, attr.GetValue <string>("WritePermission")); } }
/// <summary> /// Create the supports-screens element /// </summary> private void CreateSupportsScreens(XElement manifest) { // Find supports-screens attribute var ssAttributes = assembly.GetAttributes(SupportsScreensAttribute).ToList(); if (ssAttributes.Count == 0) { return; } if (ssAttributes.Count > 1) { throw new ArgumentException("Multiple SupportsScreens attributes found"); } var attr = ssAttributes[0]; // Create supports-screens var supportsScreens = new XElement("supports-screens"); manifest.Add(supportsScreens); supportsScreens.AddAttrIfFound("smallScreens", Namespace, attr, "SmallScreens"); supportsScreens.AddAttrIfFound("normalScreens", Namespace, attr, "NormalScreens"); supportsScreens.AddAttrIfFound("largeScreens", Namespace, attr, "LargeScreens"); supportsScreens.AddAttrIfFound("xlargeScreens", Namespace, attr, "XLargeScreens"); supportsScreens.AddAttrIfNotDefault("requiresSmallestWidthDp", Namespace, attr.GetValue <int>("RequiresSmallestWidthDp"), 0, x => x.ToString()); supportsScreens.AddAttrIfNotDefault("compatibleWidthLimitDp", Namespace, attr.GetValue <int>("CompatibleWidthLimitDp"), 0, x => x.ToString()); supportsScreens.AddAttrIfNotDefault("largestWidthLimitDp", Namespace, attr.GetValue <int>("LargestWidthLimitDp"), 0, x => x.ToString()); }
/// <summary> /// Create all service elements /// </summary> private void CreateService(XElement application) { // Create services foreach (var tuple in FindServices()) { var type = tuple.Item1; var xType = XBuilder.AsTypeDefinition(module, type); var attr = tuple.Item2; var service = new XElement("service"); application.Add(service); service.AddAttr("name", Namespace, FormatClassName(xType)); service.AddAttrIfNotEmpty("label", Namespace, attr.GetValue <string>("Label"), FormatStringOrLiteral); service.AddAttrIfNotEmpty("icon", Namespace, attr.GetValue <string>("Icon"), FormatDrawable); service.AddAttrIfFound("enabled", Namespace, attr, "Enabled"); service.AddAttrIfFound("exported", Namespace, attr, "Exporter"); service.AddAttrIfFound("isolatedProcess", Namespace, attr, "IsolatedProcess"); service.AddAttrIfNotEmpty("permission", Namespace, attr.GetValue <string>("Permission")); service.AddAttrIfNotEmpty("process", Namespace, attr.GetValue <string>("Process")); service.AddAttrIfFound("stopWithTask", Namespace, attr, "StopWithTask"); CreateIntentFilter(service, type, false, false); CreateMetaData(service, type); } }
/// <summary> /// Create the application element /// </summary> private void CreateApplication(Targets target, XElement manifest, string outputFolder) { // Find application attribute var appTuple = FindApplication(); var attr = appTuple.Item2; var label = attr.GetValue <string>(0, "Label"); if (string.IsNullOrEmpty(label)) { throw new ArgumentException(string.Format("No Label set in {0}", attr)); } var icon = attr.GetValue <string>("Icon"); if (string.IsNullOrEmpty(icon)) { // Select icon from activity var activityIcons = FindActivities().Select(x => x.Item2.GetValue <string>("Icon")).Where(x => !string.IsNullOrEmpty(x)); icon = activityIcons.FirstOrDefault(); } // Create application var application = new XElement("application"); manifest.Add(application); application.AddAttr("label", Namespace, FormatStringOrLiteral(label)); if (appTuple.Item1 != null) { var xType = XBuilder.AsTypeDefinition(module, appTuple.Item1); application.AddAttr("name", Namespace, FormatClassName(xType)); } application.AddAttrIfNotEmpty("icon", Namespace, icon, FormatDrawable); application.AddAttrIfNotEmpty("theme", Namespace, attr.GetValue <string>("Theme"), FormatStyle); application.AddAttrIfNotEmpty("description", Namespace, attr.GetValue <string>("Description")); application.AddAttrIfNotEmpty("logo", Namespace, attr.GetValue <string>("Logo"), FormatDrawable); application.AddAttrIfNotDefault("debuggable", Namespace, attr.GetValue <bool>("Debuggable", debuggable), false); application.AddAttrIfFound("enabled", Namespace, attr, "Enabled"); application.AddAttrIfNotDefault("persistent", Namespace, attr.GetValue <bool>("Persistent"), false); application.AddAttrIfFound("allowTaskReparenting", Namespace, attr, "AllowTaskReparenting"); application.AddAttrIfNotEmpty("backupAgent", Namespace, attr.GetValue <Type>("BackupAgent"), nsConverter.GetConvertedFullName); application.AddAttrIfFound("hardwareAccelerated", Namespace, attr, "HardwareAccelerated"); application.AddAttrIfFound("killAfterRestore", Namespace, attr, "KillAfterRestore"); application.AddAttrIfFound("largeHeap", Namespace, attr, "LargeHeap"); application.AddAttrIfNotEmpty("manageSpaceActivity", Namespace, attr.GetValue <Type>("ManageSpaceActivity"), nsConverter.GetConvertedFullName); application.AddAttrIfNotEmpty("process", Namespace, attr.GetValue <string>("Process")); application.AddAttrIfFound("restoreAnyVersion", Namespace, attr, "RestoreAnyVersion"); application.AddAttrIfNotEmpty("taskAffinity", Namespace, attr.GetValue <string>("TaskAffinity")); application.AddAttrIfNotDefault("uiOptions", Namespace, attr.GetValue <int>("UIOptions"), 0, uiOptions.Format); // Create child elements CreateActivity(application); CreateService(application); CreateReceiver(application); CreateAppWidgetProvider(application, outputFolder); CreateUsesLibrary(application); CreateProvider(application); CreateMetaData(application, assembly); // Must be last }
/// <summary> /// Create all receiver elements /// </summary> private void CreateReceiver(XElement application) { // Create receivers foreach (var tuple in FindReceivers()) { var type = tuple.Item1; var xType = XBuilder.AsTypeDefinition(module, type); var attr = tuple.Item2; var receiver = new XElement("receiver"); application.Add(receiver); receiver.AddAttr("name", Namespace, FormatClassName(xType)); receiver.AddAttrIfNotEmpty("label", Namespace, attr.GetValue <string>("Label"), FormatStringOrLiteral); receiver.AddAttrIfNotEmpty("icon", Namespace, attr.GetValue <string>("Icon"), FormatDrawable); receiver.AddAttrIfFound("enabled", Namespace, attr, "Enabled"); receiver.AddAttrIfFound("exported", Namespace, attr, "Exported"); receiver.AddAttrIfNotEmpty("permission", Namespace, attr.GetValue <string>("Permission")); receiver.AddAttrIfNotEmpty("process", Namespace, attr.GetValue <string>("Process")); CreateIntentFilter(receiver, type, false, false); CreateMetaData(receiver, type); } }
/// <summary> /// Create all activity elements /// </summary> private void CreateActivity(XElement application) { // Create activities foreach (var tuple in FindActivities()) { var type = tuple.Item1; var xType = XBuilder.AsTypeDefinition(module, type); var attr = tuple.Item2; var activity = new XElement("activity"); application.Add(activity); activity.AddAttr("name", Namespace, FormatClassName(xType)); activity.AddAttrIfNotEmpty("label", Namespace, attr.GetValue <string>("Label"), FormatStringOrLiteral); activity.AddAttrIfNotEmpty("icon", Namespace, attr.GetValue <string>("Icon"), FormatDrawable); activity.AddAttrIfFound("allowTaskReparenting", Namespace, attr, "AllowTaskReparenting"); activity.AddAttrIfFound("alwaysRetainTaskState", Namespace, attr, "AlwaysRetainTaskState"); activity.AddAttrIfFound("clearTaskOnLaunch", Namespace, attr, "ClearTaskOnLaunch"); activity.AddAttrIfNotDefault("configChanges", Namespace, attr.GetValue <int>("ConfigChanges"), 0, configChangesOptions.Format); activity.AddAttrIfFound("enabled", Namespace, attr, "Enabled"); activity.AddAttrIfFound("excludeFromRecents", Namespace, attr, "ExcludeFromRecents"); activity.AddAttrIfFound("exported", Namespace, attr, "Exported"); activity.AddAttrIfFound("finishOnTaskLaunch", Namespace, attr, "FinishOnTaskLaunch"); activity.AddAttrIfFound("hardwareAccelerated", Namespace, attr, "HardwareAccelerated"); activity.AddAttrIfNotDefault("launchMode", Namespace, attr.GetValue <int>("LaunchMode"), 0, launchModesOptions.Format); activity.AddAttrIfFound("multiprocess", Namespace, attr, "MultiProcess"); activity.AddAttrIfFound("noHistory", Namespace, attr, "NoHistory"); activity.AddAttrIfNotEmpty("parentActivityName", Namespace, attr.GetValue <Type>("ParentActivity"), nsConverter.GetConvertedFullName); activity.AddAttrIfNotEmpty("permission", Namespace, attr.GetValue <string>("Permission")); activity.AddAttrIfNotEmpty("process", Namespace, attr.GetValue <string>("Process")); activity.AddAttrIfNotDefault("screenOrientation", Namespace, attr.GetValue <int>("ScreenOrientation"), 0, screenOrientationsOptions.Format); activity.AddAttrIfFound("stateNotNeeded", Namespace, attr, "StateNotNeeded"); activity.AddAttrIfNotEmpty("taskAffinity", Namespace, attr.GetValue <string>("TaskAffinity")); activity.AddAttrIfNotEmpty("theme", Namespace, attr.GetValue <string>("Theme"), FormatStyle); activity.AddAttrIfNotDefault("uiOptions", Namespace, attr.GetValue <int>("UIOptions"), 0, uiOptions.Format); activity.AddAttrIfNotDefault("windowSoftInputMode", Namespace, attr.GetValue <int>("WindowSoftInputMode"), 0, windowSoftInputModeOptions.Format); var visibleInLauncher = attr.GetValue("VisibleInLauncher", true); CreateIntentFilter(activity, type, visibleInLauncher, false); CreateMetaData(activity, type); } }