Initial commit
authorSofian Brabez <sbz@6dev.net>
Sat, 20 Jun 2020 13:50:22 +0000 (14:50 +0100)
committerSofian Brabez <sbz@6dev.net>
Sun, 21 Jun 2020 17:31:12 +0000 (18:31 +0100)
.gitignore [new file with mode: 0644]
Android.mk [new file with mode: 0644]
Makefile [new file with mode: 0644]
README.md [new file with mode: 0644]
sysinfo.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..589e124
--- /dev/null
@@ -0,0 +1,2 @@
+/libs/
+/obj
diff --git a/Android.mk b/Android.mk
new file mode 100644 (file)
index 0000000..c2470e8
--- /dev/null
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_LDFLAGS   += -llog
+LOCAL_CFLAGS    += -DDEBUG
+LOCAL_MODULE    := android-sysinfo
+LOCAL_SRC_FILES := sysinfo.c
+
+include $(BUILD_EXECUTABLE)
+
+
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..bc210d9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+ARCH := $(shell adb shell getprop ro.product.cpu.abi)
+SDK_VERSION := $(shell adb shell getprop ro.build.version.sdk)
+DESTDIR := /data/local/tmp/
+
+all: install
+
+build:
+       ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_PLATFORM=android-$(SDK_VERSION) APP_ABI=$(ARCH)
+
+push: build
+       adb push libs/$(ARCH)/android-sysinfo $(DESTDIR)/android-sysinfo
+
+run:
+       adb shell $(DESTDIR)/android-sysinfo
+
+clean:
+       rm -rf libs
+       rm -rf obj
+
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..584e067
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+# android-sysinfo
+
+## Overview
+
+`android-sysinfo` is a Android Native program which reports the system
+properties of any android device using the [system properties][1] [C API][2]
+existing in Android libc [bionic][3].
+
+It is simlar to the `Settings or System > About the Phone` system information
+displayed on your mobile device.
+
+It reports the model, build version and kernel info, etc.
+
+## Requirements
+
+You need to install the Android SDK and Android NDK to use `adb` and `ndk-build`
+used in the build process.
+
+## Build
+
+The build Makefile is using [adb][4] to determine the Android version and ABI of
+the NDK to use in order to produce the binary.
+
+Connect your Android device via USB and enable USB Debugging, then run:
+
+```
+make push
+```
+
+## Run
+
+```
+make run
+```
+
+
+[1]: https://android.googlesource.com/platform/bionic/+/master/libc/include/sys/system_properties.h
+[2]: https://developer.android.com/ndk/guides/stable_apis#c_library
+[3]: https://android.googlesource.com/platform/bionic/
+[4]: https://developer.android.com/studio/command-line/adb
diff --git a/sysinfo.c b/sysinfo.c
new file mode 100644 (file)
index 0000000..3e53ae2
--- /dev/null
+++ b/sysinfo.c
@@ -0,0 +1,57 @@
+#include <stdio.h>
+
+#include <sys/utsname.h>
+#include <sys/system_properties.h>
+
+struct prop {
+    char *key_name;
+    char *prop_name;
+};
+
+static void system_kernel(void)
+{
+    struct utsname uts;
+    char build_host[512];
+    char build_user[512];
+
+    __system_property_get("ro.build.host", build_host);
+    __system_property_get("ro.build.user", build_user);
+
+    if (uname(&uts) != -1) {
+        printf("%-25s: %s %s %s@%s %s %s\n", "Kernel version", uts.sysname,
+                uts.release, build_user, build_host, uts.version, uts.machine);
+    }
+}
+
+static void system_properties(struct prop *array, int size)
+{
+    int i, len;
+    char value[1024] = {0};
+
+    for (i=0; i < size; i++) {
+        if (i == 4)
+            system_kernel();
+
+        len = __system_property_get(array[i].prop_name, value);
+        value[len] = '\0';
+        printf("%-25s: %s\n", array[i].key_name, value);
+    }
+
+}
+
+int
+main(void)
+{
+    struct prop props[] = {
+        {.key_name = "Model number", .prop_name = "ro.product.model"},
+        {.key_name = "Android codename", .prop_name = "ro.build.product"},
+        {.key_name = "Android version", .prop_name = "ro.build.version.release"},
+        {.key_name = "Android SDK version", .prop_name = "ro.build.version.sdk"},
+        {.key_name = "Baseband version", .prop_name = "gsm.version.baseband"},
+        {.key_name = "Build number", .prop_name = "ro.build.display.id"},
+    };
+
+    system_properties(props, sizeof(props) / sizeof(props[0]));
+
+    return (0);
+}