Commit a39fb2a8 authored by axet's avatar axet 🍄

Merge branch 'smsgate-1.8.19'

parents a22ac375 b2f30005
Pipeline #19687984 (#) passed with stage
in 28 seconds
......@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '27.0.1'
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.github.axet.smsgate"
minSdkVersion 9
targetSdkVersion 23
versionCode 202
versionName "1.8.18"
versionCode 203
versionName "1.8.19"
}
packagingOptions {
exclude 'META-INF/LICENSE'
......@@ -38,26 +38,25 @@ android {
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.github.axet:android-library:1.22.7' // compile project(':android-library')
compile 'com.android.support:design:25.3.1'
compile 'com.intellij:annotations:12.0'
compile 'com.beetstra.jutf7:jutf7:1.0.0'
compile 'com.github.axet:k9-lib:0.0.1@aar'
compile 'com.squareup:otto:1.3.5'
compile('oauth.signpost:signpost-commonshttp4:1.2.1.2') {
testImplementation 'junit:junit:4.12'
implementation 'com.github.axet:android-library:1.22.7' // implementation project(':android-library')
implementation 'com.android.support:design:25.3.1'
implementation 'com.intellij:annotations:12.0'
implementation 'com.beetstra.jutf7:jutf7:1.0.0'
implementation 'com.github.axet:k9-lib:0.0.1@aar'
implementation 'com.squareup:otto:1.3.5'
implementation('oauth.signpost:signpost-commonshttp4:1.2.1.2') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'org.apache.httpcomponents', module: 'httpcore'
}
compile 'org.apache.james:apache-mime4j-core:0.7.2'
compile 'jp.wasabeef:recyclerview-animators:2.2.3'
// compile project(':android-firebase-fake') // compile 'com.github.axet:firebase-fake:0.0.4'
compile 'com.google.firebase:firebase-core:9.8.0'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.firebase:firebase-storage:9.8.0'
implementation 'org.apache.james:apache-mime4j-core:0.7.2'
implementation 'jp.wasabeef:recyclerview-animators:2.2.3'
// implementation project(':android-firebase-fake') // implementation 'com.github.axet:firebase-fake:0.0.4'
implementation 'com.google.firebase:firebase-core:9.8.0'
implementation 'com.google.firebase:firebase-database:9.8.0'
implementation 'com.google.firebase:firebase-auth:9.8.0'
implementation 'com.google.firebase:firebase-messaging:9.8.0'
implementation 'com.google.firebase:firebase-storage:9.8.0'
}
apply plugin: 'com.google.gms.google-services'
......@@ -21,3 +21,6 @@
-dontwarn com.fsck.k9.mail.**
-dontwarn com.google.firebase.**
-dontwarn com.google.android.**
-keep class com.github.axet.smsgate.services.FirebaseService$Info {*;}
-keep class com.github.axet.smsgate.services.FirebaseService$Message {*;}
......@@ -122,7 +122,7 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
FirebaseAuth mFirebaseAuth;
DatabaseReference connected;
ValueEventListener connectedList;
DatabaseReference users;
DatabaseReference user;
DatabaseReference messages;
DatabaseReference shares;
DatabaseReference notifications;
......@@ -157,7 +157,12 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
commands.put("refresh", new Command() {
@Override
public void run(JSONObject obj) {
messages();
messagesExists(new Runnable() {
@Override
public void run() {
messages();
}
});
}
});
commands.put("send", new Command() {
......@@ -396,14 +401,14 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
return version;
}
public void setVersion(String v) {
version = v;
public void setVersion(String version) {
this.version = version;
}
}
public static class Message {
private String id;
private long date;
private Long date;
private String text;
public Message() {
......@@ -430,11 +435,11 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
this.text = text;
}
public void setDate(long date) {
public void setDate(Long date) {
this.date = date;
}
public long getDate() {
public Long getDate() {
return date;
}
}
......@@ -906,13 +911,13 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
};
connected.addValueEventListener(connectedList);
users = db.getReference().child("/users/" + keyPair.getAddress());
shares = users.child("shares");
notifications = users.child("notifications");
messages = users.child("messages");
info = users.child("info");
user = db.getReference().child("/users/" + keyPair.getAddress());
shares = user.child("shares");
notifications = user.child("notifications");
messages = user.child("messages");
info = user.child("info");
storage = FirebaseStorage.getInstance().getReference().child("/users/" + keyPair.getAddress());
uploads = users.child("uploads");
uploads = user.child("uploads");
// load current uploads after restart / reconnect
uploads.addListenerForSingleValueEvent(new ValueEventListener() {
......@@ -1216,14 +1221,32 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
}
public void incoming() {
if (messages() == 0) { // we expect message. not yet here? retry
handler.postDelayed(new Runnable() {
@Override
public void run() {
incoming();
final Runnable run = new Runnable() {
@Override
public void run() {
if (messages() == 0) { // we expect message. not yet here? retry
handler.postDelayed(this, 1000);
}
}, 1000);
}
}
};
messagesExists(run);
}
public void messagesExists(final Runnable run) {
user.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.hasChild("messages")) {
QueryBuilder b = new QueryBuilder(FirebaseService.this);
b.setLastSMS(0);
}
run.run();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public int messages() {
......@@ -1509,51 +1532,36 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
}
void info() {
info.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object v = dataSnapshot.getValue();
try {
if (v == null) {
QueryBuilder b = new QueryBuilder(FirebaseService.this);
b.setLastSMS(0);
}
final JSONObject json = new JSONObject();
json.put("uptime", Long.toString(SystemClock.elapsedRealtime()));
json.put("os", Build.BRAND + " " + android.os.Build.VERSION.RELEASE);
json.put("sim", sim.getCount());
json.put("battery", getBatteryLevel());
if (phone.isTelephony())
json.put("signal", getSignalLevel());
String version = "";
try {
PackageManager pm = getPackageManager();
ApplicationInfo a = pm.getApplicationInfo(getPackageName(), 0);
PackageInfo pInfo = pm.getPackageInfo(getPackageName(), 0);
version = "v" + pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
info.setValue(new Info(version, keyPair.encrypt(json.toString()))).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "info updated");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "info failed update");
}
});
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
try {
final JSONObject json = new JSONObject();
json.put("uptime", Long.toString(SystemClock.elapsedRealtime()));
json.put("os", Build.BRAND + " " + android.os.Build.VERSION.RELEASE);
json.put("sim", sim.getCount());
json.put("battery", getBatteryLevel());
if (phone.isTelephony())
json.put("signal", getSignalLevel());
String version = "";
try {
PackageManager pm = getPackageManager();
PackageInfo pInfo = pm.getPackageInfo(getPackageName(), 0);
version = "v" + pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
});
info.setValue(new Info(version, keyPair.encrypt(json.toString()))).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "info updated");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "info failed update");
}
});
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
String getBatteryLevel() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment