Skip to content

Commit 9b87fac

Browse files
committed
Merge branch 'main' into all-assemblies-per-rid
* main: [Xamarin.Android.Build.Tasks] Fix up ForegroundService.ToString() (dotnet#8412) [monodroid] Hush some messages logged by default on startup (dotnet#8414)
2 parents 073c507 + 58a81eb commit 9b87fac

File tree

7 files changed

+63
-24
lines changed

7 files changed

+63
-24
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,33 @@ class TestActivity : Activity { }"
908908
}
909909
}
910910

911+
[Test]
912+
[TestCase ("Android.Content.PM.ForegroundService.TypeSpecialUse", "specialUse")]
913+
[TestCase ("Android.Content.PM.ForegroundService.TypeConnectedDevice", "connectedDevice")]
914+
[TestCase ("Android.Content.PM.ForegroundService.TypeCamera|Android.Content.PM.ForegroundService.TypeMicrophone", "camera|microphone")]
915+
public void AllForegroundServiceTypes (string serviceType, string expected)
916+
{
917+
var proj = new XamarinAndroidApplicationProject {
918+
};
919+
920+
proj.Sources.Add (new BuildItem.Source ("TestActivity.cs") {
921+
TextContent = () => $@"using Android.App;
922+
using Android.Content.PM;
923+
using Android.Views;
924+
[Service (ForegroundServiceType = {serviceType})]
925+
class TestService : Service {{ public override Android.OS.IBinder OnBind (Android.Content.Intent intent) {{ return null; }} }}"
926+
});
927+
using (ProjectBuilder builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
928+
Assert.IsTrue (builder.Build (proj), "Build should have succeeded");
929+
string manifest = builder.Output.GetIntermediaryAsText (Path.Combine ("android", "AndroidManifest.xml"));
930+
var doc = XDocument.Parse (manifest);
931+
var ns = XNamespace.Get ("http://schemas.android.com/apk/res/android");
932+
IEnumerable<XElement> services = doc.Element ("manifest")?.Element ("application")?.Elements ("service");
933+
XElement e = services.FirstOrDefault (x => x.Attribute (ns.GetName ("foregroundServiceType"))?.Value == expected);
934+
Assert.IsNotNull (e, $"Manifest should contain an service with a foregroundServiceType of {expected}");
935+
}
936+
}
937+
911938
[Test]
912939
public void AllServiceAttributeProperties ([Values ("legacy", "manifestmerger.jar")] string manifestMerger)
913940
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void AssertCommercialBuild (bool fail = false)
4545
}
4646
}
4747

48-
char [] invalidChars = { '{', '}', '(', ')', '$', ':', ';', '\"', '\'', ',', '=' };
48+
char [] invalidChars = { '{', '}', '(', ')', '$', ':', ';', '\"', '\'', ',', '=', '|' };
4949

5050
public string TestName {
5151
get {

src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,26 @@ static string ToString (ForegroundService value)
383383
values.Add ("mediaProjection");
384384
if (value.HasFlag (ForegroundService.TypePhoneCall))
385385
values.Add ("phoneCall");
386-
387-
// These can be changed to enum members when API-R is the stable binding.
388-
if (value.HasFlag ((ForegroundService)64))
386+
if (value.HasFlag (ForegroundService.TypeCamera))
389387
values.Add ("camera");
390-
if (value.HasFlag ((ForegroundService)128))
388+
if (value.HasFlag (ForegroundService.TypeMicrophone))
391389
values.Add ("microphone");
390+
if (value.HasFlag (ForegroundService.TypeHealth))
391+
values.Add ("health");
392+
if (value.HasFlag (ForegroundService.TypeRemoteMessaging))
393+
values.Add ("remoteMessaging");
394+
if (value.HasFlag (ForegroundService.TypeSystemExempted))
395+
values.Add ("systemExempted");
396+
if (value.HasFlag (ForegroundService.TypeShortService))
397+
values.Add ("shortService");
398+
if (value.HasFlag (ForegroundService.TypeSpecialUse))
399+
values.Add ("specialUse");
400+
401+
// When including a non-stable value you can cast the integer value
402+
// to ForegroundService. We need to do this because the Build.Tasks
403+
// only build against the latest STABLE api.
404+
//if (value.HasFlag ((ForegroundService)128))
405+
// values.Add ("newValue");
392406

393407
return string.Join ("|", values.ToArray ());
394408
}

src/monodroid/jni/android-system.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ AndroidSystem::setup_environment ()
669669
}
670670

