1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AlreadyReceivingException
;
4 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
5 import org
.asamk
.signal
.manager
.api
.CaptchaRejectedException
;
6 import org
.asamk
.signal
.manager
.api
.CaptchaRequiredException
;
7 import org
.asamk
.signal
.manager
.api
.Configuration
;
8 import org
.asamk
.signal
.manager
.api
.Device
;
9 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
10 import org
.asamk
.signal
.manager
.api
.Group
;
11 import org
.asamk
.signal
.manager
.api
.GroupId
;
12 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
13 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
14 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
15 import org
.asamk
.signal
.manager
.api
.Identity
;
16 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
17 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
18 import org
.asamk
.signal
.manager
.api
.IncorrectPinException
;
19 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
20 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
21 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
22 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
23 import org
.asamk
.signal
.manager
.api
.Message
;
24 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
25 import org
.asamk
.signal
.manager
.api
.NonNormalizedPhoneNumberException
;
26 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
27 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
28 import org
.asamk
.signal
.manager
.api
.Pair
;
29 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
30 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
31 import org
.asamk
.signal
.manager
.api
.RateLimitException
;
32 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
33 import org
.asamk
.signal
.manager
.api
.Recipient
;
34 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
35 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
36 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
37 import org
.asamk
.signal
.manager
.api
.StickerPack
;
38 import org
.asamk
.signal
.manager
.api
.StickerPackId
;
39 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
40 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
41 import org
.asamk
.signal
.manager
.api
.TypingAction
;
42 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
43 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
44 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
45 import org
.asamk
.signal
.manager
.api
.UserStatus
;
46 import org
.asamk
.signal
.manager
.api
.UsernameLinkUrl
;
47 import org
.asamk
.signal
.manager
.api
.UsernameStatus
;
48 import org
.asamk
.signal
.manager
.api
.VerificationMethodNotAvailableException
;
49 import org
.slf4j
.Logger
;
50 import org
.slf4j
.LoggerFactory
;
51 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
53 import java
.io
.Closeable
;
55 import java
.io
.IOException
;
56 import java
.io
.InputStream
;
57 import java
.time
.Duration
;
58 import java
.util
.Collection
;
59 import java
.util
.List
;
61 import java
.util
.Optional
;
64 public interface Manager
extends Closeable
{
66 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
67 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
70 static boolean isSignalClientAvailable() {
71 final Logger logger
= LoggerFactory
.getLogger(Manager
.class);
74 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
75 } catch (Exception e
) {
76 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
79 } catch (UnsatisfiedLinkError e
) {
80 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
85 String
getSelfNumber();
88 * This is used for checking a set of phone numbers for registration on Signal
90 * @param numbers The set of phone number in question
91 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
92 * @throws IOException if it's unable to get the contacts to check if they're registered
94 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
, RateLimitException
;
96 Map
<String
, UsernameStatus
> getUsernameStatus(Set
<String
> usernames
);
98 void updateAccountAttributes(
100 Boolean unrestrictedUnidentifiedSender
,
101 final Boolean discoverableByNumber
,
102 final Boolean numberSharing
103 ) throws IOException
;
105 Configuration
getConfiguration();
107 void updateConfiguration(Configuration configuration
) throws NotPrimaryDeviceException
;
110 * Update the user's profile.
111 * If a field is null, the previous value will be kept.
113 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
115 String
getUsername();
117 UsernameLinkUrl
getUsernameLink();
120 * Set a username for the account.
121 * If the username is null, it will be deleted.
123 void setUsername(String username
) throws IOException
, InvalidUsernameException
;
126 * Set a username for the account.
127 * If the username is null, it will be deleted.
129 void deleteUsername() throws IOException
;
131 void startChangeNumber(
132 String newNumber
, boolean voiceVerification
, String captcha
133 ) throws RateLimitException
, IOException
, CaptchaRequiredException
, NonNormalizedPhoneNumberException
, NotPrimaryDeviceException
, VerificationMethodNotAvailableException
;
135 void finishChangeNumber(
136 String newNumber
, String verificationCode
, String pin
137 ) throws IncorrectPinException
, PinLockedException
, IOException
, NotPrimaryDeviceException
;
139 void unregister() throws IOException
;
141 void deleteAccount() throws IOException
;
143 void submitRateLimitRecaptchaChallenge(
144 String challenge
, String captcha
145 ) throws IOException
, CaptchaRejectedException
;
147 List
<Device
> getLinkedDevices() throws IOException
;
149 void removeLinkedDevices(int deviceId
) throws IOException
, NotPrimaryDeviceException
;
151 void addDeviceLink(DeviceLinkUrl linkUri
) throws IOException
, InvalidDeviceLinkException
, NotPrimaryDeviceException
;
153 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
155 List
<Group
> getGroups();
157 SendGroupMessageResults
quitGroup(
158 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
159 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
161 void deleteGroup(GroupId groupId
) throws IOException
;
163 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
164 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
165 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
167 SendGroupMessageResults
updateGroup(
168 final GroupId groupId
, final UpdateGroup updateGroup
169 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
171 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
172 GroupInviteLinkUrl inviteLinkUrl
173 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
175 SendMessageResults
sendTypingMessage(
176 TypingAction action
, Set
<RecipientIdentifier
> recipients
177 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
179 SendMessageResults
sendReadReceipt(
180 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
183 SendMessageResults
sendViewedReceipt(
184 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
187 SendMessageResults
sendMessage(
188 Message message
, Set
<RecipientIdentifier
> recipients
, boolean notifySelf
189 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
191 SendMessageResults
sendEditMessage(
192 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
193 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
195 SendMessageResults
sendRemoteDeleteMessage(
196 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
197 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
199 SendMessageResults
sendMessageReaction(
202 RecipientIdentifier
.Single targetAuthor
,
203 long targetSentTimestamp
,
204 Set
<RecipientIdentifier
> recipients
,
205 final boolean isStory
206 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
208 SendMessageResults
sendPaymentNotificationMessage(
209 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
210 ) throws IOException
;
212 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
214 SendMessageResults
sendMessageRequestResponse(
215 MessageEnvelope
.Sync
.MessageRequestResponse
.Type type
, Set
<RecipientIdentifier
> recipientIdentifiers
218 void hideRecipient(RecipientIdentifier
.Single recipient
);
220 void deleteRecipient(RecipientIdentifier
.Single recipient
);
222 void deleteContact(RecipientIdentifier
.Single recipient
);
225 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
226 ) throws NotPrimaryDeviceException
, UnregisteredRecipientException
;
228 void setContactsBlocked(
229 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
230 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
232 void setGroupsBlocked(
233 Collection
<GroupId
> groupId
, boolean blocked
234 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
237 * Change the expiration timer for a contact
239 void setExpirationTimer(
240 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
241 ) throws IOException
, UnregisteredRecipientException
;
244 * Upload the sticker pack from path.
246 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
247 * @return if successful, returns the URL to install the sticker pack in the signal app
249 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
251 void installStickerPack(StickerPackUrl url
) throws IOException
;
253 List
<StickerPack
> getStickerPacks();
255 void requestAllSyncData() throws IOException
;
258 * Add a handler to receive new messages.
259 * Will start receiving messages from server, if not already started.
261 default void addReceiveHandler(ReceiveMessageHandler handler
) {
262 addReceiveHandler(handler
, false);
265 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
268 * Remove a handler to receive new messages.
269 * Will stop receiving messages from server, if this was the last registered receiver.
271 void removeReceiveHandler(ReceiveMessageHandler handler
);
273 boolean isReceiving();
276 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
278 void receiveMessages(
279 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
280 ) throws IOException
, AlreadyReceivingException
;
282 void stopReceiveMessages();
284 void setReceiveConfig(ReceiveConfig receiveConfig
);
286 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
288 void sendContacts() throws IOException
;
290 List
<Recipient
> getRecipients(
291 boolean onlyContacts
,
292 Optional
<Boolean
> blocked
,
293 Collection
<RecipientIdentifier
.Single
> address
,
294 Optional
<String
> name
297 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
299 Group
getGroup(GroupId groupId
);
301 List
<Identity
> getIdentities();
303 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
306 * Trust this the identity with this fingerprint/safetyNumber
308 * @param recipient account of the identity
310 boolean trustIdentityVerified(
311 RecipientIdentifier
.Single recipient
, IdentityVerificationCode verificationCode
312 ) throws UnregisteredRecipientException
;
315 * Trust all keys of this identity without verification
317 * @param recipient account of the identity
319 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
321 void addAddressChangedListener(Runnable listener
);
323 void addClosedListener(Runnable listener
);
325 InputStream
retrieveAttachment(final String id
) throws IOException
;
327 InputStream
retrieveContactAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
329 InputStream
retrieveProfileAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
331 InputStream
retrieveGroupAvatar(final GroupId groupId
) throws IOException
;
333 InputStream
retrieveSticker(final StickerPackId stickerPackId
, final int stickerId
) throws IOException
;
338 interface ReceiveMessageHandler
{
340 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
343 void handleMessage(MessageEnvelope envelope
, Throwable e
);