Skip to content

Commit 7e5bb3a

Browse files
committed
Update AdjustImeiEditor not to overwrite unchanged AndroidManifest.xml
1 parent 25e5939 commit 7e5bb3a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

Assets/AdjustImei/Editor/AdjustImeiEditor.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,32 @@ private static void RunPostProcessTasksAndroid()
129129
// Let's open the app's AndroidManifest.xml file.
130130
XmlDocument manifestFile = new XmlDocument();
131131
manifestFile.Load(appManifestPath);
132+
133+
bool manifestHasChanged = false;
132134

133135
// Add needed permissions if they are missing.
134-
AddPermissions(manifestFile);
136+
manifestHasChanged |= AddPermissions(manifestFile);
135137

136-
// Save the changes.
137-
manifestFile.Save(appManifestPath);
138+
if (manifestHasChanged)
139+
{
140+
// Save the changes.
141+
manifestFile.Save(appManifestPath);
138142

139-
// Clean the manifest file.
140-
CleanManifestFile(appManifestPath);
143+
// Clean the manifest file.
144+
CleanManifestFile(appManifestPath);
141145

142-
UnityEngine.Debug.Log("[AdjustImei]: App's AndroidManifest.xml file check and potential modification completed.");
143-
UnityEngine.Debug.Log("[AdjustImei]: Please check if any error message was displayed during this process "
144-
+ "and make sure to fix all issues in order to properly use the Adjust IMEI plugin in your app.");
146+
UnityEngine.Debug.Log("[AdjustImei]: App's AndroidManifest.xml file check and potential modification completed.");
147+
UnityEngine.Debug.Log("[AdjustImei]: Please check if any error message was displayed during this process "
148+
+ "and make sure to fix all issues in order to properly use the Adjust IMEI plugin in your app.");
149+
}
150+
else
151+
{
152+
UnityEngine.Debug.Log("[AdjustImei]: App's AndroidManifest.xml file check completed.");
153+
UnityEngine.Debug.Log("[AdjustImei]: No modifications performed due to app's AndroidManifest.xml file compatibility.");
154+
}
145155
}
146156

147-
private static void AddPermissions(XmlDocument manifest)
157+
private static bool AddPermissions(XmlDocument manifest)
148158
{
149159
// The Adjust IMEI plugin needs following permissions to be added to you app's manifest file:
150160
// <uses-permission android:name="android.permission.READ_PHONE_STATE" />
@@ -169,19 +179,24 @@ private static void AddPermissions(XmlDocument manifest)
169179
}
170180
}
171181

182+
bool manifestHasChanged = false;
183+
172184
// If android.permission.READ_PHONE_STATE permission is missing, add it.
173185
if (!hasReadPhoneStatePermission)
174186
{
175187
XmlElement element = manifest.CreateElement("uses-permission");
176188
element.SetAttribute("android__name", "android.permission.READ_PHONE_STATE");
177189
manifestRoot.AppendChild(element);
178190
UnityEngine.Debug.Log("[AdjustImei]: android.permission.READ_PHONE_STATE permission successfully added to your app's AndroidManifest.xml file.");
191+
manifestHasChanged = true;
179192
}
180193
else
181194
{
182195
UnityEngine.Debug.Log("[AdjustImei]: Your app's AndroidManifest.xml file already contains android.permission.READ_PHONE_STATE permission.");
183196
UnityEngine.Debug.Log("[AdjustImei]: All good.");
184197
}
198+
199+
return manifestHasChanged;
185200
}
186201

187202
private static void CleanManifestFile(String manifestPath)

0 commit comments

Comments
 (0)