Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85e0e610 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Refine dumpEffectConfigFile with getopt replace strcpy with strlcpy"...

Merge "Refine dumpEffectConfigFile with getopt replace strcpy with strlcpy" am: 823009fc am: a4f6c2a1

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2592067



Change-Id: I3ff381308096bcb0a5e6825ded1957ad8fb9d8a5
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f35df28a a4f6c2a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -137,7 +137,7 @@ int checkLibraryPath(const char *lib_path_in, char *lib_path_out) {
                 kLibraryPathRoot[i],
                 kLibraryPathRoot[i],
                 lib_name);
                 lib_name);
        if (F_OK == access(path, 0)) {
        if (F_OK == access(path, 0)) {
            strcpy(lib_path_out, path);
            strlcpy(lib_path_out, path, PATH_MAX);
            ALOGW_IF(strncmp(lib_path_out, lib_path_in, PATH_MAX) != 0,
            ALOGW_IF(strncmp(lib_path_out, lib_path_in, PATH_MAX) != 0,
                "checkLibraryPath() corrected library path %s to %s", lib_path_in, lib_path_out);
                "checkLibraryPath() corrected library path %s to %s", lib_path_in, lib_path_out);
            return 0;
            return 0;
+35 −40
Original line number Original line Diff line number Diff line
@@ -14,54 +14,49 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <getopt.h>

#include <media/EffectsFactoryApi.h>
#include <media/EffectsFactoryApi.h>
#include <unistd.h>
#include "EffectsXmlConfigLoader.h"
#include "EffectsXmlConfigLoader.h"
#include "EffectsConfigLoader.h"
#include "EffectsConfigLoader.h"


int main(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
    const char* path = nullptr;
    const char* const short_opts = "lx:h";
    bool legacyFormat;
    const option long_opts[] = {{"legacy", no_argument, nullptr, 'l'},
                                {"xml", optional_argument, nullptr, 'x'},
                                {"help", no_argument, nullptr, 'h'}};


    if (argc == 2 && strcmp(argv[1], "--legacy") == 0) {
    const auto opt = getopt_long(argc, argv, short_opts, long_opts, nullptr);
        legacyFormat = true;
    switch (opt) {
        fprintf(stderr, "Dumping legacy effect config file\n");
        case 'l': { // -l or --legacy
    } else if ((argc == 2 || argc == 3) && strcmp(argv[1], "--xml") == 0) {
            printf("Dumping legacy effect config file\n");
        legacyFormat = false;
            if (EffectLoadEffectConfig() < 0) {
        if (argc == 3) {
                fprintf(stderr, "loadEffectConfig failed, see logcat for detail.\n");
            fprintf(stderr, "Dumping XML effect config file: %s\n", path);
        } else {
            fprintf(stderr, "Dumping default XML effect config file.\n");
        }
    } else {
        fprintf(stderr, "Invalid arguments.\n"
                        "Usage: %s [--legacy|--xml [FILE]]\n", argv[0]);
                return 1;
                return 1;
            }
            }

            return EffectDumpEffects(STDOUT_FILENO);
    if (!legacyFormat) {
        }
        ssize_t ret = EffectLoadXmlEffectConfig(path);
        case 'x': { // -x or --xml
            printf("Dumping effect config file: %s\n", (optarg == NULL) ? "default" : optarg);
            ssize_t ret = EffectLoadXmlEffectConfig(optarg);
            if (ret < 0) {
            if (ret < 0) {
                fprintf(stderr, "loadXmlEffectConfig failed, see logcat for detail.\n");
                fprintf(stderr, "loadXmlEffectConfig failed, see logcat for detail.\n");
            return 2;
                return 1;
            }
            }
            if (ret > 0) {
            if (ret > 0) {
            fprintf(stderr, "Partially failed to load config. Skipped %zu elements, "
                printf("Partially failed to load config. Skipped %zu elements.\n",
                    "see logcat for detail.\n", (size_t)ret);
                        (size_t)ret);
            }
            }
            return EffectDumpEffects(STDOUT_FILENO);
        }
        }

        case 'h': // -h or --help
    if (legacyFormat) {
        default: {
        auto ret = EffectLoadEffectConfig();
            printf("Usage: %s\n"
        if (ret < 0) {
                   "--legacy (or -l):        Legacy audio effect config file to load\n"
            fprintf(stderr, "loadEffectConfig failed, see logcat for detail.\n");
                   "--xml (or -x) <FILE>:    Audio effect config file to load\n"
            return 3;
                   "--help (or -h):          Show this help\n",
                   argv[0]);
            return 0;
        }
        }
        fprintf(stderr, "legacy loadEffectConfig has probably succeed, see logcat to make sure.\n");
    }

    if (EffectDumpEffects(STDOUT_FILENO) != 0) {
        fprintf(stderr, "Effect dump failed, see logcat for detail.\n");
        return 4;
    }
    }
}
}