HIDL Return withDefault const am: faad16dded am: 0844dad16c am: 1e1216610b am: b87e562e3a

Original change: https://android-review.googlesource.com/c/platform/system/libhidl/+/1866758

Change-Id: I82b5fad1b00124da597366858f7ba16acdfe18ee
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 74901bb..a204af5 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -235,9 +235,7 @@
         return mVal;
     }
 
-    T withDefault(T t) {
-        return isOk() ? mVal : t;
-    }
+    T withDefault(T t) const { return isOk() ? mVal : t; }
 };
 
 template<typename T> class Return<sp<T>> : public details::return_status {
@@ -264,9 +262,7 @@
         return mVal;
     }
 
-    sp<T> withDefault(sp<T> t) {
-        return isOk() ? mVal : t;
-    }
+    sp<T> withDefault(sp<T> t) const { return isOk() ? mVal : t; }
 };
 
 
diff --git a/test_main.cpp b/test_main.cpp
index 5c6c78e..8681375 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -550,7 +550,7 @@
 
     hidl_string one = "1";
     hidl_string two = "2";
-    Return<hidl_string> ret = Return<hidl_string>(Status::fromStatusT(DEAD_OBJECT));
+    const Return<hidl_string> ret = Return<hidl_string>(Status::fromStatusT(DEAD_OBJECT));
 
     EXPECT_EQ(one, Return<hidl_string>(one).withDefault(two));
     EXPECT_EQ(two, ret.withDefault(two));