Skip to content

Commit

Permalink
Full support for latest theos, latest SDK and iOS 10
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetrich committed May 4, 2017
1 parent e62ea4c commit 7c1a453
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 32 deletions.
35 changes: 22 additions & 13 deletions ALApplicationList.x
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define ROCKETBOOTSTRAP_LOAD_DYNAMIC
#import "LightMessaging/LightMessaging.h"
#import "unfair_lock.h"

#import "SpringBoard.h"

Expand All @@ -33,6 +34,8 @@ static LMConnection connection = {
MACH_PORT_NULL,
"applist.datasource"
};
static NSMutableDictionary *cachedIcons;
static unfair_lock spinLock;

__attribute__((visibility("hidden")))
@interface ALApplicationListImpl : ALApplicationList
Expand Down Expand Up @@ -84,7 +87,6 @@ static BOOL IsIpad(void)
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Only one instance of ALApplicationList is permitted at a time! Use [ALApplicationList sharedApplicationList] instead." userInfo:nil];
}
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
cachedIcons = [[NSMutableDictionary alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[pool drain];
if ([UIImage respondsToSelector:@selector(_applicationIconImageForBundleIdentifier:format:scale:)]) {
Expand All @@ -98,12 +100,14 @@ static BOOL IsIpad(void)
return self;
}

#if 0
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[cachedIcons release];
[super dealloc];
}
#endif

- (NSInteger)applicationCount
{
Expand All @@ -120,9 +124,11 @@ static BOOL IsIpad(void)

- (void)didReceiveMemoryWarning
{
OSSpinLockLock(&spinLock);
[cachedIcons removeAllObjects];
OSSpinLockUnlock(&spinLock);
unfair_lock_lock(&spinLock);
NSDictionary *oldCachedIcons = cachedIcons;
cachedIcons = nil;
unfair_lock_unlock(&spinLock);
[oldCachedIcons release];
}

- (NSDictionary *)applications
Expand Down Expand Up @@ -183,7 +189,7 @@ static NSArray *hiddenDisplayIdentifiers;

- (NSArray *)_hiddenDisplayIdentifiers
{
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
NSArray *result = hiddenDisplayIdentifiers;
if (!result) {
result = [[NSArray alloc] initWithObjects:
Expand Down Expand Up @@ -242,7 +248,7 @@ static NSArray *hiddenDisplayIdentifiers;
nil];
hiddenDisplayIdentifiers = result;
}
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
return result;
}

Expand All @@ -261,14 +267,14 @@ static NSArray *hiddenDisplayIdentifiers;
if (iconSize <= 0)
return NULL;
NSString *key = [displayIdentifier stringByAppendingFormat:@"#%f", (CGFloat)iconSize];
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
CGImageRef result = (CGImageRef)[cachedIcons objectForKey:key];
if (result) {
result = CGImageRetain(result);
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
return result;
}
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
if (iconSize == ALApplicationIconSizeSmall) {
switch (supportedDirectAPI) {
case LADirectAPINone:
Expand All @@ -292,9 +298,12 @@ static NSArray *hiddenDisplayIdentifiers;
if (!result)
return NULL;
skip:
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
if (!cachedIcons) {
cachedIcons = [[NSMutableDictionary alloc] init];
}
[cachedIcons setObject:(id)result forKey:key];
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:iconSize], ALIconSizeKey,
displayIdentifier, ALDisplayIdentifierKey,
Expand Down Expand Up @@ -325,9 +334,9 @@ skip:
- (BOOL)hasCachedIconOfSize:(ALApplicationIconSize)iconSize forDisplayIdentifier:(NSString *)displayIdentifier
{
NSString *key = [displayIdentifier stringByAppendingFormat:@"#%f", (CGFloat)iconSize];
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
id result = [cachedIcons objectForKey:key];
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
return result != nil;
}

Expand Down
15 changes: 8 additions & 7 deletions ALApplicationTableDataSource.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ALApplicationTableDataSource.h"

#import "ALApplicationList-private.h"
#import "unfair_lock.h"

#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
Expand Down Expand Up @@ -71,7 +72,7 @@ - (void)sectionRequestedSectionReload:(ALApplicationTableDataSourceSection *)sec
@end

static NSMutableArray *iconsToLoad;
static OSSpinLock spinLock;
static unfair_lock spinLock;
static UIImage *defaultImage;

@implementation ALApplicationTableDataSourceSection
Expand All @@ -86,21 +87,21 @@ + (void)initialize
+ (void)loadIconsFromBackground
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
ALApplicationList *appList = [ALApplicationList sharedApplicationList];
while ([iconsToLoad count]) {
NSDictionary *userInfo = [[iconsToLoad objectAtIndex:0] retain];
[iconsToLoad removeObjectAtIndex:0];
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
CGImageRelease([appList copyIconOfSize:[[userInfo objectForKey:ALIconSizeKey] integerValue] forDisplayIdentifier:[userInfo objectForKey:ALDisplayIdentifierKey]]);
[userInfo release];
[pool drain];
pool = [[NSAutoreleasePool alloc] init];
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
}
[iconsToLoad release];
iconsToLoad = nil;
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
[pool drain];
}

Expand Down Expand Up @@ -299,14 +300,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)ro
[NSNumber numberWithInteger:iconSize], ALIconSizeKey,
displayIdentifier, ALDisplayIdentifierKey,
nil];
OSSpinLockLock(&spinLock);
unfair_lock_lock(&spinLock);
if (iconsToLoad)
[iconsToLoad insertObject:userInfo atIndex:0];
else {
iconsToLoad = [[NSMutableArray alloc] initWithObjects:userInfo, nil];
[ALApplicationTableDataSourceSection performSelectorInBackground:@selector(loadIconsFromBackground) withObject:nil];
}
OSSpinLockUnlock(&spinLock);
unfair_lock_unlock(&spinLock);
}
} else {
cell.imageView.image = nil;
Expand Down
2 changes: 1 addition & 1 deletion LightMessaging
Submodule LightMessaging updated 1 files
+83 −9 LightMessaging.h
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ libapplist_OBJC_FILES = ALApplicationList.x ALApplicationTableDataSource.m ALVal
libapplist_CFLAGS = -I./
libapplist_FRAMEWORKS = UIKit CoreGraphics QuartzCore
libapplist_LIBRARIES = MobileGestalt
libapplist_USE_MODULES = 0

BUNDLE_NAME = AppList
AppList_OBJC_FILES = ALApplicationPreferenceViewController.m
Expand All @@ -18,19 +19,35 @@ AppList_PRIVATE_FRAMEWORKS = Preferences
AppList_LDFLAGS = -L$(FW_OBJ_DIR)
AppList_LIBRARIES = applist
AppList_INSTALL_PATH = /System/Library/PreferenceBundles
AppList_USE_MODULES = 0

TARGET_IPHONEOS_DEPLOYMENT_VERSION := 3.0

LEGACY_XCODE_PATH ?= /Applications/Xcode_Legacy.app/Contents/Developer
CLASSIC_XCODE_PATH ?= /Volumes/Xcode/Xcode.app/Contents/Developer

ifeq ($(FINALPACKAGE),1)
ifneq ($(wildcard $(LEGACY_XCODE_PATH)/*),)
THEOS_PLATFORM_SDK_ROOT_armv6 = $(LEGACY_XCODE_PATH)
THEOS_PLATFORM_SDK_ROOT_armv7 = $(CLASSIC_XCODE_PATH)
SDKVERSION_armv6 = 5.1
INCLUDE_SDKVERSION_armv6 = latest
TARGET_IPHONEOS_DEPLOYMENT_VERSION = 7.0
TARGET_IPHONEOS_DEPLOYMENT_VERSION_armv6 = 3.0
TARGET_IPHONEOS_DEPLOYMENT_VERSION_armv7 = 3.0
TARGET_IPHONEOS_DEPLOYMENT_VERSION_armv7s = 6.0
TARGET_IPHONEOS_DEPLOYMENT_VERSION_arm64 = 7.0
IPHONE_ARCHS = armv6 armv7 arm64
libapplist_IPHONE_ARCHS = armv6 armv7 armv7s arm64
SDKVERSION_armv6 = 5.1
INCLUDE_SDKVERSION_armv6 = 8.4
THEOS_PLATFORM_SDK_ROOT_armv6 = /Applications/Xcode_Legacy.app/Contents/Developer
else
TARGET_IPHONEOS_DEPLOYMENT_VERSION = 7.0
IPHONE_ARCHS = armv7 arm64
libapplist_IPHONE_ARCHS = armv7 armv7s arm64
ifeq ($(FINALPACKAGE),1)
$(error Building final package requires a legacy Xcode install!)
endif
endif

ifeq ($(THEOS_CURRENT_ARCH),armv6)
GO_EASY_ON_ME=1
endif

ADDITIONAL_CFLAGS = -Ipublic -Ioverlayheaders -I.
Expand Down
2 changes: 1 addition & 1 deletion framework
Submodule framework updated 108 files
6 changes: 1 addition & 5 deletions public/ALApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ enum {
};
typedef NSUInteger ALApplicationIconSize;

@interface ALApplicationList : NSObject {
@private
NSMutableDictionary *cachedIcons;
OSSpinLock spinLock;
}
@interface ALApplicationList : NSObject
+ (ALApplicationList *)sharedApplicationList;

@property (nonatomic, readonly) NSDictionary *applications;
Expand Down
45 changes: 45 additions & 0 deletions unfair_lock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#if __IPHONE_OS_VERSION_MAX_ALLOWED > 100000
// New SDK
#include <os/lock.h>
#define unfair_lock os_unfair_lock
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
// Only targeting new iOS, always use unfair locks
#define unfair_lock_lock os_unfair_lock_lock
#define unfair_lock_trylock os_unfair_lock_trylock
#define unfair_lock_unlock os_unfair_lock_unlock
#else
// Support both at runtime
#import <libkern/OSAtomic.h>
static inline void unfair_lock_lock(unfair_lock *lock)
{
if (&os_unfair_lock_lock != NULL) {
os_unfair_lock_lock(lock);
} else {
OSSpinLockLock((volatile OSSpinLock *)lock);
}
}
static inline bool unfair_lock_trylock(unfair_lock *lock)
{
if (&os_unfair_lock_trylock != NULL) {
return os_unfair_lock_trylock(lock);
} else {
return OSSpinLockTry((volatile OSSpinLock *)lock);
}
}
static inline void unfair_lock_unlock(unfair_lock *lock)
{
if (&os_unfair_lock_unlock != NULL) {
os_unfair_lock_unlock(lock);
} else {
OSSpinLockUnlock((volatile OSSpinLock *)lock);
}
}
#endif
#else
// Old SDK, fallback to using regular old spinlocks
#import <libkern/OSAtomic.h>
#define unfair_lock volatile OSSpinLock
#define unfair_lock_lock OSSpinLockLock
#define unfair_lock_trylock OSSpinLockTry
#define unfair_lock_unlock OSSpinLockUnlock
#endif

0 comments on commit 7c1a453

Please sign in to comment.