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
.api
.UpdateGroup
;
12 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
13 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
14 import org
.asamk
.signal
.manager
.groups
.GroupId
;
15 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
16 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
17 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
18 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
19 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
20 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
21 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
22 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
23 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
24 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
25 import org
.whispersystems
.libsignal
.IdentityKey
;
26 import org
.whispersystems
.libsignal
.InvalidKeyException
;
27 import org
.whispersystems
.libsignal
.util
.Pair
;
28 import org
.whispersystems
.libsignal
.util
.guava
.Optional
;
29 import org
.whispersystems
.signalservice
.api
.groupsv2
.GroupLinkNotActiveException
;
30 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentRemoteId
;
31 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceContent
;
32 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceEnvelope
;
33 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
34 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.UnregisteredUserException
;
35 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
36 import org
.whispersystems
.signalservice
.internal
.contacts
.crypto
.UnauthenticatedResponseException
;
38 import java
.io
.Closeable
;
40 import java
.io
.IOException
;
42 import java
.util
.Arrays
;
43 import java
.util
.List
;
46 import java
.util
.UUID
;
47 import java
.util
.concurrent
.TimeUnit
;
48 import java
.util
.stream
.Collectors
;
50 public interface Manager
extends Closeable
{
55 ServiceEnvironment serviceEnvironment
,
57 TrustNewIdentity trustNewIdentity
58 ) throws IOException
, NotRegisteredException
{
59 var pathConfig
= PathConfig
.createDefault(settingsPath
);
61 if (!SignalAccount
.userExists(pathConfig
.getDataPath(), number
)) {
62 throw new NotRegisteredException();
65 var account
= SignalAccount
.load(pathConfig
.getDataPath(), number
, true, trustNewIdentity
);
67 if (!account
.isRegistered()) {
68 throw new NotRegisteredException();
71 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
73 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
76 static List
<String
> getAllLocalNumbers(File settingsPath
) {
77 var pathConfig
= PathConfig
.createDefault(settingsPath
);
78 final var dataPath
= pathConfig
.getDataPath();
79 final var files
= dataPath
.listFiles();
85 return Arrays
.stream(files
)
88 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
89 .collect(Collectors
.toList());
92 String
getSelfNumber();
94 void checkAccountState() throws IOException
;
96 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
98 void updateAccountAttributes(String deviceName
) throws IOException
;
100 void updateConfiguration(
101 final Boolean readReceipts
,
102 final Boolean unidentifiedDeliveryIndicators
,
103 final Boolean typingIndicators
,
104 final Boolean linkPreviews
105 ) throws IOException
, NotMasterDeviceException
;
108 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
109 ) throws IOException
;
111 void unregister() throws IOException
;
113 void deleteAccount() throws IOException
;
115 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
117 List
<Device
> getLinkedDevices() throws IOException
;
119 void removeLinkedDevices(long deviceId
) throws IOException
;
121 void addDeviceLink(URI linkUri
) throws IOException
, InvalidKeyException
;
123 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, UnauthenticatedResponseException
;
125 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws UnregisteredUserException
;
127 List
<Group
> getGroups();
129 SendGroupMessageResults
quitGroup(
130 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
131 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
133 void deleteGroup(GroupId groupId
) throws IOException
;
135 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
136 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
137 ) throws IOException
, AttachmentInvalidException
;
139 SendGroupMessageResults
updateGroup(
140 final GroupId groupId
, final UpdateGroup updateGroup
141 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
143 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
144 GroupInviteLinkUrl inviteLinkUrl
145 ) throws IOException
, GroupLinkNotActiveException
;
147 void sendTypingMessage(
148 TypingAction action
, Set
<RecipientIdentifier
> recipients
149 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
151 void sendReadReceipt(
152 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
153 ) throws IOException
, UntrustedIdentityException
;
155 void sendViewedReceipt(
156 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
157 ) throws IOException
, UntrustedIdentityException
;
159 SendMessageResults
sendMessage(
160 Message message
, Set
<RecipientIdentifier
> recipients
161 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
163 SendMessageResults
sendRemoteDeleteMessage(
164 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
165 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
167 SendMessageResults
sendMessageReaction(
170 RecipientIdentifier
.Single targetAuthor
,
171 long targetSentTimestamp
,
172 Set
<RecipientIdentifier
> recipients
173 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
175 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
178 RecipientIdentifier
.Single recipient
, String name
179 ) throws NotMasterDeviceException
, UnregisteredUserException
;
181 void setContactBlocked(
182 RecipientIdentifier
.Single recipient
, boolean blocked
183 ) throws NotMasterDeviceException
, IOException
;
185 void setGroupBlocked(
186 GroupId groupId
, boolean blocked
187 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
189 void setExpirationTimer(
190 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
191 ) throws IOException
;
193 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
195 void requestAllSyncData() throws IOException
;
197 void receiveMessages(
200 boolean returnOnTimeout
,
201 boolean ignoreAttachments
,
202 ReceiveMessageHandler handler
203 ) throws IOException
;
205 boolean hasCaughtUpWithOldMessages();
207 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
209 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
211 void sendContacts() throws IOException
;
213 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
215 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
217 Group
getGroup(GroupId groupId
);
219 List
<Identity
> getIdentities();
221 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
223 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
225 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
227 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
229 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
231 String
computeSafetyNumber(SignalServiceAddress theirAddress
, IdentityKey theirIdentityKey
);
233 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
236 void close() throws IOException
;
238 interface ReceiveMessageHandler
{
240 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);