notification.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_
  5. #define ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_
  6. #include <stdint.h>
  7. #include <ostream>
  8. #include <string>
  9. #include <unordered_map>
  10. #include "base/containers/flat_map.h"
  11. #include "base/time/time.h"
  12. #include "base/values.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. #include "ui/gfx/image/image.h"
  15. // Serves the same purpose as a forward declare to avoid an extra include.
  16. typedef uint32_t SkColor;
  17. namespace ash {
  18. namespace phonehub {
  19. // A notification generated on the phone, whose contents are transferred to
  20. // Chrome OS via a Phone Hub connection. Notifications in Phone Hub support
  21. // inline reply and images.
  22. class Notification {
  23. public:
  24. // Describes the app which generates a notification.
  25. struct AppMetadata {
  26. AppMetadata(const std::u16string& visible_app_name,
  27. const std::string& package_name,
  28. const gfx::Image& icon,
  29. const absl::optional<SkColor> icon_color,
  30. bool icon_is_monochrome,
  31. int64_t user_id);
  32. AppMetadata(const AppMetadata& other);
  33. AppMetadata& operator=(const AppMetadata& other);
  34. bool operator==(const AppMetadata& other) const;
  35. bool operator!=(const AppMetadata& other) const;
  36. static AppMetadata FromValue(const base::Value& value);
  37. base::Value ToValue() const;
  38. std::u16string visible_app_name;
  39. std::string package_name;
  40. gfx::Image icon;
  41. // Color for a monochrome icon. Leave empty to use the system theme default.
  42. absl::optional<SkColor> icon_color;
  43. // Whether the icon image is just a mask used to generate a monochrome icon.
  44. bool icon_is_monochrome;
  45. int64_t user_id;
  46. };
  47. // Interaction behavior for integration with other features.
  48. enum class InteractionBehavior {
  49. // Default value. No interactions available.
  50. kNone,
  51. // Notification can be opened.
  52. kOpenable,
  53. };
  54. // Interaction behavior for integration with other features.
  55. enum class ActionType {
  56. // Default value. No interactions available.
  57. kNone,
  58. // User can click the reply button for the conversation type notification.
  59. kInlineReply,
  60. // User can click answer button for the incoming call notification.
  61. kAnswer,
  62. // User can click decline button for the incoming call notification.
  63. kDecline,
  64. // User can click hang up button for the ongoing call notification.
  65. kHangup,
  66. };
  67. enum class Category {
  68. // Default value..
  69. kNone,
  70. // User can click the reply button for the conversation type notification.
  71. kConversation,
  72. // The incoming call notification with answer and decline action buttons.
  73. // User can click the answer button to open the App streaming window to
  74. // answer the call and click the decline button to decline call directly.
  75. kIncomingCall,
  76. // The ongoing call notification with a hangup action button. User can
  77. // click on the body of notification to open the App streaming window to
  78. // resume the call.
  79. kOngoingCall,
  80. // The Screening call notification with a screening call action button.
  81. kScreenCall,
  82. };
  83. // Notification importance; for more details, see
  84. // https://developer.android.com/reference/android/app/NotificationManager.
  85. enum class Importance {
  86. // Older versions of Android do not specify an importance level.
  87. kUnspecified,
  88. // Does not show in the Android notification shade.
  89. kNone,
  90. // Shows in the Android notification shade, below the fold.
  91. kMin,
  92. // Shows in the Android notification shade and potentially status bar, but
  93. // is not audibly intrusive.
  94. kLow,
  95. // Shows in the Android notification shade and status bar and makes noise,
  96. // but does not visually intrude.
  97. kDefault,
  98. // Shows in the Android notification shade and status bar, makes noise, and
  99. // "peeks" down onto the screen when received.
  100. kHigh
  101. };
  102. // Note: A notification should include at least one of |title|,
  103. // |text_content|, and |shared_image| so that it can be rendered in the UI.
  104. Notification(
  105. int64_t id,
  106. const AppMetadata& app_metadata,
  107. const base::Time& timestamp,
  108. Importance importance,
  109. Notification::Category category,
  110. const base::flat_map<Notification::ActionType, int64_t>& action_id_map,
  111. InteractionBehavior interaction_behavior,
  112. const absl::optional<std::u16string>& title = absl::nullopt,
  113. const absl::optional<std::u16string>& text_content = absl::nullopt,
  114. const absl::optional<gfx::Image>& shared_image = absl::nullopt,
  115. const absl::optional<gfx::Image>& contact_image = absl::nullopt);
  116. Notification(const Notification& other);
  117. ~Notification();
  118. bool operator<(const Notification& other) const;
  119. bool operator==(const Notification& other) const;
  120. bool operator!=(const Notification& other) const;
  121. int64_t id() const { return id_; }
  122. const AppMetadata& app_metadata() const { return app_metadata_; }
  123. base::Time timestamp() const { return timestamp_; }
  124. Importance importance() const { return importance_; }
  125. Notification::Category category() const { return category_; }
  126. base::flat_map<Notification::ActionType, int64_t> action_id_map() const {
  127. return action_id_map_;
  128. }
  129. InteractionBehavior interaction_behavior() const {
  130. return interaction_behavior_;
  131. }
  132. const absl::optional<std::u16string>& title() const { return title_; }
  133. const absl::optional<std::u16string>& text_content() const {
  134. return text_content_;
  135. }
  136. const absl::optional<gfx::Image>& shared_image() const {
  137. return shared_image_;
  138. }
  139. const absl::optional<gfx::Image>& contact_image() const {
  140. return contact_image_;
  141. }
  142. private:
  143. int64_t id_;
  144. AppMetadata app_metadata_;
  145. base::Time timestamp_;
  146. Importance importance_;
  147. Notification::Category category_;
  148. base::flat_map<Notification::ActionType, int64_t> action_id_map_;
  149. InteractionBehavior interaction_behavior_;
  150. absl::optional<std::u16string> title_;
  151. absl::optional<std::u16string> text_content_;
  152. absl::optional<gfx::Image> shared_image_;
  153. absl::optional<gfx::Image> contact_image_;
  154. };
  155. std::ostream& operator<<(std::ostream& stream,
  156. const Notification::AppMetadata& app_metadata);
  157. std::ostream& operator<<(std::ostream& stream,
  158. Notification::Importance importance);
  159. std::ostream& operator<<(std::ostream& stream,
  160. const Notification& notification);
  161. std::ostream& operator<<(std::ostream& stream,
  162. const Notification::InteractionBehavior behavior);
  163. std::ostream& operator<<(std::ostream& stream,
  164. const Notification::Category category);
  165. } // namespace phonehub
  166. } // namespace ash
  167. // TODO(https://crbug.com/1164001): remove after the migration is finished.
  168. namespace chromeos {
  169. namespace phonehub {
  170. using ::ash::phonehub::Notification;
  171. }
  172. } // namespace chromeos
  173. #endif // ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_