Skip to content

[ApiXmlAdjuster] Fix for finding "mono.app.android.IntentService". #718

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ public static JavaType FindNonGenericType (this JavaApi api, string name)
ret = ManagedType.DummyManagedPackages
.SelectMany (p => p.Types)
.FirstOrDefault (t => t.FullName == name);
if (ret == null)
if (ret == null) {
// We moved this type to "mono.android.app.IntentService" which makes this
// type resolution fail if a user tries to reference it in Java.
if (name == "android.app.IntentService")
return FindNonGenericType (api, "mono.android.app.IntentService");

throw new JavaTypeResolutionException (string.Format ("Type '{0}' was not found.", name));
}

return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JavaApiTestHelper
"..",
"..");

static readonly string ApiPath = Path.Combine (
public static readonly string ApiPath = Path.Combine (
TopDir,
"tests",
"Xamarin.Android.Tools.ApiXmlAdjuster-Tests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using NUnit.Framework;

namespace Xamarin.Android.Tools.ApiXmlAdjuster.Tests
Expand Down Expand Up @@ -65,6 +68,35 @@ public void ResolveGenericArguments ()
para.ResolvedType.ToString (),
"referenced type is not correctly resolved");
}

[Test]
public void IntentServiceHack ()
{
// https://github.com/xamarin/java.interop/issues/717
var api = JavaApiTestHelper.GetLoadedApi ();

// Create "mono.android.app" package
var mono_android_app = new JavaPackage (api) { Name = "mono.android.app", JniName = "mono/android/app", Types = new List<JavaType> () };
api.Packages.Add (mono_android_app);

// Remove "android.app.IntentService" type
var android_app = api.Packages.Single (p => p.Name == "android.app");
var intent_service = android_app.Types.Single (t => t.Name == "IntentService");
android_app.Types.Remove (intent_service);

// Create new "mono.android.app.IntentService" type
var new_intent_service = new JavaClass (mono_android_app) {
Name = intent_service.Name,
};

mono_android_app.Types.Add (new_intent_service);

api.Resolve ();

// Ensure we can resolve the type by either name
Assert.AreSame (new_intent_service, api.FindNonGenericType ("android.app.IntentService"));
Assert.AreSame (new_intent_service, api.FindNonGenericType ("mono.android.app.IntentService"));
}
}
}