From f2fad196c3ba809bdd78e7820c843d1915956c0a Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Tue, 5 Nov 2019 18:01:02 +0300 Subject: [PATCH 1/5] fix merger script --- Assets/AppCenter/Editor/CreateManifest.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/AppCenter/Editor/CreateManifest.cs b/Assets/AppCenter/Editor/CreateManifest.cs index 3de65675..09852b5e 100644 --- a/Assets/AppCenter/Editor/CreateManifest.cs +++ b/Assets/AppCenter/Editor/CreateManifest.cs @@ -143,18 +143,22 @@ public class CreateManifest Directory.Delete(loaderFolder, true); return; } + var activityElement = new XElement("activity"); var activityElements = applicationElements[0].Elements().Where(element => element.Name.LocalName == "activity").ToList(); - // Delete the unzipped folder if the activity element already exists in the AndroidManifest.xml file if (activityElements.Count == 1) { - Directory.Delete(loaderFolder, true); - return; + activityElement = activityElements[0]; } - var intentElement = new XElement("intent-filter"); + var intentElements = activityElement.Elements().Where(element => element.Name.LocalName == "intent-filter").ToList(); + + if (intentElements.Count == 1) + { + intentElement = intentElements[0]; + } XNamespace ns = "http://schemas.android.com/apk/res/android"; - var activityElement = new XElement("activity"); + activityElement.SetAttributeValue(ns + "name", "com.microsoft.identity.client.BrowserTabActivity"); var actionElement = new XElement("action"); actionElement.SetAttributeValue(ns + "name", "android.intent.action.VIEW"); From 9e1a0174776a68409119c7b175a8d80c7f371899 Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Tue, 5 Nov 2019 18:03:08 +0300 Subject: [PATCH 2/5] Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d55b9f9..cdcf623b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Updated native SDK versions: * **[Fix]** Fix `AppCenterStarter.m` was not included in the first build. * **[Fix]** Fix Unity 2019.3 iOS build. +### App Center Auth + +* **[Fix]** Fix Auth was incorrectly caching the old app secret in the manifest if it wqas changed. + ### App Center Crashes #### Android From c8adb3238a04bcae78b0f3a235c6e7932ffc2a8d Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Tue, 5 Nov 2019 18:12:01 +0300 Subject: [PATCH 3/5] One more fix and formatting --- Assets/AppCenter/Editor/CreateManifest.cs | 19 ++++++++----------- CHANGELOG.md | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Assets/AppCenter/Editor/CreateManifest.cs b/Assets/AppCenter/Editor/CreateManifest.cs index 09852b5e..f0f9aa85 100644 --- a/Assets/AppCenter/Editor/CreateManifest.cs +++ b/Assets/AppCenter/Editor/CreateManifest.cs @@ -143,22 +143,19 @@ public class CreateManifest Directory.Delete(loaderFolder, true); return; } - var activityElement = new XElement("activity"); - var activityElements = applicationElements[0].Elements().Where(element => element.Name.LocalName == "activity").ToList(); - if (activityElements.Count == 1) + var activityElement = applicationElements[0].Elements().FirstOrDefault(element => element.Name.LocalName == "activity"); + if (activityElement == null) { - activityElement = activityElements[0]; + activityElement = new XElement("activity"); + } + var intentElement = activityElement.Elements().FirstOrDefault(element => element.Name.LocalName == "intent-filter"); + if (intentElement == null) + { + intentElement = new XElement("intent-filter"); } - var intentElement = new XElement("intent-filter"); - var intentElements = activityElement.Elements().Where(element => element.Name.LocalName == "intent-filter").ToList(); - if (intentElements.Count == 1) - { - intentElement = intentElements[0]; - } XNamespace ns = "http://schemas.android.com/apk/res/android"; - activityElement.SetAttributeValue(ns + "name", "com.microsoft.identity.client.BrowserTabActivity"); var actionElement = new XElement("action"); actionElement.SetAttributeValue(ns + "name", "android.intent.action.VIEW"); diff --git a/CHANGELOG.md b/CHANGELOG.md index cdcf623b..a545a66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Updated native SDK versions: ### App Center Auth -* **[Fix]** Fix Auth was incorrectly caching the old app secret in the manifest if it wqas changed. +* **[Fix]** Fix Auth was incorrectly caching the old app secret in the manifest if it was changed. ### App Center Crashes From cfd199734916e9d25e70b07577fe14a5d3f8e57a Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Tue, 5 Nov 2019 18:33:11 +0300 Subject: [PATCH 4/5] Prevent duplicate elements --- Assets/AppCenter/Editor/CreateManifest.cs | 41 +++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Assets/AppCenter/Editor/CreateManifest.cs b/Assets/AppCenter/Editor/CreateManifest.cs index f0f9aa85..35a8b3e7 100644 --- a/Assets/AppCenter/Editor/CreateManifest.cs +++ b/Assets/AppCenter/Editor/CreateManifest.cs @@ -143,36 +143,63 @@ public class CreateManifest Directory.Delete(loaderFolder, true); return; } - + bool activityElementIsNew = false; var activityElement = applicationElements[0].Elements().FirstOrDefault(element => element.Name.LocalName == "activity"); if (activityElement == null) { + activityElementIsNew = true; activityElement = new XElement("activity"); } + bool intentElementIsNew = false; var intentElement = activityElement.Elements().FirstOrDefault(element => element.Name.LocalName == "intent-filter"); if (intentElement == null) { + intentElementIsNew = true; intentElement = new XElement("intent-filter"); } XNamespace ns = "http://schemas.android.com/apk/res/android"; activityElement.SetAttributeValue(ns + "name", "com.microsoft.identity.client.BrowserTabActivity"); - var actionElement = new XElement("action"); + var actionElement = intentElement.Elements().FirstOrDefault(element => element.Name.LocalName == "intent-filter"); + bool actionElementIsNew = false; + if (actionElement == null) + { + actionElementIsNew = true; + actionElement = new XElement("action"); + } actionElement.SetAttributeValue(ns + "name", "android.intent.action.VIEW"); var categoryElement1 = new XElement("category"); categoryElement1.SetAttributeValue(ns + "name", "android.intent.category.DEFAULT"); var categoryElement2 = new XElement("category"); categoryElement2.SetAttributeValue(ns + "name", "android.intent.category.BROWSABLE"); - var dataElement = new XElement("data"); + bool dataElementIsNew = false; + var dataElement = intentElement.Elements().FirstOrDefault(element => element.Name.LocalName == "data"); + if (dataElement == null) + { + dataElementIsNew = true; + dataElement = new XElement("data"); + } dataElement.SetAttributeValue(ns + "host", "auth"); dataElement.SetAttributeValue(ns + "scheme", "msal" + settings.AndroidAppSecret); - intentElement.Add(actionElement); + if (actionElementIsNew) + { + intentElement.Add(actionElement); + } intentElement.Add(categoryElement1); intentElement.Add(categoryElement2); - intentElement.Add(dataElement); - activityElement.Add(intentElement); - applicationElements[0].Add(activityElement); + if (dataElementIsNew) + { + intentElement.Add(dataElement); + } + if (intentElementIsNew) + { + activityElement.Add(intentElement); + } + if (activityElementIsNew) + { + applicationElements[0].Add(activityElement); + } xmlFile.Save(manifestPath); // Delete the AndroidManifest.xml.meta file if generated From 9730e281d8c2605deb703f93d9a291d34bdf5f18 Mon Sep 17 00:00:00 2001 From: Anna Kocheshkova Date: Tue, 5 Nov 2019 18:50:43 +0300 Subject: [PATCH 5/5] Simplify merging logic --- Assets/AppCenter/Editor/CreateManifest.cs | 54 ++++++----------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/Assets/AppCenter/Editor/CreateManifest.cs b/Assets/AppCenter/Editor/CreateManifest.cs index 35a8b3e7..153991b7 100644 --- a/Assets/AppCenter/Editor/CreateManifest.cs +++ b/Assets/AppCenter/Editor/CreateManifest.cs @@ -143,60 +143,34 @@ public class CreateManifest Directory.Delete(loaderFolder, true); return; } - bool activityElementIsNew = false; - var activityElement = applicationElements[0].Elements().FirstOrDefault(element => element.Name.LocalName == "activity"); - if (activityElement == null) - { - activityElementIsNew = true; - activityElement = new XElement("activity"); - } - bool intentElementIsNew = false; - var intentElement = activityElement.Elements().FirstOrDefault(element => element.Name.LocalName == "intent-filter"); - if (intentElement == null) - { - intentElementIsNew = true; - intentElement = new XElement("intent-filter"); - } + var activityElementOld = applicationElements[0].Elements().FirstOrDefault(element => element.Name.LocalName == "activity"); + + var intentElement = new XElement("intent-filter"); XNamespace ns = "http://schemas.android.com/apk/res/android"; + var activityElement = new XElement("activity"); activityElement.SetAttributeValue(ns + "name", "com.microsoft.identity.client.BrowserTabActivity"); - var actionElement = intentElement.Elements().FirstOrDefault(element => element.Name.LocalName == "intent-filter"); - bool actionElementIsNew = false; - if (actionElement == null) - { - actionElementIsNew = true; - actionElement = new XElement("action"); - } + var actionElement = new XElement("action"); actionElement.SetAttributeValue(ns + "name", "android.intent.action.VIEW"); var categoryElement1 = new XElement("category"); categoryElement1.SetAttributeValue(ns + "name", "android.intent.category.DEFAULT"); var categoryElement2 = new XElement("category"); categoryElement2.SetAttributeValue(ns + "name", "android.intent.category.BROWSABLE"); - bool dataElementIsNew = false; - var dataElement = intentElement.Elements().FirstOrDefault(element => element.Name.LocalName == "data"); - if (dataElement == null) - { - dataElementIsNew = true; - dataElement = new XElement("data"); - } + var dataElement = new XElement("data"); dataElement.SetAttributeValue(ns + "host", "auth"); dataElement.SetAttributeValue(ns + "scheme", "msal" + settings.AndroidAppSecret); - if (actionElementIsNew) - { - intentElement.Add(actionElement); - } + intentElement.Add(actionElement); intentElement.Add(categoryElement1); intentElement.Add(categoryElement2); - if (dataElementIsNew) + intentElement.Add(dataElement); + activityElement.Add(intentElement); + + if (activityElementOld != null) { - intentElement.Add(dataElement); + activityElementOld.ReplaceWith(activityElement); } - if (intentElementIsNew) - { - activityElement.Add(intentElement); - } - if (activityElementIsNew) + else { applicationElements[0].Add(activityElement); } @@ -213,4 +187,4 @@ public class CreateManifest ZipFile(loaderFolder, loaderZipFile); Directory.Delete(loaderFolder, true); } -} +} \ No newline at end of file