|
| 1 | +package mono; |
| 2 | + |
| 3 | +import java.io.*; |
| 4 | +import java.lang.String; |
| 5 | +import java.time.OffsetDateTime; |
| 6 | +import java.time.ZoneOffset; |
| 7 | +import java.util.Calendar; |
| 8 | +import java.util.Locale; |
| 9 | +import java.util.HashSet; |
| 10 | +import java.util.zip.*; |
| 11 | +import java.util.Arrays; |
| 12 | +import android.content.Context; |
| 13 | +import android.content.Intent; |
| 14 | +import android.content.pm.ApplicationInfo; |
| 15 | +import android.content.res.AssetManager; |
| 16 | +import android.os.Build; |
| 17 | +import android.util.Log; |
| 18 | +import mono.android.Runtime; |
| 19 | +import mono.android.DebugRuntime; |
| 20 | +import mono.android.BuildConfig; |
| 21 | + |
| 22 | +public class MonoPackageManager { |
| 23 | + |
| 24 | + static Object lock = new Object (); |
| 25 | + static boolean initialized; |
| 26 | + |
| 27 | + static android.content.Context Context; |
| 28 | + |
| 29 | + public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks) |
| 30 | + { |
| 31 | + synchronized (lock) { |
| 32 | + if (context instanceof android.app.Application) { |
| 33 | + Context = context; |
| 34 | + } |
| 35 | + if (!initialized) { |
| 36 | + android.content.IntentFilter timezoneChangedFilter = new android.content.IntentFilter ( |
| 37 | + android.content.Intent.ACTION_TIMEZONE_CHANGED |
| 38 | + ); |
| 39 | + context.registerReceiver (new mono.android.app.NotifyTimeZoneChanges (), timezoneChangedFilter); |
| 40 | + |
| 41 | + Locale locale = Locale.getDefault (); |
| 42 | + String language = locale.getLanguage () + "-" + locale.getCountry (); |
| 43 | + String filesDir = context.getFilesDir ().getAbsolutePath (); |
| 44 | + String cacheDir = context.getCacheDir ().getAbsolutePath (); |
| 45 | + String dataDir = getNativeLibraryPath (context); |
| 46 | + ClassLoader loader = context.getClassLoader (); |
| 47 | + String runtimeDir = getNativeLibraryPath (runtimePackage); |
| 48 | + int localDateTimeOffset; |
| 49 | + |
| 50 | + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { |
| 51 | + localDateTimeOffset = OffsetDateTime.now().getOffset().getTotalSeconds(); |
| 52 | + } else { |
| 53 | + localDateTimeOffset = (Calendar.getInstance ().get (Calendar.ZONE_OFFSET) + Calendar.getInstance ().get (Calendar.DST_OFFSET)) / 1000; |
| 54 | + } |
| 55 | + |
| 56 | + // |
| 57 | + // Should the order change here, src/native-clr/include/constants.hh must be updated accordingly |
| 58 | + // |
| 59 | + String[] appDirs = new String[] {filesDir, cacheDir, dataDir}; |
| 60 | + boolean haveSplitApks = runtimePackage.splitSourceDirs != null && runtimePackage.splitSourceDirs.length > 0; |
| 61 | + |
| 62 | + System.loadLibrary("monodroid"); |
| 63 | + |
| 64 | + Runtime.initInternal ( |
| 65 | + language, |
| 66 | + apks, |
| 67 | + runtimeDir, |
| 68 | + appDirs, |
| 69 | + localDateTimeOffset, |
| 70 | + loader, |
| 71 | + MonoPackageManager_Resources.Assemblies, |
| 72 | + isEmulator (), |
| 73 | + haveSplitApks |
| 74 | + ); |
| 75 | + |
| 76 | + mono.android.app.ApplicationRegistration.registerApplications (); |
| 77 | + |
| 78 | + initialized = true; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + // We need to detect the emulator in order to determine the maximum gref count. |
| 84 | + // The official Android emulator requires a much lower maximum than actual |
| 85 | + // devices. Hopefully other emulators don't need the treatment. If they do, we |
| 86 | + // can add their detection here. We should perform the absolute minimum of |
| 87 | + // checking in order to save time. |
| 88 | + static boolean isEmulator() |
| 89 | + { |
| 90 | + String val = Build.HARDWARE; |
| 91 | + |
| 92 | + // This detects the official Android emulator |
| 93 | + if (val.contains ("ranchu") || val.contains ("goldfish")) |
| 94 | + return true; |
| 95 | + |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + public static void setContext (Context context) |
| 100 | + { |
| 101 | + // Ignore; vestigial |
| 102 | + } |
| 103 | + |
| 104 | + static String getNativeLibraryPath (Context context) |
| 105 | + { |
| 106 | + return getNativeLibraryPath (context.getApplicationInfo ()); |
| 107 | + } |
| 108 | + |
| 109 | + static String getNativeLibraryPath (ApplicationInfo ainfo) |
| 110 | + { |
| 111 | + return ainfo.nativeLibraryDir; |
| 112 | + } |
| 113 | + |
| 114 | + public static String[] getAssemblies () |
| 115 | + { |
| 116 | + return MonoPackageManager_Resources.Assemblies; |
| 117 | + } |
| 118 | + |
| 119 | + public static String[] getDependencies () |
| 120 | + { |
| 121 | + return MonoPackageManager_Resources.Dependencies; |
| 122 | + } |
| 123 | +} |
0 commit comments