-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3167d6d
Showing
64 changed files
with
3,260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
**/.idea | ||
**/build | ||
**/*.iml | ||
.gradle | ||
**/local.properties | ||
**/.DS_Store | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Contributing | ||
|
||
When contributing to this repository, please first discuss the change you wish to make via issue, | ||
email, or any other method with the owners of this repository before making a change. | ||
|
||
Please note we have a code of conduct, please follow it in all your interactions with the project. | ||
|
||
## Pull Request Process | ||
|
||
1. Ensure any install or build dependencies are removed before the end of the layer when doing a | ||
build. | ||
2. Update the README.md with details of changes to the interface, this includes new environment | ||
variables, exposed ports, useful file locations and container parameters. | ||
3. Increase the version numbers in any examples files and the README.md to the new version that this | ||
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). | ||
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you | ||
do not have permission to do that, you may request the second reviewer to merge it for you. | ||
|
||
## Code of Conduct | ||
|
||
### Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, gender identity and expression, level of experience, | ||
nationality, personal appearance, race, religion, or sexual identity and | ||
orientation. | ||
|
||
### Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
### Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
### Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
### Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
### Attribution | ||
|
||
This Code of Conduct is adapted from [Purple Booth], | ||
available at [https://gist.github.com/PurpleBooth/b24679402957c63ec426] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# Snap Services | ||
|
||
A drop-in replacement (almost ;)) for Android services! | ||
|
||
## Getting Started | ||
|
||
This library is meant to serve as a clean and straightforward way to replace Android Services due to the new Android O limitations in using them. | ||
The purpose of this library is to keep your existing code working, without much changes required. | ||
|
||
## Why do I need this? | ||
Due to the limitations to start a service in Android O, we can no longer rely on Services to execute background tasks when we need it. | ||
|
||
Without this library you are very confined to what you can do. You can either: | ||
|
||
1. Abuse of the AlarmManager to launch Services to run immediately. | ||
2. Abuse of the JobScheduler to launch "jobs" to run immediately. | ||
3. Use bounded Services (if you do this at all) | ||
4. Refactor your entire logic to start using specific components, with very limited abstraction and re-usability, in order to be able to run stuff in background whenever you need. | ||
5. Use foreground services. | ||
|
||
At the end, there's no direct solution to run something in background when you want, without the use of foreground services, and, IMHO, this is not a very good option. | ||
If you simply want to perform an internal cleanup/refresh/etc, do you really need to bother the user with yet another useless notification? (I fear that, when Android O does come, users will start to be flooded with such notifications giving the user no other option than to simply disallow them all). | ||
|
||
But enough of my random musings. | ||
|
||
### What can this offer me? | ||
|
||
Well, this library follows the Services API when possible, to give you the possibility of launching background services like you are used to. | ||
However, instead of using Android Services, we use our own SnapSerices. | ||
|
||
All Android services should be replaced with SnapServices. Most features that you were used to have with Services, you still have with SnapServices. | ||
|
||
Features: | ||
|
||
* follows the IntentService approach, where all work is queued and delivered on a separate thread | ||
* start Snap Services like you would start an Android Service | ||
* bind to and unbind from Snap Services like you're used to do with Android Services | ||
* schedule alarms for Snap Services like you're used to do with Android Services | ||
* notification actions support Snap Services. This will allow you to add PendingIntents to SnapServices on ANY notification you launch. | ||
* all SnapServices have a real Application Context, wrapped around inside SnapContextWrapper (which extends from ContextWrapper), to give the option to start another Snap Service without the need of accessing SnapServicesContext. | ||
|
||
This library also expands on features that existed in the past, but were limited: | ||
* run ANY Snap Service on another process | ||
* schedule ANY Snap Service to run on another process | ||
|
||
**NOTE:** just like Android Services, Snap Services only have one instance running at ANY single time. The SnapService will only be killed if all actions were handled and if it's not binded. | ||
|
||
## Examples | ||
|
||
* Create a Service: | ||
``` | ||
public class ExampleService extends SnapService { | ||
public ExampleService() { | ||
super("ExampleService"); | ||
} | ||
@Override | ||
protected void onHandleIntent(Intent intent) { | ||
} | ||
} | ||
``` | ||
|
||
* Start a Snap Service: | ||
``` | ||
Intent intent = new Intent(getApplicationContext(), ExampleService.class); | ||
intent.setAction("com.exampleservice.myaction"); | ||
intent.putExtra("EXTRA_KEY", "value for this key") | ||
SnapServicesContext.startService(intent) | ||
``` | ||
|
||
If you're inside a SnapService, you don't need to call ```SnapServicesContext.startService(Intent)```. Instead, you can invoke ```startService(Intent)``` directly from the SnapService. | ||
|
||
* Start a Snap Service on another process | ||
``` | ||
Intent intent = new Intent(getApplicationContext(), ExampleService.class); | ||
intent.setAction("com.exampleservice.my.other.action"); | ||
intent.putExtra("EXTRA_KEY", "value for this key") | ||
SnapServicesContext.startServiceOnOtherProcess(intent) | ||
``` | ||
|
||
Once again, if you're inside a SnapService, you don't need to call ```SnapServicesContext.startServiceOnOtherProcess(Intent)```. Instead, you can invoke ```startServiceOnOtherProcess(Intent)``` directly from the SnapService. | ||
|
||
* Bind a Snap Service | ||
|
||
Binding a Snap Service still follows the same approach as you would do for an Android Service, but, instead of using the ```IBinder``` interface, ```Binder``` and ```ServiceConnection``` classes from Android, you use the ```ISnapBinder``` interface, ```SnapBinder``` and ```SnapServiceConnection```. | ||
|
||
You should do what you do already in order to bind a service: | ||
1. Implement a Binder: | ||
```` | ||
private final ISnapBinder mBinder = new LocalBinder(); | ||
public class LocalBinder extends SnapBinder { | ||
public ExampleService getService() { | ||
return ExampleService.this; | ||
} | ||
} | ||
```` | ||
|
||
|
||
2. Override the onBind: | ||
```` | ||
@Override | ||
public ISnapBinder onBind(Intent intent) { | ||
return mBinder; | ||
} | ||
```` | ||
|
||
3. Create your Service Connection: | ||
```` | ||
private SnapServiceConnection mConnection = new SnapServiceConnection() { | ||
@Override | ||
public void onServiceConnected(ComponentName name, ISnapBinder service) { | ||
ExampleService.LocalBinder binder = (ExampleService.LocalBinder) service; | ||
mService = binder.getService(); | ||
//additional logic | ||
... | ||
mServiceBinded = true; | ||
} | ||
@Override | ||
public void onServiceDisconnected(ComponentName name) { | ||
mService = null; | ||
mServiceBinded = false; | ||
} | ||
}; | ||
```` | ||
|
||
4. When you're ready, bind the service: | ||
```` | ||
Intent bindIntent = new Intent(getApplicationContext(), ExampleService.class); | ||
SnapServicesContext.bindService(bindIntent, mConnection); | ||
```` | ||
|
||
5. When done, don't forget to unbind it: | ||
```` | ||
SnapServicesContext.unbindService(mConnection); | ||
```` | ||
|
||
## How to import | ||
|
||
* Make sure you have ````jcenter()```` configured on your project. | ||
* Add this line to yout dependencies: ````compile 'com.snapround.android:snapservices:1.0.0'```` | ||
* Happy coding! | ||
|
||
## Contributing | ||
|
||
Please read [CONTRIBUTING.md](https://github.com/mindbirth/snap-services/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. | ||
|
||
## Authors | ||
|
||
See also the list of [contributors](https://github.com/mindbirth/snap-services/graphs/contributors) who participated in this project. | ||
|
||
## Acknowledgments | ||
|
||
* Thank you Google for removing the possibility to use background Services... | ||
|
||
## License | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
maven { | ||
url 'https://maven.google.com' | ||
} | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.3.3' | ||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' | ||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' | ||
} | ||
} | ||
|
||
allprojects { | ||
|
||
ext { | ||
snapProperties = new Properties() | ||
snapProperties.load(new FileInputStream("snapservices.properties")) | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
maven { | ||
url "https://maven.google.com" | ||
} | ||
} | ||
} | ||
|
||
/*task continuousIntegration | ||
continuousIntegration.dependsOn(':sample:build', 'snapservices:assembleRelease', | ||
'snapservices:javadocrelease') | ||
//'snapservices:testReleaseUnitTest',*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx1536m | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Fri May 26 11:16:29 WEST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip |
Oops, something went wrong.