Android: Clean up JNI generated code

It's now possible to generate JNI code for constructors and enums
correctly. This CL cleans that up.

Bug: webrtc:8278,webrtc:8551,webrtc:8556
Change-Id: I2284a30139cbb186c80713eb6113eda5659c16ad
Reviewed-on: https://webrtc-review.googlesource.com/25622
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20860}
diff --git a/sdk/android/api/org/webrtc/EncodedImage.java b/sdk/android/api/org/webrtc/EncodedImage.java
index dc8eb62..84c72b1 100644
--- a/sdk/android/api/org/webrtc/EncodedImage.java
+++ b/sdk/android/api/org/webrtc/EncodedImage.java
@@ -12,8 +12,6 @@
 
 import java.nio.ByteBuffer;
 import java.util.concurrent.TimeUnit;
-// TODO(bugs.webrtc.org/8556): Remove unnecessary import.
-import org.webrtc.EncodedImage;
 
 /**
  * An encoded frame from a video stream. Used as an input for decoders and as an output for
@@ -36,9 +34,8 @@
       return nativeIndex;
     }
 
-    // TODO(bugs.webrtc.org/8556): Remove unnecessary 'EncodedImage.'.
     @CalledByNative("FrameType")
-    static EncodedImage.FrameType fromNativeIndex(int nativeIndex) {
+    static FrameType fromNativeIndex(int nativeIndex) {
       for (FrameType type : FrameType.values()) {
         if (type.getNative() == nativeIndex) {
           return type;
@@ -58,6 +55,7 @@
   public final boolean completeFrame;
   public final Integer qp;
 
+  @CalledByNative
   private EncodedImage(ByteBuffer buffer, int encodedWidth, int encodedHeight, long captureTimeNs,
       FrameType frameType, int rotation, boolean completeFrame, Integer qp) {
     this.buffer = buffer;
@@ -138,13 +136,4 @@
           rotation, completeFrame, qp);
     }
   }
-
-  // TODO(bugs.webrtc.org/8551) Remove.
-  @CalledByNative
-  static EncodedImage create(ByteBuffer buffer, int encodedWidth, int encodedHeight,
-      long captureTimeNs, EncodedImage.FrameType frameType, int rotation, boolean completeFrame,
-      Integer qp) {
-    return new EncodedImage(
-        buffer, encodedWidth, encodedHeight, captureTimeNs, frameType, rotation, completeFrame, qp);
-  }
 }
diff --git a/sdk/android/api/org/webrtc/Metrics.java b/sdk/android/api/org/webrtc/Metrics.java
index 3057067..fac41ed 100644
--- a/sdk/android/api/org/webrtc/Metrics.java
+++ b/sdk/android/api/org/webrtc/Metrics.java
@@ -38,6 +38,9 @@
   public final Map<String, HistogramInfo> map =
       new HashMap<String, HistogramInfo>(); // <name, HistogramInfo>
 
+  @CalledByNative
+  Metrics() {}
+
   /**
    * Class holding histogram information.
    */
@@ -48,6 +51,7 @@
     public final Map<Integer, Integer> samples =
         new HashMap<Integer, Integer>(); // <value, # of events>
 
+    @CalledByNative("HistogramInfo")
     public HistogramInfo(int min, int max, int bucketCount) {
       this.min = min;
       this.max = max;
@@ -76,18 +80,6 @@
     return getAndResetNative();
   }
 
-  // TODO(bugs.webrtc.org/8551) Remove.
-  @CalledByNative
-  static Metrics createMetrics() {
-    return new Metrics();
-  }
-
-  // TODO(bugs.webrtc.org/8551) Remove.
-  @CalledByNative
-  static HistogramInfo createHistogramInfo(int min, int max, int bucketCount) {
-    return new HistogramInfo(min, max, bucketCount);
-  }
-
   private static native void enableNative();
   private static native Metrics getAndResetNative();
 }
