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 5 #ifndef CHROMEOS_COMPONENTS_PHONEHUB_NOTIFICATION_H_ 6 #define CHROMEOS_COMPONENTS_PHONEHUB_NOTIFICATION_H_ 7 8 #include <stdint.h> 9 #include <ostream> 10 #include <string> 11 12 #include "base/optional.h" 13 #include "base/strings/string16.h" 14 #include "base/time/time.h" 15 #include "ui/gfx/image/image.h" 16 17 namespace chromeos { 18 namespace phonehub { 19 20 // A notification generated on the phone, whose contents are transferred to 21 // Chrome OS via a Phone Hub connection. Notifications in Phone Hub support 22 // inline reply and images. 23 class Notification { 24 public: 25 // Describes the app which generates a notification. 26 struct AppMetadata { 27 AppMetadata(const base::string16& visible_app_name, 28 const std::string& package_name, 29 const gfx::Image& icon); 30 AppMetadata(const AppMetadata& other); 31 32 bool operator==(const AppMetadata& other) const; 33 bool operator!=(const AppMetadata& other) const; 34 35 base::string16 visible_app_name; 36 std::string package_name; 37 gfx::Image icon; 38 }; 39 40 // Notification importance; for more details, see 41 // https://developer.android.com/reference/android/app/NotificationManager. 42 enum class Importance { 43 // Older versions of Android do not specify an importance level. 44 kUnspecified, 45 46 // Does not show in the Android notification shade. 47 kNone, 48 49 // Shows in the Android notification shade, below the fold. 50 kMin, 51 52 // Shows in the Android notification shade and potentially status bar, but 53 // is not audibly intrusive. 54 kLow, 55 56 // Shows in the Android notification shade and status bar and makes noise, 57 // but does not visually intrude. 58 kDefault, 59 60 // Shows in the Android notification shade and status bar, makes noise, and 61 // "peeks" down onto the screen when received. 62 kHigh 63 }; 64 65 // Note: A notification should include at least one of |title|, 66 // |text_content|, and |shared_image| so that it can be rendered in the UI. 67 Notification( 68 int64_t id, 69 const AppMetadata& app_metadata, 70 const base::Time& timestamp, 71 Importance importance, 72 int64_t inline_reply_id, 73 const base::Optional<base::string16>& title = base::nullopt, 74 const base::Optional<base::string16>& text_content = base::nullopt, 75 const base::Optional<gfx::Image>& shared_image = base::nullopt, 76 const base::Optional<gfx::Image>& contact_image = base::nullopt); 77 Notification(const Notification& other); 78 ~Notification(); 79 80 bool operator<(const Notification& other) const; 81 bool operator==(const Notification& other) const; 82 bool operator!=(const Notification& other) const; 83 id()84 int64_t id() const { return id_; } app_metadata()85 const AppMetadata& app_metadata() const { return app_metadata_; } timestamp()86 base::Time timestamp() const { return timestamp_; } importance()87 Importance importance() const { return importance_; } inline_reply_id()88 int64_t inline_reply_id() const { return inline_reply_id_; } title()89 const base::Optional<base::string16>& title() const { return title_; } text_content()90 const base::Optional<base::string16>& text_content() const { 91 return text_content_; 92 } shared_image()93 const base::Optional<gfx::Image>& shared_image() const { 94 return shared_image_; 95 } contact_image()96 const base::Optional<gfx::Image>& contact_image() const { 97 return contact_image_; 98 } 99 100 private: 101 int64_t id_; 102 AppMetadata app_metadata_; 103 base::Time timestamp_; 104 Importance importance_; 105 int64_t inline_reply_id_; 106 base::Optional<base::string16> title_; 107 base::Optional<base::string16> text_content_; 108 base::Optional<gfx::Image> shared_image_; 109 base::Optional<gfx::Image> contact_image_; 110 }; 111 112 std::ostream& operator<<(std::ostream& stream, 113 const Notification::AppMetadata& app_metadata); 114 std::ostream& operator<<(std::ostream& stream, 115 Notification::Importance importance); 116 std::ostream& operator<<(std::ostream& stream, 117 const Notification& notification); 118 119 } // namespace phonehub 120 } // namespace chromeos 121 122 #endif // CHROMEOS_COMPONENTS_PHONEHUB_NOTIFICATION_H_ 123