Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotnet/android
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 58f17e2c12cf0ae6285a4767d51d6a5c5b8f00a1
Choose a base ref
..
head repository: dotnet/android
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6f5f5c6b9a6b27a1e67c70f314daaf7e13b9e3d8
Choose a head ref
5 changes: 4 additions & 1 deletion build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -74,7 +74,10 @@ extends:
binskim:
scanOutputDirectoryOnly: true
codeql:
runSourceLanguagesInSourceAnalysis: true
${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}:
compiled:
enabled: false
justificationForDisabling: CodeQL disabled for non-main branch builds
policheck:
enabled: false
justification: Built in task does not support multi-language scanning
5 changes: 5 additions & 0 deletions build-tools/automation/yaml-templates/build-linux.yaml
Original file line number Diff line number Diff line change
@@ -35,6 +35,11 @@ stages:
CC: gcc-10
${{ if eq(parameters.use1ESTemplate, true) }}:
templateContext:
sdl:
codeql:
compiled:
enabled: false
justificationForDisabling: CodeQL runs against the Windows build and nightly macOS build
outputs:
- output: pipelineArtifact
displayName: upload linux sdk
5 changes: 5 additions & 0 deletions build-tools/automation/yaml-templates/build-macos.yaml
Original file line number Diff line number Diff line change
@@ -43,6 +43,11 @@ stages:
clean: all
${{ if eq(parameters.use1ESTemplate, true) }}:
templateContext:
sdl:
codeql:
compiled:
enabled: false
justificationForDisabling: CodeQL runs against the Windows build and nightly macOS build
outputParentDirectory: ${{ parameters.xaSourcePath }}/bin
outputs:
- output: pipelineArtifact
31 changes: 15 additions & 16 deletions build-tools/automation/yaml-templates/commercial-build.yaml
Original file line number Diff line number Diff line change
@@ -71,46 +71,45 @@ steps:
condition: and(succeeded(), eq(variables['MicroBuildSignType'], 'Real'))

# Restore needs to be executed first or MicroBuild targets won't be imported in time
- task: MSBuild@1
- task: DotNetCoreCLI@2
displayName: msbuild /t:Restore sign-content.proj
condition: and(succeeded(), eq(variables['MicroBuildSignType'], 'Real'))
inputs:
solution: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
configuration: $(XA.Build.Configuration)
msbuildArguments: /t:Restore /bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/restore-sign-content.binlog
projects: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
arguments: /t:Restore /p:Configuration=$(XA.Build.Configuration) -v:n /bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/restore-sign-content.binlog

- task: MSBuild@1
- task: DotNetCoreCLI@2
displayName: PKG signing - add entitlements and sign
condition: and(succeeded(), eq(variables['MicroBuildSignType'], 'Real'))
inputs:
solution: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
configuration: $(XA.Build.Configuration)
msbuildArguments: >-
projects: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
arguments: >-
/t:AddMachOEntitlements;AddMSBuildFilesUnixSign;AddMSBuildFilesUnixSignAndHarden;Build
/p:Configuration=$(XA.Build.Configuration) -v:n
/p:SignType=$(MicroBuildSignType)
/p:MicroBuildOverridePluginDirectory=$(Build.StagingDirectory)/MicroBuild/Plugins
/bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/sign-content.binlog
- task: MSBuild@1
- task: DotNetCoreCLI@2
displayName: PKG signing - sign binutils libraries
condition: and(succeeded(), eq(variables['MicroBuildSignType'], 'Real'))
inputs:
solution: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
configuration: $(XA.Build.Configuration)
msbuildArguments: >-
projects: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
arguments: >-
/t:AddBinUtilsFilesUnixSign;Build
/p:Configuration=$(XA.Build.Configuration) -v:n
/p:SignType=$(MicroBuildSignType)
/p:MicroBuildOverridePluginDirectory=$(Build.StagingDirectory)/MicroBuild/Plugins
/bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/sign-bu-lib.binlog
- task: MSBuild@1
- task: DotNetCoreCLI@2
displayName: PKG signing - sign binutils executables
condition: and(succeeded(), eq(variables['MicroBuildSignType'], 'Real'))
inputs:
solution: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
configuration: $(XA.Build.Configuration)
msbuildArguments: >-
projects: ${{ parameters.xaSourcePath }}/build-tools/installers/sign-content.proj
arguments: >-
/t:AddBinUtilsFilesUnixSignAndHarden;Build
/p:Configuration=$(XA.Build.Configuration) -v:n
/p:SignType=$(MicroBuildSignType)
/p:MicroBuildOverridePluginDirectory=$(Build.StagingDirectory)/MicroBuild/Plugins
/bl:${{ parameters.xaSourcePath }}/bin/Build$(XA.Build.Configuration)/sign-bu-ex.binlog
41 changes: 38 additions & 3 deletions src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
using Mono.Cecil;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Tuner;
using Java.Interop.Tools.Cecil;
using Xamarin.Android.Tasks;
using Profile = Microsoft.Android.Sdk.ILLink.Profile;

