Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-Plattform Crash Reporting: Add Android Support #4484

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/functional_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2
- name: Install dependecies
if: steps.cache-build.outputs.cache-hit != 'true'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Qt
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sentry_native repo itself has submodules:
https://github.com/getsentry/sentry-native/tree/master/external


- name: Set up Python 3
uses: actions/setup-python@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_qml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Grcov
shell: bash
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Generating glean samples
shell: bash
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Qt
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Cache grcov
id: cache-grcov
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Qt6
shell: bash
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Qt
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=2

- name: Install Qt
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ vscode-cpptools/*
*.xcodeproj/
MozillaVPN.vcxproj*
*.autosave
# Visual Studio stuff.
CMakeSettings.json

# Qt Creator
CMakeLists.txt.user
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "3rdparty/adjust-android-sdk"]
path = 3rdparty/adjust-android-sdk
url = https://github.com/adjust/android_sdk
[submodule "3rdparty/sentry_native"]
path = 3rdparty/sentry_native
url = https://github.com/getsentry/sentry-native
1 change: 1 addition & 0 deletions 3rdparty/sentry_native
Submodule sentry_native added at b0fab1
30 changes: 30 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ the terms of the MIT Public License (*MIT*), a copy of which is available
[available here](https://opensource.org/licenses/MIT) and a copy is provided
below.

The project relies on [sentry-native](https://github.com/getsentry/sentry-native), under
the terms of the MIT Public License (*MIT*), a copy of which is available
[available here](https://opensource.org/licenses/MIT) and a copy is provided
below.

Finally, this project uses EC25519 and CHACHA-POLY implementations from
[HACL\*](https://hacl-star.github.io/), available under the terms of the MIT
Public License (*MIT*) and copyright (c) 2016-2020 INRIA, CMU, and Microsoft
Expand Down Expand Up @@ -1437,3 +1442,28 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


The MIT License (MIT) - sentry-native
=================================

Copyright (c) 2019 Sentry (https://sentry.io) and individual contributors.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion i18n
Submodule i18n updated 127 files
11 changes: 11 additions & 0 deletions scripts/android/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
if [ -f .env ]; then
. .env
fi
set -x


JOBS=8
QTPATH=
Expand Down Expand Up @@ -127,6 +129,15 @@ rm -rf "android/src/com/adjust" || die "Failed to remove the adjust folder"
cp -a "3rdparty/adjust-android-sdk/Adjust/sdk-core/src/main/java/com/." "android/src/com/" || die "Failed to copy the adjust codebase"
git apply --directory="android/src/" "3rdparty/adjust_https_to_http.diff" || die "Failed to apply the adjust http patch"

print Y "Compile Sentry..."
cmake -B .tmp/sentry_build -S 3rdparty/sentry_native --toolchain ${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DSENTRY_BUILD_SHARED_LIBS=false \
-DANDROID_ABI=${ARCH} || die "Failed to generate the sentry project"

cmake --build .tmp/sentry_build --parallel
cmake --install .tmp/sentry_build --prefix .tmp/sentry_install --config RelWithDebInfo


printn Y "Computing the version... "
export SHORTVERSION=$(cat version.pri | grep VERSION | grep defined | cut -d= -f2 | tr -d \ ) # Export so gradle can pick it up
export VERSIONCODE=$(date +%s | sed 's/.\{3\}$//' )"0" #Remove the last 3 digits of the timestamp, so we only get every ~16m a new versioncode
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif()
target_link_libraries(mozillavpn PRIVATE glean lottie nebula translations)

include(cmake/sources.cmake)
include(cmake/sentry.cmake)

if(${BUILD_DUMMY})
set(MVPN_PLATFORM_NAME "dummy")
Expand Down
67 changes: 67 additions & 0 deletions src/cmake/sentry.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# This CMAKE File will Integrate Sentry into MVPN


# Defines which OS builds can include sentry. Check src/cmake Lists for all values of MVPN_PLATFORM_NAME
set(SENTRY_SUPPORTED_OS "Windows" "Darwin")
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)
include(ExternalProject)



LIST(FIND SENTRY_SUPPORTED_OS ${CMAKE_SYSTEM_NAME} _SUPPORTED)

if( ${_SUPPORTED} GREATER -1 )
message("Building sentry for ${CMAKE_SYSTEM_NAME}")
target_compile_definitions(mozillavpn PRIVATE SENTRY_ENABLED)
# Sentry support is given
target_sources(mozillavpn PRIVATE
sentry/sentryadapter.cpp
sentry/sentryadapter.h
)

# Configure Linking and Compile
if(APPLE)
# Compile Static for apple and link to libsentry.a
target_link_libraries(mozillavpn PUBLIC libsentry.a)
SET(SENTRY_ARGS -DSENTRY_BUILD_SHARED_LIBS=false)
osx_bundle_files(mozillavpn
FILES ${CMAKE_BINARY_DIR}/external/bin/crashpad_handler
DESTINATION MacOS
)
endif()
if(WIN32)
SET(SENTRY_ARGS -DSENTRY_BUILD_SHARED_LIBS=false -D SENTRY_BACKEND=breakpad)
# Link against static sentry + breakpad + the stack unwind utils
target_link_libraries(mozillavpn PUBLIC sentry.lib)
target_link_libraries(mozillavpn PUBLIC breakpad_client.lib)
target_link_libraries(mozillavpn PUBLIC dbghelp.lib)
# Make sure the sentry header does not try to dll-link it :)
target_compile_definitions(mozillavpn PRIVATE SENTRY_BUILD_STATIC)

endif()

include(ExternalProject)
ExternalProject_Add(sentry
GIT_REPOSITORY https://github.com/getsentry/sentry-native/
GIT_TAG 0.5.0
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} ${SENTRY_ARGS}
)

target_include_directories(mozillavpn PUBLIC ${EXTERNAL_INSTALL_LOCATION}/include)
target_link_directories( mozillavpn PUBLIC ${EXTERNAL_INSTALL_LOCATION}/lib)
add_dependencies(mozillavpn sentry)
else()
message("Sentry supported OS -> ${SENTRY_SUPPORTED_OS}")
message("Skipping building sentry for ${CMAKE_SYSTEM_NAME}")
# Sentry is not supported on this Plattform, let's
# only include a dummy client :)
target_sources(mozillavpn PRIVATE
sentry/dummysentryadapter.cpp
sentry/sentryadapter.h
)
endif()
4 changes: 0 additions & 4 deletions src/commands/commandui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#endif

#ifdef MVPN_WINDOWS
# include "crashreporter/crashclient.h"
# include "eventlistener.h"
# include "platforms/windows/windowsstartatbootwatcher.h"
# include "platforms/windows/windowsappimageprovider.h"
Expand Down Expand Up @@ -168,9 +167,6 @@ int CommandUI::run(QStringList& tokens) {
std::cerr.clear();
}
# endif

CrashClient::instance().start(CommandLineParser::argc(),
CommandLineParser::argv());
#endif

#ifdef MVPN_DEBUG
Expand Down
7 changes: 7 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ CONSTEXPR(uint32_t, controllerPeriodicStateRecorderMsec, 10800000, 60000, 0)
#define PRODBETAEXPR(type, functionName, prod, beta) \
inline type functionName() { return inProduction() ? prod : beta; }

// TODO: Get a mozilla one - this is bastis project :)
constexpr const char* SENTRY_DER =
"https://[email protected]/"
"6719480";
constexpr const char* SENTRY_ENVELOPE_INGESTION =
"https://o1396220.ingest.sentry.io/api/6719480/envelope/";

constexpr const char* API_PRODUCTION_URL = "https://vpn.mozilla.org";
constexpr const char* API_STAGING_URL =
"https://stage-vpn.guardian.nonprod.cloudops.mozgcp.net";
Expand Down
1 change: 1 addition & 0 deletions src/errorhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ErrorHandler final : public QObject {
UnrecoverableError,
IgnoredError,
};
Q_ENUM(ErrorType)

static ErrorType toErrorType(QNetworkReply::NetworkError error);

Expand Down
14 changes: 14 additions & 0 deletions src/mozillavpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "tasks/sendfeedback/tasksendfeedback.h"
#include "tasks/getfeaturelist/taskgetfeaturelist.h"
#include "taskscheduler.h"
#include "sentry/sentryadapter.h"
#include "telemetry/gleansample.h"
#include "update/updater.h"
#include "update/versionapi.h"
Expand Down Expand Up @@ -1066,6 +1067,11 @@ void MozillaVPN::errorHandle(ErrorHandler::ErrorType error) {
default:
break;
}
// Report all User visible Error-Banners to Sentry so we can observe and
// assess.
QMetaEnum metaEnum = QMetaEnum::fromType<ErrorHandler::ErrorType>();
QString error_name = metaEnum.valueToKey(error);
SentryAdapter::instance()->report("MainError", error_name, true);

setAlert(alert);

Expand Down Expand Up @@ -1187,6 +1193,7 @@ void MozillaVPN::mainWindowLoaded() {
m_gleanTimer.start(Constants::gleanTimeoutMsec());
m_gleanTimer.setSingleShot(false);
#endif
SentryAdapter::instance()->init();
}

void MozillaVPN::telemetryPolicyCompleted() {
Expand Down Expand Up @@ -1793,6 +1800,13 @@ void MozillaVPN::hardResetAndQuit() {

void MozillaVPN::crashTest() {
logger.debug() << "Crashing Application";

unsigned char* test = NULL;
test[1000] = 'a'; //<< here it should crash

// Interestingly this does not cause a "Signal" but a VC runtime exception
// and more interestingly, neither breakpad nor crashpad are catchting this on
// windows...
char* text = new char[100];
delete[] text;
delete[] text;
Expand Down
14 changes: 14 additions & 0 deletions src/networkrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,20 @@ NetworkRequest* NetworkRequest::createForFxaAuthz(
return r;
}

// static
NetworkRequest* NetworkRequest::createForSentry(Task* parent,
const QByteArray& envelope) {
NetworkRequest* r = new NetworkRequest(parent, 200, false);
QUrl url(Constants::SENTRY_ENVELOPE_INGESTION);
r->m_request.setUrl(url);
r->m_request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-sentry-envelope");
r->m_request.setRawHeader("dsn", Constants::SENTRY_DER);
r->postRequest(envelope);

return r;
}

#ifdef UNIT_TEST
// static
NetworkRequest* NetworkRequest::createForFxaTotpCreation(
Expand Down
3 changes: 3 additions & 0 deletions src/networkrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class NetworkRequest final : public QObject {
const QString& fxaScope,
const QString& fxaAccessType);

static NetworkRequest* createForSentry(Task* parent,
const QByteArray& envelope);

#ifdef UNIT_TEST
static NetworkRequest* createForFxaTotpCreation(
Task* parent, const QByteArray& sessionToken);
Expand Down
16 changes: 16 additions & 0 deletions src/qmake/sentry.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

android{
LIBS += $$PWD/../../.tmp/sentry_install/lib/libsentry.a
LIBS += $$PWD/../../.tmp/sentry_install/lib/libunwindstack.a
INCLUDEPATH += $$PWD/../../.tmp/sentry_install/include
SOURCES += sentry/sentryadapter.cpp
DEFINES += SENTRY_ENABLED

# We need custom transport on android
DEFINES += SENTRY_TRANSPORT_ENABLED
}else{
SOURCES += sentry/dummysentryadapter.cpp
}
Loading