Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolascione committed Jan 25, 2016
0 parents commit 84a4ed0
Show file tree
Hide file tree
Showing 38 changed files with 2,821 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[alias]
[java]
src_roots = /java/
[project]
# IntelliJ requires that every Android module have an
# AndroidManifest.xml file associated with it. In practice,
# most of this is unnecessary boilerplate, so we create one
# "shared" AndroidManifest.xml file that can be used as a default.
default_android_manifest = //res/AndroidManifest.xml
[android]
target = Google Inc.:Google APIs:21
[download]
maven_repo = https://repo1.maven.org/maven2
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
/.idea/compiler.xml
/.idea/libraries/*.xml
/.idea/modules.xml
/.idea/runConfigurations/Debug_Buck_test.xml
/buck-cache
/buck-out
/.buckd
PROJECTc
*~
.#*
*.pyc
8 changes: 8 additions & 0 deletions AndroidManifestSkeleton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.soloader"
android:versionCode="1"
android:versionName="0.1.0">
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="9"/>
<application/>
</manifest>
9 changes: 9 additions & 0 deletions BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include_defs("//oss_defs/SOLOADER_DEFS")

android_aar(
name = 'soloader',
manifest_skeleton='AndroidManifestSkeleton.xml',
deps = [
'//java/com/facebook/soloader:soloader'
]
)
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing to SoLoader
We want to make contributing to this project as easy and transparent as
possible.

## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>

## Our Development Process
Each pull request is first submitted into Facebook's internal repositories.
Once the commit has successfully passed Facebook's internal test suite, it will
be exported back out from Facebook's repository. We endeavour to do this as soon
as possible for all commits.

## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## Coding Style
* 2 spaces for indentation rather than tabs
* Line wrapping indents 4 spaces
* 100 character line length
* One parameter per line when line wrapping is required
* Use the `m` member variable prefix for private fields
* Use the `s` static variable prefix for private fields
* Opening braces to appear on the same line as code

## License
By contributing to SoLoader, you agree that your contributions will be licensed
under its [BSD license](https://github.com/facebook/soloader/blob/master/LICENSE).
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BSD License

For SoLoader software

Copyright (c) 2015-present, Facebook, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name Facebook nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 33 additions & 0 deletions PATENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Additional Grant of Patent Rights Version 2

"Software" means SoLoader software distributed by Facebook, Inc.

Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
(subject to the termination provision below) license under any Necessary
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
transfer the Software. For avoidance of doubt, no license is granted under
Facebook’s rights in any patent claims that are infringed by (i) modifications
to the Software made by you or any third party or (ii) the Software in
combination with any software or other technology.

The license granted hereunder will terminate, automatically and without notice,
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
directly or indirectly, or take a direct financial interest in, any Patent
Assertion: (i) against Facebook or any of its subsidiaries or corporate
affiliates, (ii) against any party if such Patent Assertion arises in whole or
in part from any software, technology, product or service of Facebook or any of
its subsidiaries or corporate affiliates, or (iii) against any party relating
to the Software. Notwithstanding the foregoing, if Facebook or any of its
subsidiaries or corporate affiliates files a lawsuit alleging patent
infringement against you in the first instance, and you respond by filing a
patent infringement counterclaim in that lawsuit against that party that is
unrelated to the Software, the license granted hereunder will not terminate
under section (i) of this paragraph due to such counterclaim.

A "Necessary Claim" is a claim of a patent owned by Facebook that is
necessarily infringed by the Software standing alone.

A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
or contributory infringement or inducement to infringe any patent, including a
cross-claim or counterclaim.
20 changes: 20 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NAME = 'SoLoader'

GROUP = 'com.facebook.soloader'
ARTIFACT = 'soloader'
VERSION='0.1.0'

DESCRIPTION = "Reliable native code loader for Android"

LICENSES = [
{
'name' : 'BSD License',
'url' : 'https://github.com/facebook/soloader/blob/master/LICENSE'
}
]

SCM = {
'url' : 'https://github.com/facebook/soloader.git',
'connection' : 'scm:git:https://github.com/facebook/soloader.git',
'developerConnection' : 'scm:git:git@github.com:facebook/soloader.git',
}
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SoLoader
SoLoader is a native code loader for Android. It takes care of unpacking your native libraries
and recursively loads dependencies on platforms that don't support that out of the box.

## Requirements
SoLoader can be included in any Android application.

## Including SoLoader in your apps
You can use [prebuilt aars](https://github.com/facebook/soloader/releases/latest)
or fetch SoLoader from Maven repository by adding the following to your
`build.gradle` file:
```groovy
compile 'com.facebook.soloader:soloader:0.1.0+'
```
to your build.gradle file.

## Building from source
To build SoLoader from source you'll need [Buck](https://buckbuild.com/).
Onve you have Buck installed execute following commands from the project root
directory:
```shell
python scripts/fetch_deps.py
buck build :soloader
```
The build command generates `buck-out/gen/soloader.aar` file.

## Join our community
Please use our [issues page](https://github.com/facebook/soloader/issues) to let us know of any problems.
See the [CONTRIBUTING](https://github.com/facebook/soloader/blob/master/CONTRIBUTING.md) file for how to
help out.

## License
SoLoader is [BSD-licensed](https://github.com/facebook/soloader/blob/master/LICENSE).
We also provide an additional [patent grant](https://github.com/facebook/soloader/blob/master/PATENTS).
15 changes: 15 additions & 0 deletions deps/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include_defs("//oss_defs/SOLOADER_DEFS")

maven_library(
name = 'jsr-305',
group = 'com.google.code.findbugs',
artifact = 'jsr305',
version = '3.0.0',
sha1 = '5871fb60dc68d67da54a663c3fd636a10a532948',
scope = 'provided',
visibility = [
'PUBLIC'
]
)

define_list_deps_target()
99 changes: 99 additions & 0 deletions java/com/facebook/soloader/ApkSoSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.soloader;

import java.io.File;
import java.io.IOException;
import android.content.Context;
import android.os.Parcel;
import android.util.Log;
import java.util.zip.ZipEntry;

/**
* {@link SoSource} that extracts libraries from an APK to the filesystem.
*/
public class ApkSoSource extends ExtractFromZipSoSource {

private static final String TAG = "ApkSoSource";

/**
* If this flag is given, do not extract libraries that appear to be correctly extracted to the
* application libs directory.
*/
public static final int PREFER_ANDROID_LIBS_DIRECTORY = (1<<0);

private static final byte APK_SIGNATURE_VERSION = 1;

private final int mFlags;

public ApkSoSource(Context context, String name, int flags) {
super(
context,
name,
new File(context.getApplicationInfo().sourceDir),
// The regular expression matches libraries that would ordinarily be unpacked
// during installation.
"^lib/([^/]+)/([^/]+\\.so)$");
mFlags = flags;
}

@Override
protected Unpacker makeUnpacker() throws IOException {
return new ApkUnpacker();
}

protected class ApkUnpacker extends ZipUnpacker {

private File mLibDir;
private final int mFlags;

ApkUnpacker() throws IOException {
super();
mLibDir = new File(mContext.getApplicationInfo().nativeLibraryDir);
mFlags = ApkSoSource.this.mFlags;
}

@Override
protected boolean shouldExtract(ZipEntry ze, String soName) {
String zipPath = ze.getName();
if ((mFlags & PREFER_ANDROID_LIBS_DIRECTORY) == 0) {
Log.d(TAG, "allowing consideration of " + zipPath + ": self-extraction preferred");
return true;
}

File sysLibFile = new File(mLibDir, soName);
if (!sysLibFile.isFile()) {
Log.d(
TAG,
String.format(
"allowing considering of %s: %s not in system lib dir",
zipPath,
soName));
return true;
}

long sysLibLength = sysLibFile.length();
long apkLibLength = ze.getSize();

if (sysLibLength != apkLibLength) {
Log.d(
TAG,
String.format(
"allowing consideration of %s: sysdir file length is %s, but " +
"the file is %s bytes long in the APK",
sysLibFile,
sysLibLength,
apkLibLength));
return true;
}

Log.d(TAG, "not allowing consideration of " + zipPath + ": deferring to libdir");
return false;
}
}

@Override
protected byte[] getDepsBlock() throws IOException {
return SysUtil.makeApkDepBlock(mZipFileName);
}
}
Loading

0 comments on commit 84a4ed0

Please sign in to comment.