Remove String8 from Status. Add description to Return<T>.

Test: compiles
Bug: 33760393
Bug: 31348667

Change-Id: I578b2795ed33ca87da8744c74f39cdc10ca45ea9
diff --git a/base/Status.cpp b/base/Status.cpp
index f018918..4ce26ee 100644
--- a/base/Status.cpp
+++ b/base/Status.cpp
@@ -28,7 +28,7 @@
 }
 
 Status Status::fromExceptionCode(int32_t exceptionCode,
-                                 const String8& message) {
+                                 const char *message) {
     return Status(exceptionCode, OK, message);
 }
 
@@ -37,7 +37,7 @@
 }
 
 Status Status::fromServiceSpecificError(int32_t serviceSpecificErrorCode,
-                                        const String8& message) {
+                                        const char *message) {
     return Status(EX_SERVICE_SPECIFIC, serviceSpecificErrorCode, message);
 }
 
@@ -51,18 +51,18 @@
     : mException(exceptionCode),
       mErrorCode(errorCode) {}
 
-Status::Status(int32_t exceptionCode, int32_t errorCode, const String8& message)
+Status::Status(int32_t exceptionCode, int32_t errorCode, const char *message)
     : mException(exceptionCode),
       mErrorCode(errorCode),
       mMessage(message) {}
 
-void Status::setException(int32_t ex, const String8& message) {
+void Status::setException(int32_t ex, const char *message) {
     mException = ex;
     mErrorCode = NO_ERROR;  // an exception, not a transaction failure.
-    mMessage.setTo(message);
+    mMessage = message;
 }
 
-void Status::setServiceSpecificError(int32_t errorCode, const String8& message) {
+void Status::setServiceSpecificError(int32_t errorCode, const char *message) {
     setException(EX_SERVICE_SPECIFIC, message);
     mErrorCode = errorCode;
 }
@@ -73,24 +73,24 @@
     mMessage.clear();
 }
 
-String8 Status::toString8() const {
-    String8 ret;
-    if (mException == EX_NONE) {
-        ret.append("No error");
-    } else {
-        ret.appendFormat("Status(%d): '", mException);
-        if (mException == EX_SERVICE_SPECIFIC ||
-            mException == EX_TRANSACTION_FAILED) {
-            ret.appendFormat("%d: ", mErrorCode);
-        }
-        ret.append(String8(mMessage));
-        ret.append("'");
-    }
-    return ret;
+std::string Status::description() const {
+    std::ostringstream oss;
+    oss << (*this);
+    return oss.str();
 }
 
-std::stringstream& operator<< (std::stringstream& stream, const Status& s) {
-    stream << s.toString8().string();
+std::ostream& operator<< (std::ostream& stream, const Status& s) {
+    if (s.exceptionCode() == Status::EX_NONE) {
+        stream << "No error";
+    } else {
+        stream << "Status(" << s.exceptionCode() << "): '";
+        if (s.exceptionCode() == Status::EX_SERVICE_SPECIFIC) {
+            stream << s.serviceSpecificErrorCode() << ": ";
+        } else if (s.exceptionCode() == Status::EX_TRANSACTION_FAILED) {
+            stream << s.transactionError() << ": ";
+        }
+        stream << s.exceptionMessage() << "'";
+    }
     return stream;
 }
 
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index cacaf08..c0edb84 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -22,7 +22,7 @@
 
 #include <android-base/macros.h>
 #include <hidl/HidlInternal.h>
-#include <utils/String8.h>
+#include <utils/Errors.h>
 
 namespace android {
 namespace hardware {
@@ -84,10 +84,10 @@
     //  Java clients.
     static Status fromExceptionCode(int32_t exceptionCode);
     static Status fromExceptionCode(int32_t exceptionCode,
-                                    const String8& message);
+                                    const char *message);
     static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode);
     static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode,
-                                           const String8& message);
+                                           const char *message);
     static Status fromStatusT(status_t status);
 
     Status() = default;
@@ -99,9 +99,9 @@
     Status& operator=(const Status& status) = default;
 
     // Set one of the pre-defined exception types defined above.
-    void setException(int32_t ex, const String8& message);
+    void setException(int32_t ex, const char *message);
     // Set a service specific exception with error code.
-    void setServiceSpecificError(int32_t errorCode, const String8& message);
+    void setServiceSpecificError(int32_t errorCode, const char *message);
     // Setting a |status| != OK causes generated code to return |status|
     // from Binder transactions, rather than writing an exception into the
     // reply Parcel.  This is the least preferable way of reporting errors.
@@ -109,7 +109,7 @@
 
     // Get information about an exception.
     int32_t exceptionCode() const  { return mException; }
-    const String8& exceptionMessage() const { return mMessage; }
+    const char *exceptionMessage() const { return mMessage.c_str(); }
     status_t transactionError() const {
         return mException == EX_TRANSACTION_FAILED ? mErrorCode : OK;
     }
@@ -119,12 +119,12 @@
 
     bool isOk() const { return mException == EX_NONE; }
 
-    // For logging.
-    String8 toString8() const;
+    // For debugging purposes only
+    std::string description() const;
 
 private:
     Status(int32_t exceptionCode, int32_t errorCode);
-    Status(int32_t exceptionCode, int32_t errorCode, const String8& message);
+    Status(int32_t exceptionCode, int32_t errorCode, const char *message);
 
     // If |mException| == EX_TRANSACTION_FAILED, generated code will return
     // |mErrorCode| as the result of the transaction rather than write an
@@ -135,11 +135,11 @@
     // If |mException| == EX_SERVICE_SPECIFIC we write |mErrorCode| as well.
     int32_t mException = EX_NONE;
     int32_t mErrorCode = 0;
-    String8 mMessage;
+    std::string mMessage;
 };  // class Status
 
 // For gtest output logging
-std::stringstream& operator<< (std::stringstream& stream, const Status& s);
+std::ostream& operator<< (std::ostream& stream, const Status& s);
 
 namespace details {
     class return_status : public details::hidl_log_base {
@@ -169,6 +169,12 @@
             mCheckedStatus = true;
             return mStatus;
         }
+
+        // For debugging purposes only
+        std::string description() const {
+            // Doesn't consider checked.
+            return mStatus.description();
+        }
     };
 }  // namespace details