Skip to content

Commit

Permalink
Merge pull request #609 from Microsoft/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
guperrot committed Jan 25, 2018
2 parents 12da337 + dce0710 commit 4a73ee9
Show file tree
Hide file tree
Showing 96 changed files with 3,114 additions and 677 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ google-services.json
# Localization
localization/*.zip
localization/unzip/
.externalNativeBuild

# VS Code + Java extension follows Eclipse conventions
.settings
.project
.classpath

/Configure
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "apps/sasquatch/src/main/cpp/google-breakpad"]
path = apps/sasquatch/src/main/cpp/google-breakpad
url = https://github.com/Microsoft/AppCenter-SDK-Android-Breakpad.git
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing to Visual Studio App Center SDK for Android

Welcome, and thank you for your interest in contributing to VS App Center SDK for Android!
The goal of this document is to provide a high-level overview of how you can get involved.

## Sending a pull request

Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.

Please make sure the following is done when submitting a pull request:

### Workflow and validation

1. Fork the repository and create your branch from `develop`.
1. Make sure all tests have passed and your code is covered: run `gradlew coverageReport`command to generate report.
1. Make sure that there are no lint errors: run `gradlew assemble lint` command.
1. After creating a pull request, sign the CLA, if you haven't already.

### Code formatting

1. Make sure you name all the constants in capital letters.
1. Make sure you name all the classes in upper camel case.
1. Use blank line in-between methods.
1. No newlines within methods except in front of a comment.
1. Make sure you name all the properties/methods in camel case. Start private properties with `m`, static properties with `s`.
1. Use `{}` even if you have single operation in block.

### Comments

1. Use capital letter in the beginning of each comment and dot at the end.
1. For comments use `/* */` (multiline) even if it's only one line.
1. Provide JavaDoc for each `public` and `protected` class, method, property.
1. Use blank line between description and tags like `@return` or `@param`.
> Tip: You can configure these options in Android Studio via File > Settings > Editor > Code Style > Java
## Thank You!

Your contributions to open source, large or small, constantly make projects better. Thank you for taking the time to contribute.
6 changes: 3 additions & 3 deletions apps/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def copyApkToProjectBuildTask(buildType) {
if (file.exists()) {
properties.load(file.newDataInputStream())
}
def defaultDependency = "jcenter";
def defaultDependency = "jcenter"
def dependency = properties.get("dimension.dependency", defaultDependency)
if (dependency.isEmpty()) {
dependency = defaultDependency;
dependency = defaultDependency
}
subprojects.each { project ->
def apkPath = "${project.buildDir}/outputs/apk/${dependency}DependencyVanilla/${buildType}/${project.name}-${dependency}Dependency-vanilla-${buildType}"
if ("release".equals(buildType)) {
if ("release" == buildType) {
apkPath += "-unsigned"
}
apkPath += ".apk"
Expand Down
17 changes: 17 additions & 0 deletions apps/sasquatch/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MY_ROOT_PATH := $(call my-dir)/src/main/cpp

include $(MY_ROOT_PATH)/google-breakpad/Android.mk

LOCAL_PATH := $(MY_ROOT_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE := SasquatchBreakpad
LOCAL_SRC_FILES := main.cpp

LOCAL_CPPFLAGS := -D__NDK_R16B__
LOCAL_LDFLAGS := -latomic
LOCAL_LALIBS += -llog
LOCAL_STATIC_LIBRARIES += breakpad_client

include $(BUILD_SHARED_LIBRARY)
2 changes: 2 additions & 0 deletions apps/sasquatch/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_STL := gnustl_static
APP_PLATFORM := android-9
45 changes: 45 additions & 0 deletions apps/sasquatch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
SasquatchBreakpad

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/main.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
SasquatchBreakpad

# Links the target library to the log library
# included in the NDK.
${log-lib} )
21 changes: 18 additions & 3 deletions apps/sasquatch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ android {

flavorDimensions "dependency", "pushLibrary"

defaultConfig {
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK=Application.mk", "V=1"
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
}

productFlavors {
projectDependency {
dimension "dependency"
Expand All @@ -32,6 +41,12 @@ android {
matchingFallbacks = ['release']
}
}

externalNativeBuild {
ndkBuild {
path "Android.mk"
}
}
}

repositories {
Expand Down Expand Up @@ -60,8 +75,8 @@ dependencies {
//noinspection GradleDependency
jcenterDependencyImplementation "com.microsoft.appcenter:appcenter-push:${appCenterSdkVersion}"

firebaseCompile "com.google.firebase:firebase-core:${rootProject.ext.firebaseLibVersion}"
firebaseCompile "com.google.firebase:firebase-messaging:${rootProject.ext.firebaseLibVersion}"
firebaseImplementation "com.google.firebase:firebase-core:${rootProject.ext.firebaseLibVersion}"
firebaseImplementation "com.google.firebase:firebase-messaging:${rootProject.ext.firebaseLibVersion}"

/* Force usage this version of support annotations to avoid conflict. */
androidTestImplementation "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}"
Expand All @@ -77,4 +92,4 @@ dependencies {
*/
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Firebase")) {
apply plugin: 'com.google.gms.google-services'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class AnalyticsTest {

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
public final ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void sendEventTest() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
public class CrashesTest {

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class, true, false);
public final ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class, true, false);

private Context mContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class SettingsActivityTest {

@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class, true, false);
public final ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class, true, false);

private Context mContext;

Expand Down
1 change: 1 addition & 0 deletions apps/sasquatch/src/main/cpp/google-breakpad
Submodule google-breakpad added at a8dba9
115 changes: 115 additions & 0 deletions apps/sasquatch/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) Microsoft Corporation
*
* All rights reserved.
*
* MIT License
*
* 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.
*/

#include <jni.h>
#include <string>
#include <stdio.h>
#include <string.h>
#include "android/log.h"
#include "google-breakpad/src/client/linux/handler/exception_handler.h"
#include "google-breakpad/src/client/linux/handler/minidump_descriptor.h"

#ifdef __cplusplus
extern "C"
{
#endif

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"

/*
* Triggered automatically after an attempt to write a minidump file to the breakpad folder.
*/
bool dumpCallback(const google_breakpad::MinidumpDescriptor &descriptor,
void *context,
bool succeeded) {

/* Allow system to log the native stack trace. */
__android_log_print(ANDROID_LOG_INFO, "AppCenterSasquatch",
"Wrote breakpad minidump at %s succeeded=%d\n", descriptor.path(),
succeeded);
return false;
}
#pragma clang diagnostic pop

/**
* Registers breakpad as the exception handler for NDK code.
* @param env JNI environment.
* @param path minidump directory path returned from Crashes.getMinidumpDirectory()
*/
void Java_com_microsoft_appcenter_sasquatch_activities_MainActivity_setupNativeCrashesListener(
JNIEnv *env, jobject, jstring path) {
const char *dumpPath = (char *) env->GetStringUTFChars(path, NULL);
google_breakpad::MinidumpDescriptor descriptor(dumpPath);
new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1);
env->ReleaseStringUTFChars(path, dumpPath);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
__android_log_print(ANDROID_LOG_INFO, "AppCenterSasquatch", "JNI OnLoad");
return JNI_VERSION_1_4;
}
#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma ide diagnostic ignored "OCDFAInspection"
void
Java_com_microsoft_appcenter_sasquatch_activities_CrashActivity_nativeDereferenceNullPointer(
JNIEnv *env,
jobject obj) {
volatile int *a = reinterpret_cast<volatile int *>(NULL);
*a = 1;
}
#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma ide diagnostic ignored "InfiniteRecursion"
void Java_com_microsoft_appcenter_sasquatch_activities_CrashActivity_nativeStackOverflowCrash(
JNIEnv *env, jobject obj) {
Java_com_microsoft_appcenter_sasquatch_activities_CrashActivity_nativeStackOverflowCrash(env,
obj);

/* Defeat release build optimization by adding another statement after recursion. */
__android_log_print(ANDROID_LOG_INFO, "AppCenterSasquatch",
"You will never see this log after an infinite loop.");
}
#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
void
Java_com_microsoft_appcenter_sasquatch_activities_CrashActivity_nativeAbortCall(JNIEnv *env,
jobject obj) {
abort();
}
#pragma clang diagnostic pop

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private AnalyticsPrivateHelper() {

public static void setListener(AnalyticsListener listener) {

/* TODO Change this when Analytics.setListener is package accessibility in jcenter. */
/* TODO Change this when Analytics.setListener is package accessibility in jCenter. */
// Analytics.setListener(listener);
try {
Method method = Analytics.class.getDeclaredMethod("setListener", AnalyticsListener.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.microsoft.appcenter.crashes;

import java.util.Map;

public final class CrashesPrivateHelper {

private CrashesPrivateHelper() {
}

public static void trackException(Throwable throwable) {
Crashes.trackException(throwable);
public static void trackException(Throwable throwable, Map<String, String> properties) {
try {
Crashes.class.getMethod("trackException", Throwable.class, Map.class).invoke(null, throwable, properties);
} catch (Exception ignored) {
}
}

public static void saveUncaughtException(Thread thread, Throwable exception) {
Expand Down
Loading

0 comments on commit 4a73ee9

Please sign in to comment.