-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.xm
More file actions
109 lines (91 loc) · 3.16 KB
/
Tweak.xm
File metadata and controls
109 lines (91 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#import <libactivator/libactivator.h>
@interface TUCallCenter : NSObject
+ (id)sharedInstance;
- (void)
answerCall:(id)arg1;
@end
@interface TUCall : NSObject <NSSecureCoding>
@property(nonatomic, readonly) int status;
@property(nonatomic, readonly, copy) NSString *destinationID;
@end
#define LASendEventWithName(eventName) [LASharedActivator sendEventToListener:[LAEvent eventWithName:eventName mode:[LASharedActivator currentEventMode]]]
static NSString *kCallAnswer_eventName = @"CallAnswerEvent";
///////////////////////////////////////////////////////////////////////////////////////
//
//
@interface CallAnswerDataSource : NSObject <LAEventDataSource> {}
+ (id)sharedInstance;
@end
@implementation CallAnswerDataSource
+ (id)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t token = 0;
dispatch_once(&token, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
+ (void)load {
[self sharedInstance];
}
- (id)init {
if ((self = [super init])) {
[LASharedActivator registerEventDataSource:self forEventName:kCallAnswer_eventName];
}
return self;
}
- (NSString *)localizedTitleForEventName:(NSString *)eventName {
return @"Call Auto Answer";
}
- (NSString *)localizedGroupForEventName:(NSString *)eventName {
return @"Call Events";
}
- (NSString *)localizedDescriptionForEventName:(NSString *)eventName {
return @"Call Auto Answer";
}
- (void)dealloc {
[LASharedActivator unregisterEventDataSourceWithEventName:kCallAnswer_eventName];
[super dealloc];
}
@end
///////////////////////////////////////////////////////////////////////////////////////
//
//
%hook TUCallCenter
- (void)handleCallStatusChanged:(id)call userInfo:(id)info
{
%orig;
if ([call isKindOfClass:%c(TUCall)]) {
// 1 = connected, 3 = initiate outgoing, 4 = initiate incoming
if ([call status] == 4) {
NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/net.tateu.callansweractivate.plist"];
if (!settings) {
return;
}
for (NSDictionary *numberDictionary in [settings objectForKey:@"numbers"]) {
BOOL enabled = [numberDictionary objectForKey:@"enabled"] ? [[numberDictionary objectForKey:@"enabled"] boolValue] : YES;
if (!enabled) {
continue;
}
NSString *number = [numberDictionary objectForKey:@"number"] ? : @"aaaaaaaaaa";
float answerDelay = [numberDictionary objectForKey:@"answerDelay"] ? [[numberDictionary objectForKey:@"answerDelay"] floatValue] : 0.0;
float eventDelay = [numberDictionary objectForKey:@"eventDelay"] ? [[numberDictionary objectForKey:@"eventDelay"] floatValue] : 0.0;
if ((![call destinationID] && [[number lowercaseString] isEqualToString:@"blocked"]) || ([call destinationID] && [[call destinationID] rangeOfString:number].location != NSNotFound)) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, answerDelay * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
[self answerCall:call];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, eventDelay * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
LASendEventWithName(kCallAnswer_eventName);
});
});
break;
}
}
}
}
}
%end
%ctor {
@autoreleasepool {
%init;
};
}