1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.Configuration
;
4 import org
.asamk
.signal
.manager
.api
.Device
;
5 import org
.asamk
.signal
.manager
.api
.Group
;
6 import org
.asamk
.signal
.manager
.api
.Identity
;
7 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
8 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
9 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
10 import org
.asamk
.signal
.manager
.api
.Message
;
11 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
12 import org
.asamk
.signal
.manager
.api
.Pair
;
13 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
14 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
15 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
16 import org
.asamk
.signal
.manager
.api
.StickerPack
;
17 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
18 import org
.asamk
.signal
.manager
.api
.TypingAction
;
19 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
20 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
21 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
22 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
23 import org
.asamk
.signal
.manager
.groups
.GroupId
;
24 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
25 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
26 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
27 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
28 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
29 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
30 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
31 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
33 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
34 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
36 import java
.io
.Closeable
;
38 import java
.io
.IOException
;
40 import java
.time
.Duration
;
41 import java
.util
.Arrays
;
42 import java
.util
.List
;
44 import java
.util
.Optional
;
46 import java
.util
.UUID
;
48 public interface Manager
extends Closeable
{
53 ServiceEnvironment serviceEnvironment
,
55 TrustNewIdentity trustNewIdentity
56 ) throws IOException
, NotRegisteredException
{
57 var pathConfig
= PathConfig
.createDefault(settingsPath
);
59 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
60 throw new NotRegisteredException();
63 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
65 if (!account
.isRegistered()) {
67 throw new NotRegisteredException();
70 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
72 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
75 static void initLogger() {
76 LibSignalLogger
.initLogger();
79 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
80 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
83 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
84 var pathConfig
= PathConfig
.createDefault(settingsPath
);
85 final var dataPath
= pathConfig
.dataPath();
86 final var files
= dataPath
.listFiles();
92 return Arrays
.stream(files
)
95 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
99 String
getSelfNumber();
101 void checkAccountState() throws IOException
;
104 * This is used for checking a set of phone numbers for registration on Signal
106 * @param numbers The set of phone number in question
107 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
108 * @throws IOException if it's unable to get the contacts to check if they're registered
110 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
112 void updateAccountAttributes(String deviceName
) throws IOException
;
114 Configuration
getConfiguration();
116 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
119 * @param givenName if null, the previous givenName will be kept
120 * @param familyName if null, the previous familyName will be kept
121 * @param about if null, the previous about text will be kept
122 * @param aboutEmoji if null, the previous about emoji will be kept
123 * @param avatar if avatar is null the image from the local avatar store is used (if present),
126 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
127 ) throws IOException
;
129 void unregister() throws IOException
;
131 void deleteAccount() throws IOException
;
133 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
135 List
<Device
> getLinkedDevices() throws IOException
;
137 void removeLinkedDevices(long deviceId
) throws IOException
;
139 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
141 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
143 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
145 List
<Group
> getGroups();
147 SendGroupMessageResults
quitGroup(
148 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
149 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
151 void deleteGroup(GroupId groupId
) throws IOException
;
153 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
154 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
155 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
157 SendGroupMessageResults
updateGroup(
158 final GroupId groupId
, final UpdateGroup updateGroup
159 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
161 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
162 GroupInviteLinkUrl inviteLinkUrl
163 ) throws IOException
, InactiveGroupLinkException
;
165 SendMessageResults
sendTypingMessage(
166 TypingAction action
, Set
<RecipientIdentifier
> recipients
167 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
169 SendMessageResults
sendReadReceipt(
170 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
171 ) throws IOException
;
173 SendMessageResults
sendViewedReceipt(
174 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
175 ) throws IOException
;
177 SendMessageResults
sendMessage(
178 Message message
, Set
<RecipientIdentifier
> recipients
179 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
181 SendMessageResults
sendRemoteDeleteMessage(
182 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
183 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
185 SendMessageResults
sendMessageReaction(
188 RecipientIdentifier
.Single targetAuthor
,
189 long targetSentTimestamp
,
190 Set
<RecipientIdentifier
> recipients
191 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
193 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
195 void deleteRecipient(RecipientIdentifier
.Single recipient
);
197 void deleteContact(RecipientIdentifier
.Single recipient
);
200 RecipientIdentifier
.Single recipient
, String name
201 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
203 void setContactBlocked(
204 RecipientIdentifier
.Single recipient
, boolean blocked
205 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
207 void setGroupBlocked(
208 GroupId groupId
, boolean blocked
209 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
212 * Change the expiration timer for a contact
214 void setExpirationTimer(
215 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
216 ) throws IOException
, UnregisteredRecipientException
;
219 * Upload the sticker pack from path.
221 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
222 * @return if successful, returns the URL to install the sticker pack in the signal app
224 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
226 List
<StickerPack
> getStickerPacks();
228 void requestAllSyncData() throws IOException
;
231 * Add a handler to receive new messages.
232 * Will start receiving messages from server, if not already started.
234 default void addReceiveHandler(ReceiveMessageHandler handler
) {
235 addReceiveHandler(handler
, false);
238 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
241 * Remove a handler to receive new messages.
242 * Will stop receiving messages from server, if this was the last registered receiver.
244 void removeReceiveHandler(ReceiveMessageHandler handler
);
246 boolean isReceiving();
249 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
251 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
254 * Receive new messages from server, returns only if the thread is interrupted.
256 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
258 void setIgnoreAttachments(boolean ignoreAttachments
);
260 boolean hasCaughtUpWithOldMessages();
262 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
264 void sendContacts() throws IOException
;
266 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
268 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
270 Group
getGroup(GroupId groupId
);
272 List
<Identity
> getIdentities();
274 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
277 * Trust this the identity with this fingerprint
279 * @param recipient account of the identity
280 * @param fingerprint Fingerprint
282 boolean trustIdentityVerified(
283 RecipientIdentifier
.Single recipient
, byte[] fingerprint
284 ) throws UnregisteredRecipientException
;
287 * Trust this the identity with this safety number
289 * @param recipient account of the identity
290 * @param safetyNumber Safety number
292 boolean trustIdentityVerifiedSafetyNumber(
293 RecipientIdentifier
.Single recipient
, String safetyNumber
294 ) throws UnregisteredRecipientException
;
297 * Trust this the identity with this scannable safety number
299 * @param recipient account of the identity
300 * @param safetyNumber Scannable safety number
302 boolean trustIdentityVerifiedSafetyNumber(
303 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
304 ) throws UnregisteredRecipientException
;
307 * Trust all keys of this identity without verification
309 * @param recipient account of the identity
311 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
313 void addClosedListener(Runnable listener
);
316 void close() throws IOException
;
318 interface ReceiveMessageHandler
{
320 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
323 void handleMessage(MessageEnvelope envelope
, Throwable e
);