1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.Device
;
4 import org
.asamk
.signal
.manager
.api
.Message
;
5 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
6 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
7 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
8 import org
.asamk
.signal
.manager
.api
.TypingAction
;
9 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
10 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
11 import org
.asamk
.signal
.manager
.groups
.GroupId
;
12 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
13 import org
.asamk
.signal
.manager
.groups
.GroupLinkState
;
14 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
15 import org
.asamk
.signal
.manager
.groups
.GroupPermission
;
16 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
17 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
18 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
19 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
20 import org
.asamk
.signal
.manager
.storage
.groups
.GroupInfo
;
21 import org
.asamk
.signal
.manager
.storage
.identities
.IdentityInfo
;
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
.RecipientId
;
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(), username
)) {
63 throw new NotRegisteredException();
66 var account
= SignalAccount
.load(pathConfig
.getDataPath(), username
, 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
> getAllLocalUsernames(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());
95 RecipientId
getSelfRecipientId();
99 void checkAccountState() throws IOException
;
101 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
103 void updateAccountAttributes(String deviceName
) throws IOException
;
106 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
107 ) throws IOException
;
109 void unregister() throws IOException
;
111 void deleteAccount() throws IOException
;
113 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
115 List
<Device
> getLinkedDevices() throws IOException
;
117 void removeLinkedDevices(int deviceId
) throws IOException
;
119 void addDeviceLink(URI linkUri
) throws IOException
, InvalidKeyException
;
121 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, UnauthenticatedResponseException
;
123 Profile
getRecipientProfile(RecipientId recipientId
);
125 List
<GroupInfo
> getGroups();
127 SendGroupMessageResults
quitGroup(
128 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
129 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
131 void deleteGroup(GroupId groupId
) throws IOException
;
133 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
134 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
135 ) throws IOException
, AttachmentInvalidException
;
137 SendGroupMessageResults
updateGroup(
141 Set
<RecipientIdentifier
.Single
> members
,
142 Set
<RecipientIdentifier
.Single
> removeMembers
,
143 Set
<RecipientIdentifier
.Single
> admins
,
144 Set
<RecipientIdentifier
.Single
> removeAdmins
,
145 boolean resetGroupLink
,
146 GroupLinkState groupLinkState
,
147 GroupPermission addMemberPermission
,
148 GroupPermission editDetailsPermission
,
150 Integer expirationTimer
,
151 Boolean isAnnouncementGroup
152 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
154 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
155 GroupInviteLinkUrl inviteLinkUrl
156 ) throws IOException
, GroupLinkNotActiveException
;
158 void sendTypingMessage(
159 TypingAction action
, Set
<RecipientIdentifier
> recipients
160 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
162 void sendReadReceipt(
163 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
164 ) throws IOException
, UntrustedIdentityException
;
166 void sendViewedReceipt(
167 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
168 ) throws IOException
, UntrustedIdentityException
;
170 SendMessageResults
sendMessage(
171 Message message
, Set
<RecipientIdentifier
> recipients
172 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
174 SendMessageResults
sendRemoteDeleteMessage(
175 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
176 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
178 SendMessageResults
sendMessageReaction(
181 RecipientIdentifier
.Single targetAuthor
,
182 long targetSentTimestamp
,
183 Set
<RecipientIdentifier
> recipients
184 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
186 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
189 RecipientIdentifier
.Single recipient
, String name
190 ) throws NotMasterDeviceException
, UnregisteredUserException
;
192 void setContactBlocked(
193 RecipientIdentifier
.Single recipient
, boolean blocked
194 ) throws NotMasterDeviceException
, IOException
;
196 void setGroupBlocked(
197 GroupId groupId
, boolean blocked
198 ) throws GroupNotFoundException
, IOException
;
200 void setExpirationTimer(
201 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
202 ) throws IOException
;
204 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
206 void requestAllSyncData() throws IOException
;
208 void receiveMessages(
211 boolean returnOnTimeout
,
212 boolean ignoreAttachments
,
213 ReceiveMessageHandler handler
214 ) throws IOException
;
216 boolean hasCaughtUpWithOldMessages();
218 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
220 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
222 void sendContacts() throws IOException
;
224 List
<Pair
<RecipientId
, Contact
>> getContacts();
226 String
getContactOrProfileName(RecipientIdentifier
.Single recipientIdentifier
);
228 GroupInfo
getGroup(GroupId groupId
);
230 List
<IdentityInfo
> getIdentities();
232 List
<IdentityInfo
> getIdentities(RecipientIdentifier
.Single recipient
);
234 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
236 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
238 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
240 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
242 String
computeSafetyNumber(SignalServiceAddress theirAddress
, IdentityKey theirIdentityKey
);
244 byte[] computeSafetyNumberForScanning(SignalServiceAddress theirAddress
, IdentityKey theirIdentityKey
);
246 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
248 SignalServiceAddress
resolveSignalServiceAddress(UUID uuid
);
250 SignalServiceAddress
resolveSignalServiceAddress(RecipientId recipientId
);
253 void close() throws IOException
;
255 interface ReceiveMessageHandler
{
257 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);