Skip to content

Commit 92d95eb

Browse files
committed
project: first add of android support
hope it won't end as windows lol
1 parent 97c466d commit 92d95eb

File tree

15 files changed

+633
-24
lines changed

15 files changed

+633
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TARGET = $(NAME)
5252
OLDVERSION = 0.10.1
5353
VERSION = 0.10.2
5454
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
55-
SRC = $(wildcard src/*.cpp src/query/unix/*.cpp src/query/unix/utils/*.cpp)
55+
SRC = $(wildcard src/*.cpp src/query/unix/*.cpp src/query/android/*.cpp src/query/unix/utils/*.cpp)
5656
OBJ = $(SRC:.cpp=.o)
5757
LDFLAGS += -L./$(BUILDDIR)/fmt -lfmt -ldl
5858
CXXFLAGS ?= -mtune=generic -march=native

include/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pkg-managers = ["pacman", "dpkg", "flatpak"]
338338
#
339339
# If you don't know what these ares, leave them by default settings
340340
pacman-dirs = ["/var/lib/pacman/local/"]
341-
dpkg-files = ["/var/lib/dpkg/status"]
341+
dpkg-files = ["/var/lib/dpkg/status", "/data/data/com.termux/files/usr/var/lib/dpkg/status"]
342342
flatpak-dirs = ["/var/lib/flatpak/app/", "~/.local/share/flatpak/app/"]
343343
apk-files = ["/var/lib/apk/db/installed"]
344344

include/platform.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _PLATFORM_H
2+
#define _PLATFORM_H
3+
4+
#if (defined(unix) || defined(__unix) || defined(__unix__))
5+
# define CF_UNIX 1
6+
#else
7+
# define CF_UNIX 0
8+
#endif
9+
10+
#if (defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__))
11+
# define CF_WINDOWS 1
12+
#else
13+
# define CF_WINDOWS 0
14+
#endif
15+
16+
#if (defined(__ANDROID__) || defined(ANDROID_API))
17+
# define CF_ANDROID 1
18+
#else
19+
# define CF_ANDROID 0
20+
#endif
21+
22+
#if !(CF_UNIX || CF_ANDROID) || CF_WINDOWS
23+
# error "Platform currently not supported, only Unix and Android"
24+
#endif
25+
26+
#endif // _PLATFORM_H

include/query.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class User
107107
public:
108108
struct User_t
109109
{
110+
std::string shell_path{ UNKNOWN };
110111
std::string shell_name{ UNKNOWN };
111112
std::string shell_version{ UNKNOWN };
112113
std::string wm_name{ MAGIC_LINE };

include/util.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "fmt/color.h"
3737
#include "fmt/core.h"
38+
#include "platform.hpp"
3839

3940
// clang-format off
4041
constexpr std::size_t operator""_len(const char*, std::size_t ln) noexcept
@@ -106,6 +107,10 @@ std::string getHomeConfigDir();
106107
std::string getConfigDir();
107108
std::vector<std::string> split(const std::string_view text, char delim);
108109

110+
#if CF_ANDROID
111+
std::string get_android_property(const std::string_view name);
112+
#endif
113+
109114
template <typename... Args>
110115
void error(const std::string_view fmt, Args&&... args) noexcept
111116
{

src/query/android/gpu.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2024 Toni500git
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
* following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
* following disclaimer in the documentation and/or other materials provided with the distribution.
12+
*
13+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
14+
* products derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
17+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
*/
25+
26+
#include "platform.hpp"
27+
#if CF_ANDROID
28+
29+
#include "query.hpp"
30+
31+
using namespace Query;
32+
33+
GPU::GPU(const std::uint16_t id, std::vector<std::uint16_t>& queried_gpus)
34+
{
35+
m_gpu_infos.name = m_gpu_infos.vendor = MAGIC_LINE;
36+
}
37+
38+
// clang-format off
39+
std::string& GPU::name() noexcept
40+
{ return m_gpu_infos.name; }
41+
42+
std::string& GPU::vendor() noexcept
43+
{ return m_gpu_infos.vendor; }
44+
45+
#endif

src/query/android/system.cpp

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright 2024 Toni500git
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
* following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
* following disclaimer in the documentation and/or other materials provided with the distribution.
12+
*
13+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
14+
* products derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
17+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
*/
25+
26+
#include "platform.hpp"
27+
#if CF_ANDROID
28+
29+
#include "query.hpp"
30+
#include "util.hpp"
31+
32+
#include <unistd.h>
33+
#include <sys/stat.h>
34+
#include <array>
35+
#include <string_view>
36+
37+
#include "../unix/utils/packages.hpp"
38+
39+
using namespace Query;
40+
41+
static System::System_t get_system_infos()
42+
{
43+
System::System_t ret;
44+
45+
ret.os_name = "Android";
46+
ret.os_id = "android";
47+
ret.os_version_id = get_android_property("ro.build.version.release");
48+
ret.os_version_codename = get_android_property("ro.build.version.codename");
49+
ret.os_pretty_name = "Android " + ret.os_version_codename + " " + ret.os_version_id;
50+
51+
const std::array<std::string_view, 8> properties_name = {"ro.product.marketname", "ro.vendor.product.display", "ro.config.devicename", "ro.config.marketing_name", "ro.product.vendor.model", "ro.product.oppo_model", "ro.oppo.market.name", "ro.product.brand"};
52+
for (const std::string_view name : properties_name)
53+
{
54+
if (ret.host_modelname.empty() || ret.host_modelname == UNKNOWN)
55+
ret.host_modelname = get_android_property(name);
56+
else
57+
break;
58+
}
59+
60+
ret.host_vendor = get_android_property("ro.product.manufacturer");
61+
ret.host_version = get_android_property("ro.product.model");
62+
if (access("/system/bin/init", F_OK) == 0)
63+
{
64+
ret.os_initsys_name = "init";
65+
ret.os_initsys_version.clear();
66+
}
67+
68+
return ret;
69+
}
70+
71+
System::System()
72+
{
73+
if (!m_bInit)
74+
{
75+
if (uname(&m_uname_infos) != 0)
76+
die("uname() failed: {}\nCould not get system infos", strerror(errno));
77+
78+
if (sysinfo(&m_sysInfos) != 0)
79+
die("sysinfo() failed: {}\nCould not get system infos", strerror(errno));
80+
81+
m_system_infos = get_system_infos();
82+
}
83+
m_bInit = true;
84+
85+
}
86+
87+
// clang-format off
88+
std::string System::kernel_name() noexcept
89+
{ return m_uname_infos.sysname; }
90+
91+
std::string System::kernel_version() noexcept
92+
{ return m_uname_infos.release; }
93+
94+
std::string System::hostname() noexcept
95+
{ return m_uname_infos.nodename; }
96+
97+
std::string System::arch() noexcept
98+
{ return m_uname_infos.machine; }
99+
100+
long& System::uptime() noexcept
101+
{ return m_sysInfos.uptime; }
102+
103+
std::string& System::os_pretty_name() noexcept
104+
{ return m_system_infos.os_pretty_name; }
105+
106+
std::string& System::os_name() noexcept
107+
{ return m_system_infos.os_name; }
108+
109+
std::string& System::os_id() noexcept
110+
{ return m_system_infos.os_id; }
111+
112+
std::string& System::os_versionid() noexcept
113+
{ return m_system_infos.os_version_id; }
114+
115+
std::string& System::os_version_codename() noexcept
116+
{ return m_system_infos.os_version_codename; }
117+
118+
std::string& System::host_modelname() noexcept
119+
{ return m_system_infos.host_modelname; }
120+
121+
std::string& System::host_vendor() noexcept
122+
{ return m_system_infos.host_vendor; }
123+
124+
std::string& System::host_version() noexcept
125+
{ return m_system_infos.host_version; }
126+
127+
std::string& System::os_initsys_name()
128+
{ return m_system_infos.os_initsys_name; }
129+
130+
std::string& System::os_initsys_version()
131+
{ return m_system_infos.os_initsys_version; }
132+
133+
std::string& System::pkgs_installed(const Config& config)
134+
{
135+
static bool done = false;
136+
if (!done)
137+
{
138+
m_system_infos.pkgs_installed = get_all_pkgs(config);
139+
140+
done = true;
141+
}
142+
143+
return m_system_infos.pkgs_installed;
144+
}
145+
146+
#endif

src/query/android/theme.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2024 Toni500git
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
* following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8+
* disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+
* following disclaimer in the documentation and/or other materials provided with the distribution.
12+
*
13+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
14+
* products derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
17+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*
24+
*/
25+
26+
#include "platform.hpp"
27+
#if CF_ANDROID
28+
29+
#include "query.hpp"
30+
#include "util.hpp"
31+
32+
using namespace Query;
33+
34+
Theme::Theme(const std::uint8_t ver, systemInfo_t& queried_themes, std::vector<std::string>& queried_themes_names,
35+
const std::string& theme_name_version, const Config& config, const bool gsettings_only)
36+
: m_queried_themes(queried_themes),
37+
m_theme_name_version(theme_name_version)
38+
{
39+
m_theme_infos.cursor = m_theme_infos.gtk_font = m_theme_infos.cursor_size = m_theme_infos.gtk_theme_name = m_theme_infos.gtk_icon_theme = MAGIC_LINE;
40+
}
41+
42+
Theme::Theme(systemInfo_t& queried_themes, const Config& config, const bool gsettings_only) : m_queried_themes(queried_themes)
43+
{
44+
m_theme_infos.cursor = m_theme_infos.gtk_font = m_theme_infos.cursor_size = m_theme_infos.gtk_theme_name = m_theme_infos.gtk_icon_theme = MAGIC_LINE;
45+
}
46+
47+
std::string Theme::gtk_theme() noexcept
48+
{ return m_theme_infos.gtk_theme_name; }
49+
50+
std::string Theme::gtk_icon_theme() noexcept
51+
{ return m_theme_infos.gtk_icon_theme; }
52+
53+
std::string Theme::gtk_font() noexcept
54+
{ return m_theme_infos.gtk_font; }
55+
56+
std::string& Theme::cursor() noexcept
57+
{ return m_theme_infos.cursor; }
58+
59+
std::string& Theme::cursor_size() noexcept
60+
{ return m_theme_infos.cursor_size; }
61+
62+
#endif

0 commit comments

Comments
 (0)