1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AccountCheckException
;
4 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
5 import org
.asamk
.signal
.manager
.api
.Configuration
;
6 import org
.asamk
.signal
.manager
.api
.Device
;
7 import org
.asamk
.signal
.manager
.api
.Group
;
8 import org
.asamk
.signal
.manager
.api
.Identity
;
9 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
11 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
12 import org
.asamk
.signal
.manager
.api
.Message
;
13 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
14 import org
.asamk
.signal
.manager
.api
.NotMasterDeviceException
;
15 import org
.asamk
.signal
.manager
.api
.NotRegisteredException
;
16 import org
.asamk
.signal
.manager
.api
.Pair
;
17 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
18 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
19 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
20 import org
.asamk
.signal
.manager
.api
.StickerPack
;
21 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
22 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
23 import org
.asamk
.signal
.manager
.api
.TypingAction
;
24 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
25 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
26 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
27 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
28 import org
.asamk
.signal
.manager
.groups
.GroupId
;
29 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
30 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
31 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
32 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
33 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
34 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
35 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
36 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
37 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
38 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
39 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
41 import java
.io
.Closeable
;
43 import java
.io
.IOException
;
45 import java
.time
.Duration
;
46 import java
.util
.List
;
48 import java
.util
.Optional
;
50 import java
.util
.UUID
;
52 public interface Manager
extends Closeable
{
57 ServiceEnvironment serviceEnvironment
,
59 TrustNewIdentity trustNewIdentity
60 ) throws IOException
, NotRegisteredException
, AccountCheckException
{
61 var pathConfig
= PathConfig
.createDefault(settingsPath
);
63 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
64 throw new NotRegisteredException();
67 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
69 if (!account
.isRegistered()) {
71 throw new NotRegisteredException();
74 account
.initDatabase();
75 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
77 final var manager
= new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
80 manager
.checkAccountState();
81 } catch (IOException e
) {
83 throw new AccountCheckException("Error while checking account " + account
+ ": " + e
.getMessage(), e
);
89 static void initLogger() {
90 LibSignalLogger
.initLogger();
93 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
94 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
97 String
getSelfNumber();
100 * This is used for checking a set of phone numbers for registration on Signal
102 * @param numbers The set of phone number in question
103 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
104 * @throws IOException if it's unable to get the contacts to check if they're registered
106 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
108 void updateAccountAttributes(String deviceName
) throws IOException
;
110 Configuration
getConfiguration();
112 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
115 * @param givenName if null, the previous givenName will be kept
116 * @param familyName if null, the previous familyName will be kept
117 * @param about if null, the previous about text will be kept
118 * @param aboutEmoji if null, the previous about emoji will be kept
119 * @param avatar if avatar is null the image from the local avatar store is used (if present),
122 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
123 ) throws IOException
;
125 void unregister() throws IOException
;
127 void deleteAccount() throws IOException
;
129 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
131 List
<Device
> getLinkedDevices() throws IOException
;
133 void removeLinkedDevices(int deviceId
) throws IOException
;
135 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
137 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
139 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
141 List
<Group
> getGroups();
143 SendGroupMessageResults
quitGroup(
144 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
145 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
147 void deleteGroup(GroupId groupId
) throws IOException
;
149 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
150 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
151 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
153 SendGroupMessageResults
updateGroup(
154 final GroupId groupId
, final UpdateGroup updateGroup
155 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
157 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
158 GroupInviteLinkUrl inviteLinkUrl
159 ) throws IOException
, InactiveGroupLinkException
;
161 SendMessageResults
sendTypingMessage(
162 TypingAction action
, Set
<RecipientIdentifier
> recipients
163 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
165 SendMessageResults
sendReadReceipt(
166 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
167 ) throws IOException
;
169 SendMessageResults
sendViewedReceipt(
170 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
171 ) throws IOException
;
173 SendMessageResults
sendMessage(
174 Message message
, Set
<RecipientIdentifier
> recipients
175 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
177 SendMessageResults
sendRemoteDeleteMessage(
178 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
179 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
181 SendMessageResults
sendMessageReaction(
184 RecipientIdentifier
.Single targetAuthor
,
185 long targetSentTimestamp
,
186 Set
<RecipientIdentifier
> recipients
187 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
189 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
191 void deleteRecipient(RecipientIdentifier
.Single recipient
);
193 void deleteContact(RecipientIdentifier
.Single recipient
);
196 RecipientIdentifier
.Single recipient
, String name
197 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
199 void setContactBlocked(
200 RecipientIdentifier
.Single recipient
, boolean blocked
201 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
203 void setGroupBlocked(
204 GroupId groupId
, boolean blocked
205 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
208 * Change the expiration timer for a contact
210 void setExpirationTimer(
211 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
212 ) throws IOException
, UnregisteredRecipientException
;
215 * Upload the sticker pack from path.
217 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
218 * @return if successful, returns the URL to install the sticker pack in the signal app
220 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
222 List
<StickerPack
> getStickerPacks();
224 void requestAllSyncData() throws IOException
;
227 * Add a handler to receive new messages.
228 * Will start receiving messages from server, if not already started.
230 default void addReceiveHandler(ReceiveMessageHandler handler
) {
231 addReceiveHandler(handler
, false);
234 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
237 * Remove a handler to receive new messages.
238 * Will stop receiving messages from server, if this was the last registered receiver.
240 void removeReceiveHandler(ReceiveMessageHandler handler
);
242 boolean isReceiving();
245 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
247 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
250 * Receive new messages from server, returns only if the thread is interrupted.
252 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
254 void setIgnoreAttachments(boolean ignoreAttachments
);
256 boolean hasCaughtUpWithOldMessages();
258 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
260 void sendContacts() throws IOException
;
262 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
264 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
266 Group
getGroup(GroupId groupId
);
268 List
<Identity
> getIdentities();
270 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
273 * Trust this the identity with this fingerprint
275 * @param recipient account of the identity
276 * @param fingerprint Fingerprint
278 boolean trustIdentityVerified(
279 RecipientIdentifier
.Single recipient
, byte[] fingerprint
280 ) throws UnregisteredRecipientException
;
283 * Trust this the identity with this safety number
285 * @param recipient account of the identity
286 * @param safetyNumber Safety number
288 boolean trustIdentityVerifiedSafetyNumber(
289 RecipientIdentifier
.Single recipient
, String safetyNumber
290 ) throws UnregisteredRecipientException
;
293 * Trust this the identity with this scannable safety number
295 * @param recipient account of the identity
296 * @param safetyNumber Scannable safety number
298 boolean trustIdentityVerifiedSafetyNumber(
299 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
300 ) throws UnregisteredRecipientException
;
303 * Trust all keys of this identity without verification
305 * @param recipient account of the identity
307 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
309 void addClosedListener(Runnable listener
);
312 void close() throws IOException
;
314 interface ReceiveMessageHandler
{
316 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
319 void handleMessage(MessageEnvelope envelope
, Throwable e
);