Snap for 10453563 from 80b3d364d7236ae6061d1d299d46657e4efffa7a to mainline-os-statsd-release

Change-Id: I034df7fac03a63151a1af5fae57e5bfa112e6b97
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index c0bf7bd..f84bcf3 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
 {
   "git": {
-    "sha1": "949875368995c00bef275dc8c554f5b34bc35a05"
-  }
-}
+    "sha1": "a4c5d5102122cf3442775fc464d6d5f976c95256"
+  },
+  "path_in_vcs": ""
+}
\ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 3b59f16..40e76cf 100644
--- a/Android.bp
+++ b/Android.bp
@@ -43,9 +43,15 @@
     host_supported: true,
     crate_name: "termcolor",
     cargo_env_compat: true,
-    cargo_pkg_version: "1.1.2",
+    cargo_pkg_version: "1.2.0",
     srcs: ["src/lib.rs"],
     edition: "2018",
+    apex_available: [
+        "//apex_available:platform",
+        "//apex_available:anyapex",
+    ],
+    product_available: true,
+    vendor_available: true,
 }
 
 rust_test {
@@ -53,7 +59,7 @@
     host_supported: true,
     crate_name: "termcolor",
     cargo_env_compat: true,
-    cargo_pkg_version: "1.1.2",
+    cargo_pkg_version: "1.2.0",
     srcs: ["src/lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
diff --git a/Cargo.toml b/Cargo.toml
index 344e18b..dbdb6e8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,24 +3,30 @@
 # When uploading crates to the registry Cargo will automatically
 # "normalize" Cargo.toml files for maximal compatibility
 # with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
 #
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
 
 [package]
 edition = "2018"
 name = "termcolor"
-version = "1.1.2"
+version = "1.2.0"
 authors = ["Andrew Gallant <jamslam@gmail.com>"]
-exclude = ["/.travis.yml", "/appveyor.yml", "/ci/**"]
-description = "A simple cross platform library for writing colored text to a terminal.\n"
+description = """
+A simple cross platform library for writing colored text to a terminal.
+"""
 homepage = "https://github.com/BurntSushi/termcolor"
 documentation = "https://docs.rs/termcolor"
 readme = "README.md"
-keywords = ["windows", "win", "color", "ansi", "console"]
+keywords = [
+    "windows",
+    "win",
+    "color",
+    "ansi",
+    "console",
+]
 license = "Unlicense OR MIT"
 repository = "https://github.com/BurntSushi/termcolor"
 
@@ -29,5 +35,6 @@
 bench = false
 
 [dev-dependencies]
+
 [target."cfg(windows)".dependencies.winapi-util]
 version = "0.1.3"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 1e9f5d3..ef7f1c1 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "termcolor"
-version = "1.1.2"  #:version
+version = "1.2.0"  #:version
 authors = ["Andrew Gallant <jamslam@gmail.com>"]
 description = """
 A simple cross platform library for writing colored text to a terminal.
@@ -11,7 +11,6 @@
 readme = "README.md"
 keywords = ["windows", "win", "color", "ansi", "console"]
 license = "Unlicense OR MIT"
-exclude = ["/.travis.yml", "/appveyor.yml", "/ci/**"]
 edition = "2018"
 
 [lib]
diff --git a/METADATA b/METADATA
index eab3cf6..4531041 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update rust/crates/termcolor
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
 name: "termcolor"
 description: "A simple cross platform library for writing colored text to a terminal."
 third_party {
@@ -7,13 +11,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/termcolor/termcolor-1.1.2.crate"
+    value: "https://static.crates.io/crates/termcolor/termcolor-1.2.0.crate"
   }
-  version: "1.1.2"
+  version: "1.2.0"
   license_type: NOTICE
   last_upgrade_date {
-    year: 2020
-    month: 11
-    day: 19
+    year: 2023
+    month: 2
+    day: 6
   }
 }
diff --git a/README.md b/README.md
index 1c91d07..646e3b5 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
 [![Build status](https://github.com/BurntSushi/termcolor/workflows/ci/badge.svg)](https://github.com/BurntSushi/termcolor/actions)
 [![](https://img.shields.io/crates/v/termcolor.svg)](https://crates.io/crates/termcolor)
 
-Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
+Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/).
 
 ### Documentation
 
@@ -85,7 +85,7 @@
 ### Automatic color selection
 
 When building a writer with termcolor, the caller must provide a
-[`ColorChoice`](https://docs.rs/termcolor/1.0.5/termcolor/enum.ColorChoice.html)
+[`ColorChoice`](https://docs.rs/termcolor/1.*/termcolor/enum.ColorChoice.html)
 selection. When the color choice is `Auto`, termcolor will attempt to determine
 whether colors should be enabled by inspecting the environment. Currently,
 termcolor will inspect the `TERM` and `NO_COLOR` environment variables:
diff --git a/TEST_MAPPING b/TEST_MAPPING
index f3742eb..ea6c5d1 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1,36 +1,26 @@
 // Generated by update_crate_tests.py for tests that depend on this crate.
 {
+  "imports": [
+    {
+      "path": "packages/modules/Virtualization/virtualizationmanager"
+    },
+    {
+      "path": "system/security/diced"
+    },
+    {
+      "path": "system/security/keystore2"
+    },
+    {
+      "path": "system/security/keystore2/legacykeystore"
+    }
+  ],
   "presubmit": [
     {
-      "name": "diced_test"
-    },
-    {
-      "name": "keystore2_test"
-    },
-    {
-      "name": "keystore2_vintf_test"
-    },
-    {
-      "name": "legacykeystore_test"
-    },
-    {
       "name": "termcolor_test_src_lib"
     }
   ],
   "presubmit-rust": [
     {
-      "name": "diced_test"
-    },
-    {
-      "name": "keystore2_test"
-    },
-    {
-      "name": "keystore2_vintf_test"
-    },
-    {
-      "name": "legacykeystore_test"
-    },
-    {
       "name": "termcolor_test_src_lib"
     }
   ]
diff --git a/src/lib.rs b/src/lib.rs
index 735ce97..062df18 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -82,7 +82,7 @@
 automatically when writing to a terminal and disable colors automatically when
 writing to anything else. The typical way to achieve this in Unix environments
 is via libc's
-[`isatty`](http://man7.org/linux/man-pages/man3/isatty.3.html)
+[`isatty`](https://man7.org/linux/man-pages/man3/isatty.3.html)
 function.
 Unfortunately, this notoriously does not work well in Windows environments. To
 work around that, the currently recommended solution is to use the
@@ -98,18 +98,10 @@
 use termcolor::{ColorChoice, StandardStream};
 
 let preference = argv.get_flag("color").unwrap_or("auto");
-let choice = match preference {
-    "always" => ColorChoice::Always,
-    "ansi" => ColorChoice::AlwaysAnsi,
-    "auto" => {
-        if atty::is(atty::Stream::Stdout) {
-            ColorChoice::Auto
-        } else {
-            ColorChoice::Never
-        }
-    }
-    _ => ColorChoice::Never,
-};
+let mut choice = preference.parse::<ColorChoice>()?;
+if choice == ColorChoice::Auto && !atty::is(atty::Stream::Stdout) {
+    choice = ColorChoice::Never;
+}
 let stdout = StandardStream::stdout(choice);
 // ... write to stdout
 ```
@@ -117,7 +109,7 @@
 Currently, `termcolor` does not provide anything to do this for you.
 */
 
-#![deny(missing_docs)]
+#![deny(missing_debug_implementations, missing_docs)]
 
 // #[cfg(doctest)]
 // use doc_comment::doctest;
@@ -203,6 +195,13 @@
 }
 
 /// ColorChoice represents the color preferences of an end user.
+///
+/// The `Default` implementation for this type will select `Auto`, which tries
+/// to do the right thing based on the current environment.
+///
+/// The `FromStr` implementation for this type converts a lowercase kebab-case
+/// string of the variant name to the corresponding variant. Any other string
+/// results in an error.
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
 pub enum ColorChoice {
     /// Try very hard to emit colors. This includes emitting ANSI colors
@@ -219,6 +218,29 @@
     Never,
 }
 
+/// The default is `Auto`.
+impl Default for ColorChoice {
+    fn default() -> ColorChoice {
+        ColorChoice::Auto
+    }
+}
+
+impl FromStr for ColorChoice {
+    type Err = ColorChoiceParseError;
+
+    fn from_str(s: &str) -> Result<ColorChoice, ColorChoiceParseError> {
+        match s.to_lowercase().as_str() {
+            "always" => Ok(ColorChoice::Always),
+            "always-ansi" => Ok(ColorChoice::AlwaysAnsi),
+            "never" => Ok(ColorChoice::Never),
+            "auto" => Ok(ColorChoice::Auto),
+            unknown => Err(ColorChoiceParseError {
+                unknown_choice: unknown.to_string(),
+            }),
+        }
+    }
+}
+
 impl ColorChoice {
     /// Returns true if we should attempt to write colored output.
     fn should_attempt_color(&self) -> bool {
@@ -291,6 +313,25 @@
     }
 }
 
+/// An error that occurs when parsing a `ColorChoice` fails.
+#[derive(Clone, Debug)]
+pub struct ColorChoiceParseError {
+    unknown_choice: String,
+}
+
+impl std::error::Error for ColorChoiceParseError {}
+
+impl fmt::Display for ColorChoiceParseError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(
+            f,
+            "unrecognized color choice '{}': valid choices are: \
+             always, always-ansi, never, auto",
+            self.unknown_choice,
+        )
+    }
+}
+
 /// `std::io` implements `Stdout` and `Stderr` (and their `Lock` variants) as
 /// separate types, which makes it difficult to abstract over them. We use
 /// some simple internal enum types to work around this.
@@ -302,6 +343,7 @@
     StderrBuffered,
 }
 
+#[derive(Debug)]
 enum IoStandardStream {
     Stdout(io::Stdout),
     Stderr(io::Stderr),
@@ -371,6 +413,7 @@
 
 // Same rigmarole for the locked variants of the standard streams.
 
+#[derive(Debug)]
 enum IoStandardStreamLock<'a> {
     StdoutLock(io::StdoutLock<'a>),
     StderrLock(io::StderrLock<'a>),
@@ -396,6 +439,7 @@
 
 /// Satisfies `io::Write` and `WriteColor`, and supports optional coloring
 /// to either of the standard output streams, stdout and stderr.
+#[derive(Debug)]
 pub struct StandardStream {
     wtr: LossyStandardStream<WriterInner<IoStandardStream>>,
 }
@@ -407,17 +451,20 @@
 ///
 /// The lifetime `'a` refers to the lifetime of the corresponding
 /// `StandardStream`.
+#[derive(Debug)]
 pub struct StandardStreamLock<'a> {
     wtr: LossyStandardStream<WriterInnerLock<'a, IoStandardStreamLock<'a>>>,
 }
 
 /// Like `StandardStream`, but does buffered writing.
+#[derive(Debug)]
 pub struct BufferedStandardStream {
     wtr: LossyStandardStream<WriterInner<IoStandardStream>>,
 }
 
 /// WriterInner is a (limited) generic representation of a writer. It is
 /// limited because W should only ever be stdout/stderr on Windows.
+#[derive(Debug)]
 enum WriterInner<W> {
     NoColor(NoColor<W>),
     Ansi(Ansi<W>),
@@ -430,6 +477,7 @@
 
 /// WriterInnerLock is a (limited) generic representation of a writer. It is
 /// limited because W should only ever be stdout/stderr on Windows.
+#[derive(Debug)]
 enum WriterInnerLock<'a, W> {
     NoColor(NoColor<W>),
     Ansi(Ansi<W>),
@@ -855,6 +903,7 @@
 ///
 /// It is intended for a `BufferWriter` to be put in an `Arc` and written to
 /// from multiple threads simultaneously.
+#[derive(Debug)]
 pub struct BufferWriter {
     stream: LossyStandardStream<IoStandardStream>,
     printed: AtomicBool,
@@ -908,7 +957,7 @@
         }
         let stream = LossyStandardStream::new(IoStandardStream::new(sty));
         BufferWriter {
-            stream: stream,
+            stream,
             printed: AtomicBool::new(false),
             separator: None,
             color_choice: choice,
@@ -1013,9 +1062,11 @@
 /// method, which will take color preferences and the environment into
 /// account. However, buffers can also be manually created using `no_color`,
 /// `ansi` or `console` (on Windows).
+#[derive(Debug)]
 pub struct Buffer(BufferInner);
 
 /// BufferInner is an enumeration of different buffer types.
+#[derive(Debug)]
 enum BufferInner {
     /// No coloring information should be applied. This ignores all coloring
     /// directives.
@@ -1195,6 +1246,7 @@
 }
 
 /// Satisfies `WriteColor` but ignores all color options.
+#[derive(Debug)]
 pub struct NoColor<W>(W);
 
 impl<W: Write> NoColor<W> {
@@ -1255,6 +1307,7 @@
 }
 
 /// Satisfies `WriteColor` using standard ANSI escape sequences.
+#[derive(Debug)]
 pub struct Ansi<W>(W);
 
 impl<W: Write> Ansi<W> {
@@ -1286,6 +1339,17 @@
         self.0.write(buf)
     }
 
+    // Adding this method here is not required because it has a default impl,
+    // but it seems to provide a perf improvement in some cases when using
+    // a `BufWriter` with lots of writes.
+    //
+    // See https://github.com/BurntSushi/termcolor/pull/56 for more details
+    // and a minimized example.
+    #[inline]
+    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
+        self.0.write_all(buf)
+    }
+
     #[inline]
     fn flush(&mut self) -> io::Result<()> {
         self.0.flush()
@@ -1315,6 +1379,9 @@
         if spec.underline {
             self.write_str("\x1B[4m")?;
         }
+        if spec.strikethrough {
+            self.write_str("\x1B[9m")?;
+        }
         if let Some(ref c) = spec.fg_color {
             self.write_color(true, c, spec.intense)?;
         }
@@ -1450,6 +1517,20 @@
     }
 }
 
+impl WriteColor for io::Sink {
+    fn supports_color(&self) -> bool {
+        false
+    }
+
+    fn set_color(&mut self, _: &ColorSpec) -> io::Result<()> {
+        Ok(())
+    }
+
+    fn reset(&mut self) -> io::Result<()> {
+        Ok(())
+    }
+}
+
 /// An in-memory buffer that provides Windows console coloring.
 ///
 /// This doesn't actually communicate with the Windows console. Instead, it
@@ -1572,6 +1653,7 @@
     dimmed: bool,
     italic: bool,
     reset: bool,
+    strikethrough: bool,
 }
 
 impl Default for ColorSpec {
@@ -1585,6 +1667,7 @@
             dimmed: false,
             italic: false,
             reset: true,
+            strikethrough: false,
         }
     }
 }
@@ -1677,6 +1760,21 @@
         self
     }
 
+    /// Get whether this is strikethrough or not.
+    ///
+    /// Note that the strikethrough setting has no effect in a Windows console.
+    pub fn strikethrough(&self) -> bool {
+        self.strikethrough
+    }
+
+    /// Set whether the text is strikethrough or not.
+    ///
+    /// Note that the strikethrough setting has no effect in a Windows console.
+    pub fn set_strikethrough(&mut self, yes: bool) -> &mut ColorSpec {
+        self.strikethrough = yes;
+        self
+    }
+
     /// Get whether reset is enabled or not.
     ///
     /// reset is enabled by default. When disabled and using ANSI escape
@@ -1738,6 +1836,7 @@
             && !self.dimmed
             && !self.italic
             && !self.intense
+            && !self.strikethrough
     }
 
     /// Clears this color specification so that it has no color/style settings.
@@ -1749,6 +1848,7 @@
         self.intense = false;
         self.dimmed = false;
         self.italic = false;
+        self.strikethrough = false;
     }
 
     /// Writes this color spec to the given Windows console.
@@ -1985,6 +2085,7 @@
     }
 }
 
+#[derive(Debug)]
 struct LossyStandardStream<W> {
     wtr: W,
     #[cfg(windows)]
@@ -1994,14 +2095,14 @@
 impl<W: io::Write> LossyStandardStream<W> {
     #[cfg(not(windows))]
     fn new(wtr: W) -> LossyStandardStream<W> {
-        LossyStandardStream { wtr: wtr }
+        LossyStandardStream { wtr }
     }
 
     #[cfg(windows)]
     fn new(wtr: W) -> LossyStandardStream<W> {
         let is_console = wincon::Console::stdout().is_ok()
             || wincon::Console::stderr().is_ok();
-        LossyStandardStream { wtr: wtr, is_console: is_console }
+        LossyStandardStream { wtr, is_console }
     }
 
     #[cfg(not(windows))]
@@ -2011,7 +2112,7 @@
 
     #[cfg(windows)]
     fn wrap<Q: io::Write>(&self, wtr: Q) -> LossyStandardStream<Q> {
-        LossyStandardStream { wtr: wtr, is_console: self.is_console }
+        LossyStandardStream { wtr, is_console: self.is_console }
     }
 
     fn get_ref(&self) -> &W {
@@ -2202,16 +2303,19 @@
                     for underline in vec![false, true] {
                         for intense in vec![false, true] {
                             for italic in vec![false, true] {
-                                for dimmed in vec![false, true] {
-                                    let mut color = ColorSpec::new();
-                                    color.set_fg(fg);
-                                    color.set_bg(bg);
-                                    color.set_bold(bold);
-                                    color.set_underline(underline);
-                                    color.set_intense(intense);
-                                    color.set_dimmed(dimmed);
-                                    color.set_italic(italic);
-                                    result.push(color);
+                                for strikethrough in vec![false, true] {
+                                    for dimmed in vec![false, true] {
+                                        let mut color = ColorSpec::new();
+                                        color.set_fg(fg);
+                                        color.set_bg(bg);
+                                        color.set_bold(bold);
+                                        color.set_underline(underline);
+                                        color.set_intense(intense);
+                                        color.set_italic(italic);
+                                        color.set_dimmed(dimmed);
+                                        color.set_strikethrough(strikethrough);
+                                        result.push(color);
+                                    }
                                 }
                             }
                         }