• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.android.setupcompat.portal;
18 
19 import android.os.Bundle;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import androidx.annotation.IntDef;
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 
26 /**
27  * A class that represents how a persistent notification is to be presented to the user using the
28  * {@link com.google.android.setupcompat.portal.ISetupNotificationService}.
29  */
30 public class NotificationComponent implements Parcelable {
31 
32   @NotificationType private final int notificationType;
33   private Bundle extraBundle = new Bundle();
34 
NotificationComponent(@otificationType int notificationType)35   private NotificationComponent(@NotificationType int notificationType) {
36     this.notificationType = notificationType;
37   }
38 
NotificationComponent(Parcel in)39   protected NotificationComponent(Parcel in) {
40     this(in.readInt());
41     extraBundle = in.readBundle(Bundle.class.getClassLoader());
42   }
43 
getIntExtra(String key, int defValue)44   public int getIntExtra(String key, int defValue) {
45     return extraBundle.getInt(key, defValue);
46   }
47 
48   @NotificationType
getNotificationType()49   public int getNotificationType() {
50     return notificationType;
51   }
52 
53   @Override
writeToParcel(Parcel dest, int flags)54   public void writeToParcel(Parcel dest, int flags) {
55     dest.writeInt(notificationType);
56     dest.writeBundle(extraBundle);
57   }
58 
59   @Override
describeContents()60   public int describeContents() {
61     return 0;
62   }
63 
64   public static final Creator<NotificationComponent> CREATOR =
65       new Creator<NotificationComponent>() {
66         @Override
67         public NotificationComponent createFromParcel(Parcel in) {
68           return new NotificationComponent(in);
69         }
70 
71         @Override
72         public NotificationComponent[] newArray(int size) {
73           return new NotificationComponent[size];
74         }
75       };
76 
77   @Retention(RetentionPolicy.SOURCE)
78   @IntDef({
79     NotificationType.UNKNOWN,
80     NotificationType.INITIAL_ONGOING,
81     NotificationType.PREDEFERRED,
82     NotificationType.PREDEFERRED_PREPARING,
83     NotificationType.DEFERRED,
84     NotificationType.DEFERRED_ONGOING,
85     NotificationType.PORTAL
86   })
87   public @interface NotificationType {
88     int UNKNOWN = 0;
89     int INITIAL_ONGOING = 1;
90     int PREDEFERRED = 2;
91     int PREDEFERRED_PREPARING = 3;
92     int DEFERRED = 4;
93     int DEFERRED_ONGOING = 5;
94     int PORTAL = 6;
95     int MAX = 7;
96   }
97 
98   public static class Builder {
99 
100     private final NotificationComponent component;
101 
Builder(@otificationType int notificationType)102     public Builder(@NotificationType int notificationType) {
103       component = new NotificationComponent(notificationType);
104     }
105 
putIntExtra(String key, int value)106     public Builder putIntExtra(String key, int value) {
107       component.extraBundle.putInt(key, value);
108       return this;
109     }
110 
build()111     public NotificationComponent build() {
112       return component;
113     }
114   }
115 }
116