1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.Device
;
4 import org
.asamk
.signal
.manager
.api
.Group
;
5 import org
.asamk
.signal
.manager
.api
.Identity
;
6 import org
.asamk
.signal
.manager
.api
.Message
;
7 import org
.asamk
.signal
.manager
.api
.Pair
;
8 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
9 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
10 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
11 import org
.asamk
.signal
.manager
.api
.TypingAction
;
12 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
13 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
14 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
15 import org
.asamk
.signal
.manager
.groups
.GroupId
;
16 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
17 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
18 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
19 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
20 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
21 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
22 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
23 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
24 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
25 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
26 import org
.whispersystems
.libsignal
.InvalidKeyException
;
27 import org
.whispersystems
.signalservice
.api
.groupsv2
.GroupLinkNotActiveException
;
28 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentRemoteId
;
29 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceContent
;
30 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceEnvelope
;
31 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
32 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.UnregisteredUserException
;
33 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
34 import org
.whispersystems
.signalservice
.internal
.contacts
.crypto
.UnauthenticatedResponseException
;
36 import java
.io
.Closeable
;
38 import java
.io
.IOException
;
40 import java
.util
.Arrays
;
41 import java
.util
.List
;
43 import java
.util
.Optional
;
45 import java
.util
.UUID
;
46 import java
.util
.concurrent
.TimeUnit
;
47 import java
.util
.stream
.Collectors
;
49 public interface Manager
extends Closeable
{
54 ServiceEnvironment serviceEnvironment
,
56 TrustNewIdentity trustNewIdentity
57 ) throws IOException
, NotRegisteredException
{
58 var pathConfig
= PathConfig
.createDefault(settingsPath
);
60 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
61 throw new NotRegisteredException();
64 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
66 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 List
<String
> getAllLocalNumbers(File settingsPath
) {
76 var pathConfig
= PathConfig
.createDefault(settingsPath
);
77 final var dataPath
= pathConfig
.dataPath();
78 final var files
= dataPath
.listFiles();
84 return Arrays
.stream(files
)
87 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
88 .collect(Collectors
.toList());
91 String
getSelfNumber();
93 void checkAccountState() throws IOException
;
95 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
97 void updateAccountAttributes(String deviceName
) throws IOException
;
99 void updateConfiguration(
100 final Boolean readReceipts
,
101 final Boolean unidentifiedDeliveryIndicators
,
102 final Boolean typingIndicators
,
103 final Boolean linkPreviews
104 ) throws IOException
, NotMasterDeviceException
;
107 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
108 ) throws IOException
;
110 void unregister() throws IOException
;
112 void deleteAccount() throws IOException
;
114 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
116 List
<Device
> getLinkedDevices() throws IOException
;
118 void removeLinkedDevices(long deviceId
) throws IOException
;
120 void addDeviceLink(URI linkUri
) throws IOException
, InvalidKeyException
;
122 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, UnauthenticatedResponseException
;
124 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws UnregisteredUserException
;
126 List
<Group
> getGroups();
128 SendGroupMessageResults
quitGroup(
129 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
130 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
132 void deleteGroup(GroupId groupId
) throws IOException
;
134 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
135 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
136 ) throws IOException
, AttachmentInvalidException
;
138 SendGroupMessageResults
updateGroup(
139 final GroupId groupId
, final UpdateGroup updateGroup
140 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
142 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
143 GroupInviteLinkUrl inviteLinkUrl
144 ) throws IOException
, GroupLinkNotActiveException
;
146 void sendTypingMessage(
147 TypingAction action
, Set
<RecipientIdentifier
> recipients
148 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
150 void sendReadReceipt(
151 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
152 ) throws IOException
, UntrustedIdentityException
;
154 void sendViewedReceipt(
155 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
156 ) throws IOException
, UntrustedIdentityException
;
158 SendMessageResults
sendMessage(
159 Message message
, Set
<RecipientIdentifier
> recipients
160 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
162 SendMessageResults
sendRemoteDeleteMessage(
163 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
164 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
166 SendMessageResults
sendMessageReaction(
169 RecipientIdentifier
.Single targetAuthor
,
170 long targetSentTimestamp
,
171 Set
<RecipientIdentifier
> recipients
172 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
174 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
177 RecipientIdentifier
.Single recipient
, String name
178 ) throws NotMasterDeviceException
, UnregisteredUserException
;
180 void setContactBlocked(
181 RecipientIdentifier
.Single recipient
, boolean blocked
182 ) throws NotMasterDeviceException
, IOException
;
184 void setGroupBlocked(
185 GroupId groupId
, boolean blocked
186 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
188 void setExpirationTimer(
189 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
190 ) throws IOException
;
192 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
194 void requestAllSyncData() throws IOException
;
197 * Add a handler to receive new messages.
198 * Will start receiving messages from server, if not already started.
200 void addReceiveHandler(ReceiveMessageHandler handler
);
203 * Remove a handler to receive new messages.
204 * Will stop receiving messages from server, if this was the last registered receiver.
206 void removeReceiveHandler(ReceiveMessageHandler handler
);
208 boolean isReceiving();
211 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
213 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
216 * Receive new messages from server, returns only if the thread is interrupted.
218 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
220 void setIgnoreAttachments(boolean ignoreAttachments
);
222 boolean hasCaughtUpWithOldMessages();
224 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
226 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
228 void sendContacts() throws IOException
;
230 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
232 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
234 Group
getGroup(GroupId groupId
);
236 List
<Identity
> getIdentities();
238 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
240 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
242 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
244 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
246 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
248 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
251 void close() throws IOException
;
253 interface ReceiveMessageHandler
{
255 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);