pax_global_header00006660000000000000000000000064145545005310014514gustar00rootroot0000000000000052 comment=e42f12b96d1745286f3c3c88b4a19bd7c3ead9ef deviceinfo-0.2.2/000077500000000000000000000000001455450053100136305ustar00rootroot00000000000000deviceinfo-0.2.2/.gitignore000066400000000000000000000006001455450053100156140ustar00rootroot00000000000000 # Created by https://www.gitignore.io/api/cmake # Edit at https://www.gitignore.io/?templates=cmake ### CMake ### CMakeLists.txt.user CMakeCache.txt CMakeFiles CMakeScripts Testing Makefile cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake _deps ### CMake Patch ### # External projects *-prefix/ # End of https://www.gitignore.io/api/cmake build deviceinfo-0.2.2/AUTHORS000066400000000000000000000002371455450053100147020ustar00rootroot00000000000000Alfred Neumayer Dalton Durst Erfan Abdi Jami Kettunen Luca Weiss Marius Gripsgard Michele Mike Gabriel Muhammad Oren Klopfer Ratchanan Srirattanamet Wouter182 deviceinfo-0.2.2/CMakeLists.txt000066400000000000000000000027671455450053100164040ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.0) project(deviceinfo VERSION 0.2.2) set(CMAKE_CXX_STANDARD 14) set(VERSION_MAJOR 0) set(VERSION_MINOR 2) set(VERSION_PATCH 0) include(FindPkgConfig) include(GNUInstallDirs) option(DISABLE_TESTS "Disable tests" off) option(WITH_EXTRAS "Build extra component(s)" off) pkg_search_module(YAMLCPP yaml-cpp REQUIRED) pkg_search_module(ANDROIDPROPS libandroid-properties) if(NOT ANDROIDPROPS_FOUND) message(WARNING "Did not find android properties, bulding without!") endif() set(TARGET deviceinfo) include_directories(headers) set(CONFIG_PATH ${CMAKE_INSTALL_FULL_SYSCONFDIR}/deviceinfo CACHE STRING "") install(DIRECTORY configs/ DESTINATION ${CONFIG_PATH}) add_subdirectory(headers) add_subdirectory(src) add_subdirectory(tools) if (DISABLE_TESTS) message(STATUS "Tests disabled") else() include(CTest) enable_testing() add_subdirectory(tests) endif() if (WITH_EXTRAS) pkg_check_modules(GLib REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0) add_subdirectory(extras) endif () # Coverage ##################################################################### # Enable code coverage calculation with gcov/gcovr/lcov # Usage: # * Switch build type to coverage (use ccmake or cmake-gui) # * Invoke make, make test, make coverage (or ninja if you use that backend) # * Find html report in subdir coveragereport # * Find xml report feasible for jenkins in coverage.xml ##################################################################### find_package(CoverageReport) deviceinfo-0.2.2/ChangeLog000066400000000000000000000237201455450053100154060ustar00rootroot000000000000002024-01-25 Mike Gabriel * Release 0.2.2 (HEAD -> main, tag: 0.2.2) 2023-12-16 Mike Gabriel * Merge branch 'main' into 'main' (0a200dc) 2023-12-14 Oren Klopfer * pinetab patch: PT2 sensors, PT1+PT2 morph scaling (b992327) 2023-10-15 Mike Gabriel * Release 0.2.1 (7e819c1) (tag: 0.2.1) 2023-09-18 Ratchanan Srirattanamet * Merge branch 'main' into 'main' (72afc44) 2023-09-18 Oren Klopfer * use same WebkitDpr's on tabs (e0fc80d) 2023-09-17 Oren Klopfer * use pine64 name on all devices + allow tab2v0.1 (cbf1f6c) * use conventional naming (5a378fa) 2023-09-15 Oren Klopfer * add pinetab2 + fix pinetab orientation sensor (17cb99e) 2023-06-16 Mike Gabriel * Merge branch 'muhammad23012009-main-patch-13945' into 'main' (56e8dd0) 2023-06-15 Muhammad * deviceinfo: update documentation (98ce40e) 2023-06-14 Mike Gabriel * Merge branch 'personal/peat-psuwit/no-hybris-sensorfw-config' into 'main' (5dada77) 2023-06-13 Ratchanan Srirattanamet * configs: remove SensorFW config for hybris (1a7cf34) 2023-06-11 Mike Gabriel * Release 0.2.0 (0a9f705) (tag: 0.2.0) 2023-06-06 Mike Gabriel * Merge branch 'main' into 'main' (58c0af2) 2023-06-06 Oren Klopfer * Merge branch deviceinfo:main into main (d24e9e7) 2023-06-06 Mike Gabriel * Merge branch 'personal/peat-psuwit/fixup-legacy-formfactor' into 'main' (767e793) 2023-06-05 Oren Klopfer * Merge branch deviceinfo:main into main (790635f) 2023-05-09 Ratchanan Srirattanamet * config: correctly transform legacy FORM_FACTOR and DeviceInfo values (799caaf) Fixes: https://gitlab.com/ubports/development/core/deviceinfo/-/issues/9 2023-06-05 Mike Gabriel * Merge branch 'personal/peat-psuwit/6-machine-info' into 'main' (cc69f67) 2023-05-08 Ratchanan Srirattanamet * debian/*: update packaging to have deviceinfo-extras (c8953b3) 2023-05-04 Ratchanan Srirattanamet * extras: add a program to update machine info from deviceinfo (7db2be8) Fixes: https://gitlab.com/ubports/development/core/deviceinfo/-/issues/6 2023-05-08 Ratchanan Srirattanamet * debian/*: upgrade debhelper-compat to 12 (0088709) 2023-06-05 Mike Gabriel * Merge branch 'personal/peat-psuwit/8-also-read-android-conf' into 'main' (413d1fc) 2023-05-04 Ratchanan Srirattanamet * config: also read legacy props from android.conf (7cc3050) Fixes: https://gitlab.com/ubports/development/core/deviceinfo/-/issues/8 2023-06-05 Mike Gabriel * Merge branch 'personal/peat-psuwit/jenkinsfile-shared-library' into 'main' (7528175) 2023-05-22 Oren Klopfer * Merge branch deviceinfo:main into main (b9b0aa4) 2023-05-22 Ratchanan Srirattanamet * Update Jenkinsfile to use shared library (c6fb609) 2023-05-20 Ratchanan Srirattanamet * Merge branch 'main' into 'main' (5e4d0fa) 2023-05-12 Muhammad * deviceinfo_c_api: return an int for deviceType() and driverType() (06cef49) 2023-05-10 Muhammad * tree: rename deviceinfo_c_connector to deviceinfo_c_api (bbc2966) 2023-05-09 Muhammad * deviceinfo_c_connector: make to_cstr() static (00cc816) 2023-05-08 Muhammad * CMakeLists: Bump minor version to 2 (ec52a65) * src: integrate deviceinfo_c_connector with libdeviceinfo (894c4c2) * deviceinfo_c_connector: use strdup() instead of manually converting (b9908a7) * deviceinfo_connector: remove repeated EXTERNC (65e4c3d) 2023-05-06 Muhammad * deviceinfo_c_connector: rename DeviceInfo to deviceinfo (97d093c) * headers: Add headers for C wrapper (ad713bd) * Add C wrapper for accessing libdeviceinfo; Integrated within `libdeviceinfo.so`, header used is named `deviceinfo_c_api.h` (efb3c04) 2023-05-05 Oren Klopfer * Updated: Add PinePhone Pro configs + Fix PinePhone (c9636dc) 2023-02-07 Mike Gabriel * Merge branch 'revert-aec6d886' into 'main' (fe939f0) * Revert "Merge branch 'main' into 'main'" (0d42bce) * Merge branch 'main' into 'main' (aec6d88) 2023-02-07 Oren Klopfer * Add `pinephone-pro` configs (27d40f8) 2023-02-05 Mike Gabriel * Release 0.1.1 (2f76423) (tag: 0.1.1) 2022-10-04 Mike Gabriel * Merge branch 'fix-spesific-typo' into 'main' (90cac0d) 2022-10-04 Jami Kettunen * Fix help "spesific" -> "specific" typo (5cab17a) 2022-07-14 Ratchanan Srirattanamet * Merge branch 'empty-halium-yaml' into 'main' (8483ed6) 2022-07-08 Alfred Neumayer * devices: Ship empty Halium overlay target file (501d133) 2021-08-16 Dalton Durst * Merge branch 'revert-020fd7ed' into 'main' (aec1333) * Revert "Merge branch 'wouter182-main-patch-72613' into 'main'" (2cad801) 2021-08-10 Dalton Durst * Name PineTab device correctly (e8ca13b) * Merge branch 'wouter182-main-patch-72613' into 'main' (020fd7e) 2021-08-08 wouter182 * Update pinephone.conf Closely tight to https://github.com/ubports/sensorfw/pull/4 Cleanup some settings which don't work. (b0c8450) 2021-08-03 Dalton Durst * Merge branch 'personal/usb/pinetab-fun' into 'main' (f0d2f92) 2021-07-29 Dalton Durst * Enable accelerometer on PineTab (fcfe94b) * Fix PineTab config with new kernel (7931b04) 2021-04-07 Dalton Durst * Merge branch 'ubports/xenial_-_edge' into 'main' (d47492b) 2021-04-06 Marius Gripsgard * platform: Fix wrong defined name in previous commit (8cb0ecb) 2021-04-01 Marius Gripsgard * device: Search for device configs using case insensitive matching (and tests) (6927ca2) * utils: Add compareInsensitive function and tests (ebe1e10) * tests: Add tests for ends- and starts- with (8479319) 2021-04-01 Dalton Durst * Add libgtest-dev to build-depends (0d51430) 2021-03-29 Marius Gripsgard * Move Jenkinsfile to debian folder (65348c9) * Merge pull request #11 from z3ntu/xenial_-_edge_-_cmake-config-path (47255cc) * Merge pull request #12 from ubports/xenial_-_edge_-_yaml (a55aad2) 2021-03-17 Marius Gripsgard * Merge branch 'mr/device-info-manpage' into 'master' (3bdd6b1) * Merge branch 'mr/fix-build-without-androidprops' into 'master' (7203468) 2021-03-14 Mike Gabriel * debian/deviceinfo-tools.manpages: Install manpage into -tools package. (62429dd) * tools/: Add rudimentary device-info man page. (cf2b7d7) * src/platform/platform.cpp: Fix FTBFS when building without Android properties. (c25eedf) 2021-03-12 Marius Gripsgard * tests: Add tests for utils (6ffc1b6) * tests: Use older MOCK_METHOD macro style (748ff41) 2021-02-03 Marius Gripsgard * Add more tests (db3278c) (tag: 0.1.0) * Add more tests, coverage raports and fix legacyprops (02d4a52) 2021-02-01 Marius Gripsgard * Move to yaml for config files (b7de280) 2020-08-17 Marius Gripsgard * Inital tests (e270414) 2020-09-01 Marius Gripsgard * Refactor platform dependent information getter logic (304a925) 2020-09-16 Luca Weiss * Allow changing of CONFIG_PATH during compile-time (e3dd087) 2020-09-04 Marius Gripsgard * Don't hardcode config directory and rename default config dir to match project (#9) (a830f33) 2020-08-17 Marius Gripsgard * Inital tests (2292809) 2020-08-06 Marius Gripsgard * Add alias for pinephone board v1.2 (06e02d4) 2020-06-11 Marius Gripsgard * Merge pull request #5 from erfanoabdi/xenial_-_edge (544833a) 2020-06-11 Erfan Abdi * Use vendor props if available (a494268) 2020-04-14 Marius Gripsgard * Add newer pinephone alias (93ac032) 2020-04-04 Marius Gripsgard * Fix prox threshold (97036dc) 2020-03-21 Marius Gripsgard * Fix derp (291573e) 2020-03-09 Marius Gripsgard * Add pinephone sensorfw configs (d30458b) 2020-03-03 Michele * fix typo (3333598) 2020-02-08 Dalton Durst * Make scaling smaller on Pinephone (a2f5590) 2019-12-13 Marius Gripsgard * Pinephone should be in Portrait (1d15431) 2019-12-08 Marius Gripsgard * default should be Landscape on desktop and Portrait on halium (360d81b) 2019-11-13 Marius Gripsgard * Fix derp (c85cda2) 2019-11-05 Marius Gripsgard * Update to new jenkinsfile (a07797f) 2019-11-03 Marius Gripsgard * Add sensorfw config, move folder and fix gridunit on pine/librem (bcfc13d) 2019-09-20 Marius Gripsgard * Add configs for pine(book/tab) and librem5 (6de9c93) * Turn detectedName std::string into cont char* to "normalify it" (8df2516) * Build depend on pkg-config (2e9e5f5) * Add "about this device" option to the tool (36a30f9) * Add api point to set printmode after construction (0b00336) * Add ability to read legacy config files (39a594b) * Give default gridunit if cant convert string to int (7a27663) * Add error logger (f404eb4) * Cleanup data and add alias (6019348) 2019-09-19 Marius Gripsgard * Add support for alias, logging and general improvements (0a8e12f) 2019-09-18 Marius Gripsgard * Make sure -dev depends on its libs (d4bbbc9) * Seperate supportedOrientations into vector (4d9c858) * Dont write anything on error, scripts wont like this (e519694) * [tool] Add help and move get under get subcommand (e29252e) * Add WebkitDpr to config and edit PrimaryOr to reflect native Or (0a68281) 2019-09-17 Marius Gripsgard * Merge branch 'master' into xenial_-_edge (cb09574) * Add jenkinsfile (922f8fc) * Inital commit (4539116) * Create README.md (d162457) * Create LICENSE (edf81f4) deviceinfo-0.2.2/LICENSE000066400000000000000000001045151455450053100146430ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . deviceinfo-0.2.2/README.md000066400000000000000000000074451455450053100151210ustar00rootroot00000000000000# Deviceinfo Library to detect and configure devices ## Config files Deviceinfo has 2 types of configs: * halium.yaml, which is read by libdeviceinfo if a device-specific configuration cannot be found. * [device].yaml, which is read by libdeviceinfo and prioritized over halium.yaml. In any case, the syntax is same for both configurations, which is as follows: ``` $ cat /etc/deviceinfo/devices/sample.yaml sample: Names: - SAMPLE1 - 2SAMPLE - SAMPL3 PrettyName: Hello World! DeviceType: phone GridUnit: 21 SupportedOrientation: - Portrait - Landscape - InvertedLandscape ``` `sample` is actually supposed to match the name of the device-specific yaml (if you're using that), but in case of halium.yaml, it is supposed to be match your device model (aka ro.product.vendor.device). ## Built in config keys (with special logic and fallback logic) - Name: Device name/codename - PrettyName: Pretty name of the device - DeviceType: Sets device type (desktop, tablet, phone) - GridUnit: Sets scale units - SupportedOrientations: (Portrait,InvertedPortrait,Landscape,InvertedLandscape) - PrimaryOrientation - PortraitOrientation - InvertedPortraitOrientation - LandscapeOrientation - InvertedLandscapeOrientation Any key can be added to your yaml for using it yourself, without needing to modify deviceinfo itself. But beware, you will not get the fancy fallbacks that you get with the built-in configs. ## Detect logic `Name` is autodetected by using the model of the device, using android props for halium/android devices and dtb for native linux devices. (this can be overwritten by config) `DeviceType` on android/halium this is autodetected by trying to look at the android characteristics prop, if this include tablet we assume its a tablet, if not we assume it's an phpne. On linux we have no way of detecting this atm, it fallsback to desktop. (this can be overwritten by config) `DriverType` is autodetected by trying to get any type of android prop, if it can find it we assume its an android device, if not we assume it's a native linux device. (this can `NOT` be overwritten by config) ## Tool usage ``` $ device-info get PrettyName Hello World! ``` ## Override enviroment varables - DEVICEINFO_CONFIG_PATH overrides path to find config files - DEVICEINFO_DEFAULT_CONFIG overrides default config file - DEVICEINFO_DEVICE_CONFIG overrides device config file - DEVICEINFO_ALIAS_CONFIG overrides alias config file - DEVICEINFO_DEVICE_NAME overrides device detected name - DEVICEINFO_DEBUG overrides debug level (-1 = None, 0 = Info, 1 = Debug, 2 = Verbose) ## Building ``` mkdir build cd build cmake .. ``` ## C++ API The API is fairly simple, look into headers/deviceinfo.h for the full API. Example: ``` // Include deviceinfo headers #include // Considering you added /usr/include/deviceinfo to includes. ... // To initialize the object std::shared_ptr info = std::make_shared(); std::cout << info->name() << std::endl; ``` ## C API Deviceinfo can be used with pure C projects just like you would with C++, except you will include deviceinfo_c_api.h instead of deviceinfo.h. Full API is present in headers/deviceinfo_c_api.h. Example: ``` // Include C API header #include // Considering you added /usr/include/deviceinfo to includes. ... struct DeviceInfo* di = new DeviceInfo(); printf("device name is %s", di->deviceinfo_name()); ``` ## Notes * Deviceinfo picks the device-specific yaml by reading either the `ro.product.vendor.device` prop or `ro.product.device` prop. The former is prioritized and the latter serves as a fallback. The * If `PrettyName` is not defined, then either `ro.product.vendor.model` or `ro.product.model` is used as a fallback. Like before, the latter is only a fallback for the prop. deviceinfo-0.2.2/configs/000077500000000000000000000000001455450053100152605ustar00rootroot00000000000000deviceinfo-0.2.2/configs/default.yaml000066400000000000000000000014641455450053100175750ustar00rootroot00000000000000defaults: default: Name: generic PrettyName: Generic device DeviceType: desktop GridUnit: 8 SupportedOrientations: - Portrait - InvertedPortrait - Landscape - InvertedLandscape PrimaryOrientation: Landscape PortraitOrientation: Portrait InvertedPortraitOrientation: InvertedPortrait LandscapeOrientation: Landscape InvertedLandscapeOrientation: InvertedLandscape WebkitDpr: 1 halium: Name: generic PrettyName: Generic Halium device DeviceType: phone GridUnit: 21 WebkitDpr: 2 PrimaryOrientation: Portrait phone: GridUnit: 21 WebkitDpr: 2 PrimaryOrientation: Portrait tablet: GridUnit: 21 WebkitDpr: 2 PrimaryOrientation: Landscape desktop: GridUnit: 8 PrimaryOrientation: Landscape deviceinfo-0.2.2/configs/devices/000077500000000000000000000000001455450053100167025ustar00rootroot00000000000000deviceinfo-0.2.2/configs/devices/halium.yaml000066400000000000000000000001541455450053100210450ustar00rootroot00000000000000# Empty device config # Intended for use as a bind-mount overlay target, like device-specific Halium ports. deviceinfo-0.2.2/configs/devices/pinebook.yaml000066400000000000000000000001171455450053100213730ustar00rootroot00000000000000pinebook: Names: - pinebook PrettyName: PineBook DeviceType: desktop deviceinfo-0.2.2/configs/devices/pinephone-pro.yaml000066400000000000000000000005121455450053100223470ustar00rootroot00000000000000pinephone-pro: Names: - Pine64 PinePhonePro PrettyName: Pine64 PinePhonePro DeviceType: phone GridUnit: 14 SupportedOrientations: - Portrait - InvertedPortrait - Landscape - InvertedLandscape PrimaryOrientation: Portrait WebkitDpr: 2 SensorfwConfig: /etc/deviceinfo/sensorfw/pinephone-pro.conf deviceinfo-0.2.2/configs/devices/pinephone.yaml000066400000000000000000000005171455450053100215560ustar00rootroot00000000000000pinephone: Names: - PinePhone Don't be evil development kit - Pine64 PinePhone Developer Batch (1.0) - Pine64 PinePhone Braveheart (1.1) - Pine64 PinePhone (1.2) PrettyName: Pine64 PinePhone DeviceType: phone GridUnit: 14 PrimaryOrientation: Portrait SensorfwConfig: /etc/deviceinfo/sensorfw/pinephone.conf deviceinfo-0.2.2/configs/devices/pinetab.yaml000066400000000000000000000006031455450053100212070ustar00rootroot00000000000000pinetab: Names: - pinetab - "PineTab, Early Adopter's version" - "PineTab, Development Sample" PrettyName: Pine64 PineTab DeviceType: tablet GridUnit: 8 SupportedOrientations: - Portrait - InvertedPortrait - Landscape - InvertedLandscape PrimaryOrientation: InvertedLandscape WebkitDpr: 1 SensorfwConfig: /etc/deviceinfo/sensorfw/pinetab.conf deviceinfo-0.2.2/configs/devices/pinetab2.yaml000066400000000000000000000005451455450053100212760ustar00rootroot00000000000000pinetab2: Names: - "Pine64 PineTab2 v0.1" - "Pine64 PineTab2 v2.0" PrettyName: Pine64 PineTab2 DeviceType: tablet GridUnit: 8 SupportedOrientations: - Portrait - InvertedPortrait - Landscape - InvertedLandscape PrimaryOrientation: InvertedLandscape WebkitDpr: 1 SensorfwConfig: /etc/deviceinfo/sensorfw/pinetab2.conf deviceinfo-0.2.2/configs/sensorfw/000077500000000000000000000000001455450053100171265ustar00rootroot00000000000000deviceinfo-0.2.2/configs/sensorfw/pinephone-pro.conf000066400000000000000000000015701455450053100225630ustar00rootroot00000000000000[plugins] accelerometeradaptor = iiosensorsadaptor alsadaptor = iiosensorsadaptor magnetometeradaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor proximityadaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor [accelerometer] input_match=mpu6500 intervals = "2,5,10,20,50,100" default_interval = 10 transformation_matrix = "1,0,0,0,-1,0,0,0,1" [als] input_match=stk3311 [gyroscope] input_match=mpu6500 intervals = "2,5,10,50,100" default_interval = 10 transformation_matrix = "1,0,0,0,-1,0,0,0,1" [magnetometer] input_match=af8133j #intervals = "25,50,100,200,500,1000" #default_interval = 50 scale_coefficient = 1 needs_calibration = 1 #interval_compensation = 0 # Calibration with 40 Hz. calibration_rate = 10 # 1 second long calibration. calibration_timeout = 60000 tranformation_matrix = "-1,0,0,0,1,0,0,0,1" [proximity] input_match=stk3311 threshold=19 deviceinfo-0.2.2/configs/sensorfw/pinephone.conf000066400000000000000000000015231455450053100217630ustar00rootroot00000000000000[plugins] accelerometeradaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor alsadaptor = iiosensorsadaptor magnetometeradaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor proximityadaptor = iiosensorsadaptor [accelerometer] input_match=mpu6050 intervals = "2,5,10,20,50,100" default_interval = 20 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [als] input_match=stk3310 [gyroscope] input_match=mpu6050 intervals = "2,5,10,20,50,100" default_interval = 50 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [magnetometer] input_match=lis3mdl #intervals = "25,50,100,200,500,1000" #default_interval = 1000 scale_coefficient = 1 needs_calibration = 1 #interval_compensation = 0 # Calibration with 40 Hz. calibration_rate = 25 # 1 second long calibration. calibration_timeout = 60000 [proximity] input_match=stk3310 threshold=19 deviceinfo-0.2.2/configs/sensorfw/pinetab.conf000066400000000000000000000005741455450053100214250ustar00rootroot00000000000000[plugins] accelerometeradaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor [accelerometer] input_match=BMA222E intervals = "200=>2000" default_interval=500 transformation_matrix = "0,-1,0,-1,0,0,0,0,-1" [gyroscope] input_match=BMA222E intervals = "200=>2000" default_interval=500 transformation_matrix = "0,-1,0,-1,0,0,0,0,-1"deviceinfo-0.2.2/configs/sensorfw/pinetab2.conf000066400000000000000000000006341455450053100215040ustar00rootroot00000000000000[plugins] accelerometeradaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor [accelerometer] input_match=sc7a20 intervals = "1,10,25,50,100,200,400,1600" default_interval = 10 transformation_matrix = "1,0,0,0,0,1,0,-1,0" [gyroscope] input_match=sc7a20 intervals = "1,10,25,50,100,200,400,1600" default_interval = 10 transformation_matrix = "1,0,0,0,0,1,0,-1,0"deviceinfo-0.2.2/debian/000077500000000000000000000000001455450053100150525ustar00rootroot00000000000000deviceinfo-0.2.2/debian/Jenkinsfile000066400000000000000000000015271455450053100172430ustar00rootroot00000000000000@Library('ubports-build-tools') _ /* * Arguments of buildAndProvideDebianPackage(): * - isArchIndependent: a hint that this package contains only 'Architecture: * all' package(s), and thus Jenkins doesn't have to dispatch build to nodes * of every architecture. Note that this will confuse BlueOcean UI, causing it * to not show any progress during the 'Build binary' step. However, if * needed, one can still track the progress on the classic UI. * - ignoredArches: a list of architectures where the package should not be * built. For example, [ 'armhf' ]. * - isHeavyPackage: a hint that this package requires a significantly more * resource to build, and would benefit from building on faster nodes. */ buildAndProvideDebianPackage( /* isArchIndependent */ false, /* ignoredArchs */ [], /* isHeavyPackage */ false )deviceinfo-0.2.2/debian/changelog000066400000000000000000000020331455450053100167220ustar00rootroot00000000000000deviceinfo (0.2.2) unstable; urgency=medium * Upstream-provided Debian package for deviceinfo. See upstream ChangeLog for recent changes. -- UBports developers Thu, 25 Jan 2024 16:41:56 +0100 deviceinfo (0.2.1) unstable; urgency=medium * Upstream-provided Debian package for deviceinfo. See upstream ChangeLog for recent changes. -- UBports developers Sun, 15 Oct 2023 01:04:21 +0200 deviceinfo (0.2.0) unstable; urgency=medium * Upstream-provided Debian package for deviceinfo. See upstream ChangeLog for recent changes. -- UBports developers Sun, 11 Jun 2023 13:59:07 +0200 deviceinfo (0.1.1) unstable; urgency=medium * Upstream-provided Debian package for deviceinfo. See upstream ChangeLog for recent changes. -- UBports developers Sun, 05 Feb 2023 00:17:10 +0100 deviceinfo (0.1.0) xenial; urgency=medium * initial release -- Marius Gripsgard Tue, 17 Sep 2019 23:09:12 +0200 deviceinfo-0.2.2/debian/control000066400000000000000000000030611455450053100164550ustar00rootroot00000000000000Source: deviceinfo Section: admin Priority: optional Build-Depends: cmake (>= 2.8.10), cmake-extras, debhelper-compat (= 12), pkg-config, libandroid-properties-dev, libyaml-cpp-dev, googletest | google-mock, libgtest-dev, libglib2.0-dev, systemd, Maintainer: Marius Gripsgard Standards-Version: 3.9.5 Homepage: https://github.com/ubports/deviceinfo Package: libdeviceinfo0 Section: libs Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, Description: Library to detect and configure devices Library to detect and configure devices Package: libdeviceinfo-dev Section: libdevel Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, libdeviceinfo0 (= ${binary:Version}), Description: Development headers to detect and configure devices Development headers for libdeviceinfo, to detect and configure devices Package: deviceinfo-tools Section: admin Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, Description: Tools to detect and configure devices Tools to detect and configure devices Package: deviceinfo-extras Section: admin Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, Description: Library to detect and configure devices - extra programs Library to detect and configure devices . This package contains extra programs shipped with deviceinfo. At the moment, this includes update-machine-info-from-deviceinfo tool. deviceinfo-0.2.2/debian/copyright000066400000000000000000000020561455450053100170100ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: deviceinfo Upstream-Contact: Marius Gripsgard Source: https://github.com/ubports/deviceinfo Files: * Copyright: 2019 UBports foundation, Marius Gripsgard License: GPL-3 License: GPL-3 This program is free software: you can redistribute it and/or modify it under the terms of the the GNU General Public License version 3, as published by the Free Software Foundation. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR PURPOSE. See the applicable version of the GNU Lesser General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . . On Debian systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-3' deviceinfo-0.2.2/debian/deviceinfo-extras.install000066400000000000000000000001611455450053100220570ustar00rootroot00000000000000/usr/libexec/update-machine-info-from-deviceinfo /lib/systemd/system/update-machine-info-from-deviceinfo.service deviceinfo-0.2.2/debian/deviceinfo-tools.install000066400000000000000000000000241455450053100217070ustar00rootroot00000000000000usr/bin/device-info deviceinfo-0.2.2/debian/deviceinfo-tools.manpages000066400000000000000000000000231455450053100220330ustar00rootroot00000000000000tools/device-info.1deviceinfo-0.2.2/debian/libdeviceinfo-dev.install000066400000000000000000000002131455450053100220140ustar00rootroot00000000000000usr/include/deviceinfo/deviceinfo.h usr/include/deviceinfo/deviceinfo_c_api.h usr/lib/*/pkgconfig/deviceinfo.pc usr/lib/*/libdeviceinfo.so deviceinfo-0.2.2/debian/libdeviceinfo0.install000066400000000000000000000000551455450053100213240ustar00rootroot00000000000000usr/lib/*/libdeviceinfo.so.0* etc/deviceinfo deviceinfo-0.2.2/debian/rules000077500000000000000000000002471455450053100161350ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ --buildsystem cmake override_dh_missing: dh_missing --fail-missing override_dh_auto_configure: dh_auto_configure -- -DWITH_EXTRAS=ON deviceinfo-0.2.2/extras/000077500000000000000000000000001455450053100151365ustar00rootroot00000000000000deviceinfo-0.2.2/extras/CMakeLists.txt000066400000000000000000000012141455450053100176740ustar00rootroot00000000000000add_executable(update-machine-info-from-deviceinfo update-machine-info-from-deviceinfo.cpp ) target_link_libraries(update-machine-info-from-deviceinfo deviceinfo PkgConfig::GLib ) install(TARGETS update-machine-info-from-deviceinfo DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) configure_file( update-machine-info-from-deviceinfo.service.in "${CMAKE_CURRENT_BINARY_DIR}/update-machine-info-from-deviceinfo.service" @ONLY ) pkg_get_variable(SYSTEMD_SYSTEM_UNIT_DIR systemd systemdsystemunitdir) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/update-machine-info-from-deviceinfo.service" DESTINATION ${SYSTEMD_SYSTEM_UNIT_DIR} ) deviceinfo-0.2.2/extras/update-machine-info-from-deviceinfo.cpp000066400000000000000000000072271455450053100245410ustar00rootroot00000000000000#include #include #include #include #include int main() { DeviceInfo info; bool has_error = false; g_autoptr(GError) error = NULL; g_autoptr(GDBusProxy) hostname1 = g_dbus_proxy_new_for_bus_sync( G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, /* interface info */ NULL, "org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1", /* cancellable */ NULL, &error); if (!hostname1) { g_error("Can't connect to org.freedesktop.hostname1, can't update machine info (%s)", error->message); return EXIT_FAILURE; } g_autoptr(GVariant) pretty_hostname_v = g_dbus_proxy_get_cached_property(hostname1, "PrettyHostname"); const char *pretty_hostname = NULL; if (pretty_hostname_v) pretty_hostname = g_variant_get_string(pretty_hostname_v, /* (out) length */ NULL); g_autoptr(GVariant) chassis_v = g_dbus_proxy_get_cached_property(hostname1, "Chassis"); const char *chassis = NULL; if (chassis_v) chassis = g_variant_get_string(chassis_v, /* (out) length */ NULL); g_debug("From org.freedesktop.hostname1, PrettyHostname = '%s', Chassis = '%s'", pretty_hostname ?: "(NULL)", chassis ?: "(NULL)"); /* Only update hostname when pretty hostname is not present yet * as otherwise it could have been overriden by the user */ if (!pretty_hostname || pretty_hostname[0] == '\0') { std::string pretty_name = info.prettyName(); g_autoptr(GVariant) ret = g_dbus_proxy_call_sync( hostname1, "SetPrettyHostname", g_variant_new("(sb)", pretty_name.c_str(), /* interactive */ FALSE), G_DBUS_CALL_FLAGS_NONE, /* timeout_msec */ 1000, /* cancellable */ NULL, &error); if (error) { g_warning("Can't set pretty hostname: %s", error->message); g_clear_error(&error); has_error = true; } else { g_debug("Set pretty hostname to '%s'", pretty_name.c_str()); } } /* When not chassis type is set yet we update it with the * value from the touch session configuration. We check this * always as we need to care about the case where this * updated systemd unit was introduced and the machine-info * file was already present on the device. */ if (!chassis || chassis[0] == '\0') { const char* chassis = NULL; switch (info.deviceType()) { case DeviceInfo::DeviceType::Phone: chassis = "handset"; break; case DeviceInfo::DeviceType::Tablet: chassis = "tablet"; break; case DeviceInfo::DeviceType::Desktop: case DeviceInfo::DeviceType::Unknown: /* In these cases Hostnamed usually knows better. */ break; } if (chassis) { g_autoptr(GVariant) ret = g_dbus_proxy_call_sync( hostname1, "SetChassis", g_variant_new("(sb)", chassis, /* interactive */ FALSE), G_DBUS_CALL_FLAGS_NONE, /* timeout_msec */ 1000, /* cancellable */ NULL, &error); if (error) { g_warning("Can't set chassis: %s", error->message); g_clear_error(&error); has_error = true; } else { g_debug("Set chassis to '%s'", chassis); } } } return has_error ? EXIT_FAILURE : EXIT_SUCCESS; } deviceinfo-0.2.2/extras/update-machine-info-from-deviceinfo.service.in000066400000000000000000000010361455450053100260140ustar00rootroot00000000000000[Unit] Description=Use information from DeviceInfo, update pretty hostname and chassis info. Requires=dbus.socket After=dbus.socket # To allow Bluetooth to use this information. Before=bluetooth.service # To be safe After=lxc-android-config.service # Not strictly necessary as DBus will activate it for us, but it's an optimization. # Note that ordering is not needed. Wants=systemd-hostnamed.service [Service] Type=oneshot ExecStart=@CMAKE_INSTALL_FULL_LIBEXECDIR@/update-machine-info-from-deviceinfo [Install] WantedBy=multi-user.target deviceinfo-0.2.2/headers/000077500000000000000000000000001455450053100152435ustar00rootroot00000000000000deviceinfo-0.2.2/headers/CMakeLists.txt000066400000000000000000000005101455450053100177770ustar00rootroot00000000000000set(PUBLIC_HEADERS deviceinfo.h deviceinfo_c_api.h ) configure_file(${TARGET}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/deviceinfo) deviceinfo-0.2.2/headers/deviceinfo.h000066400000000000000000000042311455450053100175270ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include #include class Device; class DeviceInfo { public: enum DeviceType { Phone, Tablet, Desktop, Unknown = -1 }; enum DriverType { Linux, Halium }; enum PrintMode { None = -2, Error = -1, Info = 0, Debug = 1, Verbose = 2 }; DeviceInfo(PrintMode printMode = PrintMode::Info); // For tests DeviceInfo(Device *device); // Internal logging void setPrintMode(PrintMode printMode); // Props with auto detections std::string name(); std::string prettyName(); DeviceType deviceType(); DriverType driverType(); int gridUnit(); // Get props that does not have auto detection std::string get(std::string prop, std::string defaultValue); bool contains(std::string prop); // Handy wrappers around get std::vector supportedOrientations(); std::string primaryOrientation(); std::string portraitOrientation(); std::string invertedPortraitOrientation(); std::string landscapeOrientation(); std::string invertedLandscapeOrientation(); // Handy helpers static std::string deviceTypeToString(DeviceType type); static DeviceType deviceTypeFromString(std::string str); static std::string driverTypeToString(DriverType type); static DriverType driverTypeFromString(std::string str); private: std::shared_ptr m_device; }; deviceinfo-0.2.2/headers/deviceinfo.pc.in000066400000000000000000000004261455450053100203110ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include/deviceinfo Name: deviceinfo Description: Device info lib Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ Libs: -L${libdir} -ldeviceinfo Cflags: -I${includedir} deviceinfo-0.2.2/headers/deviceinfo_c_api.h000066400000000000000000000025641455450053100206710ustar00rootroot00000000000000#ifndef DEVICEINFO_C_API_H #define DEVICEINFO_C_API_H // Values to use for deviceinfo_deviceType() and deviceinfo_driverType() #define DEVICEINFO_DEVICETYPE_PHONE 0 #define DEVICEINFO_DEVICETYPE_TABLET 1 #define DEVICEINFO_DEVICETYPE_DESKTOP 2 #define DEVICEINFO_DEVICETYPE_UNKNOWN -1 #define DEVICEINFO_DRIVERTYPE_LINUX 0 #define DEVICEINFO_DRIVERTYPE_HALIUM 1 #ifdef __cplusplus extern "C" { #else #include #endif typedef struct DeviceInfo DeviceInfo; DeviceInfo* deviceinfo_new(); void deviceinfo_delete(DeviceInfo* instance); char* deviceinfo_name(DeviceInfo* instance); char* deviceinfo_prettyName(DeviceInfo* instance); char* deviceinfo_supportedOrientations(DeviceInfo* instance); char* deviceinfo_primaryOrientation(DeviceInfo* instance); char* deviceinfo_portraitOrientation(DeviceInfo* instance); char* deviceinfo_invertedPortraitOrientation(DeviceInfo* instance); char* deviceinfo_landscapeOrientation(DeviceInfo* instance); char* deviceinfo_invertedLandscapeOrientation(DeviceInfo* instance); int deviceinfo_deviceType(DeviceInfo* instance); int deviceinfo_driverType(DeviceInfo* instance); int deviceinfo_gridUnit(DeviceInfo* instance); char* deviceinfo_get(DeviceInfo* instance, const char* prop, const char* defaultValue); bool deviceinfo_contains(DeviceInfo* instance, const char* prop); #ifdef __cplusplus } // extern "C" #endif #endif // DEVICEINFO_C_API_H deviceinfo-0.2.2/src/000077500000000000000000000000001455450053100144175ustar00rootroot00000000000000deviceinfo-0.2.2/src/CMakeLists.txt000066400000000000000000000014131455450053100171560ustar00rootroot00000000000000if(ANDROIDPROPS_FOUND) add_definitions(-DHAVE_PROPS) set(HALIUM_SRC platform/halium.cpp ) endif() add_library(${TARGET} SHARED config.cpp device.cpp deviceinfo.cpp deviceinfo_c_api.cpp logger.cpp utils.cpp platform/platform.cpp platform/linux.cpp ${HALIUM_SRC} ) add_definitions(-DENABLE_LEGACY=1) add_definitions(-DCONFIG_PATH="${CONFIG_PATH}") add_definitions(-DDEVICES_PATH="${CONFIG_PATH}/devices") target_link_libraries(${TARGET} ${ANDROIDPROPS_LDFLAGS} ${YAMLCPP_LDFLAGS} ) set_target_properties( ${TARGET} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} SOVERSION ${VERSION_MAJOR} ) install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_LIBDIR}) deviceinfo-0.2.2/src/config.cpp000066400000000000000000000230131455450053100163670ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ // ENABLE_LEGACY set by cmake // CONFIG_PATH set by cmake // DEVICES_PATH set by cmake #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include "device.h" #include "deviceinfo.h" #include "logger.h" #include "utils.h" #include "platform/platform.h" namespace { std::string getConfigPath() { return utils::env::get(ENV_CONFIG_PATH, CONFIG_PATH); } std::string getDevicePath() { return utils::env::get(ENV_DEVICE_PATH, DEVICES_PATH); } std::string getDefaultFile() { return utils::path::join(getConfigPath(), DEFAULT_CONFIG_FILE); } }; Config::Config(std::shared_ptr platform) : m_platform(platform) { auto detectedName = utils::env::get(ENV_DEVICE_NAME, platform->name().c_str()); Log::debug("Detected name: %s", detectedName.c_str()); // Lets try to find the devices config auto devicePath = getDevicePath(); if (utils::path::exists(devicePath)) { DIR *dir; struct dirent *diread; std::vector files; if ((dir = opendir(devicePath.c_str())) != nullptr) { while ((diread = readdir(dir)) != nullptr && m_configNode.IsNull()) { if (!strcmp(diread->d_name, ".") || !strcmp(diread->d_name, "..")) continue; auto file = utils::path::join(devicePath, std::string(diread->d_name)); Log::verbose("Trying to load yaml file: %s", file.c_str()); auto yaml = YAML::LoadFile(file); for (auto a : yaml) { auto name = a.first.as(); if (a.first.IsDefined() && utils::string::compareInsensitive(name, detectedName)) { m_configNode = std::move(a.second); m_configNode["DetectedName"] = detectedName; if (!m_configNode["Name"].IsDefined()) m_configNode["Name"] = name; } else if (a.second["Names"].IsDefined()) { auto names = a.second["Names"].as>(); auto findNameFunc = [detectedName](std::string name){ return utils::string::compareInsensitive(name, detectedName); }; if (std::find_if(std::begin(names), std::end(names), findNameFunc) != std::end(names)) { m_configNode = std::move(a.second); m_configNode["DetectedName"] = detectedName; if (!m_configNode["Name"].IsDefined()) m_configNode["Name"] = name; } } } } closedir(dir); } } if (!m_configNode.IsNull()) Log::debug("Found device yaml with name: %s", m_configNode["Name"].as().c_str()); else Log::info("No device yaml config found!"); // Lets merge platfrom detected names // Override if valid if (m_platform->hasValidName() && !contains("Name")) m_configNode["Name"] = m_platform->name(); if (m_platform->hasValidPrettyName() && !contains("PrettyName")) m_configNode["PrettyName"] = m_platform->prettyName(); #ifdef ENABLE_LEGACY // Legacy should use raw detectedName as this is what the old bash script did. mergeLegacy(detectedName); #endif auto defaultPath = getDefaultFile(); if (utils::path::exists(defaultPath)) { Log::debug("Using %s for default config", defaultPath.c_str()); auto defaultNode = YAML::LoadFile(defaultPath)["defaults"]; // Lets merge all nodes to one // First we merge defaults from driverType auto driverType = DeviceInfo::driverTypeToString(m_platform->driverType()); mergeWithConfigNode(defaultNode[driverType]); std::string type = "desktop"; if (m_configNode["DeviceType"].IsDefined()) type = m_configNode["DeviceType"].as(); else if (defaultNode["default"]["DeviceType"].IsDefined()) type = defaultNode["default"]["DeviceType"].as(); mergeWithConfigNode(defaultNode[type]); mergeWithConfigNode(defaultNode["default"]); } else { Log::info("No default config found!"); } } void Config::mergeWithConfigNode(YAML::Node node) { for (auto n : node) { if (!m_configNode[n.first.as()].IsDefined()) { Log::debug("MergeWithConfigNode value: %s", n.first.as().c_str()); m_configNode[n.first.as()] = n.second; } } } bool Config::contains(std::string prop) { return m_configNode[prop].IsDefined(); } std::string Config::get(std::string prop) { return get(prop, ""); } std::string Config::get(std::string prop, std::string defaultValue) { if (!contains(prop)) return defaultValue; // TODO: allow to return vectors if (m_configNode[prop].IsSequence()) { std::string ret; auto siz = m_configNode[prop].size(); for (std::size_t i=0;i()); if (i >= siz-1) break; ret.append(","); } return ret; } return m_configNode[prop].as(); } #ifdef ENABLE_LEGACY // Legacy void Config::mergeLegacy(std::string device) { std::string dfile = utils::path::join(utils::env::get(ENV_LEGACY_PATH, LEGACY_PATH), device, ".conf"); if (!utils::path::exists(dfile)) { Log::debug("Did not find legacy file '%s', trying android.conf...", dfile.c_str()); dfile = utils::path::join(utils::env::get(ENV_LEGACY_PATH, LEGACY_PATH), "android.conf"); } if (!utils::path::exists(dfile)) { Log::debug("Did not find legacy file '%s'", dfile.c_str()); return; } std::ifstream file(dfile); std::string str; std::map legacyEnv; while (std::getline(file, str)) { auto splitted = utils::string::split(str, *"="); if (splitted.size() != 2) continue; if (utils::string::startsWith(splitted[1], "\"") && utils::string::endsWith(splitted[1], "\"")) splitted[1] = splitted[1].substr(1, splitted[1].size()-2); legacyEnv[splitted[0]] = splitted[1]; Log::verbose("Found legacy env %s = %s", splitted[0].c_str(), splitted[1].c_str()); } for (auto prop : legacyEnv) { auto keyAndTransfomer = fromLegacy(prop.first); auto key = std::get<0>(keyAndTransfomer); auto transformer = std::get<1>(keyAndTransfomer); if (!key.empty() && !contains(key)) { Log::debug("Merging legacy prop as it's not set by devicefile: %s", key.c_str()); auto newValue = transformer(prop.second); if (!newValue.empty()) m_configNode[key] = newValue; } } } // Return DeviceInfo config name & a function used to transform the value; std::tuple> Config::fromLegacy(std::string str) { const auto noneTransform = [](const std::string & value) { return value; }; Log::verbose("fromLegacy %s", str.c_str()); if (str == LEGACY_GRID) return std::make_tuple("GridUnit", noneTransform); if (str == LEGACY_DPR) return std::make_tuple("WebkitDpr", noneTransform); if (str == LEGACY_ORI) return std::make_tuple("PrimaryOrientation", noneTransform); if (str == LEGACY_FORM) return std::make_tuple("DeviceType", [](const std::string & legacy_value) { // Legacy config specifies it in terms of Hostnamed's chassis. // We, however, have our own values. if (legacy_value == "handset") { return std::string("phone"); } else if (legacy_value == "tablet") { return std::string("tablet"); } else if (legacy_value == "desktop" || legacy_value == "laptop" || legacy_value == "server") { // FIXME: DeviceInfo's enum is not expressive enough, but not really possible to // update it without breaking consumers. return std::string("desktop"); } else { // Unknown to us. Treated as if it's not set. Log::info("Unknown value for FORM_FACTOR: %s", legacy_value.c_str()); return std::string(); } }); return std::make_tuple(std::string(), noneTransform); } #endif deviceinfo-0.2.2/src/config.h000066400000000000000000000036241455450053100160420ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include #include #include #define DEFAULT_CONFIG_FILE "default.yaml" #define DEFAULT_SECTION "default" #define DEVICE_SECTION "device" #define ENV_CONFIG_PATH "DEVICEINFO_CONFIG_PATH" #define ENV_DEFAULT_CONFIG "DEVICEINFO_DEFAULT_CONFIG" #define ENV_DEVICE_PATH "DEVICEINFO_DEVICE_PATH" #define ENV_DEVICE_NAME "DEVICEINFO_DEVICE_NAME" #ifdef ENABLE_LEGACY #define LEGACY_GRID "GRID_UNIT_PX" #define LEGACY_DPR "QTWEBKIT_DPR" #define LEGACY_ORI "NATIVE_ORIENTATION" #define LEGACY_FORM "FORM_FACTOR" #define LEGACY_PATH "/etc/ubuntu-touch-session.d/" #define ENV_LEGACY_PATH "DEVICEINFO_LEGACY_PATH" #endif class Platform; class IniParser; class Config { public: Config(std::shared_ptr platform); std::string get(std::string prop, std::string defaultValue); std::string get(std::string prop); bool contains(std::string prop); private: void mergeWithConfigNode(YAML::Node node); #ifdef ENABLE_LEGACY void mergeLegacy(std::string device); std::tuple> fromLegacy(std::string str); #endif std::shared_ptr m_platform; YAML::Node m_configNode; }; deviceinfo-0.2.2/src/device.cpp000066400000000000000000000053101455450053100163610ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "device.h" #include "config.h" #include "logger.h" #include "platform/platform.h" #include #include #include #include #include #if HAVE_PROPS #include #endif // For hybris #define DEVICE_PROP_KEY "ro.product.device" #define MODEL_PROP_KEY "ro.product.model" #define VENDOR_DEVICE_PROP_KEY "ro.product.vendor.device" #define VENDOR_MODEL_PROP_KEY "ro.product.vendor.model" #define CHARA_PROP_KEY "ro.build.characteristics" // For linux #define LINUX_MODEL "/proc/device-tree/model" Device::Device() : m_platform(Platform::create()), m_config(std::make_shared(m_platform)) { } Device::Device(std::shared_ptr platform, std::shared_ptr config) : m_platform(platform), m_config(config) { } std::string Device::name() { // If all else fails, platform returns default value for the // current platform use this if config has no set value return m_config->get("Name", m_platform->name()); } std::string Device::prettyName() { // If all else fails, platform returns default value for the // current platform use this if config has no set value return m_config->get("PrettyName", m_platform->prettyName()); } int Device::gridUnit() { auto str = get("GridUnit", "8"); Log::verbose("Got gridunit str: %s", str.c_str()); try { return stoi(str); } catch(...) { Log::error("GridUnit IS NOT A VALID NUMBER got %s", str.c_str()); return 8; } } std::string Device::get(std::string prop, std::string defaultValue) { return m_config->get(prop, defaultValue); } bool Device::contains(std::string prop) { return m_config->contains(prop); } DeviceInfo::DeviceType Device::deviceType() { auto defaultValue = DeviceInfo::deviceTypeToString(m_platform->deviceType()); return DeviceInfo::deviceTypeFromString(m_config->get("DeviceType", defaultValue)); } DeviceInfo::DriverType Device::driverType() { return m_platform->driverType(); } deviceinfo-0.2.2/src/device.h000066400000000000000000000025201455450053100160260ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include "deviceinfo.h" class Config; class Platform; class Device { public: Device(); Device(std::shared_ptr platform, std::shared_ptr config); virtual std::string name(); virtual std::string prettyName(); virtual DeviceInfo::DeviceType deviceType(); virtual DeviceInfo::DriverType driverType(); virtual int gridUnit(); // get props that does not have auto detection virtual std::string get(std::string prop, std::string defaultValue); virtual bool contains(std::string prop); private: std::shared_ptr m_platform; std::shared_ptr m_config; }; deviceinfo-0.2.2/src/deviceinfo.cpp000066400000000000000000000077111455450053100172440ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "deviceinfo.h" #include "device.h" #include "logger.h" #include #include #include #define ENV_DEBUG "DEVICEINFO_DEBUG" DeviceInfo::DeviceInfo(PrintMode printMode) { setPrintMode(printMode); // Needs to happen after we set print mode m_device = std::make_shared(); } DeviceInfo::DeviceInfo(Device *device) { setPrintMode(PrintMode::Info); // Needs to happen after we set print mode m_device = std::shared_ptr(device, [](auto){}); } void DeviceInfo::setPrintMode(PrintMode printMode) { Logger::setMode(printMode); auto env = getenv(ENV_DEBUG); if (env) { try { Logger::setMode((PrintMode) std::stoi(env)); } catch(...){} } } std::string DeviceInfo::name() { return m_device->name(); } std::string DeviceInfo::prettyName() { return m_device->prettyName(); } DeviceInfo::DeviceType DeviceInfo::deviceType() { return m_device->deviceType(); } DeviceInfo::DriverType DeviceInfo::driverType() { return m_device->driverType(); } int DeviceInfo::gridUnit() { return m_device->gridUnit(); } std::string DeviceInfo::get(std::string prop, std::string defaultValue) { return m_device->get(prop, defaultValue); } bool DeviceInfo::contains(std::string prop) { return m_device->contains(prop); } std::vector DeviceInfo::supportedOrientations() { auto str = get("SupportedOrientations", "Portrait,InvertedPortrait,Landscape,InvertedLandscape"); std::vector ret; std::string tmp; std::istringstream istr(str); while (std::getline(istr, tmp, *",")) { ret.push_back(tmp); } return ret; } std::string DeviceInfo::primaryOrientation() { return get("PrimaryOrientation", "Portrait"); } std::string DeviceInfo::portraitOrientation() { return get("PortraitOrientation", "Portrait"); } std::string DeviceInfo::invertedPortraitOrientation() { return get("InvertedPortraitOrientation", "InvertedPortrait"); } std::string DeviceInfo::landscapeOrientation() { return get("LandscapeOrientation", "Landscape"); } std::string DeviceInfo::invertedLandscapeOrientation() { return get("InvertedLandscapeOrientation", "InvertedLandscape"); } std::string DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType type) { switch(type) { case DeviceInfo::DeviceType::Phone: return "phone"; case DeviceInfo::DeviceType::Tablet: return "tablet"; case DeviceInfo::DeviceType::Desktop: default: return "desktop"; } } DeviceInfo::DeviceType DeviceInfo::deviceTypeFromString(std::string str) { if (str == "phone") return DeviceInfo::DeviceType::Phone; if (str == "tablet") return DeviceInfo::DeviceType::Tablet; return DeviceInfo::DeviceType::Desktop; } std::string DeviceInfo::driverTypeToString(DeviceInfo::DriverType type) { switch(type) { case DeviceInfo::DriverType::Halium: return "halium"; case DeviceInfo::DriverType::Linux: default: return "linux"; } } DeviceInfo::DriverType DeviceInfo::driverTypeFromString(std::string str) { if (str == "halium") return DeviceInfo::DriverType::Halium; return DeviceInfo::DriverType::Linux; } deviceinfo-0.2.2/src/deviceinfo_c_api.cpp000066400000000000000000000040761455450053100204000ustar00rootroot00000000000000#include #include #include #include #ifdef __cplusplus extern "C" { #endif DeviceInfo* deviceinfo_new() { return new DeviceInfo(); } void deviceinfo_delete(DeviceInfo* instance) { delete instance; } static char* to_cstr(std::string& input) { char* cstr = strdup(input.c_str()); return cstr; } // libdeviceinfo function declarations char* deviceinfo_name(DeviceInfo* instance) { std::string str = instance->name(); return to_cstr(str); } char* deviceinfo_prettyName(DeviceInfo* instance) { std::string str = instance->prettyName(); return to_cstr(str); } int deviceinfo_gridUnit(DeviceInfo* instance) { return instance->gridUnit(); } bool deviceinfo_contains(DeviceInfo* instance, const char* prop) { return instance->contains(prop); } char* deviceinfo_get(DeviceInfo* instance, const char* prop, const char* defaultValue) { std::string str = instance->get(prop, defaultValue); return to_cstr(str); } char* deviceinfo_supportedOrientations(DeviceInfo* instance) { std::string str = instance->get("SupportedOrientations", "Portrait,InvertedPortrait,Landscape,InvertedLandscape"); return to_cstr(str); } char* deviceinfo_primaryOrientation(DeviceInfo* instance) { std::string str = instance->primaryOrientation(); return to_cstr(str); } char* deviceinfo_portraitOrientation(DeviceInfo* instance) { std::string str = instance->portraitOrientation(); return to_cstr(str); } char* deviceinfo_invertedPortraitOrientation(DeviceInfo* instance) { std::string str = instance->invertedPortraitOrientation(); return to_cstr(str); } char* deviceinfo_landscapeOrientation(DeviceInfo* instance) { std::string str = instance->landscapeOrientation(); return to_cstr(str); } char* deviceinfo_invertedLandscapeOrientation(DeviceInfo* instance) { std::string str = instance->invertedLandscapeOrientation(); return to_cstr(str); } int deviceinfo_deviceType(DeviceInfo* instance) { return instance->deviceType(); } int deviceinfo_driverType(DeviceInfo* instance) { return instance->driverType(); } #ifdef __cplusplus } // extern "C" #endif deviceinfo-0.2.2/src/logger.cpp000066400000000000000000000037361455450053100164130ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "logger.h" #include #include DeviceInfo::PrintMode Logger::m_mode = DeviceInfo::PrintMode::Info; void Logger::setMode(DeviceInfo::PrintMode mode) { m_mode = mode; } void Logger::log(DeviceInfo::PrintMode mode, std::string &format) { if (mode > m_mode) return; std::cout << "[" << modeToStr(mode) << "] " << format << std::endl; } void Logger::logv(DeviceInfo::PrintMode mode, char const* fmt, va_list va) { if (mode > m_mode) return; char message[1024]; int max = sizeof(message) - 1; int len = vsnprintf(message, max, fmt, va); if (len > max) len = max; message[len] = '\0'; std::cout << "[" << modeToStr(mode) << "] " << message << std::endl; } void Logger::log(DeviceInfo::PrintMode mode, char const* fmt, ...) { if (mode > m_mode) return; va_list va; va_start(va, fmt); logv(mode, fmt, va); va_end(va); } const char* Logger::modeToStr(DeviceInfo::PrintMode mode) { switch (mode) { case DeviceInfo::PrintMode::Error: return "error"; case DeviceInfo::PrintMode::Info: return "info"; case DeviceInfo::PrintMode::Debug: return "debug"; case DeviceInfo::PrintMode::Verbose: return "verbose"; default: return "wat"; } } deviceinfo-0.2.2/src/logger.h000066400000000000000000000042731455450053100160550ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include "deviceinfo.h" #include class Logger { public: static void setMode(DeviceInfo::PrintMode mode); static void log(DeviceInfo::PrintMode mode, std::string &format); static void logv(DeviceInfo::PrintMode mode, char const* fmt, va_list va); static void log(DeviceInfo::PrintMode mode, char const* fmt, ...); static const char* modeToStr(DeviceInfo::PrintMode mode); private: static DeviceInfo::PrintMode m_mode; }; class Log { public: static void error(std::string &m) { Logger::log(DeviceInfo::PrintMode::Error, m); } static void info(std::string &m) { Logger::log(DeviceInfo::PrintMode::Info, m); } static void debug(std::string &m) { Logger::log(DeviceInfo::PrintMode::Debug, m); } static void verbose(std::string &m) { Logger::log(DeviceInfo::PrintMode::Verbose, m); } template static void error(const char* fmt, Args&&... args) { Logger::log(DeviceInfo::PrintMode::Error, fmt, std::forward(args)...); } template static void info(const char* fmt, Args&&... args) { Logger::log(DeviceInfo::PrintMode::Info, fmt, std::forward(args)...); } template static void debug(const char* fmt, Args&&... args) { Logger::log(DeviceInfo::PrintMode::Debug, fmt, std::forward(args)...); } template static void verbose(const char* fmt, Args&&... args) { Logger::log(DeviceInfo::PrintMode::Verbose, fmt, std::forward(args)...); } }; deviceinfo-0.2.2/src/platform/000077500000000000000000000000001455450053100162435ustar00rootroot00000000000000deviceinfo-0.2.2/src/platform/halium.cpp000066400000000000000000000060001455450053100202220ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "halium.h" #include #include #include #include // Android props #define DEVICE_PROP_KEY "ro.product.device" #define MODEL_PROP_KEY "ro.product.model" #define VENDOR_DEVICE_PROP_KEY "ro.product.vendor.device" #define VENDOR_MODEL_PROP_KEY "ro.product.vendor.model" #define CHARA_PROP_KEY "ro.build.characteristics" std::string platform::Halium::name() { if (hasHaliumProp(VENDOR_DEVICE_PROP_KEY)) return getHaliumProp(VENDOR_DEVICE_PROP_KEY); else if (hasHaliumProp(DEVICE_PROP_KEY)) return getHaliumProp(DEVICE_PROP_KEY); return "unknown"; } bool platform::Halium::hasValidName() { return hasHaliumProp(VENDOR_DEVICE_PROP_KEY) || hasHaliumProp(DEVICE_PROP_KEY); } std::string platform::Halium::prettyName() { if (hasHaliumProp(VENDOR_MODEL_PROP_KEY)) return getHaliumProp(VENDOR_MODEL_PROP_KEY); else if (hasHaliumProp(MODEL_PROP_KEY)) return getHaliumProp(MODEL_PROP_KEY); return "unknown"; } bool platform::Halium::hasValidPrettyName() { return hasHaliumProp(VENDOR_MODEL_PROP_KEY) || hasHaliumProp(MODEL_PROP_KEY); } DeviceInfo::DeviceType platform::Halium::deviceType() { auto chara = getHaliumProp(CHARA_PROP_KEY); if (chara.find("tablet") != std::string::npos) return DeviceInfo::DeviceType::Tablet; // As this is a halium device, the best guess will be phone return DeviceInfo::DeviceType::Phone; } bool platform::Halium::hasValidDeviceType() { return hasHaliumProp(CHARA_PROP_KEY); } DeviceInfo::DriverType platform::Halium::driverType() { return DeviceInfo::DriverType::Halium; } std::string platform::Halium::getHaliumProp(const char* prop) { return getHaliumProp(prop, ""); } std::string platform::Halium::getHaliumProp(const char* prop, const char* default_value) { char value[PROP_VALUE_MAX]; property_get(prop, value, default_value); return std::string(value); } bool platform::Halium::hasHaliumProp(const char* key) { char const* default_value = "hasnodevice"; char value[PROP_VALUE_MAX]; property_get(key, value, default_value); return strcmp(value, default_value) != 0; } bool platform::Halium::usable() { return hasHaliumProp(VENDOR_DEVICE_PROP_KEY) || hasHaliumProp(DEVICE_PROP_KEY); } deviceinfo-0.2.2/src/platform/halium.h000066400000000000000000000025731455450053100177020ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include #include "platform.h" namespace platform { class Halium : public Platform { public: Halium() = default; std::string name() override; std::string prettyName() override; DeviceInfo::DeviceType deviceType() override; DeviceInfo::DriverType driverType() override; bool hasValidName() override; bool hasValidPrettyName() override; bool hasValidDeviceType() override; static bool usable(); private: std::string getHaliumProp(const char* prop); std::string getHaliumProp(const char* prop, const char* default_value);\ // Static as this is used by usable() static bool hasHaliumProp(const char* key); }; } deviceinfo-0.2.2/src/platform/linux.cpp000066400000000000000000000033551455450053100201140ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "linux.h" #include #include #include #include #include // dts based model #define LINUX_MODEL "/proc/device-tree/model" std::string platform::Linux::readFile(std::string file) { std::ifstream model(file); std::string ret; if (model.good()) ret = std::string(std::istreambuf_iterator{model}, std::istreambuf_iterator()); return ret; } std::string platform::Linux::name() { if (hasValidName()) { auto model = readFile(LINUX_MODEL); if (!model.empty()) return model; } return "generic-linux"; } bool platform::Linux::hasValidName() { return access(LINUX_MODEL, F_OK) != -1; } // Just returns default value std::string platform::Linux::prettyName() { return "Generic linux device"; } DeviceInfo::DeviceType platform::Linux::deviceType() { return DeviceInfo::DeviceType::Unknown; } DeviceInfo::DriverType platform::Linux::driverType() { return DeviceInfo::DriverType::Linux; } deviceinfo-0.2.2/src/platform/linux.h000066400000000000000000000022151455450053100175530ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include "platform.h" #include namespace platform { class Linux : public Platform { public: Linux() = default; std::string name() override; std::string prettyName() override; DeviceInfo::DeviceType deviceType() override; DeviceInfo::DriverType driverType() override; bool hasValidName() override; static bool usable() { return true; }; private: std::string readFile(std::string file); }; } deviceinfo-0.2.2/src/platform/platform.cpp000066400000000000000000000020241455450053100205710ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "platform.h" #include "linux.h" #ifdef HAVE_PROPS # include "halium.h" #endif std::shared_ptr Platform::create() { #ifdef HAVE_PROPS if (platform::Halium::usable()) return std::make_shared(); #endif // Linux is our fallback return std::make_shared(); } deviceinfo-0.2.2/src/platform/platform.h000066400000000000000000000024101455450053100202350ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include #include "deviceinfo.h" class Platform { public: Platform() = default; virtual std::string name() = 0; virtual std::string prettyName() = 0; virtual DeviceInfo::DeviceType deviceType() = 0; virtual DeviceInfo::DriverType driverType() = 0; // Checks if the value returned is valid or default value virtual bool hasValidName() { return false; }; virtual bool hasValidPrettyName() { return false; }; virtual bool hasValidDeviceType() { return false; }; static std::shared_ptr create(); }; deviceinfo-0.2.2/src/utils.cpp000066400000000000000000000057421455450053100162730ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "utils.h" #include "logger.h" #include #include namespace utils { namespace path { std::string join(std::string first, std::string second) { if (first.back() != '/') first.append("/"); first.append(second); return first; } std::string join(std::string first, std::string file, std::string suffix) { auto path = join(first, file); path.append(suffix); return path; } std::string join(std::string first, std::string second, std::string file, std::string suffix) { return join(join(first, second), file, suffix); } bool exists(std::string name) { Log::verbose("Seeing if %s exists", name.c_str()); std::ifstream infile(name); return infile.good(); } }; // path namespace env { std::string get(const char *name, std::string dval) { const char* env = getenv(name); if (env) { Log::verbose("Using provided env %s", env); return std::string(env); } return dval; } bool set(const char *name, std::string val, bool overwrite) { return setenv(name, val.c_str(), overwrite) == 0; } bool unset(const char *name) { return unsetenv(name) == 0; } }; // env namespace string { std::vector split(std::string strToSplit, char delimeter) { std::stringstream ss(strToSplit); std::string item; std::vector splittedStrings; while (std::getline(ss, item, delimeter)) { splittedStrings.push_back(item); } return splittedStrings; } // string bool endsWith(const std::string& str, const std::string& suffix) { return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix); } bool startsWith(const std::string& str, const std::string& prefix) { return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix); } // Not perfect as it will only handle C chars // It's also created to optimize performance this is why we dont do // std::transform on both and then do == on the results. bool compareInsensitive(const std::string& str1, const std::string& str2) { auto size = str1.size(); if (str2.size() != size) return false; for (auto i = 0; i < size; ++i) if (tolower(str1[i]) != tolower(str2[i])) return false; return true; } }; }; // utils deviceinfo-0.2.2/src/utils.h000066400000000000000000000034571455450053100157410ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #pragma once #include #include namespace utils { namespace path { std::string join(std::string first, std::string second); std::string join(std::string first, std::string file, std::string suffix); std::string join(std::string first, std::string second, std::string file, std::string suffix); bool exists(std::string name); }; // path namespace env { std::string get(const char *name, std::string dval = ""); bool set(const char *name, std::string val, bool overwrite = true); bool unset(const char *name); class SetUnsetAfter { public: SetUnsetAfter(const char *name, std::string val, bool overwrite = true) : name_(name) { set(name_, val, overwrite); }; ~SetUnsetAfter() { unset(name_); }; private: const char *name_; }; }; // env namespace string { std::vector split(std::string strToSplit, char delimeter); bool endsWith(const std::string& str, const std::string& suffix); bool startsWith(const std::string& str, const std::string& prefix); bool compareInsensitive(const std::string& str1, const std::string& str2); }; // string }; // utils deviceinfo-0.2.2/tests/000077500000000000000000000000001455450053100147725ustar00rootroot00000000000000deviceinfo-0.2.2/tests/CMakeLists.txt000066400000000000000000000001031455450053100175240ustar00rootroot00000000000000find_package(GMock) add_subdirectory(data) add_subdirectory(unit) deviceinfo-0.2.2/tests/data/000077500000000000000000000000001455450053100157035ustar00rootroot00000000000000deviceinfo-0.2.2/tests/data/CMakeLists.txt000066400000000000000000000000751455450053100204450ustar00rootroot00000000000000 set(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) deviceinfo-0.2.2/tests/data/android.conf000066400000000000000000000002201455450053100201640ustar00rootroot00000000000000GRID_UNIT_PX=24 QTWEBKIT_DPR=2.7 NATIVE_ORIENTATION=InvertedPortrait FORM_FACTOR="tablet" IGNORE="S" # garbage jkl2' '3k 6' 4'23' 54k6j 6j32;l3 deviceinfo-0.2.2/tests/data/default.yaml000066400000000000000000000015551455450053100202210ustar00rootroot00000000000000defaults: default: Name: generic PrettyName: Generic device DeviceType: desktop GridUnit: 8 SupportedOrientations: - Portrait - InvertedPortrait - Landscape - InvertedLandscape PrimaryOrientation: Landscape PortraitOrientation: Portrait InvertedPortraitOrientation: InvertedPortrait LandscapeOrientation: Landscape InvertedLandscapeOrientation: InvertedLandscape WebkitDpr: 1 halium: Name: generic PrettyName: Generic Halium device DeviceType: phone GridUnit: 21 WebkitDpr: 2 SensorfwConfig: /etc/deviceinfo/sensorfw/hybris.conf PrimaryOrientation: Portrait phone: GridUnit: 21 WebkitDpr: 2 PrimaryOrientation: Portrait tablet: GridUnit: 21 WebkitDpr: 2 PrimaryOrientation: Landscape desktop: GridUnit: 8 PrimaryOrientation: Landscape deviceinfo-0.2.2/tests/data/devices/000077500000000000000000000000001455450053100173255ustar00rootroot00000000000000deviceinfo-0.2.2/tests/data/devices/bigdevice.yaml000066400000000000000000000000001455450053100221200ustar00rootroot00000000000000deviceinfo-0.2.2/tests/data/devices/device1.yaml000066400000000000000000000001671455450053100215350ustar00rootroot00000000000000device1: Names: - device1-alias1 - device1-alias2 PrettyName: Device 1 DeviceType: phone GridUnit: 18 deviceinfo-0.2.2/tests/data/devices/invalid.yaml000066400000000000000000000000001455450053100216250ustar00rootroot00000000000000deviceinfo-0.2.2/tests/data/devices/vendor1.yaml000066400000000000000000000007551455450053100215760ustar00rootroot00000000000000default: GridUnit: 5 Vendor: Vendor 1 vendor1-device3: Names: - vendor1-device3-alias1 - vendor1-device3-alias2 PrettyName: Vendor 1 Device 3 DeviceType: phone GridUnit: 18 vendor1-device1: Names: - vendor1-device1-alias1 - vendor1-device1-alias2 PrettyName: Vendor 1 Device 1 DeviceType: tablet GridUnit: 10 random-device503: Names: - random-device503-alias1 - random-device503-alias2 PrettyName: Random device 503 DeviceType: desktop deviceinfo-0.2.2/tests/data/legacy.conf000066400000000000000000000002551455450053100200200ustar00rootroot00000000000000GRID_UNIT_PX=16 QTWEBKIT_DPR=1.8 NATIVE_ORIENTATION=InvertedLandscape # Use Hostnamed convention FORM_FACTOR="handset" IGNORE="S" # garbage jkl2' '3k 6' 4'23' 54k6j 6j32;l3 deviceinfo-0.2.2/tests/unit/000077500000000000000000000000001455450053100157515ustar00rootroot00000000000000deviceinfo-0.2.2/tests/unit/CMakeLists.txt000066400000000000000000000022061455450053100205110ustar00rootroot00000000000000include_directories( ${CMAKE_SOURCE_DIR}/src ${GMOCK_INCLUDE_DIRS} ) add_definitions(-DENABLE_LEGACY=1) add_definitions(-DTEST_DEFAULT_DIR="${TEST_DATA_DIR}") add_definitions(-DTEST_DEVICE_DIR="${TEST_DATA_DIR}/devices") macro(declare_test test testname) add_executable(${testname} ${testname}.cpp) target_link_libraries(${testname} ${TARGET} ${GTEST_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARIES} ) if(TEST_XML_OUTPUT) set(TEST_ARGS -p -xunitxml -p -o -p ${testname}.xml) else() set(TEST_ARGS "") endif() add_test(${test} ${testname}) #set_tests_properties(${testname} PROPERTIES # TIMEOUT ${CTEST_TESTING_TIMEOUT} # ENVIRONMENT "QT_QPA_PLATFORM=minimal") set(TESTS ${TESTS} ${testname}) endmacro(declare_test testname) declare_test(TestConfig tst_config) declare_test(TestDeviceinfo tst_deviceinfo) declare_test(TestUtils tst_utils) find_package(CoverageReport) enable_coverage_report( TARGETS deviceinfo FILTER ${CMAKE_SOURCE_DIR}/tests/* ${CMAKE_BINARY_DIR}/* TESTS ${TESTS} ) deviceinfo-0.2.2/tests/unit/mock_device.h000066400000000000000000000021761455450053100204000ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include "device.h" class MockDevice : public Device { public: MOCK_METHOD0(name, std::string()); MOCK_METHOD0(prettyName, std::string()); MOCK_METHOD0(deviceType, DeviceInfo::DeviceType()); MOCK_METHOD0(driverType, DeviceInfo::DriverType()); MOCK_METHOD0(gridUnit, int()); MOCK_METHOD2(get, std::string(std::string, std::string)); MOCK_METHOD1(contains, bool(std::string)); }; deviceinfo-0.2.2/tests/unit/mock_platform.h000066400000000000000000000043331455450053100207620ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include "platform/platform.h" class MockPlatform : public Platform { public: MOCK_METHOD0(name, std::string()); MOCK_METHOD0(prettyName, std::string()); MOCK_METHOD0(deviceType, DeviceInfo::DeviceType()); MOCK_METHOD0(driverType, DeviceInfo::DriverType()); MOCK_METHOD0(hasValidName, bool()); MOCK_METHOD0(hasValidPrettyName, bool()); MOCK_METHOD0(hasValidDeviceType, bool()); }; class DummyPlatform : public Platform { public: DummyPlatform() {}; DummyPlatform(std::string name, std::string pName) : m_name(name), m_pName(pName) {}; DummyPlatform(std::string name, std::string pName, DeviceInfo::DeviceType deType, DeviceInfo::DriverType drType) : m_name(name), m_pName(pName), m_deType(deType), m_drType(drType) {}; std::string name() override { return m_name; }; std::string prettyName() override { return m_pName; }; DeviceInfo::DeviceType deviceType() override { return m_deType; }; DeviceInfo::DriverType driverType() override { return m_drType; }; bool hasValidName() override { return !m_name.empty(); }; bool hasValidPrettyName() override { return !m_pName.empty(); }; bool hasValidDeviceType() override { return m_deType != DeviceInfo::DeviceType::Unknown; }; private: std::string m_name; std::string m_pName; DeviceInfo::DeviceType m_deType; DeviceInfo::DriverType m_drType; }; deviceinfo-0.2.2/tests/unit/tst_config.cpp000066400000000000000000000214021455450053100206130ustar00rootroot00000000000000/* * Copyright (C) 2020 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include #include "config.h" #include "logger.h" #include "mock_platform.h" class BaseConfigTest : public ::testing::Test { public: BaseConfigTest() { Logger::setMode(DeviceInfo::PrintMode::Verbose); unsetenv(ENV_CONFIG_PATH); unsetenv(ENV_DEFAULT_CONFIG); unsetenv(ENV_DEVICE_PATH); unsetenv(ENV_DEVICE_NAME); unsetenv(ENV_LEGACY_PATH); } }; class DefaultsConfigTest : public BaseConfigTest { public: DefaultsConfigTest() : BaseConfigTest() { setenv(ENV_CONFIG_PATH, TEST_DEFAULT_DIR, true); } }; class DeviceConfigTest : public BaseConfigTest { public: DeviceConfigTest() : BaseConfigTest() { setenv(ENV_DEVICE_PATH, TEST_DEVICE_DIR, true); } }; class DeviceDefaultConfigTest : public DefaultsConfigTest { public: DeviceDefaultConfigTest() : DefaultsConfigTest() { setenv(ENV_DEVICE_PATH, TEST_DEVICE_DIR, true); } }; class CommonConfigTest : public DeviceDefaultConfigTest { public: CommonConfigTest() : DeviceDefaultConfigTest(), m_platform(std::make_shared("vendor1-device1", "Dummy Device")), m_config(std::make_shared(m_platform)) {}; std::shared_ptr config() { return m_config; }; private: std::shared_ptr m_platform; std::shared_ptr m_config; }; TEST_F(BaseConfigTest, checkNoConfigFallbackValue) { auto platform = std::make_shared(); auto config = std::make_shared(platform); // As long as we dont provide any default files // We should not "contain" anything info EXPECT_FALSE(config->contains("Name")); EXPECT_FALSE(config->contains("PrettyName")); // Test that get retruns "default" provided fallback value EXPECT_EQ(config->get("Name", "NoName"), "NoName"); EXPECT_EQ(config->get("PrettyName", "No Name"), "No Name"); } TEST_F(DefaultsConfigTest, checkDefaultsNoDeviceFound) { auto platform = std::make_shared(); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "generic"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Generic device"); } TEST_F(BaseConfigTest, checkPlatformDefaults) { auto platform = std::make_shared("Dummy", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "Dummy"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Dummy Device"); } TEST_F(DeviceConfigTest, checkContains) { auto platform = std::make_shared("Dummy", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_FALSE(config->contains("ddssdsd")); EXPECT_FALSE(config->contains("343543257'[;p-;a")); EXPECT_FALSE(config->contains("435r 6 23k'le[ =-r0-thioj23d m,")); } TEST_F(DeviceConfigTest, testDeviceConfigOnly) { auto platform = std::make_shared("device1", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "device1"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Device 1"); } TEST_F(DeviceConfigTest, testVendorConfigOnly) { auto platform = std::make_shared("vendor1-device1", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "vendor1-device1"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Vendor 1 Device 1"); } TEST_F(DeviceDefaultConfigTest, testDeviceOverridesDefault) { auto platform = std::make_shared("vendor1-device1", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name"), "vendor1-device1"); EXPECT_TRUE(config->contains("DetectedName")); EXPECT_EQ(config->get("DetectedName"), "vendor1-device1"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName"), "Vendor 1 Device 1"); } TEST_F(DeviceDefaultConfigTest, testDeviceAlias) { auto platform = std::make_shared("device1-alias2", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name"), "device1"); EXPECT_TRUE(config->contains("DetectedName")); EXPECT_EQ(config->get("DetectedName"), "device1-alias2"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName"), "Device 1"); } TEST_F(DeviceDefaultConfigTest, testVectorGet) { auto platform = std::make_shared("vendor1-device1", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("SupportedOrientations")); EXPECT_EQ(config->get("SupportedOrientations"), "Portrait,InvertedPortrait,Landscape,InvertedLandscape"); } TEST_F(DeviceDefaultConfigTest, testGetMoDefault) { auto platform = std::make_shared("vendor1-device1", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name"), "vendor1-device1"); } TEST_F(DefaultsConfigTest, testLegacyProps) { setenv(ENV_LEGACY_PATH, TEST_DEFAULT_DIR, true); auto platform = std::make_shared("legacy", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("GridUnit")); EXPECT_EQ(config->get("GridUnit"), "16"); EXPECT_TRUE(config->contains("WebkitDpr")); EXPECT_EQ(config->get("WebkitDpr"), "1.8"); EXPECT_TRUE(config->contains("PrimaryOrientation")); EXPECT_EQ(config->get("PrimaryOrientation"), "InvertedLandscape"); // Special case: convert between Hostnamed & DeviceInfo convention. EXPECT_TRUE(config->contains("DeviceType")); EXPECT_EQ(config->get("DeviceType"), "phone"); } // Test fallback of legacy prop reader to "android.conf", as used for bind mounting // from a system.img-based ports. TEST_F(DefaultsConfigTest, testLegacyPropsFallback) { setenv(ENV_LEGACY_PATH, TEST_DEFAULT_DIR, true); auto platform = std::make_shared("legacy2", "Dummy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("GridUnit")); EXPECT_EQ(config->get("GridUnit"), "24"); EXPECT_TRUE(config->contains("WebkitDpr")); EXPECT_EQ(config->get("WebkitDpr"), "2.7"); EXPECT_TRUE(config->contains("PrimaryOrientation")); EXPECT_EQ(config->get("PrimaryOrientation"), "InvertedPortrait"); EXPECT_TRUE(config->contains("DeviceType")); EXPECT_EQ(config->get("DeviceType"), "tablet"); } TEST_F(DeviceConfigTest, testDeviceMachingCaseInsensitiv) { auto platform = std::make_shared("DeVIce1", "DuMMy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "device1"); EXPECT_TRUE(config->contains("DetectedName")); EXPECT_EQ(config->get("DetectedName", ""), "DeVIce1"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Device 1"); } TEST_F(DeviceConfigTest, testDeviceMachingCaseInsensitivAlias) { auto platform = std::make_shared("DevICE1-aLiAs1", "DuMMy Device"); auto config = std::make_shared(platform); EXPECT_TRUE(config->contains("Name")); EXPECT_EQ(config->get("Name", ""), "device1"); EXPECT_TRUE(config->contains("DetectedName")); EXPECT_EQ(config->get("DetectedName", ""), "DevICE1-aLiAs1"); EXPECT_TRUE(config->contains("PrettyName")); EXPECT_EQ(config->get("PrettyName", ""), "Device 1"); } deviceinfo-0.2.2/tests/unit/tst_deviceinfo.cpp000066400000000000000000000075301455450053100214670ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include "deviceinfo.h" #include "mock_device.h" #define TEST_RETURN_FUCS(name, func, func2, ret) \ TEST(DeviceInfoTest, test##name) \ { \ MockDevice device; \ EXPECT_CALL(device, func2) \ .Times(1) \ .WillOnce(::testing::Return(ret)); \ \ DeviceInfo di(&device); \ \ EXPECT_EQ(di.func, ret); \ } TEST_RETURN_FUCS(Name, name(), name(), "a") TEST_RETURN_FUCS(PrettyName, prettyName(), prettyName(), "a") TEST_RETURN_FUCS(DeviceType, deviceType(), deviceType(), DeviceInfo::DeviceType::Tablet) TEST_RETURN_FUCS(DriverType, driverType(), driverType(), DeviceInfo::DriverType::Halium) TEST_RETURN_FUCS(GridUnit, gridUnit(), gridUnit(), 16) TEST_RETURN_FUCS(Get, get("", ""), get("", ""), "a") TEST_RETURN_FUCS(Contains, contains(""), contains(""), true) TEST(DeviceInfoTest, testSupportedOrientations) { MockDevice device; EXPECT_CALL(device, get("SupportedOrientations", "Portrait,InvertedPortrait,Landscape,InvertedLandscape")) .Times(1) .WillOnce(::testing::Return("Portrait,InvertedPortrait,Landscape,InvertedLandscape")); DeviceInfo di(&device); EXPECT_EQ(di.supportedOrientations(), (std::vector{"Portrait", "InvertedPortrait", "Landscape", "InvertedLandscape"})); } TEST_RETURN_FUCS(PrimaryOrientation, primaryOrientation(), get("PrimaryOrientation", "Portrait"), "a") TEST_RETURN_FUCS(PortraitOrientation, portraitOrientation(), get("PortraitOrientation", "Portrait"), "a") TEST_RETURN_FUCS(InvertedPortraitOrientation, invertedPortraitOrientation(), get("InvertedPortraitOrientation", "InvertedPortrait"), "a") TEST_RETURN_FUCS(LandscapeOrientation, landscapeOrientation(), get("LandscapeOrientation", "Landscape"), "a") TEST_RETURN_FUCS(InvertedLandscapeOrientation, invertedLandscapeOrientation(), get("InvertedLandscapeOrientation", "InvertedLandscape"), "a") TEST(DeviceInfoTest, testDeviceTypeToString) { EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Phone), "phone"); EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Tablet), "tablet"); EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Desktop), "desktop"); } TEST(DeviceInfoTest, testdeviceTypeFromString) { EXPECT_EQ(DeviceInfo::deviceTypeFromString("phone"), DeviceInfo::DeviceType::Phone); EXPECT_EQ(DeviceInfo::deviceTypeFromString("tablet"), DeviceInfo::DeviceType::Tablet); EXPECT_EQ(DeviceInfo::deviceTypeFromString("desktop"), DeviceInfo::DeviceType::Desktop); } TEST(DeviceInfoTest, testDriverTypeToString) { EXPECT_EQ(DeviceInfo::driverTypeToString(DeviceInfo::DriverType::Halium), "halium"); EXPECT_EQ(DeviceInfo::driverTypeToString(DeviceInfo::DriverType::Linux), "linux"); } TEST(DeviceInfoTest, testDriverTypeFromString) { EXPECT_EQ(DeviceInfo::driverTypeFromString("halium"), DeviceInfo::DriverType::Halium); EXPECT_EQ(DeviceInfo::driverTypeFromString("linux"), DeviceInfo::DriverType::Linux); } deviceinfo-0.2.2/tests/unit/tst_utils.cpp000066400000000000000000000055101455450053100205100ustar00rootroot00000000000000/* * Copyright (C) 2021 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include #include "utils.h" TEST(UtilsTest, testSplitString) { auto spl = utils::string::split("1:2:3dfdf3:5", ':'); EXPECT_EQ(spl, (std::vector{ "1", "2", "3dfdf3", "5" })); } TEST(UtilsTest, testEndsWith) { EXPECT_TRUE(utils::string::endsWith("this end with", "with")); EXPECT_FALSE(utils::string::endsWith("this end with not", "with")); } TEST(UtilsTest, testStartsWith) { EXPECT_TRUE(utils::string::startsWith("this end with", "this")); EXPECT_FALSE(utils::string::startsWith("this end with not", "with")); } TEST(UtilsTest, testCompareInsensitive) { // Test for match EXPECT_TRUE(utils::string::compareInsensitive("this should be equal", "ThIs ShOuLd BE eQuAl")); // Test for diff size EXPECT_FALSE(utils::string::compareInsensitive("this", "not equal")); // Test no match same size EXPECT_FALSE(utils::string::compareInsensitive("t", "q")); // Test for odd chars (Å is not a valid insensetive match) EXPECT_TRUE(utils::string::compareInsensitive(":#*&(%(*#)_(^%()@#(_*#* ÅFHJF", ":#*&(%(*#)_(^%()@#(_*#* Åfhjf")); } TEST(UtilsTest, testJoin) { auto str = utils::path::join("this", "that"); EXPECT_EQ(str, "this/that"); } TEST(UtilsTest, testJoinSuffix) { auto str = utils::path::join("this", "that", ".end"); EXPECT_EQ(str, "this/that.end"); } TEST(UtilsTest, testJoinFileSuffix) { auto str = utils::path::join("this", "that", "file", ".end"); EXPECT_EQ(str, "this/that/file.end"); } TEST(UtilsTest, testEnvGet) { utils::env::SetUnsetAfter setUnset("DEVICEINFO_TESTING_ENV", "test_this"); EXPECT_EQ(utils::env::get("DEVICEINFO_TESTING_ENV"), "test_this"); } TEST(UtilsTest, testEnvSetAndUnset) { EXPECT_TRUE(utils::env::set("DEVICEINFO_TESTING_ENV", "test_this")); EXPECT_EQ(utils::env::get("DEVICEINFO_TESTING_ENV"), "test_this"); EXPECT_TRUE(utils::env::unset("DEVICEINFO_TESTING_ENV")); EXPECT_EQ(utils::env::get("DEVICEINFO_TESTING_ENV"), ""); } TEST(UtilsTest, testEnvGetNoVal) { EXPECT_EQ(utils::env::get("DEVICEINFO_TESTING_ENV", "test_no_val"), "test_no_val"); } deviceinfo-0.2.2/tools/000077500000000000000000000000001455450053100147705ustar00rootroot00000000000000deviceinfo-0.2.2/tools/CMakeLists.txt000066400000000000000000000002421455450053100175260ustar00rootroot00000000000000add_executable(device-info device-info.cpp ) target_link_libraries(device-info deviceinfo) install(TARGETS device-info DESTINATION ${CMAKE_INSTALL_BINDIR}) deviceinfo-0.2.2/tools/device-info.1000066400000000000000000000014121455450053100172400ustar00rootroot00000000000000.TH device\-info "1" "Jan 2024" "0.2.2" "Device info" .SH NAME device\-info \- Tool to query Device Information via libdeviceinfo .SH SYNOPSIS \fB\,device\-info\/\fR \fI[get ]\fR .SH DESCRIPTION \fBdevice\-info\fR is a command line tool leveraging libdeviceinfo to query some information of the local device. .PP \fBdevice\-info\fR can be used without any option given. It then retrieves all available info and prints that to stdout. .PP Alternatively, it is possible to retrieve one specific device property (see OPTIONS). .SH OPTIONS .TP \fBget\fR \fI\fR Retrieve the device info for a specific property . .SH AUTHOR This man page has been written for the UBports project by Mike Gabriel and may be re-used by others. deviceinfo-0.2.2/tools/device-info.cpp000066400000000000000000000101511455450053100176620ustar00rootroot00000000000000/* * Copyright (C) 2019 UBports foundation. * Author(s): Marius Gripsgard * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3, as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "deviceinfo.h" #include #include #include #include void print(std::string str) { std::cout << str << std::endl; } int get(std::string arg, std::shared_ptr info) { if (arg == "Name") { print(info->name()); return 0; } if (arg == "PrettyName") { print(info->prettyName()); return 0; } if (arg == "DeviceType") { print(DeviceInfo::deviceTypeToString(info->deviceType())); return 0; } if (arg == "DriverType") { print(DeviceInfo::driverTypeToString(info->driverType())); return 0; } if (arg == "GridUnit") { print(std::to_string(info->gridUnit())); return 0; } if (arg == "SupportedOrientations") { for (auto r : info->supportedOrientations()) print(r); return 0; } if (arg == "PrimaryOrientation") { print(info->primaryOrientation()); return 0; } if (arg == "PortraitOrientation") { print(info->portraitOrientation()); return 0; } if (arg == "InvertedPortraitOrientation") { print(info->invertedPortraitOrientation()); return 0; } if (arg == "LandscapeOrientation") { print(info->landscapeOrientation()); return 0; } if (arg == "InvertedLandscapeOrientation") { print(info->invertedLandscapeOrientation()); return 0; } if (arg == "GridUnit") { print(std::to_string(info->gridUnit())); return 0; } if (info->contains(arg)) { print(info->get(arg, "")); return 0; } print("Unknown prop"); return 1; } int printAboutMe(std::shared_ptr info) { std::cout << " -- About this device --" << std::endl; std::cout << "Name: " << info->name() << std::endl; std::cout << "PrettyName: " << info->prettyName() << std::endl; std::cout << "DeviceType: " << DeviceInfo::deviceTypeToString(info->deviceType()) << std::endl; std::cout << "DriverType: " << DeviceInfo::driverTypeToString(info->driverType()) << std::endl; std::cout << "GridUnit: " << info->gridUnit() << std::endl; std::cout << "SupportedOrientations: "; for (auto r : info->supportedOrientations()) std::cout << r << " "; std::cout << std::endl; std::cout << "PrimaryOrientation: " << info->primaryOrientation() << std::endl; std::cout << "PortraitOrientation: " << info->portraitOrientation() << std::endl; std::cout << "InvertedPortraitOrientation: " << info->invertedPortraitOrientation() << std::endl; std::cout << "LandscapeOrientation: " << info->landscapeOrientation() << std::endl; std::cout << "InvertedLandscapeOrientation: " << info->invertedLandscapeOrientation() << std::endl; return 0; } void help() { print("device-info usage:"); print(" - device-info - list all about device"); print(" - device-info get [prop] - get specific prop"); } int main (int argc, char *argv[]) { if (argc == 1) { return printAboutMe(std::make_shared()); } else if (argc == 3) { std::string argv1 = argv[1]; if (argv1 == "get") { // We shoud not log anything as that might mess with scripts using this return get(std::string(argv[2]), std::make_shared(DeviceInfo::PrintMode::None)); } // TODO: add set function } help(); return 1; }