Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[java-runtime] move MonoPackageManager.Context to ApplicationRegistration #9779

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2025
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
6 changes: 5 additions & 1 deletion samples/NativeAOT/NativeAotRuntimeProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.dot.jni.nativeaot;

import android.util.Log;
import net.dot.android.ApplicationRegistration;

public class NativeAotRuntimeProvider
extends android.content.ContentProvider
Expand All @@ -20,9 +21,12 @@ public boolean onCreate() {
@Override
public void attachInfo(android.content.Context context, android.content.pm.ProviderInfo info) {
Log.d(TAG, "NativeAotRuntimeProvider.attachInfo(): calling JavaInteropRuntime.init()…");
if (context instanceof android.app.Application) {
ApplicationRegistration.Context = context;
}
JavaInteropRuntime.init();
// NOTE: only required for custom applications
net.dot.android.ApplicationRegistration.registerApplications();
ApplicationRegistration.registerApplications();
super.attachInfo (context, info);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.App/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static Context Context {
if (_context != null)
return _context;

IntPtr klass = JNIEnv.FindClass ("mono/MonoPackageManager");
IntPtr klass = JNIEnv.FindClass ("net/dot/android/ApplicationRegistration");
try {
IntPtr field = JNIEnv.GetStaticFieldID (klass, "Context", "Landroid/content/Context;");
IntPtr lref = JNIEnv.GetStaticObjectField (klass, field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class ApplicationRegistration {

public static android.content.Context Context;

public static void registerApplications ()
{
// REGISTER_APPLICATION_AND_INSTRUMENTATION_CLASSES_HERE
Expand Down
7 changes: 3 additions & 4 deletions src/java-runtime/java/mono/android/MonoPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
import mono.android.Runtime;
import mono.android.DebugRuntime;
import mono.android.BuildConfig;
import net.dot.android.ApplicationRegistration;

public class MonoPackageManager {

static Object lock = new Object ();
static boolean initialized;

static android.content.Context Context;

public static void LoadApplication (Context context)
{
synchronized (lock) {
Expand All @@ -41,7 +40,7 @@ public static void LoadApplication (Context context)
}

if (context instanceof android.app.Application) {
Context = context;
ApplicationRegistration.Context = context;
}
if (!initialized) {
android.content.IntentFilter timezoneChangedFilter = new android.content.IntentFilter (
Expand Down Expand Up @@ -129,7 +128,7 @@ public static void LoadApplication (Context context)
haveSplitApks
);

net.dot.android.ApplicationRegistration.registerApplications ();
ApplicationRegistration.registerApplications ();

initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class ApplicationRegistration {

public static android.content.Context Context;

public static void registerApplications ()
{
// REGISTER_APPLICATION_AND_INSTRUMENTATION_CLASSES_HERE
Expand Down