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
.TypingAction
;
17 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
18 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
19 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
20 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
21 import org
.asamk
.signal
.manager
.groups
.GroupId
;
22 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
23 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
24 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
25 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
26 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
27 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
28 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
29 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
30 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
31 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
32 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
34 import java
.io
.Closeable
;
36 import java
.io
.IOException
;
38 import java
.time
.Duration
;
39 import java
.util
.Arrays
;
40 import java
.util
.List
;
42 import java
.util
.Optional
;
44 import java
.util
.UUID
;
46 public interface Manager
extends Closeable
{
51 ServiceEnvironment serviceEnvironment
,
53 TrustNewIdentity trustNewIdentity
54 ) throws IOException
, NotRegisteredException
{
55 var pathConfig
= PathConfig
.createDefault(settingsPath
);
57 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
58 throw new NotRegisteredException();
61 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
63 if (!account
.isRegistered()) {
65 throw new NotRegisteredException();
68 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
70 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
73 static void initLogger() {
74 LibSignalLogger
.initLogger();
77 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
78 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
81 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
82 var pathConfig
= PathConfig
.createDefault(settingsPath
);
83 final var dataPath
= pathConfig
.dataPath();
84 final var files
= dataPath
.listFiles();
90 return Arrays
.stream(files
)
93 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
97 String
getSelfNumber();
99 void checkAccountState() throws IOException
;
102 * This is used for checking a set of phone numbers for registration on Signal
104 * @param numbers The set of phone number in question
105 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
106 * @throws IOException if it's unable to get the contacts to check if they're registered
108 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
110 void updateAccountAttributes(String deviceName
) throws IOException
;
112 Configuration
getConfiguration();
114 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
117 * @param givenName if null, the previous givenName will be kept
118 * @param familyName if null, the previous familyName will be kept
119 * @param about if null, the previous about text will be kept
120 * @param aboutEmoji if null, the previous about emoji will be kept
121 * @param avatar if avatar is null the image from the local avatar store is used (if present),
124 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
125 ) throws IOException
;
127 void unregister() throws IOException
;
129 void deleteAccount() throws IOException
;
131 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
133 List
<Device
> getLinkedDevices() throws IOException
;
135 void removeLinkedDevices(long deviceId
) throws IOException
;
137 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
139 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
141 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
143 List
<Group
> getGroups();
145 SendGroupMessageResults
quitGroup(
146 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
147 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
149 void deleteGroup(GroupId groupId
) throws IOException
;
151 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
152 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
153 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
155 SendGroupMessageResults
updateGroup(
156 final GroupId groupId
, final UpdateGroup updateGroup
157 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
159 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
160 GroupInviteLinkUrl inviteLinkUrl
161 ) throws IOException
, InactiveGroupLinkException
;
163 SendMessageResults
sendTypingMessage(
164 TypingAction action
, Set
<RecipientIdentifier
> recipients
165 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
167 SendMessageResults
sendReadReceipt(
168 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
169 ) throws IOException
;
171 SendMessageResults
sendViewedReceipt(
172 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
173 ) throws IOException
;
175 SendMessageResults
sendMessage(
176 Message message
, Set
<RecipientIdentifier
> recipients
177 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
179 SendMessageResults
sendRemoteDeleteMessage(
180 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
181 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
183 SendMessageResults
sendMessageReaction(
186 RecipientIdentifier
.Single targetAuthor
,
187 long targetSentTimestamp
,
188 Set
<RecipientIdentifier
> recipients
189 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
191 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
193 void deleteRecipient(RecipientIdentifier
.Single recipient
);
195 void deleteContact(RecipientIdentifier
.Single recipient
);
198 RecipientIdentifier
.Single recipient
, String name
199 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
201 void setContactBlocked(
202 RecipientIdentifier
.Single recipient
, boolean blocked
203 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
205 void setGroupBlocked(
206 GroupId groupId
, boolean blocked
207 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
210 * Change the expiration timer for a contact
212 void setExpirationTimer(
213 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
214 ) throws IOException
, UnregisteredRecipientException
;
217 * Upload the sticker pack from path.
219 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
220 * @return if successful, returns the URL to install the sticker pack in the signal app
222 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
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
);