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
.TypingAction
;
18 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
19 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
20 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
21 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
22 import org
.asamk
.signal
.manager
.groups
.GroupId
;
23 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
24 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
25 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
26 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
27 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
28 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
29 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
30 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
31 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
33 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
35 import java
.io
.Closeable
;
37 import java
.io
.IOException
;
39 import java
.time
.Duration
;
40 import java
.util
.Arrays
;
41 import java
.util
.List
;
43 import java
.util
.Optional
;
45 import java
.util
.UUID
;
47 public interface Manager
extends Closeable
{
52 ServiceEnvironment serviceEnvironment
,
54 TrustNewIdentity trustNewIdentity
55 ) throws IOException
, NotRegisteredException
{
56 var pathConfig
= PathConfig
.createDefault(settingsPath
);
58 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
59 throw new NotRegisteredException();
62 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
64 if (!account
.isRegistered()) {
66 throw new NotRegisteredException();
69 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
71 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
74 static void initLogger() {
75 LibSignalLogger
.initLogger();
78 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
79 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
82 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
83 var pathConfig
= PathConfig
.createDefault(settingsPath
);
84 final var dataPath
= pathConfig
.dataPath();
85 final var files
= dataPath
.listFiles();
91 return Arrays
.stream(files
)
94 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
98 String
getSelfNumber();
100 void checkAccountState() throws IOException
;
103 * This is used for checking a set of phone numbers for registration on Signal
105 * @param numbers The set of phone number in question
106 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
107 * @throws IOException if it's unable to get the contacts to check if they're registered
109 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
111 void updateAccountAttributes(String deviceName
) throws IOException
;
113 Configuration
getConfiguration();
115 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
118 * @param givenName if null, the previous givenName will be kept
119 * @param familyName if null, the previous familyName will be kept
120 * @param about if null, the previous about text will be kept
121 * @param aboutEmoji if null, the previous about emoji will be kept
122 * @param avatar if avatar is null the image from the local avatar store is used (if present),
125 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
126 ) throws IOException
;
128 void unregister() throws IOException
;
130 void deleteAccount() throws IOException
;
132 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
134 List
<Device
> getLinkedDevices() throws IOException
;
136 void removeLinkedDevices(long deviceId
) throws IOException
;
138 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
140 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
142 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
144 List
<Group
> getGroups();
146 SendGroupMessageResults
quitGroup(
147 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
148 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
150 void deleteGroup(GroupId groupId
) throws IOException
;
152 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
153 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
154 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
156 SendGroupMessageResults
updateGroup(
157 final GroupId groupId
, final UpdateGroup updateGroup
158 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
160 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
161 GroupInviteLinkUrl inviteLinkUrl
162 ) throws IOException
, InactiveGroupLinkException
;
164 SendMessageResults
sendTypingMessage(
165 TypingAction action
, Set
<RecipientIdentifier
> recipients
166 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
168 SendMessageResults
sendReadReceipt(
169 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
170 ) throws IOException
;
172 SendMessageResults
sendViewedReceipt(
173 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
174 ) throws IOException
;
176 SendMessageResults
sendMessage(
177 Message message
, Set
<RecipientIdentifier
> recipients
178 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
180 SendMessageResults
sendRemoteDeleteMessage(
181 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
182 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
184 SendMessageResults
sendMessageReaction(
187 RecipientIdentifier
.Single targetAuthor
,
188 long targetSentTimestamp
,
189 Set
<RecipientIdentifier
> recipients
190 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
192 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
194 void deleteRecipient(RecipientIdentifier
.Single recipient
);
196 void deleteContact(RecipientIdentifier
.Single recipient
);
199 RecipientIdentifier
.Single recipient
, String name
200 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
202 void setContactBlocked(
203 RecipientIdentifier
.Single recipient
, boolean blocked
204 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
206 void setGroupBlocked(
207 GroupId groupId
, boolean blocked
208 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
211 * Change the expiration timer for a contact
213 void setExpirationTimer(
214 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
215 ) throws IOException
, UnregisteredRecipientException
;
218 * Upload the sticker pack from path.
220 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
221 * @return if successful, returns the URL to install the sticker pack in the signal app
223 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
225 List
<StickerPack
> getStickerPacks();
227 void requestAllSyncData() throws IOException
;
230 * Add a handler to receive new messages.
231 * Will start receiving messages from server, if not already started.
233 default void addReceiveHandler(ReceiveMessageHandler handler
) {
234 addReceiveHandler(handler
, false);
237 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
240 * Remove a handler to receive new messages.
241 * Will stop receiving messages from server, if this was the last registered receiver.
243 void removeReceiveHandler(ReceiveMessageHandler handler
);
245 boolean isReceiving();
248 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
250 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
253 * Receive new messages from server, returns only if the thread is interrupted.
255 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
257 void setIgnoreAttachments(boolean ignoreAttachments
);
259 boolean hasCaughtUpWithOldMessages();
261 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
263 void sendContacts() throws IOException
;
265 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
267 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
269 Group
getGroup(GroupId groupId
);
271 List
<Identity
> getIdentities();
273 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
276 * Trust this the identity with this fingerprint
278 * @param recipient account of the identity
279 * @param fingerprint Fingerprint
281 boolean trustIdentityVerified(
282 RecipientIdentifier
.Single recipient
, byte[] fingerprint
283 ) throws UnregisteredRecipientException
;
286 * Trust this the identity with this safety number
288 * @param recipient account of the identity
289 * @param safetyNumber Safety number
291 boolean trustIdentityVerifiedSafetyNumber(
292 RecipientIdentifier
.Single recipient
, String safetyNumber
293 ) throws UnregisteredRecipientException
;
296 * Trust this the identity with this scannable safety number
298 * @param recipient account of the identity
299 * @param safetyNumber Scannable safety number
301 boolean trustIdentityVerifiedSafetyNumber(
302 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
303 ) throws UnregisteredRecipientException
;
306 * Trust all keys of this identity without verification
308 * @param recipient account of the identity
310 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
312 void addClosedListener(Runnable listener
);
315 void close() throws IOException
;
317 interface ReceiveMessageHandler
{
319 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
322 void handleMessage(MessageEnvelope envelope
, Throwable e
);