Merge "StatsCompanionService sends messages to statsd"
diff --git a/cmds/incidentd/tests/EncodedBuffer_test.cpp b/cmds/incidentd/tests/EncodedBuffer_test.cpp
index 98c39bd..37a938a 100644
--- a/cmds/incidentd/tests/EncodedBuffer_test.cpp
+++ b/cmds/incidentd/tests/EncodedBuffer_test.cpp
@@ -42,40 +42,17 @@
 const string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
 const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
 
-static Privacy* create_privacy(uint32_t field_id, uint8_t type, uint8_t dest) {
-  struct Privacy* p = (struct Privacy*)malloc(sizeof(struct Privacy));
-  p->field_id = field_id;
-  p->type = type;
-  p->children = NULL;
-  p->dest = dest;
-  p->patterns = NULL;
-  return p;
-}
-
-static Privacy* create_message_privacy(uint32_t field_id, Privacy** children)
-{
-  struct Privacy* p = (struct Privacy*)malloc(sizeof(struct Privacy));
-  p->field_id = field_id;
-  p->type = MESSAGE_TYPE;
-  p->children = children;
-  p->dest = EXPLICIT;
-  p->patterns = NULL;
-  return p;
-}
-
-static Privacy* create_string_privacy(uint32_t field_id, uint8_t dest, const char** patterns)
-{
-  struct Privacy* p = (struct Privacy*)malloc(sizeof(struct Privacy));
-  p->field_id = field_id;
-  p->type = STRING_TYPE;
-  p->children = NULL;
-  p->dest = dest;
-  p->patterns = patterns;
-  return p;
-}
-
 class EncodedBufferTest : public Test {
 public:
+    virtual ~EncodedBufferTest() {
+        // Delete in reverse order of construction, to be consistent with
+        // regular allocation/deallocation.
+        while (!privacies.empty()) {
+            delete privacies.back();
+            privacies.pop_back();
+        }
+    }
+
     virtual void SetUp() override {
         ASSERT_NE(tf.fd, -1);
     }
@@ -113,9 +90,48 @@
         assertStrip(dest, expected, create_message_privacy(300, list));
     }
 
+    Privacy* create_privacy(uint32_t field_id, uint8_t type, uint8_t dest) {
+        Privacy* p = new_uninit_privacy();
+        p->field_id = field_id;
+        p->type = type;
+        p->children = NULL;
+        p->dest = dest;
+        p->patterns = NULL;
+        return p;
+    }
+
+    Privacy* create_message_privacy(uint32_t field_id, Privacy** children) {
+        Privacy* p = new_uninit_privacy();
+        p->field_id = field_id;
+        p->type = MESSAGE_TYPE;
+        p->children = children;
+        p->dest = EXPLICIT;
+        p->patterns = NULL;
+        return p;
+    }
+
+    Privacy* create_string_privacy(uint32_t field_id, uint8_t dest, const char** patterns) {
+        Privacy* p = new_uninit_privacy();
+        p->field_id = field_id;
+        p->type = STRING_TYPE;
+        p->children = NULL;
+        p->dest = dest;
+        p->patterns = patterns;
+        return p;
+    }
+
     FdBuffer buffer;
 private:
     TemporaryFile tf;
+    // Littering this code with unique_ptr (or similar) is ugly, so we just
+    // mass-free everything after the test completes.
+    std::vector<Privacy *> privacies;
+
+    Privacy *new_uninit_privacy() {
+        Privacy* p = new Privacy;
+        privacies.push_back(p);
+        return p;
+    }
 };
 
 TEST_F(EncodedBufferTest, NullFieldPolicy) {
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 42e9273..64e12b4 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -560,7 +560,7 @@
 
     if (stream.get()) {
         std::unique_ptr<SkStreamRewindable> bufferedStream(
-                SkFrontBufferedStream::Create(stream.release(), SkCodec::MinBufferedBytesNeeded()));
+                SkFrontBufferedStream::Make(std::move(stream), SkCodec::MinBufferedBytesNeeded()));
         SkASSERT(bufferedStream.get() != NULL);
         bitmap = doDecode(env, std::move(bufferedStream), padding, options);
     }
@@ -610,7 +610,7 @@
     // Use a buffered stream. Although an SkFILEStream can be rewound, this
     // ensures that SkImageDecoder::Factory never rewinds beyond the
     // current position of the file descriptor.
-    std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Create(fileStream.release(),
+    std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Make(std::move(fileStream),
             SkCodec::MinBufferedBytesNeeded()));
 
     return doDecode(env, std::move(stream), padding, bitmapFactoryOptions);
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index b243817..4c10a85 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -104,7 +104,8 @@
     // will only read 6.
     // FIXME: Get this number from SkImageDecoder
     // bufferedStream takes ownership of strm
-    std::unique_ptr<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(strm, 6));
+    std::unique_ptr<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Make(
+        std::unique_ptr<SkStream>(strm), 6));
     SkASSERT(bufferedStream.get() != NULL);
 
     Movie* moov = Movie::DecodeStream(bufferedStream.get());
diff --git a/core/jni/android/graphics/Utils.cpp b/core/jni/android/graphics/Utils.cpp
index 8934c1e..630220a 100644
--- a/core/jni/android/graphics/Utils.cpp
+++ b/core/jni/android/graphics/Utils.cpp
@@ -42,7 +42,7 @@
     return fAsset->getRemainingLength() == 0;
 }
 
-SkStreamRewindable* AssetStreamAdaptor::duplicate() const {
+SkStreamRewindable* AssetStreamAdaptor::onDuplicate() const {
     // Cannot create a duplicate, since each AssetStreamAdaptor
     // would be modifying the Asset.
     //return new AssetStreamAdaptor(fAsset);
diff --git a/core/jni/android/graphics/Utils.h b/core/jni/android/graphics/Utils.h
index fffec5b..69930a5 100644
--- a/core/jni/android/graphics/Utils.h
+++ b/core/jni/android/graphics/Utils.h
@@ -36,7 +36,9 @@
     virtual size_t getLength() const;
     virtual bool isAtEnd() const;
 
-    virtual SkStreamRewindable* duplicate() const;
+protected:
+    SkStreamRewindable* onDuplicate() const override;
+
 private:
     Asset* fAsset;
 };
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto
index 0730270..523e6b2 100644
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -4610,6 +4610,11 @@
     // OS: P
     DIALOG_ENABLE_DEVELOPMENT_OPTIONS = 1158;
 
+    // OPEN: Settings > Developer options > OEM unlocking > Info dialog
+    // CATEGORY: SETTINGS
+    // OS: P
+    DIALOG_ENABLE_OEM_UNLOCKING = 1159;
+
     // Add new aosp constants above this line.
     // END OF AOSP CONSTANTS
   }