Compare commits
251 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
503d1ef452 | ||
|
|
9accd92757 | ||
|
|
306da92031 | ||
|
|
e7b6a852c5 | ||
|
|
9dfaf19516 | ||
|
|
34aece0b43 | ||
|
|
9768de2d5e | ||
|
|
c3eb0ea9db | ||
|
|
4cdc0a3e61 | ||
|
|
b568ce70b2 | ||
|
|
18b0601990 | ||
|
|
b308996885 | ||
|
|
73d896f378 | ||
|
|
36ec1d84a1 | ||
|
|
8d6b9ae43e | ||
|
|
a95cc0eba2 | ||
|
|
58d101ff2e | ||
|
|
544f06451f | ||
|
|
20cf775b1e | ||
|
|
5fcc135f81 | ||
|
|
9a0ed659f7 | ||
|
|
54612159be | ||
|
|
355d0be78a | ||
|
|
73b75a4a27 | ||
|
|
c4209a65e3 | ||
|
|
9dce376780 | ||
|
|
07c61394e9 | ||
|
|
3e287f930d | ||
|
|
7b1a37bd91 | ||
|
|
2db44a1578 | ||
|
|
006c9aae7b | ||
|
|
b147a90463 | ||
|
|
741171c49f | ||
|
|
c375ed8638 | ||
|
|
238f29c90a | ||
|
|
084f27a2e8 | ||
|
|
27b5bf54cc | ||
|
|
eda393b11c | ||
|
|
c330eef7b9 | ||
|
|
1eb3884b7a | ||
|
|
5ea3b3038e | ||
|
|
641ac9aed9 | ||
|
|
82bd75fb75 | ||
|
|
c94a7b1eff | ||
|
|
4caebdcd06 | ||
|
|
b3cece27d6 | ||
|
|
819982af7b | ||
|
|
42cf53e487 | ||
|
|
e0d2398ca5 | ||
|
|
3f299936bf | ||
|
|
540592d71f | ||
|
|
5a9e5672d3 | ||
|
|
0a23b5fcd5 | ||
|
|
f0c22d593f | ||
|
|
5f5ddd7c26 | ||
|
|
144f269059 | ||
|
|
0d532afd8e | ||
|
|
07fd17ccda | ||
|
|
fcaa3f0d73 | ||
|
|
64b40df15b | ||
|
|
77ff9cece8 | ||
|
|
6326ef73f3 | ||
|
|
f29d1e6269 | ||
|
|
d6c5e92c9d | ||
|
|
811479d168 | ||
|
|
2ed8d333d9 | ||
|
|
79020cd33c | ||
|
|
c8757c2134 | ||
|
|
2a65257182 | ||
|
|
931605a1c4 | ||
|
|
81ae9af2e4 | ||
|
|
e84a0948e9 | ||
|
|
5239b3e8f8 | ||
|
|
a601c56af1 | ||
|
|
5a3c19fe3e | ||
|
|
af45e5d544 | ||
|
|
72af8b11c2 | ||
|
|
a1db221caf | ||
|
|
14b8f97de2 | ||
|
|
d902c12941 | ||
|
|
fe3d91c40c | ||
|
|
31167d11dd | ||
|
|
6e3751a0c5 | ||
|
|
b5941fb3fd | ||
|
|
cfccd367ad | ||
|
|
2c8c6a410c | ||
|
|
2075bba86c | ||
|
|
1d7b47c982 | ||
|
|
89fb80fcc5 | ||
|
|
f1d230ce6e | ||
|
|
f51a5aa7eb | ||
|
|
cf9c9bbfd7 | ||
|
|
b8a3e87f3d | ||
|
|
e5bad2746f | ||
|
|
7316f17674 | ||
|
|
609e69a801 | ||
|
|
d979593cbb | ||
|
|
0808e00d0e | ||
|
|
2045c828be | ||
|
|
1b3bd32805 | ||
|
|
877f2a25a9 | ||
|
|
eb462f0345 | ||
|
|
102b40543d | ||
|
|
12077c6dad | ||
|
|
7441c191a7 | ||
|
|
b355991b0b | ||
|
|
350eb438c0 | ||
|
|
da7bbf4144 | ||
|
|
a0842f329f | ||
|
|
567224b4a6 | ||
|
|
9b495d8c83 | ||
|
|
8c55ea09d9 | ||
|
|
5264ebed67 | ||
|
|
7f51f9fd5b | ||
|
|
40495a2261 | ||
|
|
a6c1fdd914 | ||
|
|
020d61dd6e | ||
|
|
dee23b266f | ||
|
|
4cf57fbb55 | ||
|
|
85da05397a | ||
|
|
f4e9c4a710 | ||
|
|
28e14f47cf | ||
|
|
d2edda837a | ||
|
|
213715a0dc | ||
|
|
7b0479ff0f | ||
|
|
feabbb33d2 | ||
|
|
d3da409774 | ||
|
|
edb04138c2 | ||
|
|
8bf537bb09 | ||
|
|
b80593b5f5 | ||
|
|
b61e7839f4 | ||
|
|
7b41b1492e | ||
|
|
928b9687ef | ||
|
|
306c127803 | ||
|
|
239a11bfd2 | ||
|
|
de63b0dd96 | ||
|
|
eb4ac40051 | ||
|
|
dda4459e5a | ||
|
|
8726dd51be | ||
|
|
e53bbe8453 | ||
|
|
ecb67cd84f | ||
|
|
861d27279d | ||
|
|
bef5b8f3e9 | ||
|
|
9e74b5c892 | ||
|
|
3597915d17 | ||
|
|
40ce0cebe0 | ||
|
|
26d58047b5 | ||
|
|
7d688846f9 | ||
|
|
acc7c4c1c6 | ||
|
|
530ad7bc86 | ||
|
|
bea3c33223 | ||
|
|
9ef14a0f64 | ||
|
|
c632b32ff8 | ||
|
|
40698212bb | ||
|
|
19ae5043cc | ||
|
|
d1dd50e31c | ||
|
|
23a1c1c8fa | ||
|
|
3a62a8b428 | ||
|
|
cfac27645b | ||
|
|
f6e04d0f89 | ||
|
|
61d18f49ad | ||
|
|
f26f89d63d | ||
|
|
66aad852f8 | ||
|
|
da0eb5a779 | ||
|
|
a82d2dfc5c | ||
|
|
d429f9113b | ||
|
|
8f85eb1822 | ||
|
|
358c923891 | ||
|
|
2d9cd8eb52 | ||
|
|
db1d846833 | ||
|
|
5121ab0eed | ||
|
|
f63f95404e | ||
|
|
622d8975fc | ||
|
|
81365eff36 | ||
|
|
453610c39f | ||
|
|
5ce6dc954a | ||
|
|
c85a8bbb38 | ||
|
|
0f9a6e6296 | ||
|
|
d8cb893681 | ||
|
|
1ad54e7b88 | ||
|
|
0d35e2bfa9 | ||
|
|
983bf672cf | ||
|
|
1c2e1a07f5 | ||
|
|
2d739a324e | ||
|
|
ba1055df8e | ||
|
|
a54d20f3ef | ||
|
|
ea0fa58265 | ||
|
|
359fe280e8 | ||
|
|
34e147838a | ||
|
|
d8e6a93584 | ||
|
|
5ae8a7a8c4 | ||
|
|
0e6773b4b7 | ||
|
|
fb13d33e2e | ||
|
|
92fd8ededd | ||
|
|
8713a85beb | ||
|
|
9b82411c3d | ||
|
|
16764f74fe | ||
|
|
bd889d8fa9 | ||
|
|
d51adab76b | ||
|
|
b990202468 | ||
|
|
7208018097 | ||
|
|
c719a48a2c | ||
|
|
68747142d6 | ||
|
|
7c9282f306 | ||
|
|
fa3cb871d0 | ||
|
|
a19899a11f | ||
|
|
667da3b2cf | ||
|
|
1a86483b7f | ||
|
|
de90222c95 | ||
|
|
7cf84e904a | ||
|
|
12e92b9cdf | ||
|
|
4153c8dae9 | ||
|
|
ef72702f0d | ||
|
|
f5e2010455 | ||
|
|
bc769debe2 | ||
|
|
df1c96a662 | ||
|
|
db356a0ec9 | ||
|
|
468eb3382c | ||
|
|
12d217991c | ||
|
|
5785860631 | ||
|
|
addea8d340 | ||
|
|
59899b1caf | ||
|
|
829097d891 | ||
|
|
d95bb21065 | ||
|
|
0fbe765447 | ||
|
|
f190321e40 | ||
|
|
1cb4d479f1 | ||
|
|
023d776e96 | ||
|
|
ce7b8ab75a | ||
|
|
82bb0c07e8 | ||
|
|
d8d5848dae | ||
|
|
542e1984c1 | ||
|
|
dff6997a65 | ||
|
|
5bfe64752e | ||
|
|
d6d76fa953 | ||
|
|
03ecd79fe0 | ||
|
|
7a3d509ef4 | ||
|
|
7a54f33f68 | ||
|
|
d4b4667d5a | ||
|
|
08d899e2e1 | ||
|
|
716519f4b8 | ||
|
|
02d3760b31 | ||
|
|
521fbc77c6 | ||
|
|
0574ec170a | ||
|
|
cebad39422 | ||
|
|
1d07ca3e6f | ||
|
|
ca8c950553 | ||
|
|
7349378d8d | ||
|
|
dc9a9b14b2 | ||
|
|
df9afc4e7f | ||
|
|
e9a50ce6c3 |
7
.travis.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
language: android
|
||||
android:
|
||||
components:
|
||||
- platform-tools
|
||||
- build-tools-19.1.0
|
||||
- android-19
|
||||
- extra-android-m2repository
|
||||
@@ -2,10 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.thoughtcrime.securesms"
|
||||
android:versionCode="70"
|
||||
android:versionName="2.0.7">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>
|
||||
android:versionCode="83"
|
||||
android:versionName="2.2.0">
|
||||
|
||||
<permission android:name="org.thoughtcrime.securesms.ACCESS_SECRETS"
|
||||
android:label="Access to TextSecure Secrets"
|
||||
@@ -33,18 +31,20 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_CALL_LOG" />
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
|
||||
<permission android:name="org.thoughtcrime.securesms.permission.C2D_MESSAGE"
|
||||
android:protectionLevel="signature" />
|
||||
<uses-permission android:name="org.thoughtcrime.securesms.permission.C2D_MESSAGE" />
|
||||
|
||||
<application android:name="org.thoughtcrime.securesms.ApplicationListener"
|
||||
<application android:name=".ApplicationContext"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/TextSecure.LightTheme">
|
||||
|
||||
<meta-data android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
|
||||
<activity android:name=".RoutingActivity"
|
||||
android:theme="@style/NoAnimation.Theme.BlackScreen"
|
||||
android:launchMode="singleTask"
|
||||
@@ -126,15 +126,15 @@
|
||||
<activity android:name=".PassphraseCreateActivity"
|
||||
android:label="@string/AndroidManifest__create_passphrase"
|
||||
android:windowSoftInputMode="stateUnchanged"
|
||||
android:theme="@style/NoAnimation.Theme.Sherlock.Light.DarkActionBar"
|
||||
android:theme="@style/TextSecure.IntroTheme"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".PassphrasePromptActivity"
|
||||
android:label="@string/AndroidManifest__enter_passphrase"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/NoAnimation.Theme.Sherlock.Light.DarkActionBar"
|
||||
android:windowSoftInputMode="stateUnchanged"
|
||||
android:theme="@style/TextSecure.IntroTheme"
|
||||
android:windowSoftInputMode="stateAlwaysVisible"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".ContactSelectionActivity"
|
||||
@@ -172,11 +172,7 @@
|
||||
android:label="@string/AndroidManifest__verify_identity"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".ReviewIdentitiesActivity"
|
||||
android:label="@string/AndroidManifest__manage_identity_keys"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".ReceiveKeyActivity"
|
||||
<activity android:name=".ReceiveKeyActivity"
|
||||
android:label="@string/AndroidManifest__complete_key_exchange"
|
||||
android:theme="@style/TextSecure.Light.Dialog"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
@@ -207,13 +203,13 @@
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:finishOnTaskLaunch="true" />
|
||||
|
||||
<service android:enabled="true" android:name=".service.GcmRegistrationService"/>
|
||||
<service android:enabled="true" android:name=".service.ApplicationMigrationService"/>
|
||||
<service android:enabled="true" android:name=".service.KeyCachingService"/>
|
||||
<service android:enabled="true" android:name=".service.SendReceiveService"/>
|
||||
<service android:enabled="true" android:name=".service.RegistrationService"/>
|
||||
<service android:enabled="true" android:name=".service.DirectoryRefreshService"/>
|
||||
<service android:enabled="true" android:name=".service.PreKeyService"/>
|
||||
<service android:enabled="true" android:name=".gcm.GcmIntentService"/>
|
||||
|
||||
<service android:name=".service.QuickResponseService"
|
||||
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
|
||||
@@ -240,7 +236,6 @@
|
||||
<receiver android:name=".gcm.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
||||
<category android:name="org.thoughtcrime.securesms" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
@@ -306,8 +301,4 @@
|
||||
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||
android:targetPackage="org.thoughtcrime.securesms.tests" android:label="Tests for My App" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -45,12 +45,12 @@ Setting up a development environment
|
||||
|
||||
[Android Studio](https://developer.android.com/sdk/installing/studio.html) is the recommended development environment.
|
||||
|
||||
1. Install Android Studio
|
||||
1. Install Android Studio.
|
||||
2. Make sure the "Android Support Repository" is installed in the Android Studio SDK.
|
||||
3. Make sure the latest "Android SDK build-tools" is installed in the Android Studio SDK.
|
||||
4. Create a new Android Studio project. from the Quickstart pannel (use File > Close Project to see it), choose "Checkout from Version Control" then "git".
|
||||
5. Paste the URL for the TextSecure project when prompted (https://github.com/WhisperSystems/TextSecure.git)
|
||||
6. Android studio should detect the presence of a project file and ask you wethere to open it. Click "yes".
|
||||
5. Paste the URL for the TextSecure project when prompted (https://github.com/WhisperSystems/TextSecure.git).
|
||||
6. Android studio should detect the presence of a project file and ask you whether to open it. Click "yes".
|
||||
7. Default config options should be good enough.
|
||||
8. Project initialisation and build should proceed.
|
||||
|
||||
|
||||
80
README.md
@@ -1,73 +1,73 @@
|
||||
TextSecure
|
||||
=================
|
||||
# TextSecure [](https://travis-ci.org/WhisperSystems/TextSecure)
|
||||
|
||||
A secure text messaging application for Android.
|
||||
TextSecure is a messaging app for easy private communicate with friends.
|
||||
|
||||
TextSecure is a replacement for the standard text messaging application, allowing you to send and receive text messages as normal. Additionally, TextSecure provides:
|
||||
TextSecure can use either data (WiFi/3G/4G) or SMS to communicate securely, and all TextSecure
|
||||
messages can also be encrypted locally on your device.
|
||||
|
||||
1. *Local Encryption* -- All text messages, regardless of destination, that are sent or received with TextSecure are stored in an encrypted database on your phone.
|
||||
2. *Wire Encryption* -- When communicating with a recipient who is also using TextSecure, text messages are encrypted during transmission.
|
||||
Currently available on the Play store.
|
||||
|
||||
Current BitHub Payment For Commit:
|
||||
=================
|
||||
[](https://whispersystems.org/blog/bithub/)
|
||||
*[](https://play.google.com/store/apps/details?id=org.thoughtcrime.securesms)*
|
||||
|
||||
Building and contributing code
|
||||
==============================
|
||||
Instructions on how to build TextSecure, as well as on how to setup an IDE to modify it can be found in the "BUILDING.md" file.
|
||||
|
||||
Bug tracker
|
||||
-----------
|
||||
|
||||
Have a bug? Please create an issue here on GitHub!
|
||||
## Contributing Bug reports
|
||||
We use GitHub for bug tracking. Please search the existing issues for your bug and create a new one if the issue is not yet tracked!
|
||||
|
||||
https://github.com/WhisperSystems/TextSecure/issues
|
||||
|
||||
## Contributing Translations
|
||||
Interested in helping to translate TextSecure? Contribute here:
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
https://www.transifex.com/projects/p/textsecure-official/
|
||||
|
||||
Looking for documentation? Check out the wiki!
|
||||
## Contributing Code
|
||||
Instructions on how to setup your development environment and build TextSecure can be found in [BUILDING.md](https://github.com/WhisperSystems/TextSecure/blob/master/BUILDING.md).
|
||||
|
||||
https://github.com/WhisperSystems/TextSecure/wiki
|
||||
If you're new to the TextSecure codebase, we recommend going through our issues and picking out a simple bug to fix (check the "easy" label in our issues) in order to get yourself familiar.
|
||||
|
||||
Mailing list
|
||||
------------
|
||||
For larger changes and feature ideas, we ask that you propose it on the mailing list for a high-level discussion before implementation.
|
||||
|
||||
Have a question? Ask on our mailing list!
|
||||
This repository is set up with [BitHub](https://whispersystems.org/blog/bithub/), so you can make money for committing to TextSecure. The current BitHub price for an accepted pull request is:
|
||||
|
||||
[](https://whispersystems.org/blog/bithub/)
|
||||
|
||||
## Contributing Ideas
|
||||
Have something you want to say about Open Whisper Systems projects or want to be part of the conversation? Get involved in the mailing list!
|
||||
|
||||
whispersystems@lists.riseup.net
|
||||
|
||||
https://lists.riseup.net/www/info/whispersystems
|
||||
|
||||
Translation
|
||||
------------
|
||||
## Contributing Funds
|
||||
[](https://whispersystems.org/blog/bithub/)
|
||||
|
||||
Interested in helping to translate TextSecure? Contribute here:
|
||||
You can add funds to BitHub to directly help further development efforts.
|
||||
|
||||
https://www.transifex.com/projects/p/textsecure-official/
|
||||
Help
|
||||
====
|
||||
## Support
|
||||
For troubleshooting and questions, please visit our support center!
|
||||
|
||||
Downloads
|
||||
------------
|
||||
http://support.whispersystems.org/
|
||||
|
||||
TextSecure can be downloaded from the Play Store here:
|
||||
## Documentation
|
||||
Looking for documentation? Check out the wiki!
|
||||
|
||||
https://play.google.com/store/apps/details?id=org.thoughtcrime.securesms
|
||||
https://github.com/WhisperSystems/TextSecure/wiki
|
||||
|
||||
Cryptography Notice
|
||||
------------
|
||||
# Legal things
|
||||
## Cryptography Notice
|
||||
|
||||
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
|
||||
BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
|
||||
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
|
||||
BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
|
||||
See <http://www.wassenaar.org/> for more information.
|
||||
|
||||
The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms.
|
||||
The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms.
|
||||
The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.
|
||||
|
||||
License
|
||||
---------------------
|
||||
## License
|
||||
|
||||
Copyright 2011 Whisper Systems
|
||||
Copyright 2013 Open WhisperSystems
|
||||
|
||||
Copyright 2013-2014 Open Whisper Systems
|
||||
|
||||
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class CanonicalAddressDatabaseTest extends InstrumentationTestCase {
|
||||
private static final String AMBIGUOUS_NUMBER = "222-3333";
|
||||
private static final String SPECIFIC_NUMBER = "+49 444 222 3333";
|
||||
private static final String EMAIL = "a@b.fom";
|
||||
private static final String SIMILAR_EMAIL = "a@b.com";
|
||||
private static final String GROUP = "__textsecure_group__!000111222333";
|
||||
private static final String SIMILAR_GROUP = "__textsecure_group__!100111222333";
|
||||
private static final String ALPHA = "T-Mobile";
|
||||
private static final String SIMILAR_ALPHA = "T-Mobila";
|
||||
|
||||
private CanonicalAddressDatabase db;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.db = CanonicalAddressDatabase.getInstance(getInstrumentation().getTargetContext());
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw two equivalent numbers (one without locale info, one with full info) at the canonical
|
||||
* address db and see that the caching and DB operations work properly in revealing the right
|
||||
* addresses. This is run twice to ensure cache logic is hit.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testNumberAddressUpdates() throws Exception {
|
||||
final long id = db.getCanonicalAddressId(AMBIGUOUS_NUMBER);
|
||||
|
||||
assertThat(db.getAddressFromId(id)).isEqualTo(AMBIGUOUS_NUMBER);
|
||||
assertThat(db.getCanonicalAddressId(SPECIFIC_NUMBER)).isEqualTo(id);
|
||||
assertThat(db.getAddressFromId(id)).isEqualTo(SPECIFIC_NUMBER);
|
||||
assertThat(db.getCanonicalAddressId(AMBIGUOUS_NUMBER)).isEqualTo(id);
|
||||
|
||||
assertThat(db.getCanonicalAddressId(AMBIGUOUS_NUMBER)).isEqualTo(id);
|
||||
assertThat(db.getAddressFromId(id)).isEqualTo(AMBIGUOUS_NUMBER);
|
||||
assertThat(db.getCanonicalAddressId(SPECIFIC_NUMBER)).isEqualTo(id);
|
||||
assertThat(db.getAddressFromId(id)).isEqualTo(SPECIFIC_NUMBER);
|
||||
assertThat(db.getCanonicalAddressId(AMBIGUOUS_NUMBER)).isEqualTo(id);
|
||||
}
|
||||
|
||||
public void testSimilarNumbers() throws Exception {
|
||||
assertThat(db.getCanonicalAddressId("This is a phone number 222-333-444"))
|
||||
.isNotEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("222-333-444"))
|
||||
.isNotEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("222-333-44"))
|
||||
.isNotEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("222-333-4"))
|
||||
.isNotEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("+49 222-333-4444"))
|
||||
.isNotEqualTo(db.getCanonicalAddressId("+1 222-333-4444"));
|
||||
|
||||
assertThat(db.getCanonicalAddressId("1 222-333-4444"))
|
||||
.isEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("1 (222) 333-4444"))
|
||||
.isEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("+12223334444"))
|
||||
.isEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("+1 (222) 333.4444"))
|
||||
.isEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
assertThat(db.getCanonicalAddressId("+49 (222) 333.4444"))
|
||||
.isEqualTo(db.getCanonicalAddressId("222-333-4444"));
|
||||
|
||||
}
|
||||
|
||||
public void testEmailAddresses() throws Exception {
|
||||
final long emailId = db.getCanonicalAddressId(EMAIL);
|
||||
final long similarEmailId = db.getCanonicalAddressId(SIMILAR_EMAIL);
|
||||
|
||||
assertThat(emailId).isNotEqualTo(similarEmailId);
|
||||
|
||||
assertThat(db.getAddressFromId(emailId)).isEqualTo(EMAIL);
|
||||
assertThat(db.getAddressFromId(similarEmailId)).isEqualTo(SIMILAR_EMAIL);
|
||||
}
|
||||
|
||||
public void testGroups() throws Exception {
|
||||
final long groupId = db.getCanonicalAddressId(GROUP);
|
||||
final long similarGroupId = db.getCanonicalAddressId(SIMILAR_GROUP);
|
||||
|
||||
assertThat(groupId).isNotEqualTo(similarGroupId);
|
||||
|
||||
assertThat(db.getAddressFromId(groupId)).isEqualTo(GROUP);
|
||||
assertThat(db.getAddressFromId(similarGroupId)).isEqualTo(SIMILAR_GROUP);
|
||||
}
|
||||
|
||||
public void testAlpha() throws Exception {
|
||||
final long id = db.getCanonicalAddressId(ALPHA);
|
||||
final long similarId = db.getCanonicalAddressId(SIMILAR_ALPHA);
|
||||
|
||||
assertThat(id).isNotEqualTo(similarId);
|
||||
|
||||
assertThat(db.getAddressFromId(id)).isEqualTo(ALPHA);
|
||||
assertThat(db.getAddressFromId(similarId)).isEqualTo(SIMILAR_ALPHA);
|
||||
}
|
||||
|
||||
public void testIsNumber() throws Exception {
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("+495556666777")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("(222) 333-4444")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("1 (222) 333-4444")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("T-Mobile123")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("333-4444")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("12345")).isTrue();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("T-Mobile")).isFalse();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("T-Mobile1")).isFalse();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("Wherever bank")).isFalse();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("__textsecure_group__!afafafafafaf")).isFalse();
|
||||
assertThat(CanonicalAddressDatabase.isNumberAddress("email@domain.com")).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.thoughtcrime.securesms.service;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import org.whispersystems.libaxolotl.ecc.Curve;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
|
||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||
import org.whispersystems.textsecure.push.SignedPreKeyEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PreKeyServiceTest extends AndroidTestCase {
|
||||
|
||||
public void testSignedPreKeyRotationNotRegistered() throws IOException {
|
||||
SignedPreKeyStore signedPreKeyStore = mock(SignedPreKeyStore.class);
|
||||
PushServiceSocket pushServiceSocket = mock(PushServiceSocket.class);
|
||||
|
||||
when(pushServiceSocket.getCurrentSignedPreKey()).thenReturn(null);
|
||||
|
||||
PreKeyService.CleanSignedPreKeysTask cleanTask = new PreKeyService.CleanSignedPreKeysTask(signedPreKeyStore,
|
||||
pushServiceSocket);
|
||||
|
||||
cleanTask.run();
|
||||
|
||||
verify(pushServiceSocket).getCurrentSignedPreKey();
|
||||
verifyNoMoreInteractions(signedPreKeyStore);
|
||||
}
|
||||
|
||||
public void testSignedPreKeyEviction() throws Exception {
|
||||
SignedPreKeyStore signedPreKeyStore = mock(SignedPreKeyStore.class);
|
||||
PushServiceSocket pushServiceSocket = mock(PushServiceSocket.class);
|
||||
SignedPreKeyEntity currentSignedPreKeyEntity = mock(SignedPreKeyEntity.class);
|
||||
|
||||
when(currentSignedPreKeyEntity.getKeyId()).thenReturn(3133);
|
||||
when(pushServiceSocket.getCurrentSignedPreKey()).thenReturn(currentSignedPreKeyEntity);
|
||||
|
||||
final SignedPreKeyRecord currentRecord = new SignedPreKeyRecord(3133, System.currentTimeMillis(), Curve.generateKeyPair(true), new byte[64]);
|
||||
|
||||
List<SignedPreKeyRecord> records = new LinkedList<SignedPreKeyRecord>() {{
|
||||
add(new SignedPreKeyRecord(1, 10, Curve.generateKeyPair(true), new byte[32]));
|
||||
add(new SignedPreKeyRecord(2, 11, Curve.generateKeyPair(true), new byte[32]));
|
||||
add(new SignedPreKeyRecord(3, System.currentTimeMillis() - 90, Curve.generateKeyPair(true), new byte[64]));
|
||||
add(new SignedPreKeyRecord(4, System.currentTimeMillis() - 100, Curve.generateKeyPair(true), new byte[64]));
|
||||
add(currentRecord);
|
||||
}};
|
||||
|
||||
when(signedPreKeyStore.loadSignedPreKeys()).thenReturn(records);
|
||||
when(signedPreKeyStore.loadSignedPreKey(eq(3133))).thenReturn(currentRecord);
|
||||
|
||||
PreKeyService.CleanSignedPreKeysTask cleanTask = new PreKeyService.CleanSignedPreKeysTask(signedPreKeyStore, pushServiceSocket);
|
||||
cleanTask.run();
|
||||
|
||||
verify(signedPreKeyStore).removeSignedPreKey(eq(1));
|
||||
verify(signedPreKeyStore).removeSignedPreKey(eq(2));
|
||||
verify(signedPreKeyStore, times(2)).removeSignedPreKey(anyInt());
|
||||
}
|
||||
|
||||
public void testSignedPreKeyNoEviction() throws Exception {
|
||||
SignedPreKeyStore signedPreKeyStore = mock(SignedPreKeyStore.class);
|
||||
PushServiceSocket pushServiceSocket = mock(PushServiceSocket.class);
|
||||
SignedPreKeyEntity currentSignedPreKeyEntity = mock(SignedPreKeyEntity.class);
|
||||
|
||||
when(currentSignedPreKeyEntity.getKeyId()).thenReturn(3133);
|
||||
when(pushServiceSocket.getCurrentSignedPreKey()).thenReturn(currentSignedPreKeyEntity);
|
||||
|
||||
final SignedPreKeyRecord currentRecord = new SignedPreKeyRecord(3133, System.currentTimeMillis(), Curve.generateKeyPair(true), new byte[64]);
|
||||
|
||||
List<SignedPreKeyRecord> records = new LinkedList<SignedPreKeyRecord>() {{
|
||||
add(currentRecord);
|
||||
}};
|
||||
|
||||
when(signedPreKeyStore.loadSignedPreKeys()).thenReturn(records);
|
||||
when(signedPreKeyStore.loadSignedPreKey(eq(3133))).thenReturn(currentRecord);
|
||||
|
||||
PreKeyService.CleanSignedPreKeysTask cleanTask = new PreKeyService.CleanSignedPreKeysTask(signedPreKeyStore, pushServiceSocket);
|
||||
cleanTask.run();
|
||||
|
||||
verify(signedPreKeyStore, never()).removeSignedPreKey(anyInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class PhoneNumberFormatterTest extends AndroidTestCase {
|
||||
private static final String LOCAL_NUMBER = "+15555555555";
|
||||
|
||||
public void testFormatNumberE164() throws Exception, InvalidNumberException {
|
||||
assertThat(PhoneNumberFormatter.formatNumber("(555) 555-5555", LOCAL_NUMBER)).isEqualTo(LOCAL_NUMBER);
|
||||
assertThat(PhoneNumberFormatter.formatNumber("555-5555", LOCAL_NUMBER)).isEqualTo(LOCAL_NUMBER);
|
||||
assertThat(PhoneNumberFormatter.formatNumber("(123) 555-5555", LOCAL_NUMBER)).isNotEqualTo(LOCAL_NUMBER);
|
||||
}
|
||||
|
||||
public void testFormatNumberEmail() throws Exception {
|
||||
try {
|
||||
PhoneNumberFormatter.formatNumber("person@domain.com", LOCAL_NUMBER);
|
||||
throw new AssertionFailedError("should have thrown on email");
|
||||
} catch (InvalidNumberException ine) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class UtilTest extends AndroidTestCase {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.thoughtcrime.securesms.service;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.*;
|
||||
|
||||
public class MmsReceiverTest extends InstrumentationTestCase {
|
||||
|
||||
private MmsReceiver mmsReceiver;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mmsReceiver = new MmsReceiver(getInstrumentation().getContext());
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public void testProcessMalformedData() throws Exception {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(SendReceiveService.RECEIVE_MMS_ACTION);
|
||||
intent.putExtra("data", new byte[]{0x00});
|
||||
mmsReceiver.process(null, intent);
|
||||
}
|
||||
|
||||
}
|
||||
2
apntool/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.db
|
||||
*.db.gz
|
||||
1759
apntool/apnlists/cyanogenmod.xml
Normal file
2218
apntool/apnlists/hangouts.xml
Normal file
81
apntool/apntool.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import sys
|
||||
import argparse
|
||||
import sqlite3
|
||||
import gzip
|
||||
from progressbar import ProgressBar, Counter, Timer
|
||||
from lxml import etree
|
||||
|
||||
parser = argparse.ArgumentParser(prog='apntool', description="""Process Android's apn xml files and drop them into an easily
|
||||
queryable SQLite db. Tested up to version 9 of their APN file.""")
|
||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s v1.0')
|
||||
parser.add_argument('-i', '--input', help='the xml file to parse', default='apns.xml', required=False)
|
||||
parser.add_argument('-o', '--output', help='the sqlite db output file', default='apns.db', required=False)
|
||||
parser.add_argument('--quiet', help='do not show progress or verbose instructions', action='store_true', required=False)
|
||||
parser.add_argument('--no-gzip', help="do not gzip after creation", action='store_true', required=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
connection = sqlite3.connect(args.output)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('SELECT SQLITE_VERSION()')
|
||||
version = cursor.fetchone()
|
||||
if not args.quiet:
|
||||
print("SQLite version: %s" % version)
|
||||
print("Opening %s" % args.input)
|
||||
|
||||
cursor.execute("PRAGMA legacy_file_format=ON")
|
||||
cursor.execute("PRAGMA journal_mode=DELETE")
|
||||
cursor.execute("PRAGMA page_size=32768")
|
||||
cursor.execute("VACUUM")
|
||||
cursor.execute("DROP TABLE IF EXISTS apns")
|
||||
cursor.execute("""CREATE TABLE apns(_id INTEGER PRIMARY KEY, mccmnc TEXT, mcc TEXT, mnc TEXT, carrier TEXT, apn TEXT,
|
||||
mmsc TEXT, port INTEGER, type TEXT, protocol TEXT, bearer TEXT, roaming_protocol TEXT,
|
||||
carrier_enabled INTEGER, mmsproxy TEXT, mmsport INTEGER, proxy TEXT, mvno_match_data TEXT,
|
||||
mvno_type TEXT, authtype INTEGER, user TEXT, password TEXT, server TEXT)""")
|
||||
|
||||
apns = etree.parse(args.input)
|
||||
root = apns.getroot()
|
||||
pbar = ProgressBar(widgets=['Processed: ', Counter(), ' apns (', Timer(), ')'], maxval=len(list(root))).start() if not args.quiet else None
|
||||
|
||||
count = 0
|
||||
for apn in root.iter("apn"):
|
||||
if apn.get("mmsc") == None:
|
||||
continue
|
||||
sqlvars = ["?" for x in apn.attrib.keys()] + ["?"]
|
||||
mccmnc = "%s%s" % (apn.get("mcc"), apn.get("mnc"))
|
||||
values = [apn.get(attrib) for attrib in apn.attrib.keys()] + [mccmnc]
|
||||
keys = apn.attrib.keys() + ["mccmnc"]
|
||||
|
||||
cursor.execute("SELECT 1 FROM apns WHERE mccmnc = ? AND apn = ?", [mccmnc, apn.get("apn")])
|
||||
if cursor.fetchone() == None:
|
||||
statement = "INSERT INTO apns (%s) VALUES (%s)" % (", ".join(keys), ", ".join(sqlvars))
|
||||
cursor.execute(statement, values)
|
||||
|
||||
count += 1
|
||||
if not args.quiet:
|
||||
pbar.update(count)
|
||||
|
||||
if not args.quiet:
|
||||
pbar.finish()
|
||||
connection.commit()
|
||||
print("Successfully written to %s" % args.output)
|
||||
|
||||
if not args.no_gzip:
|
||||
gzipped_file = "%s.gz" % (args.output,)
|
||||
with open(args.output, 'rb') as orig:
|
||||
with gzip.open(gzipped_file, 'wb') as gzipped:
|
||||
gzipped.writelines(orig)
|
||||
print("Successfully gzipped to %s" % gzipped_file)
|
||||
|
||||
if not args.quiet:
|
||||
print("\nTo include this in the distribution, copy it to the project's assets/databases/ directory.")
|
||||
print("If you support API 10 or lower, you must use the gzipped version to avoid corruption.")
|
||||
|
||||
except sqlite3.Error, e:
|
||||
if connection:
|
||||
connection.rollback()
|
||||
print("Error: %s" % e.args[0])
|
||||
sys.exit(1)
|
||||
finally:
|
||||
if connection:
|
||||
connection.close()
|
||||
3
apntool/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
argparse>=1.2.1
|
||||
lxml>=3.3.3
|
||||
progressbar-latest>=2.4
|
||||
|
Before Width: | Height: | Size: 582 KiB After Width: | Height: | Size: 496 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 93 KiB |
BIN
assets/databases/apns.db
Normal file
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
BIN
assets/emoji_0_wrapped.png
Normal file
|
After Width: | Height: | Size: 445 KiB |
BIN
assets/emoji_1_wrapped.png
Normal file
|
After Width: | Height: | Size: 547 KiB |
BIN
assets/emoji_2_wrapped.png
Normal file
|
After Width: | Height: | Size: 660 KiB |
BIN
assets/emoji_3_wrapped.png
Normal file
|
After Width: | Height: | Size: 369 KiB |
BIN
assets/emoji_4_wrapped.png
Normal file
|
After Width: | Height: | Size: 363 KiB |
65
build.gradle
@@ -1,42 +1,81 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://repo1.maven.org/maven2"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:0.9.+'
|
||||
classpath 'com.android.tools.build:gradle:0.12.2'
|
||||
classpath files('libs/gradle-witness.jar')
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'android'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'witness'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://repo1.maven.org/maven2"
|
||||
}
|
||||
maven {
|
||||
url "https://raw.github.com/whispersystems/maven/master/gcm-client/releases/"
|
||||
}
|
||||
maven {
|
||||
url "https://raw.github.com/whispersystems/maven/master/gson/releases/"
|
||||
}
|
||||
maven {
|
||||
url "https://raw.github.com/whispersystems/maven/master/smil/releases/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
|
||||
compile 'com.android.support:support-v4:19.0.1'
|
||||
compile 'com.google.android.gcm:gcm-client:1.0.2'
|
||||
compile 'com.android.support:support-v4:20.0.0'
|
||||
compile 'se.emilsjolander:stickylistheaders:2.2.0'
|
||||
compile 'com.google.android.gms:play-services:5.0.89'
|
||||
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
|
||||
compile 'org.w3c:smil:1.0.0'
|
||||
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
|
||||
|
||||
androidTestCompile 'com.squareup:fest-android:1.0.8'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker:1.1'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.1'
|
||||
|
||||
compile project(':library')
|
||||
compile project(':jobqueue')
|
||||
}
|
||||
|
||||
dependencyVerification {
|
||||
verify = [
|
||||
'com.actionbarsherlock:actionbarsherlock:5ab04d74101f70024b222e3ff9c87bee151ec43331b4a2134b6cc08cf8565819',
|
||||
'com.android.support:support-v4:81f2b1c2c94efd5a4ec7fcd97b6cdcd00e87a933905c5c86103c7319eb024572',
|
||||
'se.emilsjolander:stickylistheaders:89146b46c96fea0e40200474a2625cda10fe94891e4128f53cdb42375091b9b6',
|
||||
'com.google.android.gms:play-services:38f326e525830f1d70f60f594ceafcbdf5b312287ddbecd338fd1ed7958a4b1e',
|
||||
'com.astuetz:pagerslidingtabstrip:f1641396732c7132a7abb837e482e5ee2b0ebb8d10813fc52bbaec2c15c184c2',
|
||||
'org.w3c:smil:085dc40f2bb249651578bfa07499fd08b16ad0886dbe2c4078586a408da62f9b',
|
||||
'org.apache.httpcomponents:httpclient-android:6f56466a9bd0d42934b90bfbfe9977a8b654c058bf44a12bdc2877c4e1f033f1',
|
||||
'com.android.support:support-annotations:1aa96ef0cc4a445bfc2f93ccf762305bc57fa107b12afe9d11f3863ae8a11036',
|
||||
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
|
||||
'com.madgag:sc-light-jdk15on:931f39d351429fb96c2f749e7ecb1a256a8ebbf5edca7995c9cc085b94d1841d',
|
||||
'com.googlecode.libphonenumber:libphonenumber:eba17eae81dd622ea89a00a3a8c025b2f25d342e0d9644c5b62e16f15687c3ab',
|
||||
'org.whispersystems:gson:08f4f7498455d1539c9233e5aac18e9b1805815ef29221572996508eb512fe51',
|
||||
]
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 19
|
||||
buildToolsVersion '19.0.2'
|
||||
buildToolsVersion '19.1.0'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 19
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
android {
|
||||
sourceSets {
|
||||
main {
|
||||
@@ -48,6 +87,12 @@ android {
|
||||
res.srcDirs = ['res']
|
||||
assets.srcDirs = ['assets']
|
||||
}
|
||||
androidTest {
|
||||
java.srcDirs = ['androidTest/java']
|
||||
resources.srcDirs = ['androidTest/java']
|
||||
aidl.srcDirs = ['androidTest/java']
|
||||
renderscript.srcDirs = ['androidTest/java']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +110,12 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.whenTaskAdded { task ->
|
||||
if (task.name.equals("lint")) {
|
||||
task.enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
def Properties props = new Properties()
|
||||
def propFile = new File('signing.properties')
|
||||
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
##Translations
|
||||
|
||||
Please do not submit issues or pull requests for translation fixes. Anyone can update the translations in [Transifex](https://www.transifex.com/projects/p/textsecure-official/). Please submit your corrections there.
|
||||
|
||||
## Submitting useful bug reports
|
||||
1. Search our issues first to make sure this is not a duplicate.
|
||||
1. Read the [Submitting useful bug reports guide](https://github.com/WhisperSystems/TextSecure/wiki/Submitting-useful-bug-reports) before posting a bug.
|
||||
|
||||
## Development Ideology
|
||||
|
||||
Truths which we believe to be self-evident:
|
||||
|
||||
1. **The answer is not more options.** If you feel compelled to add a
|
||||
preference that's exposed to the user, it's very possible you've made
|
||||
a wrong turn somewhere.
|
||||
1. **The user doesn't know what a key is.** We need to minimize the points
|
||||
at which a user is exposed to this sort of terminology as extremely as
|
||||
possible.
|
||||
1. **There are no power users.** The idea that some users "understand"
|
||||
concepts better than others has proven to be, for the most part, false.
|
||||
If anything, "power users" are more dangerous than the rest, and we
|
||||
should avoid exposing dangerous functionality to them.
|
||||
1. **If it's "like PGP," it's wrong.** PGP is our spirit guide for what
|
||||
not to do.
|
||||
1. **It's an asynchronous world.** Be wary of anything that is
|
||||
anti-asynchronous: ACKs, protocol confirmations, or any protocol-level
|
||||
"advisory" message.
|
||||
1. **There is no such thing as time.** Protocol ideas that require synchronized
|
||||
clocks are doomed to failure.
|
||||
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Mar 10 23:44:05 PDT 2014
|
||||
#Mon Jun 09 23:26:49 PDT 2014
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
|
||||
|
||||
1
jobqueue/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
19
jobqueue/build.gradle
Normal file
@@ -0,0 +1,19 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 20
|
||||
buildToolsVersion "20.0.0"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "org.whispersystems.jobqueue"
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 19
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package org.whispersystems.jobqueue;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import org.whispersystems.jobqueue.jobs.PersistentTestJob;
|
||||
import org.whispersystems.jobqueue.jobs.RequirementDeferringTestJob;
|
||||
import org.whispersystems.jobqueue.jobs.RequirementTestJob;
|
||||
import org.whispersystems.jobqueue.jobs.TestJob;
|
||||
import org.whispersystems.jobqueue.persistence.JavaJobSerializer;
|
||||
import org.whispersystems.jobqueue.util.MockRequirement;
|
||||
import org.whispersystems.jobqueue.util.MockRequirementProvider;
|
||||
import org.whispersystems.jobqueue.util.PersistentMockRequirement;
|
||||
import org.whispersystems.jobqueue.util.PersistentRequirement;
|
||||
import org.whispersystems.jobqueue.util.PersistentResult;
|
||||
import org.whispersystems.jobqueue.util.RunnableThrowable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JobManagerTest extends AndroidTestCase {
|
||||
|
||||
public void testTransientJobExecution() throws InterruptedException {
|
||||
TestJob testJob = new TestJob();
|
||||
JobManager jobManager = new JobManager(getContext(), "transient-test", null, null, 1);
|
||||
|
||||
jobManager.add(testJob);
|
||||
|
||||
assertTrue(testJob.isAdded());
|
||||
assertTrue(testJob.isRan());
|
||||
}
|
||||
|
||||
public void testTransientRequirementJobExecution() throws InterruptedException {
|
||||
MockRequirementProvider provider = new MockRequirementProvider();
|
||||
MockRequirement requirement = new MockRequirement(false);
|
||||
TestJob testJob = new RequirementTestJob(requirement);
|
||||
JobManager jobManager = new JobManager(getContext(), "transient-requirement-test",
|
||||
provider, null, 1);
|
||||
|
||||
jobManager.add(testJob);
|
||||
|
||||
assertTrue(testJob.isAdded());
|
||||
assertTrue(!testJob.isRan());
|
||||
|
||||
requirement.setPresent(true);
|
||||
provider.fireChange();
|
||||
|
||||
assertTrue(testJob.isRan());
|
||||
}
|
||||
|
||||
public void testTransientRequirementDeferringJobExecution() throws InterruptedException {
|
||||
final Object lock = new Object();
|
||||
|
||||
RunnableThrowable waitRunnable = new RunnableThrowable() {
|
||||
public Boolean shouldThrow = false;
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
try {
|
||||
synchronized (lock) {
|
||||
lock.wait();
|
||||
|
||||
if (shouldThrow) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void shouldThrow(Boolean value) {
|
||||
shouldThrow = value;
|
||||
}
|
||||
};
|
||||
|
||||
MockRequirementProvider provider = new MockRequirementProvider();
|
||||
MockRequirement requirement = new MockRequirement(false);
|
||||
RequirementDeferringTestJob testJob = new RequirementDeferringTestJob(requirement, 5, waitRunnable);
|
||||
JobManager jobManager = new JobManager(getContext(), "transient-requirement-test",
|
||||
provider, null, 1);
|
||||
|
||||
jobManager.add(testJob);
|
||||
|
||||
waitRunnable.shouldThrow(true);
|
||||
requirement.setPresent(true);
|
||||
provider.fireChange();
|
||||
|
||||
assertTrue(testJob.isRan());
|
||||
assertTrue(!testJob.isFinished());
|
||||
synchronized (lock) { lock.notifyAll(); }
|
||||
assertTrue(!testJob.isFinished());
|
||||
|
||||
requirement.setPresent(false);
|
||||
provider.fireChange();
|
||||
assertTrue(!testJob.isFinished());
|
||||
synchronized (lock) { lock.notifyAll(); }
|
||||
assertTrue(!testJob.isFinished());
|
||||
|
||||
waitRunnable.shouldThrow(false);
|
||||
requirement.setPresent(true);
|
||||
provider.fireChange();
|
||||
assertTrue(!testJob.isFinished());
|
||||
synchronized (lock) { lock.notifyAll(); }
|
||||
assertTrue(testJob.isFinished());
|
||||
}
|
||||
|
||||
public void testPersistentJobExecuton() throws InterruptedException {
|
||||
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
||||
PersistentTestJob testJob = new PersistentTestJob(requirement);
|
||||
JobManager jobManager = new JobManager(getContext(), "persistent-requirement-test3",
|
||||
null, new JavaJobSerializer(getContext()), 1);
|
||||
|
||||
PersistentResult.getInstance().reset();
|
||||
PersistentRequirement.getInstance().setPresent(false);
|
||||
|
||||
jobManager.add(testJob);
|
||||
|
||||
assertTrue(PersistentResult.getInstance().isAdded());
|
||||
assertTrue(!PersistentResult.getInstance().isRan());
|
||||
|
||||
PersistentRequirement.getInstance().setPresent(true);
|
||||
jobManager = new JobManager(getContext(), "persistent-requirement-test3", null,
|
||||
new JavaJobSerializer(getContext()), 1);
|
||||
|
||||
assertTrue(PersistentResult.getInstance().isRan());
|
||||
}
|
||||
|
||||
public void testEncryptedJobExecuton() throws InterruptedException {
|
||||
EncryptionKeys keys = new EncryptionKeys(new byte[30]);
|
||||
PersistentMockRequirement requirement = new PersistentMockRequirement();
|
||||
PersistentTestJob testJob = new PersistentTestJob(requirement, keys);
|
||||
JobManager jobManager = new JobManager(getContext(), "persistent-requirement-test4",
|
||||
null, new JavaJobSerializer(getContext()), 1);
|
||||
jobManager.setEncryptionKeys(keys);
|
||||
|
||||
PersistentResult.getInstance().reset();
|
||||
PersistentRequirement.getInstance().setPresent(false);
|
||||
|
||||
jobManager.add(testJob);
|
||||
|
||||
assertTrue(PersistentResult.getInstance().isAdded());
|
||||
assertTrue(!PersistentResult.getInstance().isRan());
|
||||
|
||||
PersistentRequirement.getInstance().setPresent(true);
|
||||
jobManager = new JobManager(getContext(), "persistent-requirement-test4", null, new JavaJobSerializer(getContext()), 1);
|
||||
|
||||
assertTrue(!PersistentResult.getInstance().isRan());
|
||||
|
||||
jobManager.setEncryptionKeys(keys);
|
||||
|
||||
assertTrue(PersistentResult.getInstance().isRan());
|
||||
}
|
||||
|
||||
public void testGroupIdExecution() throws InterruptedException {
|
||||
final Object lock = new Object();
|
||||
|
||||
Runnable waitRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
synchronized (lock) {
|
||||
lock.wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TestJob testJobOne = new TestJob(JobParameters.newBuilder().withGroupId("foo").create(), waitRunnable);
|
||||
TestJob testJobTwo = new TestJob(JobParameters.newBuilder().withGroupId("foo").create());
|
||||
TestJob testJobThree = new TestJob(JobParameters.newBuilder().withGroupId("bar").create());
|
||||
JobManager jobManager = new JobManager(getContext(), "transient-test", null, null, 3);
|
||||
|
||||
jobManager.add(testJobOne);
|
||||
jobManager.add(testJobTwo);
|
||||
jobManager.add(testJobThree);
|
||||
|
||||
assertTrue(testJobOne.isAdded());
|
||||
assertTrue(testJobTwo.isAdded());
|
||||
assertTrue(testJobThree.isAdded());
|
||||
|
||||
assertTrue(testJobOne.isRan());
|
||||
assertTrue(!testJobTwo.isRan());
|
||||
assertTrue(testJobThree.isRan());
|
||||
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
|
||||
assertTrue(testJobTwo.isRan());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.whispersystems.jobqueue.jobs;
|
||||
|
||||
import org.whispersystems.jobqueue.EncryptionKeys;
|
||||
import org.whispersystems.jobqueue.Job;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
import org.whispersystems.jobqueue.util.PersistentResult;
|
||||
|
||||
public class PersistentTestJob extends Job {
|
||||
|
||||
public PersistentTestJob(Requirement requirement) {
|
||||
super(JobParameters.newBuilder().withRequirement(requirement).withPersistence().create());
|
||||
}
|
||||
|
||||
public PersistentTestJob(Requirement requirement, EncryptionKeys keys) {
|
||||
super(JobParameters.newBuilder().withRequirement(requirement).withPersistence().withEncryption(keys).create());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
PersistentResult.getInstance().onAdded();;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws Throwable {
|
||||
PersistentResult.getInstance().onRun();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled() {
|
||||
PersistentResult.getInstance().onCanceled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShouldRetry(Throwable throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.whispersystems.jobqueue.jobs;
|
||||
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
import org.whispersystems.jobqueue.util.RunnableThrowable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RequirementDeferringTestJob extends TestJob {
|
||||
|
||||
private final Object FINISHED_LOCK = new Object();
|
||||
|
||||
private boolean finished = false;
|
||||
|
||||
private RunnableThrowable runnable;
|
||||
|
||||
public RequirementDeferringTestJob(Requirement requirement, int retryCount, RunnableThrowable runnable) {
|
||||
super(JobParameters.newBuilder().withRequirement(requirement).withRetryCount(retryCount).create());
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws Throwable {
|
||||
synchronized (RAN_LOCK) {
|
||||
this.ran = true;
|
||||
}
|
||||
|
||||
if (runnable != null)
|
||||
runnable.run();
|
||||
|
||||
synchronized (FINISHED_LOCK) {
|
||||
this.finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShouldRetry(Throwable throwable) {
|
||||
if (throwable instanceof Exception) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFinished() throws InterruptedException {
|
||||
synchronized (FINISHED_LOCK) {
|
||||
if (!finished) FINISHED_LOCK.wait(1000);
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.whispersystems.jobqueue.jobs;
|
||||
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
|
||||
public class RequirementTestJob extends TestJob {
|
||||
|
||||
public RequirementTestJob(Requirement requirement) {
|
||||
super(JobParameters.newBuilder().withRequirement(requirement).create());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.whispersystems.jobqueue.jobs;
|
||||
|
||||
import org.whispersystems.jobqueue.Job;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
|
||||
public class TestJob extends Job {
|
||||
|
||||
private final Object ADDED_LOCK = new Object();
|
||||
protected final Object RAN_LOCK = new Object();
|
||||
private final Object CANCELED_LOCK = new Object();
|
||||
|
||||
private boolean added = false;
|
||||
protected boolean ran = false;
|
||||
private boolean canceled = false;
|
||||
|
||||
private Runnable runnable;
|
||||
|
||||
public TestJob() {
|
||||
this(JobParameters.newBuilder().create());
|
||||
}
|
||||
|
||||
public TestJob(JobParameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
public TestJob(JobParameters parameters, Runnable runnable) {
|
||||
super(parameters);
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
synchronized (ADDED_LOCK) {
|
||||
this.added = true;
|
||||
this.ADDED_LOCK.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws Throwable {
|
||||
synchronized (RAN_LOCK) {
|
||||
this.ran = true;
|
||||
}
|
||||
|
||||
if (runnable != null)
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled() {
|
||||
synchronized (CANCELED_LOCK) {
|
||||
this.canceled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShouldRetry(Throwable throwable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAdded() throws InterruptedException {
|
||||
synchronized (ADDED_LOCK) {
|
||||
if (!added) ADDED_LOCK.wait(1000);
|
||||
return added;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRan() throws InterruptedException {
|
||||
synchronized (RAN_LOCK) {
|
||||
if (!ran) RAN_LOCK.wait(1000);
|
||||
return ran;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCanceled() throws InterruptedException {
|
||||
synchronized (CANCELED_LOCK) {
|
||||
if (!canceled) CANCELED_LOCK.wait(1000);
|
||||
return canceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class MockRequirement implements Requirement {
|
||||
|
||||
private AtomicBoolean present;
|
||||
|
||||
public MockRequirement(boolean present) {
|
||||
this.present = new AtomicBoolean(present);
|
||||
}
|
||||
|
||||
public void setPresent(boolean present) {
|
||||
this.present.set(present);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPresent() {
|
||||
return present.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
import org.whispersystems.jobqueue.requirements.RequirementListener;
|
||||
import org.whispersystems.jobqueue.requirements.RequirementProvider;
|
||||
|
||||
public class MockRequirementProvider implements RequirementProvider {
|
||||
|
||||
private RequirementListener listener;
|
||||
|
||||
public void fireChange() {
|
||||
listener.onRequirementStatusChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(RequirementListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
|
||||
public class PersistentMockRequirement implements Requirement {
|
||||
@Override
|
||||
public boolean isPresent() {
|
||||
return PersistentRequirement.getInstance().isPresent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class PersistentRequirement {
|
||||
|
||||
private AtomicBoolean present = new AtomicBoolean(false);
|
||||
|
||||
private static final PersistentRequirement instance = new PersistentRequirement();
|
||||
|
||||
public static PersistentRequirement getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setPresent(boolean present) {
|
||||
this.present.set(present);
|
||||
}
|
||||
|
||||
public boolean isPresent() {
|
||||
return present.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
public class PersistentResult {
|
||||
|
||||
private final Object ADDED_LOCK = new Object();
|
||||
private final Object RAN_LOCK = new Object();
|
||||
private final Object CANCELED_LOCK = new Object();
|
||||
|
||||
private boolean added = false;
|
||||
private boolean ran = false;
|
||||
private boolean canceled = false;
|
||||
|
||||
private static final PersistentResult instance = new PersistentResult();
|
||||
|
||||
public static PersistentResult getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void onAdded() {
|
||||
synchronized (ADDED_LOCK) {
|
||||
this.added = true;
|
||||
this.ADDED_LOCK.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRun() throws Throwable {
|
||||
synchronized (RAN_LOCK) {
|
||||
this.ran = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void onCanceled() {
|
||||
synchronized (CANCELED_LOCK) {
|
||||
this.canceled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAdded() throws InterruptedException {
|
||||
synchronized (ADDED_LOCK) {
|
||||
if (!added) ADDED_LOCK.wait(1000);
|
||||
return added;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRan() throws InterruptedException {
|
||||
synchronized (RAN_LOCK) {
|
||||
if (!ran) RAN_LOCK.wait(1000);
|
||||
return ran;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCanceled() throws InterruptedException {
|
||||
synchronized (CANCELED_LOCK) {
|
||||
if (!canceled) CANCELED_LOCK.wait(1000);
|
||||
return canceled;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
synchronized (ADDED_LOCK) {
|
||||
this.added = false;
|
||||
}
|
||||
|
||||
synchronized (RAN_LOCK) {
|
||||
this.ran = false;
|
||||
}
|
||||
|
||||
synchronized (CANCELED_LOCK) {
|
||||
this.canceled = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.whispersystems.jobqueue.util;
|
||||
|
||||
public interface RunnableThrowable {
|
||||
|
||||
public void run() throws Throwable;
|
||||
|
||||
public void shouldThrow(Boolean value);
|
||||
}
|
||||
6
jobqueue/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.whispersystems.jobqueue">
|
||||
|
||||
<application />
|
||||
|
||||
</manifest>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -14,24 +14,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
package org.whispersystems.jobqueue;
|
||||
|
||||
import android.app.Application;
|
||||
public class EncryptionKeys {
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.PRNGFixes;
|
||||
private transient final byte[] encoded;
|
||||
|
||||
/**
|
||||
* Will be called once when the TextSecure process is created.
|
||||
*
|
||||
* We're using this as an insertion point to patch up the Android PRNG disaster.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public class ApplicationListener extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
PRNGFixes.apply();
|
||||
public EncryptionKeys(byte[] encoded) {
|
||||
this.encoded = encoded;
|
||||
}
|
||||
|
||||
public byte[] getEncoded() {
|
||||
return encoded;
|
||||
}
|
||||
}
|
||||
89
jobqueue/src/main/java/org/whispersystems/jobqueue/Job.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.jobqueue;
|
||||
|
||||
import org.whispersystems.jobqueue.requirements.Requirement;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Job implements Serializable {
|
||||
|
||||
private final JobParameters parameters;
|
||||
|
||||
private transient long persistentId;
|
||||
private transient int runIteration;
|
||||
|
||||
public Job(JobParameters parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public List<Requirement> getRequirements() {
|
||||
return parameters.getRequirements();
|
||||
}
|
||||
|
||||
public boolean isRequirementsMet() {
|
||||
for (Requirement requirement : parameters.getRequirements()) {
|
||||
if (!requirement.isPresent()) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return parameters.getGroupId();
|
||||
}
|
||||
|
||||
public boolean isPersistent() {
|
||||
return parameters.isPersistent();
|
||||
}
|
||||
|
||||
public EncryptionKeys getEncryptionKeys() {
|
||||
return parameters.getEncryptionKeys();
|
||||
}
|
||||
|
||||
public void setEncryptionKeys(EncryptionKeys keys) {
|
||||
parameters.setEncryptionKeys(keys);
|
||||
}
|
||||
|
||||
public int getRetryCount() {
|
||||
return parameters.getRetryCount();
|
||||
}
|
||||
|
||||
public void setPersistentId(long persistentId) {
|
||||
this.persistentId = persistentId;
|
||||
}
|
||||
|
||||
public long getPersistentId() {
|
||||
return persistentId;
|
||||
}
|
||||
|
||||
public int getRunIteration() {
|
||||
return runIteration;
|
||||
}
|
||||
|
||||
public void setRunIteration(int runIteration) {
|
||||
this.runIteration = runIteration;
|
||||
}
|
||||
|
||||
public abstract void onAdded();
|
||||
public abstract void onRun() throws Throwable;
|
||||
public abstract void onCanceled();
|
||||
public abstract boolean onShouldRetry(Throwable throwable);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.whispersystems.jobqueue;
|
||||
|
||||
import org.whispersystems.jobqueue.persistence.PersistentStorage;
|
||||
|
||||
public class JobConsumer extends Thread {
|
||||
|
||||
enum JobResult {
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
DEFERRED
|
||||
}
|
||||
|
||||
private final JobQueue jobQueue;
|
||||
private final PersistentStorage persistentStorage;
|
||||
|
||||
public JobConsumer(String name, JobQueue jobQueue, PersistentStorage persistentStorage) {
|
||||
super(name);
|
||||
this.jobQueue = jobQueue;
|
||||
this.persistentStorage = persistentStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
Job job = jobQueue.getNext();
|
||||
|
||||
JobResult result;
|
||||
|
||||
if ((result = runJob(job)) != JobResult.DEFERRED) {
|
||||
if (result == JobResult.FAILURE) {
|
||||
job.onCanceled();
|
||||
}
|
||||
|
||||
if (job.isPersistent()) {
|
||||
persistentStorage.remove(job.getPersistentId());
|
||||
}
|
||||
} else {
|
||||
jobQueue.add(job);
|
||||
}
|
||||
|
||||
if (job.getGroupId() != null) {
|
||||
jobQueue.setGroupIdAvailable(job.getGroupId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JobResult runJob(Job job) {
|
||||
int retryCount = job.getRetryCount();
|
||||
int runIteration = job.getRunIteration();
|
||||
|
||||
for (;runIteration<retryCount;runIteration++) {
|
||||
try {
|
||||
job.onRun();
|
||||
return JobResult.SUCCESS;
|
||||
} catch (Throwable throwable) {
|
||||
if (!job.onShouldRetry(throwable)) {
|
||||
return JobResult.FAILURE;
|
||||
} else if (!job.isRequirementsMet()) {
|
||||
job.setRunIteration(runIteration+1);
|
||||
return JobResult.DEFERRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JobResult.FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||