SpringBoardAcess extension working

This commit is contained in:
matthias.ringwald 2009-09-20 15:07:11 +00:00
parent 82010c061f
commit a376a19bd1
8 changed files with 150 additions and 35 deletions

View File

@ -19,8 +19,8 @@ all: $(NAME).dylib $(NAME)-test
clean:
rm -f $(NAME).dylib $(NAME)-test
$(NAME).dylib: $(NAME).mm
$(OBJC) $(CPPFLAGS) -dynamiclib -o $@ $(NAME).mm -init _$(NAME)Initialize $(LDFLAGS) $(LIB_LDFLAGS)
$(NAME).dylib: $(NAME)Extension.mm
$(OBJC) $(CPPFLAGS) -dynamiclib -o $@ $(NAME)Extension.mm -init _$(NAME)Initialize $(LDFLAGS) $(LIB_LDFLAGS)
$(NAME)-test: $(NAME)-test.c
$(OBJC) $(CPPFLAGS) -o $@ $(NAME)-test.c $(LDFLAGS) $(APP_LDFLAGS)
$(NAME)-test: $(NAME)-test.c $(NAME).c
$(OBJC) $(CPPFLAGS) -o $@ $(NAME).c $(NAME)-test.c $(LDFLAGS) $(APP_LDFLAGS)

View File

