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
.InactiveGroupLinkException
;
7 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
8 import org
.asamk
.signal
.manager
.api
.Message
;
9 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
10 import org
.asamk
.signal
.manager
.api
.Pair
;
11 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
12 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
13 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
14 import org
.asamk
.signal
.manager
.api
.TypingAction
;
15 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
16 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
17 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
18 import org
.asamk
.signal
.manager
.groups
.GroupId
;
19 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
20 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
21 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
22 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
23 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
24 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
25 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
26 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
27 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
28 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
29 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
31 import java
.io
.Closeable
;
33 import java
.io
.IOException
;
35 import java
.util
.Arrays
;
36 import java
.util
.List
;
38 import java
.util
.Optional
;
40 import java
.util
.UUID
;
41 import java
.util
.concurrent
.TimeUnit
;
42 import java
.util
.stream
.Collectors
;
44 public interface Manager
extends Closeable
{
49 ServiceEnvironment serviceEnvironment
,
51 TrustNewIdentity trustNewIdentity
52 ) throws IOException
, NotRegisteredException
{
53 var pathConfig
= PathConfig
.createDefault(settingsPath
);
55 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
56 throw new NotRegisteredException();
59 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
61 if (!account
.isRegistered()) {
62 throw new NotRegisteredException();
65 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
67 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
70 static void initLogger() {
71 LibSignalLogger
.initLogger();
74 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
75 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
78 static List
<String
> getAllLocalNumbers(File settingsPath
) {
79 var pathConfig
= PathConfig
.createDefault(settingsPath
);
80 final var dataPath
= pathConfig
.dataPath();
81 final var files
= dataPath
.listFiles();
87 return Arrays
.stream(files
)
90 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
91 .collect(Collectors
.toList());
94 String
getSelfNumber();
96 void checkAccountState() throws IOException
;
98 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
100 void updateAccountAttributes(String deviceName
) throws IOException
;
102 void updateConfiguration(
103 final Boolean readReceipts
,
104 final Boolean unidentifiedDeliveryIndicators
,
105 final Boolean typingIndicators
,
106 final Boolean linkPreviews
107 ) throws IOException
, NotMasterDeviceException
;
110 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
111 ) throws IOException
;
113 void unregister() throws IOException
;
115 void deleteAccount() throws IOException
;
117 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
119 List
<Device
> getLinkedDevices() throws IOException
;
121 void removeLinkedDevices(long deviceId
) throws IOException
;
123 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
125 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
;
127 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
;
129 List
<Group
> getGroups();
131 SendGroupMessageResults
quitGroup(
132 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
133 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
135 void deleteGroup(GroupId groupId
) throws IOException
;
137 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
138 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
139 ) throws IOException
, AttachmentInvalidException
;
141 SendGroupMessageResults
updateGroup(
142 final GroupId groupId
, final UpdateGroup updateGroup
143 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
145 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
146 GroupInviteLinkUrl inviteLinkUrl
147 ) throws IOException
, InactiveGroupLinkException
;
149 void sendTypingMessage(
150 TypingAction action
, Set
<RecipientIdentifier
> recipients
151 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
153 void sendReadReceipt(
154 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
155 ) throws IOException
, UntrustedIdentityException
;
157 void sendViewedReceipt(
158 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
159 ) throws IOException
, UntrustedIdentityException
;
161 SendMessageResults
sendMessage(
162 Message message
, Set
<RecipientIdentifier
> recipients
163 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
165 SendMessageResults
sendRemoteDeleteMessage(
166 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
167 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
169 SendMessageResults
sendMessageReaction(
172 RecipientIdentifier
.Single targetAuthor
,
173 long targetSentTimestamp
,
174 Set
<RecipientIdentifier
> recipients
175 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
177 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
180 RecipientIdentifier
.Single recipient
, String name
181 ) throws NotMasterDeviceException
, IOException
;
183 void setContactBlocked(
184 RecipientIdentifier
.Single recipient
, boolean blocked
185 ) throws NotMasterDeviceException
, IOException
;
187 void setGroupBlocked(
188 GroupId groupId
, boolean blocked
189 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
191 void setExpirationTimer(
192 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
193 ) throws IOException
;
195 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
197 void requestAllSyncData() throws IOException
;
200 * Add a handler to receive new messages.
201 * Will start receiving messages from server, if not already started.
203 void addReceiveHandler(ReceiveMessageHandler handler
);
206 * Remove a handler to receive new messages.
207 * Will stop receiving messages from server, if this was the last registered receiver.
209 void removeReceiveHandler(ReceiveMessageHandler handler
);
211 boolean isReceiving();
214 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
216 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
219 * Receive new messages from server, returns only if the thread is interrupted.
221 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
223 void setIgnoreAttachments(boolean ignoreAttachments
);
225 boolean hasCaughtUpWithOldMessages();
227 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
229 File
getAttachmentFile(String attachmentId
);
231 void sendContacts() throws IOException
;
233 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
235 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
237 Group
getGroup(GroupId groupId
);
239 List
<Identity
> getIdentities();
241 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
243 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
245 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
247 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
249 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
252 void close() throws IOException
;
254 interface ReceiveMessageHandler
{
256 void handleMessage(MessageEnvelope envelope
, Throwable e
);