mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Android support part 3
This commit is contained in:
@@ -269,8 +269,10 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <sys/system_properties.h>
|
||||
void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) {
|
||||
ffStrbufEnsureCapacity(result, PROP_VALUE_MAX);
|
||||
result->length = (uint32_t) __system_property_get(propName, result->chars);
|
||||
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) {
|
||||
uint32_t originalLength = result->length;
|
||||
ffStrbufEnsureFree(result, PROP_VALUE_MAX);
|
||||
result->length += (uint32_t) __system_property_get(propName, result->chars + result->length);
|
||||
return result->length > originalLength;
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -400,7 +400,7 @@ FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char*
|
||||
FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
|
||||
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
|
||||
#endif
|
||||
|
||||
//detection/plasma.c
|
||||
|
||||
+37
-17
@@ -1,5 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#define FF_HOST_MODULE_NAME "Host"
|
||||
#define FF_HOST_NUM_FORMAT_ARGS 3
|
||||
|
||||
@@ -30,7 +32,7 @@ static bool hostValueSet(FFstrbuf* value)
|
||||
;
|
||||
}
|
||||
|
||||
static inline void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
|
||||
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
|
||||
{
|
||||
ffGetFileContent(devicesPath, buffer);
|
||||
|
||||
@@ -45,33 +47,51 @@ void ffPrintHost(FFinstance* instance)
|
||||
|
||||
FFstrbuf family;
|
||||
ffStrbufInit(&family);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &family);
|
||||
#ifndef __ANDROID__
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &family);
|
||||
#else
|
||||
ffSettingsGetAndroidProperty("ro.product.device", &family);
|
||||
#endif
|
||||
bool familySet = hostValueSet(&family);
|
||||
|
||||
FFstrbuf name;
|
||||
ffStrbufInit(&name);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &name);
|
||||
#ifndef __ANDROID__
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &name);
|
||||
|
||||
if(name.length == 0)
|
||||
ffGetFileContent("/sys/firmware/devicetree/base/model", &name);
|
||||
if(name.length == 0)
|
||||
ffGetFileContent("/sys/firmware/devicetree/base/model", &name);
|
||||
|
||||
if(name.length == 0)
|
||||
ffGetFileContent("/tmp/sysinfo/model", &name);
|
||||
if(name.length == 0)
|
||||
ffGetFileContent("/tmp/sysinfo/model", &name);
|
||||
|
||||
if(ffStrbufStartsWithS(&name, "Standard PC"))
|
||||
{
|
||||
FFstrbuf copy;
|
||||
ffStrbufInitCopy(©, &name);
|
||||
ffStrbufSetS(&name, "KVM/QEMU ");
|
||||
ffStrbufAppend(&name, ©);
|
||||
ffStrbufDestroy(©);
|
||||
}
|
||||
#else
|
||||
ffSettingsGetAndroidProperty("ro.product.brand", buffer);
|
||||
if(buffer->length > 0){
|
||||
toupper(buffer->chars[0]);
|
||||
ffStrbufAppendC(buffer, ' ');
|
||||
}
|
||||
|
||||
if(!ffSettingsGetAndroidProperty("ro.product.model", buffer))
|
||||
ffSettingsGetAndroidProperty("ro.product.name", buffer);
|
||||
|
||||
ffStrbufTrimRight(buffer, ' ');
|
||||
#endif
|
||||
bool nameSet = hostValueSet(&name);
|
||||
|
||||
if(ffStrbufStartsWithS(&name, "Standard PC"))
|
||||
{
|
||||
FFstrbuf copy;
|
||||
ffStrbufInitCopy(©, &name);
|
||||
ffStrbufSetS(&name, "KVM/QEMU ");
|
||||
ffStrbufAppend(&name, ©);
|
||||
ffStrbufDestroy(©);
|
||||
}
|
||||
|
||||
FFstrbuf version;
|
||||
ffStrbufInit(&version);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &version);
|
||||
#ifndef __ANDROID__
|
||||
getHostValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &version);
|
||||
#endif
|
||||
bool versionSet = hostValueSet(&version);
|
||||
|
||||
if(!familySet && !nameSet)
|
||||
|
||||
+2
-2
@@ -75,9 +75,9 @@ const FFOSResult* ffDetectOS(FFinstance* instance)
|
||||
ffStrbufSetS(&result.name, "Android");
|
||||
ffStrbufSetS(&result.id, "android");
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.versionID);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.sdk", &result.version);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.version);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.codename", &result.codename);
|
||||
ffSettingsGetAndroidProperty("ro.build.display.id", &result.buildID);
|
||||
ffSettingsGetAndroidProperty("ro.build.id", &result.buildID);
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
Reference in New Issue
Block a user