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 account
.initDatabase();
71 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
73 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
76 static void initLogger() {
77 LibSignalLogger
.initLogger();
80 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
81 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
84 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
85 var pathConfig
= PathConfig
.createDefault(settingsPath
);
86 final var dataPath
= pathConfig
.dataPath();
87 final var files
= dataPath
.listFiles();
93 return Arrays
.stream(files
)
96 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
100 String
getSelfNumber();
102 void checkAccountState() throws IOException
;
105 * This is used for checking a set of phone numbers for registration on Signal
107 * @param numbers The set of phone number in question
108 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
109 * @throws IOException if it's unable to get the contacts to check if they're registered
111 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
113 void updateAccountAttributes(String deviceName
) throws IOException
;
115 Configuration
getConfiguration();
117 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
120 * @param givenName if null, the previous givenName will be kept
121 * @param familyName if null, the previous familyName will be kept
122 * @param about if null, the previous about text will be kept
123 * @param aboutEmoji if null, the previous about emoji will be kept
124 * @param avatar if avatar is null the image from the local avatar store is used (if present),
127 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
128 ) throws IOException
;
130 void unregister() throws IOException
;
132 void deleteAccount() throws IOException
;
134 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
136 List
<Device
> getLinkedDevices() throws IOException
;
138 void removeLinkedDevices(int deviceId
) throws IOException
;
140 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
142 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
144 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
146 List
<Group
> getGroups();
148 SendGroupMessageResults
quitGroup(
149 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
150 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
152 void deleteGroup(GroupId groupId
) throws IOException
;
154 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
155 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
156 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
158 SendGroupMessageResults
updateGroup(
159 final GroupId groupId
, final UpdateGroup updateGroup
160 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
162 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
163 GroupInviteLinkUrl inviteLinkUrl
164 ) throws IOException
, InactiveGroupLinkException
;
166 SendMessageResults
sendTypingMessage(
167 TypingAction action
, Set
<RecipientIdentifier
> recipients
168 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
170 SendMessageResults
sendReadReceipt(
171 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
172 ) throws IOException
;
174 SendMessageResults
sendViewedReceipt(
175 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
176 ) throws IOException
;
178 SendMessageResults
sendMessage(
179 Message message
, Set
<RecipientIdentifier
> recipients
180 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
182 SendMessageResults
sendRemoteDeleteMessage(
183 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
184 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
186 SendMessageResults
sendMessageReaction(
189 RecipientIdentifier
.Single targetAuthor
,
190 long targetSentTimestamp
,
191 Set
<RecipientIdentifier
> recipients
192 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
194 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
196 void deleteRecipient(RecipientIdentifier
.Single recipient
);
198 void deleteContact(RecipientIdentifier
.Single recipient
);
201 RecipientIdentifier
.Single recipient
, String name
202 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
204 void setContactBlocked(
205 RecipientIdentifier
.Single recipient
, boolean blocked
206 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
208 void setGroupBlocked(
209 GroupId groupId
, boolean blocked
210 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
213 * Change the expiration timer for a contact
215 void setExpirationTimer(
216 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
217 ) throws IOException
, UnregisteredRecipientException
;
220 * Upload the sticker pack from path.
222 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
223 * @return if successful, returns the URL to install the sticker pack in the signal app
225 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
227 List
<StickerPack
> getStickerPacks();
229 void requestAllSyncData() throws IOException
;
232 * Add a handler to receive new messages.
233 * Will start receiving messages from server, if not already started.
235 default void addReceiveHandler(ReceiveMessageHandler handler
) {
236 addReceiveHandler(handler
, false);
239 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
242 * Remove a handler to receive new messages.
243 * Will stop receiving messages from server, if this was the last registered receiver.
245 void removeReceiveHandler(ReceiveMessageHandler handler
);
247 boolean isReceiving();
250 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
252 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
255 * Receive new messages from server, returns only if the thread is interrupted.
257 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
259 void setIgnoreAttachments(boolean ignoreAttachments
);
261 boolean hasCaughtUpWithOldMessages();
263 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
265 void sendContacts() throws IOException
;
267 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
269 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
271 Group
getGroup(GroupId groupId
);
273 List
<Identity
> getIdentities();
275 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
278 * Trust this the identity with this fingerprint
280 * @param recipient account of the identity
281 * @param fingerprint Fingerprint
283 boolean trustIdentityVerified(
284 RecipientIdentifier
.Single recipient
, byte[] fingerprint
285 ) throws UnregisteredRecipientException
;
288 * Trust this the identity with this safety number
290 * @param recipient account of the identity
291 * @param safetyNumber Safety number
293 boolean trustIdentityVerifiedSafetyNumber(
294 RecipientIdentifier
.Single recipient
, String safetyNumber
295 ) throws UnregisteredRecipientException
;
298 * Trust this the identity with this scannable safety number
300 * @param recipient account of the identity
301 * @param safetyNumber Scannable safety number
303 boolean trustIdentityVerifiedSafetyNumber(
304 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
305 ) throws UnregisteredRecipientException
;
308 * Trust all keys of this identity without verification
310 * @param recipient account of the identity
312 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
314 void addClosedListener(Runnable listener
);
317 void close() throws IOException
;
319 interface ReceiveMessageHandler
{
321 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
324 void handleMessage(MessageEnvelope envelope
, Throwable e
);