Don't minimize debug information if module explicitly asks for it

In some configurations (for ex: go, auto) we minimize debug information
to reduce disk and memory usage. However some tests need the debug
information to work as expected. If a test explicitly requests for debug
information by passing "-g" to javac flags don't add "-g:source,lines"
to minimize debug information. Javac gives priority to -g:source,lines
and doesn't respect the order. So check if there is a -g flag before
adding flags to minimize debug information.

Test: atest CtsJvmtiRunTest1912HostTestCases android.jvmti.cts.JvmtiHostTest1912#testJvmti
Change-Id: I45e0f5fa9e79c16c2ff6e9413941a9a637753653
diff --git a/java/base.go b/java/base.go
index 53f22a7..e1c2386 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1014,8 +1014,16 @@
 	ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags {
 	// javac flags.
 	javacFlags := j.properties.Javacflags
+	var needsDebugInfo bool
 
-	if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
+	needsDebugInfo = false
+	for _, flag := range javacFlags {
+		if strings.HasPrefix(flag, "-g") {
+			needsDebugInfo = true
+		}
+	}
+
+	if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() && !needsDebugInfo {
 		// For non-host binaries, override the -g flag passed globally to remove
 		// local variable debug info to reduce disk and memory usage.
 		javacFlags = append(javacFlags, "-g:source,lines")