adium/adium

Parents a78a400f7451
Children 6fdd4b9eebcd
Disable reachability scheduling when the system sleeps and enables it back when system wakes up.

Fixes #16249 a bug where Adium reconnected to IM services when woken up from Power Nap.

r=wix
(transplanted from 2aa34a01048d620f5283530b2c16a5ed358c33b8)
--- a/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.h Sat Apr 05 15:53:18 2014 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.h Mon Jan 20 13:48:06 2014 -0500
@@ -28,6 +28,8 @@
NSMutableArray *hosts;
NSMutableArray *observers;
NSMutableArray *reachabilities;
+ NSMutableArray *AI_hostsBeforeSleep;
+ NSMutableArray *AI_observersBeforeSleep;
NSMutableSet *unconfiguredHostsAndObservers;
--- a/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m Sat Apr 05 15:53:18 2014 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIHostReachabilityMonitor.m Mon Jan 20 13:48:06 2014 -0500
@@ -34,10 +34,16 @@
- (void)beginMonitorngIPChanges;
- (void)stopMonitoringIPChanges;
+@property (nonatomic, copy) NSArray *AI_hostsBeforeSleep;
+@property (nonatomic, copy) NSArray *AI_observersBeforeSleep;
+
+- (void)systemWillSleep:(NSNotification *)notification;
- (void)systemDidWake:(NSNotification *)notification;
+
@end
@implementation AIHostReachabilityMonitor
+@synthesize AI_hostsBeforeSleep, AI_observersBeforeSleep;
#pragma mark Shared instance management
@@ -80,6 +86,11 @@
selector:@selector(systemDidWake:)
name:AISystemDidWake_Notification
object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(systemWillSleep:)
+ name:AISystemWillSleep_Notification
+ object:nil];
}
return self;
}
@@ -93,6 +104,8 @@
[hosts release]; hosts = nil;
[observers release]; observers = nil;
[reachabilities release]; reachabilities = nil;
+ [AI_hostsBeforeSleep release]; AI_hostsBeforeSleep = nil;
+ [AI_observersBeforeSleep release]; AI_observersBeforeSleep = nil;
[unconfiguredHostsAndObservers release]; unconfiguredHostsAndObservers = nil;
[hostAndObserverListLock unlock];
@@ -625,22 +638,26 @@
CFRelease(ipChangesRunLoopSourceRef);
ipChangesRunLoopSourceRef = nil;
}
+
+ self.AI_hostsBeforeSleep = nil;
+ self.AI_observersBeforeSleep = nil;
}
#pragma mark -
#pragma mark Sleep and Wake
/*!
- * @brief System is waking from sleep
+ * @brief System will go into sleep
*
- * When the system wakes, manually reconfigure reachability checking as not all network configurations will report a change.
+ * Before the system sleeps, unschedule reachability checking, and back up a copy of the hosts and observers to
+ * re-configure reachability for when the system wakes up
*/
-- (void)systemDidWake:(NSNotification *)notification
+- (void)systemWillSleep:(NSNotification *)notification
{
[hostAndObserverListLock lock];
-
- NSArray *oldHosts = [hosts copy];
- NSArray *oldObservers = [observers copy];
+
+ self.AI_hostsBeforeSleep = hosts;
+ self.AI_observersBeforeSleep = observers;
NSEnumerator *enumerator;
SCNetworkReachabilityRef reachabilityRef;
@@ -656,7 +673,17 @@
[reachabilities removeAllObjects];
[hostAndObserverListLock unlock];
+}
+/*!
+ * @brief System is waking from sleep
+ *
+ * When the system wakes, manually reconfigure reachability checking as not all network configurations will report a change.
+ */
+- (void)systemDidWake:(NSNotification *)notification
+{
+ NSArray *oldHosts = self.AI_hostsBeforeSleep;
+ NSArray *oldObservers = self.AI_observersBeforeSleep;
NSUInteger numObservers = [oldObservers count];
for (unsigned i = 0; i < numObservers; i++) {
NSString *host = [oldHosts objectAtIndex:i];
@@ -666,8 +693,8 @@
forHost:host];
}
- [oldHosts release];
- [oldObservers release];
+ self.AI_hostsBeforeSleep = nil;
+ self.AI_observersBeforeSleep = nil;
}
#pragma mark -