File: notification.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (209 lines) | stat: -rw-r--r-- 7,483 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_
#define CHROMEOS_ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_

#include <stdint.h>

#include <optional>
#include <ostream>
#include <string>
#include <unordered_map>

#include "base/containers/flat_map.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chromeos/ash/components/phonehub/proto/phonehub_api.pb.h"
#include "ui/gfx/image/image.h"

// Serves the same purpose as a forward declare to avoid an extra include.
typedef uint32_t SkColor;

namespace ash::phonehub {

// A notification generated on the phone, whose contents are transferred to
// Chrome OS via a Phone Hub connection. Notifications in Phone Hub support
// inline reply and images.
class Notification {
 public:
  // Describes the app which generates a notification.
  struct AppMetadata {
    AppMetadata(const std::u16string& visible_app_name,
                const std::string& package_name,
                const gfx::Image& color_icon,
                const std::optional<gfx::Image>& monochrome_icon_mask,
                const std::optional<SkColor> icon_color,
                bool icon_is_monochrome,
                int64_t user_id,
                proto::AppStreamabilityStatus app_streamability_status =
                    proto::AppStreamabilityStatus::STREAMABLE);
    ~AppMetadata();
    AppMetadata(const AppMetadata& other);
    AppMetadata& operator=(const AppMetadata& other);

    bool operator==(const AppMetadata& other) const;
    bool operator!=(const AppMetadata& other) const;

    static AppMetadata FromValue(const base::Value::Dict& value);
    base::Value::Dict ToValue() const;

    std::u16string visible_app_name;
    std::string package_name;
    // The |color_icon| is the icon with it's original color whereas the
    // |monochrome_icon| is the icon with a monochrome or system theme mask.
    gfx::Image color_icon;
    std::optional<gfx::Image> monochrome_icon_mask;
    // Color for a monochrome icon. Leave empty to use the system theme default.
    std::optional<SkColor> icon_color;
    // Whether the icon image is just a mask used to generate a monochrome icon.
    bool icon_is_monochrome;
    int64_t user_id;
    proto::AppStreamabilityStatus app_streamability_status;
  };

  // Interaction behavior for integration with other features.
  enum class InteractionBehavior {
    // Default value. No interactions available.
    kNone,

    // Notification can be opened.
    kOpenable,
  };

  // Interaction behavior for integration with other features.
  enum class ActionType {
    // Default value. No interactions available.
    kNone,

    // User can click the reply button for the conversation type notification.
    kInlineReply,

    // User can click answer button for the incoming call notification.
    kAnswer,

    // User can click decline button for the incoming call notification.
    kDecline,

    // User can click hang up button for the ongoing call notification.
    kHangup,
  };

  enum class Category {
    // Default value..
    kNone,

    // User can click the reply button for the conversation type notification.
    kConversation,

    // The incoming call notification with answer and decline action buttons.
    // User can click the answer button to open the App streaming window to
    // answer the call and click the decline button to decline call directly.
    kIncomingCall,

    // The ongoing call notification with a hangup action button. User can
    // click on the body of notification to open the App streaming window to
    // resume the call.
    kOngoingCall,

    // The Screening call notification with a screening call action button.
    kScreenCall,
  };

  // Notification importance; for more details, see
  // https://developer.android.com/reference/android/app/NotificationManager.
  enum class Importance {
    // Older versions of Android do not specify an importance level.
    kUnspecified,

    // Does not show in the Android notification shade.
    kNone,

    // Shows in the Android notification shade, below the fold.
    kMin,

    // Shows in the Android notification shade and potentially status bar, but
    // is not audibly intrusive.
    kLow,

    // Shows in the Android notification shade and status bar and makes noise,
    // but does not visually intrude.
    kDefault,

    // Shows in the Android notification shade and status bar, makes noise, and
    // "peeks" down onto the screen when received.
    kHigh
  };

  // Note: A notification should include at least one of |title|,
  // |text_content|, and |shared_image| so that it can be rendered in the UI.
  Notification(
      int64_t id,
      const AppMetadata& app_metadata,
      const base::Time& timestamp,
      Importance importance,
      Notification::Category category,
      const base::flat_map<Notification::ActionType, int64_t>& action_id_map,
      InteractionBehavior interaction_behavior,
      const std::optional<std::u16string>& title = std::nullopt,
      const std::optional<std::u16string>& text_content = std::nullopt,
      const std::optional<gfx::Image>& shared_image = std::nullopt,
      const std::optional<gfx::Image>& contact_image = std::nullopt);
  Notification(const Notification& other);
  ~Notification();

  bool operator<(const Notification& other) const;
  bool operator==(const Notification& other) const;
  bool operator!=(const Notification& other) const;

  int64_t id() const { return id_; }
  const AppMetadata& app_metadata() const { return app_metadata_; }
  base::Time timestamp() const { return timestamp_; }
  Importance importance() const { return importance_; }
  Notification::Category category() const { return category_; }
  base::flat_map<Notification::ActionType, int64_t> action_id_map() const {
    return action_id_map_;
  }
  InteractionBehavior interaction_behavior() const {
    return interaction_behavior_;
  }
  const std::optional<std::u16string>& title() const { return title_; }
  const std::optional<std::u16string>& text_content() const {
    return text_content_;
  }
  const std::optional<gfx::Image>& shared_image() const {
    return shared_image_;
  }
  const std::optional<gfx::Image>& contact_image() const {
    return contact_image_;
  }

 private:
  int64_t id_;
  AppMetadata app_metadata_;
  base::Time timestamp_;
  Importance importance_;
  Notification::Category category_;
  base::flat_map<Notification::ActionType, int64_t> action_id_map_;
  InteractionBehavior interaction_behavior_;
  std::optional<std::u16string> title_;
  std::optional<std::u16string> text_content_;
  std::optional<gfx::Image> shared_image_;
  std::optional<gfx::Image> contact_image_;
};

std::ostream& operator<<(std::ostream& stream,
                         const Notification::AppMetadata& app_metadata);
std::ostream& operator<<(std::ostream& stream,
                         Notification::Importance importance);
std::ostream& operator<<(std::ostream& stream,
                         const Notification& notification);
std::ostream& operator<<(std::ostream& stream,
                         const Notification::InteractionBehavior behavior);
std::ostream& operator<<(std::ostream& stream,
                         const Notification::Category category);

}  // namespace ash::phonehub

#endif  // CHROMEOS_ASH_COMPONENTS_PHONEHUB_NOTIFICATION_H_