diff --git a/sdk/android/api/org/webrtc/NetworkMonitorAutoDetect.java b/sdk/android/api/org/webrtc/NetworkMonitorAutoDetect.java
index ae7908d..86eb1c2 100644
--- a/sdk/android/api/org/webrtc/NetworkMonitorAutoDetect.java
+++ b/sdk/android/api/org/webrtc/NetworkMonitorAutoDetect.java
@@ -35,7 +35,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import org.webrtc.NetworkMonitorAutoDetect;
 
 /**
  * Borrowed from Chromium's
@@ -90,7 +89,7 @@
     }
 
     @CalledByNative("NetworkInformation")
-    private NetworkMonitorAutoDetect.ConnectionType getConnectionType() {
+    private ConnectionType getConnectionType() {
       return type;
     }
 
diff --git a/sdk/android/api/org/webrtc/VideoDecoder.java b/sdk/android/api/org/webrtc/VideoDecoder.java
index f5acfad..7bf9ac5 100644
--- a/sdk/android/api/org/webrtc/VideoDecoder.java
+++ b/sdk/android/api/org/webrtc/VideoDecoder.java
@@ -21,6 +21,7 @@
     public final int width;
     public final int height;
 
+    @CalledByNative("Settings")
     public Settings(int numberOfCores, int width, int height) {
       this.numberOfCores = numberOfCores;
       this.width = width;
diff --git a/sdk/android/api/org/webrtc/VideoEncoder.java b/sdk/android/api/org/webrtc/VideoEncoder.java
index 30bfaaf..4f97fb0 100644
--- a/sdk/android/api/org/webrtc/VideoEncoder.java
+++ b/sdk/android/api/org/webrtc/VideoEncoder.java
@@ -10,6 +10,8 @@
 
 package org.webrtc;
 
+import org.webrtc.EncodedImage;
+
 /**
  * Interface for a video encoder that can be used with WebRTC. All calls will be made on the
  * encoding thread. The encoder may be constructed on a different thread and changing thread after
@@ -25,6 +27,7 @@
     public final int maxFramerate;
     public final boolean automaticResizeOn;
 
+    @CalledByNative("Settings")
     public Settings(int numberOfCores, int width, int height, int startBitrate, int maxFramerate,
         boolean automaticResizeOn) {
       this.numberOfCores = numberOfCores;
@@ -40,6 +43,7 @@
   public class EncodeInfo {
     public final EncodedImage.FrameType[] frameTypes;
 
+    @CalledByNative("EncodeInfo")
     public EncodeInfo(EncodedImage.FrameType[] frameTypes) {
       this.frameTypes = frameTypes;
     }
@@ -67,6 +71,7 @@
      * Initializes the allocation with a two dimensional array of bitrates. The first index of the
      * array is the spatial layer and the second index in the temporal layer.
      */
+    @CalledByNative("BitrateAllocation")
     public BitrateAllocation(int[][] bitratesBbs) {
       this.bitratesBbs = bitratesBbs;
     }
diff --git a/sdk/android/api/org/webrtc/VideoFrame.java b/sdk/android/api/org/webrtc/VideoFrame.java
index 62d4cf2..3ee368d 100644
--- a/sdk/android/api/org/webrtc/VideoFrame.java
+++ b/sdk/android/api/org/webrtc/VideoFrame.java
@@ -121,6 +121,7 @@
   private final int rotation;
   private final long timestampNs;
 
+  @CalledByNative
   public VideoFrame(Buffer buffer, int rotation, long timestampNs) {
     if (buffer == null) {
       throw new IllegalArgumentException("buffer not allowed to be null");
@@ -206,12 +207,6 @@
     return newBuffer;
   }
 
-  // TODO(bugs.webrtc.org/8278): Add a way to generate JNI code for constructors directly.
-  @CalledByNative
-  static VideoFrame create(Buffer buffer, int rotation, long timestampNs) {
-    return new VideoFrame(buffer, rotation, timestampNs);
-  }
-
   private static native void cropAndScaleI420Native(ByteBuffer srcY, int srcStrideY,
       ByteBuffer srcU, int srcStrideU, ByteBuffer srcV, int srcStrideV, int cropX, int cropY,
       int cropWidth, int cropHeight, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU,