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
.Message
;
10 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
11 import org
.asamk
.signal
.manager
.api
.Pair
;
12 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
13 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
14 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
15 import org
.asamk
.signal
.manager
.api
.TypingAction
;
16 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
17 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
18 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
19 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
20 import org
.asamk
.signal
.manager
.groups
.GroupId
;
21 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
22 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
23 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
24 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
25 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
26 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
27 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
28 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
29 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
30 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
31 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
33 import java
.io
.Closeable
;
35 import java
.io
.IOException
;
37 import java
.time
.Duration
;
38 import java
.util
.Arrays
;
39 import java
.util
.List
;
41 import java
.util
.Optional
;
43 import java
.util
.UUID
;
45 public interface Manager
extends Closeable
{
50 ServiceEnvironment serviceEnvironment
,
52 TrustNewIdentity trustNewIdentity
53 ) throws IOException
, NotRegisteredException
{
54 var pathConfig
= PathConfig
.createDefault(settingsPath
);
56 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
57 throw new NotRegisteredException();
60 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
62 if (!account
.isRegistered()) {
64 throw new NotRegisteredException();
67 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
69 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
72 static void initLogger() {
73 LibSignalLogger
.initLogger();
76 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
77 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
80 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
81 var pathConfig
= PathConfig
.createDefault(settingsPath
);
82 final var dataPath
= pathConfig
.dataPath();
83 final var files
= dataPath
.listFiles();
89 return Arrays
.stream(files
)
92 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
96 String
getSelfNumber();
98 void checkAccountState() throws IOException
;
101 * This is used for checking a set of phone numbers for registration on Signal
103 * @param numbers The set of phone number in question
104 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
105 * @throws IOException if it's unable to get the contacts to check if they're registered
107 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
109 void updateAccountAttributes(String deviceName
) throws IOException
;
111 Configuration
getConfiguration();
113 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
116 * @param givenName if null, the previous givenName will be kept
117 * @param familyName if null, the previous familyName will be kept
118 * @param about if null, the previous about text will be kept
119 * @param aboutEmoji if null, the previous about emoji will be kept
120 * @param avatar if avatar is null the image from the local avatar store is used (if present),
123 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
124 ) throws IOException
;
126 void unregister() throws IOException
;
128 void deleteAccount() throws IOException
;
130 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
132 List
<Device
> getLinkedDevices() throws IOException
;
134 void removeLinkedDevices(long deviceId
) throws IOException
;
136 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
138 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
140 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
142 List
<Group
> getGroups();
144 SendGroupMessageResults
quitGroup(
145 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
146 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
148 void deleteGroup(GroupId groupId
) throws IOException
;
150 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
151 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
152 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
154 SendGroupMessageResults
updateGroup(
155 final GroupId groupId
, final UpdateGroup updateGroup
156 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
158 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
159 GroupInviteLinkUrl inviteLinkUrl
160 ) throws IOException
, InactiveGroupLinkException
;
162 SendMessageResults
sendTypingMessage(
163 TypingAction action
, Set
<RecipientIdentifier
> recipients
164 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
166 SendMessageResults
sendReadReceipt(
167 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
168 ) throws IOException
;
170 SendMessageResults
sendViewedReceipt(
171 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
172 ) throws IOException
;
174 SendMessageResults
sendMessage(
175 Message message
, Set
<RecipientIdentifier
> recipients
176 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
178 SendMessageResults
sendRemoteDeleteMessage(
179 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
180 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
182 SendMessageResults
sendMessageReaction(
185 RecipientIdentifier
.Single targetAuthor
,
186 long targetSentTimestamp
,
187 Set
<RecipientIdentifier
> recipients
188 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
190 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
192 void deleteRecipient(RecipientIdentifier
.Single recipient
);
194 void deleteContact(RecipientIdentifier
.Single recipient
);
197 RecipientIdentifier
.Single recipient
, String name
198 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
200 void setContactBlocked(
201 RecipientIdentifier
.Single recipient
, boolean blocked
202 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
204 void setGroupBlocked(
205 GroupId groupId
, boolean blocked
206 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
209 * Change the expiration timer for a contact
211 void setExpirationTimer(
212 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
213 ) throws IOException
, UnregisteredRecipientException
;
216 * Upload the sticker pack from path.
218 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
219 * @return if successful, returns the URL to install the sticker pack in the signal app
221 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
223 void requestAllSyncData() throws IOException
;
226 * Add a handler to receive new messages.
227 * Will start receiving messages from server, if not already started.
229 default void addReceiveHandler(ReceiveMessageHandler handler
) {
230 addReceiveHandler(handler
, false);
233 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
236 * Remove a handler to receive new messages.
237 * Will stop receiving messages from server, if this was the last registered receiver.
239 void removeReceiveHandler(ReceiveMessageHandler handler
);
241 boolean isReceiving();
244 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
246 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
249 * Receive new messages from server, returns only if the thread is interrupted.
251 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
253 void setIgnoreAttachments(boolean ignoreAttachments
);
255 boolean hasCaughtUpWithOldMessages();
257 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
259 void sendContacts() throws IOException
;
261 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
263 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
265 Group
getGroup(GroupId groupId
);
267 List
<Identity
> getIdentities();
269 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
272 * Trust this the identity with this fingerprint
274 * @param recipient account of the identity
275 * @param fingerprint Fingerprint
277 boolean trustIdentityVerified(
278 RecipientIdentifier
.Single recipient
, byte[] fingerprint
279 ) throws UnregisteredRecipientException
;
282 * Trust this the identity with this safety number
284 * @param recipient account of the identity
285 * @param safetyNumber Safety number
287 boolean trustIdentityVerifiedSafetyNumber(
288 RecipientIdentifier
.Single recipient
, String safetyNumber
289 ) throws UnregisteredRecipientException
;
292 * Trust this the identity with this scannable safety number
294 * @param recipient account of the identity
295 * @param safetyNumber Scannable safety number
297 boolean trustIdentityVerifiedSafetyNumber(
298 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
299 ) throws UnregisteredRecipientException
;
302 * Trust all keys of this identity without verification
304 * @param recipient account of the identity
306 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
308 void addClosedListener(Runnable listener
);
311 void close() throws IOException
;
313 interface ReceiveMessageHandler
{
315 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
318 void handleMessage(MessageEnvelope envelope
, Throwable e
);