671671
if (aotMode != MonoAotMode::MONO_AOT_MODE_LAST) {
672-
log_info (LOG_DEFAULT, "Mono AOT mode: %s", mono_aot_mode_name);
672+
log_debug (LOG_DEFAULT, "Mono AOT mode: %s", mono_aot_mode_name);
673673
} else {
674674
if (!is_interpreter_enabled ()) {
675675
log_warn (LOG_DEFAULT, "Unknown Mono AOT mode: %s", mono_aot_mode_name);

src/monodroid/jni/basic-android-system.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ void
3131
BasicAndroidSystem::setup_app_library_directories (jstring_array_wrapper& runtimeApks, jstring_array_wrapper& appDirs, bool have_split_apks)
3232
{
3333
if (!is_embedded_dso_mode_enabled ()) {
34-
log_info (LOG_DEFAULT, "Setting up for DSO lookup in app data directories");
34+
log_debug (LOG_DEFAULT, "Setting up for DSO lookup in app data directories");
3535
BasicAndroidSystem::app_lib_directories_size = 1;
3636
BasicAndroidSystem::app_lib_directories = new const char*[app_lib_directories_size]();
3737
BasicAndroidSystem::app_lib_directories [0] = utils.strdup_new (appDirs[SharedConstants::APP_DIRS_DATA_DIR_INDEX].get_cstr ());
3838
log_debug (LOG_ASSEMBLY, "Added filesystem DSO lookup location: %s", appDirs[SharedConstants::APP_DIRS_DATA_DIR_INDEX].get_cstr ());
3939
} else {
40-
log_info (LOG_DEFAULT, "Setting up for DSO lookup directly in the APK");
40+
log_debug (LOG_DEFAULT, "Setting up for DSO lookup directly in the APK");
4141
BasicAndroidSystem::app_lib_directories_size = runtimeApks.get_length ();
4242
BasicAndroidSystem::app_lib_directories = new const char*[app_lib_directories_size]();
4343

src/monodroid/jni/monodroid-glue.cc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ MonodroidRuntime::init_android_runtime (
10281028
// GC threshold is 90% of the max GREF count
10291029
init.grefGcThreshold = static_cast<int>(androidSystem.get_gref_gc_threshold ());
10301030

1031-
log_warn (LOG_GC, "GREF GC Threshold: %i", init.grefGcThreshold);
1031+
log_info (LOG_GC, "GREF GC Threshold: %i", init.grefGcThreshold);
10321032

10331033
init.grefClass = utils.get_class_from_runtime_field (env, runtimeClass, "java_lang_Class", true);
10341034
Class_getName = env->GetMethodID (init.grefClass, "getName", "()Ljava/lang/String;");
@@ -1538,7 +1538,7 @@ MonodroidRuntime::create_xdg_directory (jstring_wrapper& home, size_t home_len,
15381538
{
15391539
static_local_string<SENSIBLE_PATH_MAX> dir (home_len + relative_path_len);
15401540
utils.path_combine (dir, home.get_cstr (), home_len, relativePath, relative_path_len);
1541-
log_info (LOG_DEFAULT, "Creating XDG directory: %s", dir.get ());
1541+
log_debug (LOG_DEFAULT, "Creating XDG directory: %s", dir.get ());
15421542
int rv = utils.create_directory (dir.get (), DEFAULT_DIRECTORY_MODE);
15431543
if (rv < 0 && errno != EEXIST)
15441544
log_warn (LOG_DEFAULT, "Failed to create XDG directory %s. %s", dir.get (), strerror (errno));
@@ -2207,7 +2207,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
22072207
if (runtimeNativeLibDir != nullptr) {
22082208
jstr = runtimeNativeLibDir;
22092209
androidSystem.set_runtime_libdir (strdup (jstr.get_cstr ()));
2210-
log_info (LOG_DEFAULT, "Using runtime path: %s", androidSystem.get_runtime_libdir ());
2210+
log_debug (LOG_DEFAULT, "Using runtime path: %s", androidSystem.get_runtime_libdir ());
22112211
}
22122212

22132213
androidSystem.setup_process_args (runtimeApks);
@@ -2261,7 +2261,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
22612261
mono_config_parse_memory (reinterpret_cast<const char*> (monodroid_config));
22622262
mono_register_machine_config (reinterpret_cast<const char*> (monodroid_machine_config));
22632263
#endif // ndef NET
2264-
log_info (LOG_DEFAULT, "Probing for Mono AOT mode\n");
2264+
log_debug (LOG_DEFAULT, "Probing for Mono AOT mode\n");
22652265

22662266
MonoAotMode mode = MonoAotMode::MONO_AOT_MODE_NONE;
22672267
if (androidSystem.is_mono_aot_enabled ()) {
@@ -2283,20 +2283,20 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
22832283
}
22842284
#else // defined (NET)
22852285
if (mode != MonoAotMode::MONO_AOT_MODE_INTERP_ONLY) {
2286-
log_info (LOG_DEFAULT, "Enabling AOT mode in Mono");
2286+
log_debug (LOG_DEFAULT, "Enabling AOT mode in Mono");
22872287
} else {
2288-
log_info (LOG_DEFAULT, "Enabling Mono Interpreter");
2288+
log_debug (LOG_DEFAULT, "Enabling Mono Interpreter");
22892289
}
22902290
#endif // !defined (NET)
22912291
}
22922292
mono_jit_set_aot_mode (mode);
22932293

2294-
log_info (LOG_DEFAULT, "Probing if we should use LLVM\n");
2294+
log_debug (LOG_DEFAULT, "Probing if we should use LLVM\n");
22952295

22962296
if (androidSystem.is_mono_llvm_enabled ()) {
22972297
char *args [1];
22982298
args[0] = const_cast<char*> ("--llvm");
2299-
log_info (LOG_DEFAULT, "Enabling LLVM mode in Mono\n");
2299+
log_debug (LOG_DEFAULT, "Enabling LLVM mode in Mono\n");
23002300
mono_jit_parse_options (1, args);
23012301
mono_set_use_llvm (true);
23022302
}
@@ -2338,17 +2338,15 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
23382338
if (XA_UNLIKELY (utils.should_log (LOG_DEFAULT))) {
23392339
log_info_nocheck (
23402340
LOG_DEFAULT,
2341-
"Xamarin.Android version: %s (%s; %s); built on %s",
2341+
".NET Android version: %s (%s; %s); built on %s; NDK version: %s; API level: %s; MonoVM version: %s",
23422342
BuildInfo::xa_version,
23432343
BuildInfo::architecture,
23442344
BuildInfo::kind,
2345-
BuildInfo::date
2345+
BuildInfo::date,
2346+
BuildInfo::ndk_version,
2347+
BuildInfo::ndk_api_level,
2348+
mono_get_runtime_build_info ()
23462349
);
2347-
2348-
#if defined (ANDROID)
2349-
log_info_nocheck (LOG_DEFAULT, "NDK version: %s; API level: %s", BuildInfo::ndk_version, BuildInfo::ndk_api_level);
2350-
log_info_nocheck (LOG_DEFAULT, "MonoVM version: %s", mono_get_runtime_build_info ());
2351-
#endif // def ANDROID
23522350
}
23532351

23542352
if (XA_UNLIKELY (FastTiming::enabled ())) {

src/monodroid/jni/util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Util::monodroid_store_package_name (const char *name)
143143
// And yes, I know it could be done in a simple loop or in even simpler 8 lines of code, but
144144
// that would be boring, wouldn't it? :)
145145
package_hash_to_hex (hash, 0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u);
146-
log_info (LOG_DEFAULT, "Generated hash 0x%s for package name %s", package_property_suffix, name);
146+
log_debug (LOG_DEFAULT, "Generated hash 0x%s for package name %s", package_property_suffix, name);
147147
}
148148

149149
#if defined (NET)

0 commit comments

Comments
 (0)