Skip to content

Commit

Permalink
[android] use OTBR_PLATFORM_ANDROID for android platform (#2333)
Browse files Browse the repository at this point in the history
Current code uses `__ANDROID__` for determine the Android platform while
that flag is also available on android-based but non-aosp devices. To
avoid misconfiguration, this commit uses `OTBR_PLATFORM_ANDROID` for
selecting the standard Android devices. This is consistent with
`OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE` in the openthread/ repo.
  • Loading branch information
wgtdkp authored Jun 18, 2024
1 parent 5349ba1 commit 5008cf3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
#include <openthread-br/config.h>

#include <algorithm>
#include <fstream>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>

#include <assert.h>
Expand All @@ -47,7 +43,7 @@
#include <openthread/logging.h>
#include <openthread/platform/radio.h>

#if __ANDROID__ && OTBR_CONFIG_ANDROID_PROPERTY_ENABLE
#if OTBR_ENABLE_PLATFORM_ANDROID
#include <cutils/properties.h>
#endif

Expand All @@ -58,6 +54,12 @@
#include "common/types.hpp"
#include "ncp/thread_host.hpp"

#ifdef OTBR_ENABLE_PLATFORM_ANDROID
#ifndef __ANDROID__
#error "OTBR_ENABLE_PLATFORM_ANDROID can be enabled for only Android devices"
#endif
#endif

static const char kDefaultInterfaceName[] = "wpan0";

// Port number used by Rest server.
Expand All @@ -79,7 +81,7 @@ enum
OTBR_OPT_REST_LISTEN_PORT,
};

#ifndef __ANDROID__
#ifndef OTBR_ENABLE_PLATFORM_ANDROID
static jmp_buf sResetJump;
#endif
static otbr::Application *gApp = nullptr;
Expand Down Expand Up @@ -117,6 +119,7 @@ static bool ParseInteger(const char *aStr, long &aOutResult)
return successful;
}

#ifndef OTBR_ENABLE_PLATFORM_ANDROID
static constexpr char kAutoAttachDisableArg[] = "--auto-attach=0";
static char sAutoAttachDisableArgStorage[sizeof(kAutoAttachDisableArg)];

Expand All @@ -134,6 +137,7 @@ static std::vector<char *> AppendAutoAttachDisableArg(int argc, char *argv[])

return args;
}
#endif

static void PrintHelp(const char *aProgramName)
{
Expand Down Expand Up @@ -161,7 +165,7 @@ static otbrLogLevel GetDefaultLogLevel(void)
{
otbrLogLevel level = OTBR_LOG_INFO;

#if __ANDROID__ && OTBR_CONFIG_ANDROID_PROPERTY_ENABLE
#if OTBR_ENABLE_PLATFORM_ANDROID
char value[PROPERTY_VALUE_MAX];

property_get("ro.build.type", value, "user");
Expand Down Expand Up @@ -329,7 +333,7 @@ void otPlatReset(otInstance *aInstance)
gApp->Deinit();
gApp = nullptr;

#ifndef __ANDROID__
#ifndef OTBR_ENABLE_PLATFORM_ANDROID
longjmp(sResetJump, 1);
assert(false);
#else
Expand All @@ -341,7 +345,7 @@ void otPlatReset(otInstance *aInstance)

int main(int argc, char *argv[])
{
#ifndef __ANDROID__
#ifndef OTBR_ENABLE_PLATFORM_ANDROID
if (setjmp(sResetJump))
{
std::vector<char *> args = AppendAutoAttachDisableArg(argc, argv);
Expand Down

0 comments on commit 5008cf3

Please sign in to comment.