Skip to content

Commit 788aa8c

Browse files
Dropping some required permissions. Smarter microphone permission.
1 parent 7a5f9f1 commit 788aa8c

File tree

10 files changed

+80
-90
lines changed

10 files changed

+80
-90
lines changed

Signal/src/AppDelegate.m

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#endif
2727

2828

29-
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
30-
3129
@interface AppDelegate ()
3230

3331
@property (nonatomic, retain) UIWindow *blankWindow;
@@ -68,7 +66,6 @@ - (BOOL) isVersion:(NSString *)thisVersionString lessThan:(NSString *)thatVersio
6866
}
6967

7068
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
71-
7269
[self setupAppearance];
7370

7471
if (getenv("runningTests_dontStartApp")) {
@@ -82,6 +79,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8279
[Environment setCurrent:[Release releaseEnvironmentWithLogging:logger]];
8380
[Environment.getCurrent.phoneDirectoryManager startUntilCancelled:nil];
8481
[Environment.getCurrent.contactsManager doAfterEnvironmentInitSetup];
82+
[Environment.getCurrent initCallListener];
8583

8684
[[TSStorageManager sharedManager] setupDatabase];
8785

@@ -120,16 +118,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
120118

121119
[self prepareScreenshotProtection];
122120

123-
[Environment.phoneManager.currentCallObservable watchLatestValue:^(CallState* latestCall) {
124-
if (latestCall == nil){
125-
return;
126-
}
127-
SignalsViewController *vc = [[Environment getCurrent] signalsViewController];
128-
[vc dismissViewControllerAnimated:NO completion:nil];
129-
vc.latestCall = latestCall;
130-
[vc performSegueWithIdentifier:kCallSegue sender:self];
131-
} onThread:NSThread.mainThread untilCancelled:nil];
132-
133121
if ([TSAccountManager isRegistered]) {
134122
[TSSocketManager becomeActive];
135123
[self refreshContacts];
@@ -236,9 +224,6 @@ - (BOOL)isRedPhonePush:(NSDictionary*)pushDict {
236224
-(void) applicationDidBecomeActive:(UIApplication *)application {
237225
if ([TSAccountManager isRegistered]) {
238226
[TSSocketManager becomeActive];
239-
[AppAudioManager.sharedInstance awake];
240-
[PushManager.sharedManager verifyPushPermissions];
241-
[AppAudioManager.sharedInstance requestRequiredPermissionsIfNeeded];
242227
}
243228
// Hacky way to clear notification center after processed push
244229
[UIApplication.sharedApplication setApplicationIconBadgeNumber:1];

Signal/src/audio/AppAudioManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import <Foundation/Foundation.h>
22

3+
#import <AVFoundation/AVAudioSession.h>
34
#import "CallProgress.h"
45
#import "CallTermination.h"
56
#import "SoundPlayer.h"
@@ -33,7 +34,7 @@ enum AudioProfile {
3334
-(BOOL) toggleSpeakerPhone;
3435
-(void) cancellAllAudio;
3536

36-
-(void) requestRequiredPermissionsIfNeeded;
37+
-(void) requestRequiredPermissionsIfNeededWithCompletion:(PermissionBlock)permissionBlock incoming:(BOOL)isIncoming;
3738
-(BOOL) requestRecordingPrivilege;
3839
-(BOOL) releaseRecordingPrivilege;
3940

Signal/src/audio/AppAudioManager.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#import "AppAudioManager.h"
22

3-
#import <AVFoundation/AVAudioSession.h>
4-
53
#import "AudioRouter.h"
64
#import "SoundBoard.h"
75
#import "SoundPlayer.h"
@@ -13,7 +11,7 @@
1311

1412
AppAudioManager* sharedAppAudioManager;
1513

16-
@interface AppAudioManager (){
14+
@interface AppAudioManager () <UIAlertViewDelegate>{
1715
enum AudioProfile _audioProfile;
1816
BOOL isSpeakerphoneActive;
1917
}
@@ -79,7 +77,6 @@ -(void) respondToProgressChange:(enum CallProgressType) progressType
7977
switch (progressType){
8078
case CallProgressType_Connecting:
8179
[sharedAppAudioManager setAudioEnabled:YES];
82-
[_soundPlayer stopAllAudio];
8380
case CallProgressType_Ringing:
8481
(initiatedLocally) ? [self handleOutboundRing] : [self handleInboundRing];
8582
break;
@@ -160,15 +157,27 @@ -(BOOL) releaseRecordingPrivilege{
160157
return [self changeAudioSessionCategoryTo:DEFAULT_CATEGORY];
161158
}
162159

163-
-(void) requestRequiredPermissionsIfNeeded {
160+
-(void) requestRequiredPermissionsIfNeededWithCompletion:(PermissionBlock)permissionBlock incoming:(BOOL)isIncoming {
164161
[AVAudioSession.sharedInstance requestRecordPermission:^(BOOL granted) {
165162
if (!granted) {
166-
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ACTION_REQUIRED_TITLE", @"") message:NSLocalizedString(@"AUDIO_PERMISSION_MESSAGE", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil];
163+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ACTION_REQUIRED_TITLE", @"") message:NSLocalizedString(@"AUDIO_PERMISSION_MESSAGE", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") otherButtonTitles:NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE",nil), nil];
164+
165+
[alertView setDelegate:self];
166+
167167
[alertView show];
168168
}
169+
170+
permissionBlock(granted);
169171
}];
170172
}
171173

174+
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
175+
if (buttonIndex == 1) { // Tapped the Settings button
176+
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
177+
[[UIApplication sharedApplication] openURL:appSettings];
178+
}
179+
}
180+
172181
-(BOOL) changeAudioSessionCategoryTo:(NSString*) category {
173182
NSError* e;
174183
[AVAudioSession.sharedInstance setCategory:category error:&e];

Signal/src/contact/ContactsManager.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ -(void) pullLatestAddressBook{
9090
CFErrorRef creationError = nil;
9191
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &creationError);
9292
checkOperationDescribe(nil == creationError, [((__bridge NSError *)creationError) localizedDescription]) ;
93-
ABAddressBookRequestAccessWithCompletion(addressBookRef, nil);
93+
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
94+
// TO DO: DISPLAY ALERT
95+
});
9496
[observableContactsController updateValue:[self getContactsFromAddressBook:addressBookRef]];
9597
}
9698

Signal/src/environment/Environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ andCurrentRegionCodeForPhoneNumbers:(NSString*)currentRegionCodeForPhoneNumbers
8080

8181
+(BOOL)isRedPhoneRegistered;
8282
+(void)resetAppData;
83+
84+
- (void)initCallListener;
8385
- (void)setSignalsViewController:(SignalsViewController *)signalsViewController;
8486
- (void)setSignUpFlowNavigationController:(UINavigationController *)signUpFlowNavigationController;
8587

Signal/src/environment/Environment.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "SignalsViewController.h"
1414
#import "TSStorageManager.h"
1515

16+
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
1617
#define isRegisteredUserDefaultString @"isRegistered"
1718

1819
static Environment* environment = nil;
@@ -158,6 +159,19 @@ +(BOOL)isRedPhoneRegistered{
158159
return signalingKey && macKey && extra && serverAuth;
159160
}
160161

162+
- (void)initCallListener {
163+
[self.phoneManager.currentCallObservable watchLatestValue:^(CallState* latestCall) {
164+
if (latestCall == nil){
165+
return;
166+
}
167+
168+
SignalsViewController *vc = [[Environment getCurrent] signalsViewController];
169+
[vc dismissViewControllerAnimated:NO completion:nil];
170+
vc.latestCall = latestCall;
171+
[vc performSegueWithIdentifier:kCallSegue sender:self];
172+
} onThread:NSThread.mainThread untilCancelled:nil];
173+
}
174+
161175
+(PropertyListPreferences*)preferences{
162176
return [PropertyListPreferences new];
163177
}

Signal/src/network/PushManager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ typedef void(^failedPushRegistrationBlock)(NSError *error);
2828

2929
+ (PushManager*)sharedManager;
3030

31-
/**
32-
* Push notification token is always registered during signup. User can however revoke notifications.
33-
* Therefore, we check on startup if mandatory permissions are granted.
34-
*/
35-
36-
- (void)verifyPushPermissions;
37-
3831
/**
3932
* Push notification registration method
4033
*

Signal/src/network/PushManager.m

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
@interface PushManager ()
1717

1818
@property TOCFutureSource *registerWithServerFutureSource;
19-
@property UIAlertView *missingPermissionsAlertView;
20-
19+
@property UIAlertView *missingPermissionsAlertView;
2120

2221
@end
2322

@@ -44,18 +43,7 @@ - (instancetype)init{
4443
return self;
4544
}
4645

47-
- (void)verifyPushPermissions{
48-
if (self.isMissingMandatoryNotificationTypes || self.needToRegisterForRemoteNotifications){
49-
[self registrationWithSuccess:^{
50-
DDLogInfo(@"Re-enabled push succesfully");
51-
} failure:^(NSError *error) {
52-
DDLogError(@"Failed to re-register for push");
53-
}];
54-
}
55-
}
56-
5746
- (void)registrationWithSuccess:(void (^)())success failure:(failedPushRegistrationBlock)failure{
58-
5947
if (!self.wantRemoteNotifications) {
6048
success();
6149
return;
@@ -69,7 +57,6 @@ - (void)registrationWithSuccess:(void (^)())success failure:(failedPushRegistrat
6957
} failure:failure];
7058
}
7159

72-
7360
#pragma mark Private Methods
7461

7562
#pragma mark Register Push Notification Token with server
@@ -128,7 +115,6 @@ - (void)registrationForPushWithSuccess:(void (^)(NSData* pushToken))success fail
128115
}];
129116
}
130117

131-
132118
- (void)registrationAndRedPhoneTokenRequestWithSuccess:(void (^)(NSData* pushToken, NSString* signupToken))success failure:(failedPushRegistrationBlock)failure{
133119
[self registrationForPushWithSuccess:^(NSData *pushToken) {
134120
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall requestTextSecureVerificationCode] success:^(NSURLSessionDataTask *task, id responseObject) {
@@ -165,11 +151,7 @@ - (void)registrationForUserNotificationWithSuccess:(void (^)())success failure:(
165151
}];
166152

167153
[registrerUserNotificationFuture thenDo:^(id types) {
168-
if (self.isMissingMandatoryNotificationTypes) {
169-
failure();
170-
} else{
171-
success();
172-
}
154+
success();
173155
}];
174156
}
175157

@@ -188,20 +170,8 @@ -(BOOL) wantRemoteNotifications {
188170
return YES;
189171
}
190172

191-
192-
-(BOOL)isMissingMandatoryNotificationTypes {
193-
int mandatoryTypes = self.mandatoryNotificationTypes;
194-
int currentTypes = UIApplication.sharedApplication.currentUserNotificationSettings.types;
195-
196-
return (mandatoryTypes & currentTypes) != mandatoryTypes;
197-
}
198-
199173
-(int)allNotificationTypes{
200174
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
201175
}
202176

203-
-(int)mandatoryNotificationTypes{
204-
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
205-
}
206-
207177
@end

Signal/src/phone/PhoneManager.m

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#import "AppAudioManager.h"
12
#import "CallAudioManager.h"
23
#import "PhoneManager.h"
34
#import "ThreadManager.h"
@@ -52,22 +53,30 @@ -(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber {
5253

5354
-(void) initiateOutgoingCallToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact {
5455
require(remoteNumber != nil);
55-
56+
57+
[[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) {
58+
if (granted) {
59+
[self callToRemoteNumber:remoteNumber withOptionallyKnownContact:contact];
60+
}
61+
} incoming:NO];
62+
}
63+
64+
- (void)callToRemoteNumber:(PhoneNumber*)remoteNumber withOptionallyKnownContact:(Contact*)contact {
5665
CallController* callController = [self cancelExistingCallAndInitNewCallWork:true
5766
remote:remoteNumber
5867
optionalContact:contact];
5968
[callController acceptCall]; // initiator implicitly accepts call
6069
TOCCancelToken* lifetime = [callController untilCancelledToken];
61-
70+
6271
TOCFuture* futureConnected = [CallConnectUtil asyncInitiateCallToRemoteNumber:remoteNumber
6372
andCallController:callController];
6473

6574
TOCFuture* futureCalling = [futureConnected thenTry:^id(CallConnectResult* connectResult) {
6675
[callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
6776
CallAudioManager *cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket
68-
andErrorHandler:callController.errorHandler
69-
untilCancelled:lifetime];
70-
[callController setCallAudioManager:cam];
77+
andErrorHandler:callController.errorHandler
78+
untilCancelled:lifetime];
79+
[callController setCallAudioManager:cam];
7180
return nil;
7281
}];
7382

@@ -96,28 +105,32 @@ -(void) incomingCallWithSession:(ResponderSessionDescriptor*)session {
96105
return;
97106
}
98107

99-
Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber];
100-
CallController* callController = [self cancelExistingCallAndInitNewCallWork:false
101-
remote:session.initiatorNumber
102-
optionalContact:callingContact];
103-
104-
TOCCancelToken* lifetime = [callController untilCancelledToken];
105-
106-
TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session
107-
andCallController:callController];
108-
109-
TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) {
110-
[callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
111-
CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket
112-
andErrorHandler:callController.errorHandler
113-
untilCancelled:lifetime];
114-
[callController setCallAudioManager:cam];
115-
return nil;
116-
}];
117-
118-
[futureStarted catchDo:^(id error) {
119-
callController.errorHandler(error, nil, true);
120-
}];
108+
[[AppAudioManager sharedInstance] requestRequiredPermissionsIfNeededWithCompletion:^(BOOL granted) {
109+
if (granted) {
110+
Contact* callingContact = [Environment.getCurrent.contactsManager latestContactForPhoneNumber:session.initiatorNumber];
111+
CallController* callController = [self cancelExistingCallAndInitNewCallWork:false
112+
remote:session.initiatorNumber
113+
optionalContact:callingContact];
114+
115+
TOCCancelToken* lifetime = [callController untilCancelledToken];
116+
117+
TOCFuture* futureConnected = [CallConnectUtil asyncRespondToCallWithSessionDescriptor:session
118+
andCallController:callController];
119+
120+
TOCFuture* futureStarted = [futureConnected thenTry:^id(CallConnectResult* connectResult) {
121+
[callController advanceCallProgressToConversingWithShortAuthenticationString:connectResult.shortAuthenticationString];
122+
CallAudioManager* cam = [CallAudioManager callAudioManagerStartedWithAudioSocket:connectResult.audioSocket
123+
andErrorHandler:callController.errorHandler
124+
untilCancelled:lifetime];
125+
[callController setCallAudioManager:cam];
126+
return nil;
127+
}];
128+
129+
[futureStarted catchDo:^(id error) {
130+
callController.errorHandler(error, nil, true);
131+
}];
132+
}
133+
} incoming:YES];
121134
}
122135
-(CallController*) curCallController {
123136
return currentCallControllerObservable.currentValue;

Signal/src/view controllers/RegistrationViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ - (void)viewDidLoad {
4949
[_countryNameButton setTitle:NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"") forState:UIControlStateNormal];
5050
_phoneNumberTextField.placeholder = NSLocalizedString(@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"");
5151
[_phoneNumberButton setTitle:NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON",@"") forState:UIControlStateNormal];
52+
[_phoneNumberButton.titleLabel setAdjustsFontSizeToFitWidth:YES];
5253
[_sendCodeButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal];
5354
}
5455

0 commit comments

Comments
 (0)