Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Cellulcar Network DataVolume

Hi,

Where would I find the value that is displayed in Preferences>Usage under Cellular Network Data?

I have found Usage Statistics.plist but that just contains the strings, no values.

Cheers,
cmyk
Post edited by cmyk on

Replies

  • roocellroocell Posts: 98Registered Users
    any luck finding this info?
    i've spent days with a jailbreak device trying to figure out how to get to this info.
    cmyk;21292 said:
    Hi,

    Where would I find the value that is displayed in Preferences>Usage under Cellular Network Data?

    I have found Usage Statistics.plist but that just contains the strings, no values.

    Cheers,
    cmyk
  • cmykcmyk Posts: 9New Users
    roocell;163680 said:
    any luck finding this info?
    i've spent days with a jailbreak device trying to figure out how to get to this info.
    I asked Deric from Apple and got this reply:
    "Deric forwarded your message to me. There's currently no way to get at that data from the iPhone SDK. Please log a bug at https://bugreport.apple.com requesting this and anything else you're interested in, along with an explanation of what you're hoping to do with the info/API."
    I logged the feature request under Bug No. 6271340

    Cheers,
    Phil
  • roocellroocell Posts: 98Registered Users
    I managed to get tcp/udp counts through sysctl

    	sysctlbyname(\"net.inet.tcp.in_sw_cksum_bytes\", NULL, &size, NULL, 0);  
    sysctlbyname(\"net.inet.tcp.in_sw_cksum_bytes\", &in_bytes, &size, NULL, 0);

    sysctlbyname(\"net.inet.tcp.in_sw_cksum\", NULL, &size, NULL, 0);
    sysctlbyname(\"net.inet.tcp.in_sw_cksum\", &in_packets, &size, NULL, 0);

    sysctlbyname(\"net.inet.tcp.out_sw_cksum_bytes\", NULL, &size, NULL, 0);
    sysctlbyname(\"net.inet.tcp.out_sw_cksum_bytes\", &out_bytes, &size, NULL, 0);

    sysctlbyname(\"net.inet.tcp.out_sw_cksum\", NULL, &size, NULL, 0);
    sysctlbyname(\"net.inet.tcp.out_sw_cksum\", &out_packets, &size, NULL, 0);


    but this is the overall count (and i dont think sysctl will get your app rejected).
    All I need for my purpose now is one or the other (wifi/cell) and subtract it from this.
    I also have some code (Reachability.h from apple site) that tells you when the network connection changes from wifi/cell. So I can use this combo to track wifi/cell traffic while my app is open, but I dont really want to have to make the user keep the app open.

    I've also looked into writing a daemon on a jailbroken device, and I think it'll work. But I dont really want to force users to jailbreak.
  • roocellroocell Posts: 98Registered Users
    I'm VERY close to getting this data.
    Basically it's in the private CoreTelephony.framework.
    There are several functions in this library related to these counts
    I came upon this information from an otool dump of CoreTelephony here
    CoreTelephonyFunctions.wiki - iphone-wireless - Project Hosting on Google Code

    I tried doing otool myself and cant this output. But the functions are definitely there and produce something. If you add CoreTelephony.framework to your project. (found in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework)



    NSLog(@\"airplane mode %d\", CTPowerGetAirplaneMode());
    long rc=-1;
    int x=0,y=0,z=0;
    //rc=_CTCallHistoryGetCount(&x,&y,&z);
    //NSLog(@\"GC Rc %d a %d b %d c %d\", rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetAllReceived(&x);
    NSLog(@\"AllRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetAllTransmitted(&x);
    NSLog(@\"AllTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastReceived(&x);
    NSLog(@\"LRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastTransmitted(&x);
    NSLog(@\"LTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLifetimeReceived(&x);
    NSLog(@\"LfTmRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLifetimeTransmitted(&x);
    NSLog(@\"LfTmTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastResetTime(&x);
    NSLog(@\"LrTime \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);



    So CTPowerGetAirplaneMode() works fine. But the trick now is to figure out exactly how to call _CTCallHistoryStoreDataCountersGetAllReceived(). I was hoping it would just return an integer, but it's not that straightforward.

    Here's the sequence of my quest thus far.
    1. jailbreak phone and use SSH
    2. And you can also see some interesting info in /Applications/Preferences.app/Usage Statistics.plist
    		
    <dict>
    <key>get</key>
    <string>[B]dataVolumeAllReceived:[/B]</string>
    <key>label</key>
    <string>RECEIVED</string>
    <key>requiredCapabilities</key>
    <array>
    <string>telephony</string>
    </array>
    </dict>

    3. And I also found some interesting info using class-dump-z on Preferences.app
    (you'll have to jailbreak, SSH into the phone for this)
    class_dump_z - networkpx - class-dump-z ? Extracting class interface for Objective-C version 2 ABI. - Project Hosting on Google Code
    @interface UsageController : PSListController {
    int _fullyChargedToken; // 96 = 0x60
    int _pluggedInToken; // 100 = 0x64
    int _isCharged; // 104 = 0x68
    int _isPlugged; // 108 = 0x6c
    float _standbySeconds; // 112 = 0x70
    float _usageSeconds; // 116 = 0x74
    BOOL _trusted; // 120 = 0x78
    PSSpecifier* _textSpecifier1; // 124 = 0x7c
    PSSpecifier* _textSpecifier2; // 128 = 0x80
    PSSpecifier* _usageSpecifier; // 132 = 0x84
    PSSpecifier* _standbySpecifier; // 136 = 0x88
    PSSpecifier* _currentSpecifier; // 140 = 0x8c
    PSSpecifier* _lifetimeSpecifier; // 144 = 0x90
    PSSpecifier* _lastResetSpecifier; // 148 = 0x94
    NSTimer* _timer; // 152 = 0x98
    NSString* _notTrustedString; // 156 = 0x9c
    NSString* _chargingString; // 160 = 0xa0
    }
    -(void)startTimer; // 0x18bec
    -(void)stopTimer; // 0x18b94
    -(void)suspend; // 0x196cc
    -(void)updateUI:(BOOL)ui; // 0x1971c
    -(void)update:(id)update; // 0x18b74
    -(void)didLock; // 0x18b58
    -(void)didUnlock; // 0x18b28
    -(void)dealloc; // 0x199a8
    -(void)_dataVolumeAllSent:(float*)sent received:(float*)received forPDP:(long)pdp; // 0x19b70
    -(void)_dataVolumeLastSent:(float*)sent received:(float*)received; // 0x19bec
    [B]-(id)dataVolumeAllReceived:(id)received; // 0x19ddc [/B]
    -(id)dataVolumeAllSent:(id)sent; // 0x19cd8
    -(id)dataVolumeLastReceived:(id)received; // 0x19c80
    -(id)dataVolumeLastSent:(id)sent; // 0x19c30
    -(id)lifetimeCallTime:(id)time; // 0x1adc4
    -(id)callTime:(id)time; // 0x1acd8
    -(void)clearStats:(id)stats; // 0x19ee0
    -(id)usageElapsed:(id)elapsed; // 0x1abd4
    -(id)standbyElapsed:(id)elapsed; // 0x1aac8
    -(void)viewWillBecomeVisible:(void*)view; // 0x19678
    -(id)specifiers; // 0x1a10c
    @end


    4. run otool on Preferences.app to see what Libraries/frameworks it uses.
    # otool -L /Applications/Preferences.app/Preferences
    /Applications/Preferences.app/Preferences:
    ......
    /System/Library/PrivateFrameworks/Preferences.framework/Preferences (compatibility version 1.0.0, current version 628.5.0)
    /System/Library/PrivateFrameworks/[B]CoreTelephony.framework[/B]/CoreTelephony (compatibility version 1.0.0, current version 277.37.0)
    /System/Library/Frameworks/AddressBookUI.framework/AddressBookUI (compatibility version 1.0.0, current version 33.0.0)
    .....
    /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 40.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.2.1)

    mrussells-iPhone:/usr/bin root#
    5. This lead me to the CoreTelephony stuff I mentioned first.


    I also found some interesting information on CoreTelephony
    iphone-wireless - Project Hosting on Google Code

    Some interesting info on IOKit and ioreg. Download IOKit tools from Cydia.


    You can pretty much call all the listed functions in CoreTelephony(which are C functions).
    You'll get a compile warning, but the call works. If the function didnt exist in the library the linker would fail.
    I could use some help figure out how to call _CTCallHistoryStoreDataCountersGetAllReceived() properly.
  • roocellroocell Posts: 98Registered Users
    Just learned about the CallHistory DB. Havent tried, but more than likely we wont be able to access this in a regular app because this file is outside the app's sandbox. And it's even possible the CoreTelephony functions try to access the DB (probably) and wont work either because of the same reason.

    But on a jailbreak device all should be possible. I still cant get the CoreTelephony functions to work, but I'm sure using SQL code to access this DB will work. Here's some preliminary with SSH and sqlite3 installed on a jailbreak device.

    iPhone:/private/var/mobile/Library/CallHistory root# sqlite3 call_history.db \"SELECT * FROM _SqliteDatabaseProperties WHERE 1\"
    call_history_limit|100
    timer_lifetime|202080
    data_up_lifetime|47558.7763671875
    data_down_lifetime|687215.264648716
    _UniqueIdentifier|A73A1A0F-B7EB-4557-9492-ABC7F5A0A7F3
    timer_last|60
    timer_outgoing|46380
    timer_incoming|90360
    timer_all|136740
    timer_last_reset|249920547.644683
    data_up_last|292.7568359375
    data_down_last|521.0888671875
    data_up_all|35321.9794921875
    data_down_all|445697.45996109
    data_last_reset|249920547.689825
    __CPRecordSequenceNumber|1884
    _ClientVersion|5


    Yeah! there it is.
    I'm going to go the SQL route for now and least be able to run this on jailbreak.
  • roocellroocell Posts: 98Registered Users
    Well got some code working. Unfortunately, I had to copy the call_history.db to someone the app could access it.
    cp /private/var/mobile/Library/CallHistory/call_history.db  /User/Media/Photos/ 


    here's a decent example i used to write the sql code
    iPhone SDK Tutorial: Reading data from a SQLite Database | dBlog.com.au

    and here's the code
    -(void) callhistorydbRead {
    // Setup the database object
    int rc;
    sqlite3 *database;

    NSLog(@\"Reading CALL History DB\");
    // Init the animals Array
    callhistorydb = [[NSMutableArray alloc] init];
    //dbpath=[NSString stringWithString:@\"/private/var/mobile/Library/CallHistory/call_history.db\"];
    dbpath=[NSString stringWithString:@\"/User/Media/Photos/call_history.db\"];

    // Open the database from the users filessytem
    if((rc=sqlite3_open([dbpath UTF8String], &database)) == SQLITE_OK) {
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = \"select * from _SqliteDatabaseProperties WHERE 1\";
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
    // Loop through the results and add them to the feeds array
    while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
    // Read the data from the result row
    NSLog(@\"%@\", [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]);
    }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);

    } else {
    NSLog(@\"SQL error %d\", rc);
    }
    sqlite3_close(database);

    }


    and here's the output
    2010-02-03 22:11:03.792 wifiOffload[170:207] Reading CALL History DB
    2010-02-03 22:11:03.832 ##[170:207] 100
    2010-02-03 22:11:03.838 ##[170:207] 202080
    2010-02-03 22:11:03.843 ##[170:207] 47558.7763671875
    2010-02-03 22:11:03.848 ##[170:207] 687215.264648716
    2010-02-03 22:11:03.854 ##[170:207] XXXXXXXXXXXXXXXXXXXX
    2010-02-03 22:11:03.859 ##[170:207] 60
    2010-02-03 22:11:03.865 ##[170:207] 46380
    2010-02-03 22:11:03.880 ##[170:207] 90360
    2010-02-03 22:11:03.886 ##[170:207] 136740
    2010-02-03 22:11:03.891 ##[170:207] 249920547.644683
    2010-02-03 22:11:03.896 ##[170:207] 292.7568359375
    2010-02-03 22:11:03.902 ##[170:207] 521.0888671875
    2010-02-03 22:11:03.908 ##[170:207] 35321.9794921875
    2010-02-03 22:11:03.914 ##[170:207] 445697.45996109
    2010-02-03 22:11:03.919 ##[170:207] 249920547.689825
    2010-02-03 22:11:03.925 ##[170:207] 1884
    2010-02-03 22:11:03.930 ##[170:207] 5



    maybe _CTCallHistoryStoreDataCountersGetAllReceived() is returning some SQL thing or a string? or accepting a string arg?
  • coolremscoolrems Posts: 1New Users
    Did you get any way for using CT APIs ? I have been hunting for some hint on how these data usage Apps working ...no success till now
    roocell;167495 said:
    I'm VERY close to getting this data.
    Basically it's in the private CoreTelephony.framework.
    There are several functions in this library related to these counts
    I came upon this information from an otool dump of CoreTelephony here
    CoreTelephonyFunctions.wiki - iphone-wireless - Project Hosting on Google Code

    I tried doing otool myself and cant this output. But the functions are definitely there and produce something. If you add CoreTelephony.framework to your project. (found in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/System/Library/PrivateFrameworks/CoreTelephony.framework)

    Did you get any possible way to access these private APIs ? this is what most of the data usage apps doing ? I have been hunting around for the hint .. no success....


    NSLog(@\"airplane mode %d\", CTPowerGetAirplaneMode());
    long rc=-1;
    int x=0,y=0,z=0;
    //rc=_CTCallHistoryGetCount(&x,&y,&z);
    //NSLog(@\"GC Rc %d a %d b %d c %d\", rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetAllReceived(&x);
    NSLog(@\"AllRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetAllTransmitted(&x);
    NSLog(@\"AllTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastReceived(&x);
    NSLog(@\"LRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastTransmitted(&x);
    NSLog(@\"LTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLifetimeReceived(&x);
    NSLog(@\"LfTmRx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLifetimeTransmitted(&x);
    NSLog(@\"LfTmTx \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);
    rc=_CTCallHistoryStoreDataCountersGetLastResetTime(&x);
    NSLog(@\"LrTime \t%-16d \t%08X a %d b %d c %d\", rc, rc, x, y, z);



    So CTPowerGetAirplaneMode() works fine. But the trick now is to figure out exactly how to call _CTCallHistoryStoreDataCountersGetAllReceived(). I was hoping it would just return an integer, but it's not that straightforward.

    Here's the sequence of my quest thus far.
    1. jailbreak phone and use SSH
    2. And you can also see some interesting info in /Applications/Preferences.app/Usage Statistics.plist
    		
    <dict>
    <key>get</key>
    <string>[B]dataVolumeAllReceived:[/B]</string>
    <key>label</key>
    <string>RECEIVED</string>
    <key>requiredCapabilities</key>
    <array>
    <string>telephony</string>
    </array>
    </dict>

    3. And I also found some interesting info using class-dump-z on Preferences.app
    (you'll have to jailbreak, SSH into the phone for this)
    class_dump_z - networkpx - class-dump-z ? Extracting class interface for Objective-C version 2 ABI. - Project Hosting on Google Code
    @interface UsageController : PSListController {
    int _fullyChargedToken; // 96 = 0x60
    int _pluggedInToken; // 100 = 0x64
    int _isCharged; // 104 = 0x68
    int _isPlugged; // 108 = 0x6c
    float _standbySeconds; // 112 = 0x70
    float _usageSeconds; // 116 = 0x74
    BOOL _trusted; // 120 = 0x78
    PSSpecifier* _textSpecifier1; // 124 = 0x7c
    PSSpecifier* _textSpecifier2; // 128 = 0x80
    PSSpecifier* _usageSpecifier; // 132 = 0x84
    PSSpecifier* _standbySpecifier; // 136 = 0x88
    PSSpecifier* _currentSpecifier; // 140 = 0x8c
    PSSpecifier* _lifetimeSpecifier; // 144 = 0x90
    PSSpecifier* _lastResetSpecifier; // 148 = 0x94
    NSTimer* _timer; // 152 = 0x98
    NSString* _notTrustedString; // 156 = 0x9c
    NSString* _chargingString; // 160 = 0xa0
    }
    -(void)startTimer; // 0x18bec
    -(void)stopTimer; // 0x18b94
    -(void)suspend; // 0x196cc
    -(void)updateUI:(BOOL)ui; // 0x1971c
    -(void)update:(id)update; // 0x18b74
    -(void)didLock; // 0x18b58
    -(void)didUnlock; // 0x18b28
    -(void)dealloc; // 0x199a8
    -(void)_dataVolumeAllSent:(float*)sent received:(float*)received forPDP:(long)pdp; // 0x19b70
    -(void)_dataVolumeLastSent:(float*)sent received:(float*)received; // 0x19bec
    [B]-(id)dataVolumeAllReceived:(id)received; // 0x19ddc [/B]
    -(id)dataVolumeAllSent:(id)sent; // 0x19cd8
    -(id)dataVolumeLastReceived:(id)received; // 0x19c80
    -(id)dataVolumeLastSent:(id)sent; // 0x19c30
    -(id)lifetimeCallTime:(id)time; // 0x1adc4
    -(id)callTime:(id)time; // 0x1acd8
    -(void)clearStats:(id)stats; // 0x19ee0
    -(id)usageElapsed:(id)elapsed; // 0x1abd4
    -(id)standbyElapsed:(id)elapsed; // 0x1aac8
    -(void)viewWillBecomeVisible:(void*)view; // 0x19678
    -(id)specifiers; // 0x1a10c
    @end


    4. run otool on Preferences.app to see what Libraries/frameworks it uses.
    # otool -L /Applications/Preferences.app/Preferences
    /Applications/Preferences.app/Preferences:
    ......
    /System/Library/PrivateFrameworks/Preferences.framework/Preferences (compatibility version 1.0.0, current version 628.5.0)
    /System/Library/PrivateFrameworks/[B]CoreTelephony.framework[/B]/CoreTelephony (compatibility version 1.0.0, current version 277.37.0)
    /System/Library/Frameworks/AddressBookUI.framework/AddressBookUI (compatibility version 1.0.0, current version 33.0.0)
    .....
    /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 40.0.0)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.2.1)

    mrussells-iPhone:/usr/bin root#
    5. This lead me to the CoreTelephony stuff I mentioned first.


    I also found some interesting information on CoreTelephony
    iphone-wireless - Project Hosting on Google Code

    Some interesting info on IOKit and ioreg. Download IOKit tools from Cydia.


    You can pretty much call all the listed functions in CoreTelephony(which are C functions).
    You'll get a compile warning, but the call works. If the function didnt exist in the library the linker would fail.
    I could use some help figure out how to call _CTCallHistoryStoreDataCountersGetAllReceived() properly.
Sign In or Register to comment.