@ -1,26 +1,29 @@
//
// SpringBoardAccess.m
// SpringBoardAccess-test.c
//
// Created by Matthias Ringwald on 9/15/09.
//
#include "SpringBoardAccess.h"
#import <CoreFoundation/CoreFoundation.h>
#include <string.h>
#include <stdio.h>
main() {
CFMessagePortRef remote = CFMessagePortCreateRemote(NULL, CFSTR("SpringBoardAccess"));
if (!remote) {
printf("Failed to get remote port\n");
exit(10);
int main(int argc, char *argv[]) {
int usage = 1;
if (argc == 3) {
if (strcmp("add", argv[1]) == 0) {
SBA_addStatusBarImage(argv[2]);
usage = 0;
} else if (strcmp("remove", argv[1]) == 0) {
SBA_removeStatusBarImage(argv[2]);
usage = 0;
}
}
char *message = "Hello, world!";
CFDataRef data, returnData = NULL;
data = CFDataCreate(NULL, (const UInt8 *)message, strlen(message)+1);
if (kCFMessagePortSuccess == CFMessagePortSendRequest(remote, 0, data, 1, 1, kCFRunLoopDefaultMode, &returnData) && NULL != returnData) {
printf("here is our return data: %s\n",
CFDataGetBytePtr(returnData));
CFRelease(returnData);
}
CFRelease(data);
CFRelease(remote);
if (usage) {
printf("Usage: %s add/remove StatuBarImageName", argv[0]);
return -1;
}
}

View File

@ -0,0 +1,40 @@
/*
* SpringBoardAcess.c
*
* Created by Matthias Ringwald on 9/20/09.
*
*/
#include "SpringBoardAccess.h"
#import <CoreFoundation/CoreFoundation.h>
static CFMessagePortRef springBoardAccessMessagePort = 0;
static int SBA_sendMessage(UInt8 cmd, UInt16 dataLen, UInt8 *data){
// check for port
if (!springBoardAccessMessagePort) {
springBoardAccessMessagePort = CFMessagePortCreateRemote(NULL, CFSTR(SBA_MessagePortName));
}
if (!springBoardAccessMessagePort) {
return kCFMessagePortIsInvalid;
}
// create message
int messageLen = 1 + dataLen;
UInt8 message[messageLen];
message[0] = cmd;
memcpy(&message[1], data, dataLen);
CFDataRef cfData = CFDataCreate(NULL, message, messageLen);
int result = CFMessagePortSendRequest(springBoardAccessMessagePort, 0, cfData, 1, 1, NULL, NULL);
CFRelease(cfData);
return result;
}
int SBA_addStatusBarImage(char *name){
return SBA_sendMessage(SBAC_addStatusBarImage, strlen(name), (UInt8*) name);
}
int SBA_removeStatusBarImage(char *name){
return SBA_sendMessage(SBAC_removeStatusBarImage, strlen(name), (UInt8*) name);
}

View File

@ -0,0 +1,31 @@
/*
* SpringBoardAccess.h
*
* Allows to add and remove images to/from status bar
*
* The images must be installed in:
* /System/Library/CoreServices/SpringBoard.app/
*
* Only the base name is required, e.g., Bluetooth instead of Default_Bluetooth.png
* Created by Matthias Ringwald on 9/20/09.
*
*/
#pragma once
#define SBA_MessagePortName "SpringBoardAccess"
#define SBAC_nop
#define SBAC_addStatusBarImage 1
#define SBAC_removeStatusBarImage 2
/**
* Enables named status bar icon in Springboard
* @returns CFMessagePortSendRequest error: 0 = ok
*/
int SBA_addStatusBarImage(char *name);
/**
* Disables named status bar icon in Springboard
* @returns CFMessagePortSendRequest error: 0 = ok
*/
int SBA_removeStatusBarImage(char *name);

View File

@ -0,0 +1 @@
Filter = {Bundles = ("com.apple.springboard");};

View File

@ -10,6 +10,8 @@
#import "../3rdparty/substrate.h"
#include "SpringBoardAccess.h"
class SpringBoard;
@interface UIApplication (privateStatusBarIconAPI)
@ -28,19 +30,29 @@ static type $ ## class ## $ ## name(class *self, SEL sel, ## args)
_ ## class ## $ ## name(self, sel, ## args)
CFDataRef myCallBack(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info) {
CFDataRef myCallBack(CFMessagePortRef local, SInt32 msgid, CFDataRef cfData, void *info) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
UIApplication *theApp = [UIApplication sharedApplication];
[theApp addStatusBarImageNamed:@"BluetoothActive"];
char *message = "Thanks for calling!";
CFDataRef returnData = CFDataCreate(NULL, (const UInt8 *) message, strlen(message)+1);
NSLog(@"here is our received data: %s\n", CFDataGetBytePtr(data));
[pool release];
return returnData; // as stated in header, both data and returnData will be released for us after callback returns
const char *data = (const char *) CFDataGetBytePtr(cfData);
UInt16 dataLen = CFDataGetLength(cfData);
if (dataLen > 1 && data) {
NSString * name = [[NSString stringWithCString:&data[1] encoding:NSASCIIStringEncoding] autorelease];
switch (data[0]){
case SBAC_addStatusBarImage:
[theApp addStatusBarImageNamed:name];
break;
case SBAC_removeStatusBarImage:
[theApp removeStatusBarImageNamed:name];
break;
default:
NSLog(@"Unknown command %u, len %u", data[0], dataLen);
}
}
[pool release];
return NULL; // as stated in header, both data and returnData will be released for us after callback returns
}
//______________________________________________________________________________

View File

@ -3,9 +3,6 @@
Last milestone reached: BTdaemon automatically started by launchd on Mac and iPhone
NEXT:
- create a SpringBoardAccess MobileSubstrate Extension
- in SpringBoard hook, start datagram Unix domain or mach port server
- control Status bar icons
- add code to toggle status bar icons via the SpringBoardAcess extension
- clean up debug output: seperate messages from errors
- decide on error reporting
@ -15,6 +12,7 @@ NEXT:
- create script to build APT package
- create new pgp key for gmail account and sign APT package
- provide test version by setting up APT repository within BTstack SVN
== Release Version 0.1
- implement rest of L2CAP state machine
- incoming connections

View File

@ -19,6 +19,8 @@
9C2071F310014D3200A07EA4 /* hci_transport_usb.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C2071F210014D3200A07EA4 /* hci_transport_usb.c */; };
9C46FC3A0FA906F700ABEF05 /* hci_transport_h4.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C46FC360FA906F700ABEF05 /* hci_transport_h4.c */; };
9C6459E01037554B0081A00B /* platform_iphone.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C6459DF1037554B0081A00B /* platform_iphone.m */; };
9C77E7511066680800F39DCF /* SpringBoardAccessExtension.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E7501066680800F39DCF /* SpringBoardAccessExtension.mm */; };
9C77E75510666B5D00F39DCF /* SpringBoardAccess.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C77E75310666B5D00F39DCF /* SpringBoardAccess.c */; };
9C7B5AC0100BD3340065D87E /* linked_list.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7B5ABF100BD3340065D87E /* linked_list.c */; };
9C7B5D01100FC9AE0065D87E /* btstack.c in Sources */ = {isa = PBXBuildFile; fileRef = 9CC813A10FFC0774002816F9 /* btstack.c */; };
9C7B5D03100FC9BB0065D87E /* test.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C7B5B7E100D04450065D87E /* test.c */; };
@ -65,7 +67,16 @@
9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = "<group>"; };
9C6459DE1037554B0081A00B /* platform_iphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = platform_iphone.h; path = src/platform_iphone.h; sourceTree = "<group>"; };
9C6459DF1037554B0081A00B /* platform_iphone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = platform_iphone.m; path = src/platform_iphone.m; sourceTree = "<group>"; };
9C77E2761060327200F39DCF /* SpringBoardAccess.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpringBoardAccess.m; path = SpringBoardAccess/SpringBoardAccess.m; sourceTree = "<group>"; };
9C77E36410618B1D00F39DCF /* Makefile.in */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; name = Makefile.in; path = SpringBoardAccess/Makefile.in; sourceTree = "<group>"; };
9C77E36710618C6500F39DCF /* SpringBoardAccess-test.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = "SpringBoardAccess-test.c"; path = "SpringBoardAccess/SpringBoardAccess-test.c"; sourceTree = "<group>"; };
9C77E4AE10634E3100F39DCF /* launch.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = launch.h; sourceTree = "<group>"; };
9C77E4AF10634E3100F39DCF /* libsubstrate.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libsubstrate.dylib; sourceTree = "<group>"; };
9C77E4B010634E3100F39DCF /* README */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
9C77E4B110634E3100F39DCF /* SpringBoard.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = SpringBoard.h; sourceTree = "<group>"; };
9C77E4B210634E3100F39DCF /* substrate.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = substrate.h; sourceTree = "<group>"; };
9C77E7501066680800F39DCF /* SpringBoardAccessExtension.mm */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.cpp.objcpp; name = SpringBoardAccessExtension.mm; path = SpringBoardAccess/SpringBoardAccessExtension.mm; sourceTree = "<group>"; };
9C77E75310666B5D00F39DCF /* SpringBoardAccess.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = SpringBoardAccess.c; path = SpringBoardAccess/SpringBoardAccess.c; sourceTree = "<group>"; };
9C77E75410666B5D00F39DCF /* SpringBoardAccess.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = SpringBoardAccess.h; path = SpringBoardAccess/SpringBoardAccess.h; sourceTree = "<group>"; };
9C78A04A103C6734003B2950 /* Default_BTstack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default_BTstack.png; path = resources/Default_BTstack.png; sourceTree = "<group>"; };
9C78A04B103C6734003B2950 /* Default_BTstackActive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default_BTstackActive.png; path = resources/Default_BTstackActive.png; sourceTree = "<group>"; };
9C78A04C103C6734003B2950 /* FSO_BTstack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = FSO_BTstack.png; path = resources/FSO_BTstack.png; sourceTree = "<group>"; };
@ -111,6 +122,7 @@
08FB7794FE84155DC02AAC07 /* project */ = {
isa = PBXGroup;
children = (
9C77E4AD10634E3100F39DCF /* 3rdparty */,
9C78A049103C671D003B2950 /* Resources */,
9C7B5B81100D04520065D87E /* Example */,
08FB7795FE84155DC02AAC07 /* Source */,
@ -174,11 +186,27 @@
9C77E2751060322300F39DCF /* SpringBoardAccess */ = {
isa = PBXGroup;
children = (
9C77E2761060327200F39DCF /* SpringBoardAccess.m */,
9C77E75310666B5D00F39DCF /* SpringBoardAccess.c */,
9C77E75410666B5D00F39DCF /* SpringBoardAccess.h */,
9C77E7501066680800F39DCF /* SpringBoardAccessExtension.mm */,
9C77E36710618C6500F39DCF /* SpringBoardAccess-test.c */,
9C77E36410618B1D00F39DCF /* Makefile.in */,
);
name = SpringBoardAccess;
sourceTree = "<group>";
};
9C77E4AD10634E3100F39DCF /* 3rdparty */ = {
isa = PBXGroup;
children = (
9C77E4AE10634E3100F39DCF /* launch.h */,
9C77E4AF10634E3100F39DCF /* libsubstrate.dylib */,
9C77E4B010634E3100F39DCF /* README */,
9C77E4B110634E3100F39DCF /* SpringBoard.h */,
9C77E4B210634E3100F39DCF /* substrate.h */,
);
path = 3rdparty;
sourceTree = "<group>";
};
9C78A049103C671D003B2950 /* Resources */ = {
isa = PBXGroup;
children = (
@ -283,6 +311,8 @@
9CCE6CEA1025BD0000FCE9F4 /* hci.c in Sources */,
9C6459E01037554B0081A00B /* platform_iphone.m in Sources */,
9C1813F81042FCCA00C68F09 /* mitm.c in Sources */,
9C77E7511066680800F39DCF /* SpringBoardAccessExtension.mm in Sources */,
9C77E75510666B5D00F39DCF /* SpringBoardAccess.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};