Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get battery current capacity #373

Merged
merged 4 commits into from Jul 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/ios-deploy/ios-deploy.m
Expand Up @@ -1318,6 +1318,22 @@ int app_exists(AMDeviceRef device)
return -1;
}

void get_battery_level(AMDeviceRef device)
{

AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
check_error(AMDeviceValidatePairing(device));
check_error(AMDeviceStartSession(device));

CFStringRef result = AMDeviceCopyValue(device, @"com.apple.mobile.battery", @"BatteryCurrentCapacity");
NSLogOut(@"BatteryCurrentCapacity:%@",result);
CFRelease(result);

check_error(AMDeviceStopSession(device));
check_error(AMDeviceDisconnect(device));
}

void list_bundle_id(AMDeviceRef device)
{
AMDeviceConnect(device);
Expand Down Expand Up @@ -1605,6 +1621,8 @@ void handle_device(AMDeviceRef device) {
uninstall_app(device);
} else if (strcmp("list_bundle_id", command) == 0) {
list_bundle_id(device);
} else if (strcmp("get_battery_level", command) == 0) {
get_battery_level(device);
}
exit(0);
}
Expand Down Expand Up @@ -1796,6 +1814,7 @@ void usage(const char* app) {
@" -e, --exists check if the app with given bundle_id is installed or not \n"
@" -B, --list_bundle_id list bundle_id \n"
@" -W, --no-wifi ignore wifi devices\n"
@" -C, --get_battery_level get battery current capacity \n"
@" -O, --output <file> write stdout to this file\n"
@" -E, --error_output <file> write stderr to this file\n"
@" --detect_deadlocks <sec> start printing backtraces for all threads periodically after specific amount of seconds\n"
Expand Down Expand Up @@ -1846,6 +1865,7 @@ int main(int argc, char *argv[]) {
{ "exists", no_argument, NULL, 'e'},
{ "list_bundle_id", no_argument, NULL, 'B'},
{ "no-wifi", no_argument, NULL, 'W'},
{ "get_battery_level", no_argument, NULL, 'C'},
{ "output", required_argument, NULL, 'O' },
{ "error_output", required_argument, NULL, 'E' },
{ "detect_deadlocks", required_argument, NULL, 1000 },
Expand All @@ -1854,7 +1874,7 @@ int main(int argc, char *argv[]) {
};
int ch;

while ((ch = getopt_long(argc, argv, "VmcdvunrILeD:R:i:b:a:t:p:1:2:o:l:w:9BWjNs:OE:", longopts, NULL)) != -1)
while ((ch = getopt_long(argc, argv, "VmcdvunrILeD:R:i:b:a:t:p:1:2:o:l:w:9BWjNs:OE:C", longopts, NULL)) != -1)
{
switch (ch) {
case 'm':
Expand Down Expand Up @@ -1960,6 +1980,10 @@ int main(int argc, char *argv[]) {
case 'W':
no_wifi = true;
break;
case 'C':
command_only = true;
command = "get_battery_level";
break;
case 'O':
output_path = optarg;
break;
Expand Down