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
.Message
;
7 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
8 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
9 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
10 import org
.asamk
.signal
.manager
.api
.TypingAction
;
11 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
12 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
13 import org
.asamk
.signal
.manager
.groups
.GroupId
;
14 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
15 import org
.asamk
.signal
.manager
.groups
.GroupLinkState
;
16 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
17 import org
.asamk
.signal
.manager
.groups
.GroupPermission
;
18 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
19 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
20 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
21 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
22 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
23 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
24 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
25 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
26 import org
.whispersystems
.libsignal
.IdentityKey
;
27 import org
.whispersystems
.libsignal
.InvalidKeyException
;
28 import org
.whispersystems
.libsignal
.util
.Pair
;
29 import org
.whispersystems
.libsignal
.util
.guava
.Optional
;
30 import org
.whispersystems
.signalservice
.api
.groupsv2
.GroupLinkNotActiveException
;
31 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentRemoteId
;
32 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceContent
;
33 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceEnvelope
;
34 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
35 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.UnregisteredUserException
;
36 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
37 import org
.whispersystems
.signalservice
.internal
.contacts
.crypto
.UnauthenticatedResponseException
;
39 import java
.io
.Closeable
;
41 import java
.io
.IOException
;
43 import java
.util
.Arrays
;
44 import java
.util
.List
;
47 import java
.util
.UUID
;
48 import java
.util
.concurrent
.TimeUnit
;
49 import java
.util
.stream
.Collectors
;
51 public interface Manager
extends Closeable
{
56 ServiceEnvironment serviceEnvironment
,
58 TrustNewIdentity trustNewIdentity
59 ) throws IOException
, NotRegisteredException
{
60 var pathConfig
= PathConfig
.createDefault(settingsPath
);
62 if (!SignalAccount
.userExists(pathConfig
.getDataPath(), number
)) {
63 throw new NotRegisteredException();
66 var account
= SignalAccount
.load(pathConfig
.getDataPath(), number
, true, trustNewIdentity
);
68 if (!account
.isRegistered()) {
69 throw new NotRegisteredException();
72 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
74 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
77 static List
<String
> getAllLocalNumbers(File settingsPath
) {
78 var pathConfig
= PathConfig
.createDefault(settingsPath
);
79 final var dataPath
= pathConfig
.getDataPath();
80 final var files
= dataPath
.listFiles();
86 return Arrays
.stream(files
)
89 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
90 .collect(Collectors
.toList());
93 String
getSelfNumber();
95 void checkAccountState() throws IOException
;
97 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
99 void updateAccountAttributes(String deviceName
) throws IOException
;
101 void updateConfiguration(
102 final Boolean readReceipts
,
103 final Boolean unidentifiedDeliveryIndicators
,
104 final Boolean typingIndicators
,
105 final Boolean linkPreviews
106 ) throws IOException
, NotMasterDeviceException
;
108 List
<Boolean
> getConfiguration() throws IOException
, NotMasterDeviceException
;
111 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
112 ) throws IOException
;
114 void unregister() throws IOException
;
116 void deleteAccount() throws IOException
;
118 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
120 List
<Device
> getLinkedDevices() throws IOException
;
122 void removeLinkedDevices(long deviceId
) throws IOException
;
124 void addDeviceLink(URI linkUri
) throws IOException
, InvalidKeyException
;
126 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, UnauthenticatedResponseException
;
128 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws UnregisteredUserException
;
130 List
<Group
> getGroups();
132 SendGroupMessageResults
quitGroup(
133 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
134 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
136 void deleteGroup(GroupId groupId
) throws IOException
;
138 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
139 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
140 ) throws IOException
, AttachmentInvalidException
;
142 SendGroupMessageResults
updateGroup(
146 Set
<RecipientIdentifier
.Single
> members
,
147 Set
<RecipientIdentifier
.Single
> removeMembers
,
148 Set
<RecipientIdentifier
.Single
> admins
,
149 Set
<RecipientIdentifier
.Single
> removeAdmins
,
150 boolean resetGroupLink
,
151 GroupLinkState groupLinkState
,
152 GroupPermission addMemberPermission
,
153 GroupPermission editDetailsPermission
,
155 Integer expirationTimer
,
156 Boolean isAnnouncementGroup
157 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
159 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
160 GroupInviteLinkUrl inviteLinkUrl
161 ) throws IOException
, GroupLinkNotActiveException
;
163 void sendTypingMessage(
164 TypingAction action
, Set
<RecipientIdentifier
> recipients
165 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
167 void sendReadReceipt(
168 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
169 ) throws IOException
, UntrustedIdentityException
;
171 void sendViewedReceipt(
172 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
173 ) throws IOException
, UntrustedIdentityException
;
175 SendMessageResults
sendMessage(
176 Message message
, Set
<RecipientIdentifier
> recipients
177 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
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
;
191 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
194 RecipientIdentifier
.Single recipient
, String name
195 ) throws NotMasterDeviceException
, UnregisteredUserException
;
197 void setContactBlocked(
198 RecipientIdentifier
.Single recipient
, boolean blocked
199 ) throws NotMasterDeviceException
, IOException
;
201 void setGroupBlocked(
202 GroupId groupId
, boolean blocked
203 ) throws GroupNotFoundException
, IOException
;
205 void setExpirationTimer(
206 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
207 ) throws IOException
;
209 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
211 void requestAllSyncData() throws IOException
;
213 void receiveMessages(
216 boolean returnOnTimeout
,
217 boolean ignoreAttachments
,
218 ReceiveMessageHandler handler
219 ) throws IOException
;
221 boolean hasCaughtUpWithOldMessages();
223 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
225 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
227 void sendContacts() throws IOException
;
229 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
231 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
233 Group
getGroup(GroupId groupId
);
235 List
<Identity
> getIdentities();
237 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
239 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
241 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
243 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
245 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
247 String
computeSafetyNumber(SignalServiceAddress theirAddress
, IdentityKey theirIdentityKey
);
249 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
252 void close() throws IOException
;
254 interface ReceiveMessageHandler
{
256 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);