namespace MonoDroid.Tuner {

@@ -27,7 +27,14 @@ public override void Initialize (LinkContext context, MarkContext markContext)

bool IsActiveFor (AssemblyDefinition assembly)
{
return assembly.MainModule.HasTypeReference ("System.Net.Http.HttpMessageHandler") || assembly.MainModule.HasTypeReference ("Android.Util.IAttributeSet");
if (Profile.IsSdkAssembly (assembly))
return false;
if (Profile.IsProductAssembly (assembly))
return false;

return assembly.MainModule.HasTypeReference ("System.Net.Http.HttpMessageHandler") ||
assembly.MainModule.HasTypeReference ("Java.Lang.Object") ||
assembly.MainModule.HasTypeReference ("Android.Util.IAttributeSet");
}

public void ProcessAssembly (AssemblyDefinition assembly, string androidHttpClientHandlerType, Dictionary<string, HashSet<string>> customViewMap)
@@ -47,14 +54,42 @@ public void ProcessAssembly (AssemblyDefinition assembly, string androidHttpClie
}
}

// Custom views in Android .xml files
// Continue if not an IJavaObject
if (!type.ImplementsIJavaObject (cache))
continue;

// Custom views in Android .xml files
if (customViewMap.ContainsKey (type.FullName)) {
Annotations.Mark (type);
PreserveJavaObjectImplementation (type);
continue;
}

// Types with Java.Interop.IJniNameProviderAttribute attributes
if (ShouldPreserveBasedOnAttributes (type)) {
Annotations.Mark (type);
PreserveJavaObjectImplementation (type);
continue;
}
}
}

bool ShouldPreserveBasedOnAttributes (TypeDefinition type)
{
if (!type.HasCustomAttributes)
return false;

foreach (var attr in type.CustomAttributes) {
// Ignore Android.Runtime.RegisterAttribute
if (attr.AttributeType.FullName == "Android.Runtime.RegisterAttribute") {
continue;
}
if (attr.AttributeType.Implements ("Java.Interop.IJniNameProviderAttribute", cache)) {
return true;
}
}

return false;
}

public void ProcessType (TypeDefinition type)
10 changes: 4 additions & 6 deletions src/Mono.Android/Android.Runtime/InputStreamInvoker.cs
Original file line number Diff line number Diff line change
@@ -37,7 +37,9 @@ protected override void Dispose (bool disposing)
if (disposing && BaseInputStream != null) {
try {
BaseFileChannel = null;
BaseInputStream.Close ();
if (BaseInputStream.PeerReference.IsValid) {
BaseInputStream.Close ();
}
BaseInputStream.Dispose ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
@@ -58,11 +60,7 @@ protected override void Dispose (bool disposing)
//
public override void Close ()
{
try {
BaseInputStream.Close ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
}
base.Close ();
}

public override void Flush ()
10 changes: 4 additions & 6 deletions src/Mono.Android/Android.Runtime/OutputStreamInvoker.cs
Original file line number Diff line number Diff line change
@@ -28,11 +28,7 @@ public OutputStreamInvoker (Java.IO.OutputStream stream)
//
public override void Close ()
{
try {
BaseOutputStream.Close ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
}
base.Close ();
}

//
@@ -50,7 +46,9 @@ protected override void Dispose (bool disposing)
{
if (disposing && BaseOutputStream != null) {
try {
BaseOutputStream.Close ();
if (BaseOutputStream.PeerReference.IsValid) {
BaseOutputStream.Close ();
}
BaseOutputStream.Dispose ();
} catch (Java.IO.IOException ex) when (JNIEnv.ShouldWrapJavaException (ex)) {
throw new IOException (ex.Message, ex);
Original file line number Diff line number Diff line change
@@ -598,6 +598,40 @@ public void PreserveIX509TrustManagerSubclasses ([Values(true, false)] bool hasS
}
}

[Test]
public void PreserveServices ()
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
TrimModeRelease = TrimMode.Full,
PackageReferences = {
new Package { Id = "Plugin.Firebase.CloudMessaging", Version = "3.0.0" },
}
};
proj.MainActivity = proj.DefaultMainActivity
.Replace ("//${FIELDS}",
"""
protected override void OnNewIntent (Android.Content.Intent? intent)
{
base.OnNewIntent (intent);
Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.OnNewIntent (intent);
}
""")
.Replace ("//${AFTER_ONCREATE}", "Plugin.Firebase.Core.Platforms.Android.CrossFirebase.Initialize (this);");

using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

var assemblyPath = BuildTest.GetLinkedPath (b, isRelease: true, "Plugin.Firebase.CloudMessaging.dll");
FileAssert.Exists (assemblyPath);
using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
var types = new [] { "Plugin.Firebase.CloudMessaging.Platforms.Android.MyFirebaseMessagingService" };
foreach (var typeName in types) {
var td = assembly.MainModule.GetType (typeName);
Assert.IsNotNull (td, $"{typeName} should not have been linked out!");
}
}

[Test]
public void DoNotErrorOnPerArchJavaTypeDuplicates ([Values(true, false)] bool enableMarshalMethods)
{
Original file line number Diff line number Diff line change
@@ -181,7 +181,6 @@ public void VirtualMethodBinding ()
}

[Test]
[Ignore("https://github.com/dotnet/runtime/issues/103987")]
[RequiresUnreferencedCode ("Tests trimming unsafe features")]
public void JavaAbstractMethodTest ()
{
Original file line number Diff line number Diff line change
@@ -12,6 +12,15 @@ namespace Android.RuntimeTests
[TestFixture]
public class InputStreamInvokerTest
{
[Test]
public void Disposing_Shared_Data_Does_Not_Throw_IOE ()
{
var javaInputStream = new Java.IO.ByteArrayInputStream (new byte[]{0x1, 0x2, 0x3, 0x4});
var invoker = new InputStreamInvoker (javaInputStream);
javaInputStream.Dispose ();
invoker.Dispose ();
}

[Test]
public void InputStreamTest ()
{