Commit d2b66c68 authored by axet's avatar axet 🍄

Merge branch 'smsgate-1.9.1'

parents db30c440 6ae7891a
Pipeline #35862463 passed with stage
in 4 minutes and 49 seconds
......@@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.smsgate"
minSdkVersion 9
targetSdkVersion 26
versionCode 209
versionName "1.9.0"
versionCode 210
versionName "1.9.1"
}
packagingOptions {
exclude 'META-INF/LICENSE'
......
......@@ -294,21 +294,21 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
public void incoming() {
final Runnable run = new Runnable() {
int count = 0;
long last = System.currentTimeMillis() - 1000; // we except message from (now - 1sec)
@Override
public void run() {
count++;
if (count > 10)
return;
if (messages() == 0) { // we expect message. not yet here? retry
if (messages() < last) // we expect message. not yet here? retry
handler.postDelayed(this, 1000);
}
}
};
run.run();
}
public int messages() {
public long messages() {
final QueryBuilder b = new QueryBuilder(context);
BackupItemsFetcher fetcher = new BackupItemsFetcher(context, context.getContentResolver(), b);
BackupCursors cursors = new BulkFetcher(fetcher).fetch(EnumSet.of(DataType.SMS), -1);
......@@ -356,7 +356,10 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
}
cursors.close();
return count;
if (count == 0)
return 0;
return b.getLastSMS();
}
public Uri getStoragePath() {
......
......@@ -1060,15 +1060,15 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
public void incoming() {
final Runnable run = new Runnable() {
int count = 0;
long last = System.currentTimeMillis() - 1000;
@Override
public void run() {
count++;
if (count > 10)
return;
if (messages() == 0) { // we expect message. not yet here? retry
if (messages() < last) // we expect message. not yet here? retry
handler.postDelayed(this, 1000);
}
}
};
messagesExists(run);
......@@ -1091,7 +1091,7 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
});
}
public int messages() {
public long messages() {
final QueryBuilder b = new QueryBuilder(this);
BackupItemsFetcher fetcher = new BackupItemsFetcher(this, getContentResolver(), b);
BackupCursors cursors = new BulkFetcher(fetcher).fetch(EnumSet.of(DataType.SMS), -1);
......@@ -1111,7 +1111,10 @@ public class FirebaseService extends Service implements FirebaseAuth.AuthStateLi
}
cursors.close();
return count;
if (count == 0)
return 0;
return b.getLastSMS();
}
@Override
......
......@@ -99,7 +99,9 @@ public class SMSGateFragment extends PreferenceFragmentCompat implements MainAct
public static final int RESULT_PERMS_FIRE = 5;
public static final int RESULT_PERMS_CONN = 6;
public static final String[] PERMISSIONS = new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS, Manifest.permission.READ_PHONE_STATE};
public static final String[] PERMISSIONS = new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.READ_SMS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.RECEIVE_SMS};
public static final String[] PERMISSIONS_STORAGE = concat(PERMISSIONS, Storage.PERMISSIONS_RW);
enum Actions {
Backup,
......@@ -131,6 +133,15 @@ public class SMSGateFragment extends PreferenceFragmentCompat implements MainAct
}
};
public static String[] concat(String[] A, String[] B) {
int aLen = A.length;
int bLen = B.length;
String[] C = new String[aLen + bLen];
System.arraycopy(A, 0, C, 0, aLen);
System.arraycopy(B, 0, C, aLen, bLen);
return C;
}
@Override
public void onCreatePreferences(Bundle bundle, String s) {
Context context = getActivity();
......@@ -177,7 +188,7 @@ public class SMSGateFragment extends PreferenceFragmentCompat implements MainAct
StoragePathPreferenceCompat storage = (StoragePathPreferenceCompat) findPreference(SMSApplication.PREF_STORAGE);
storage.setStorage(new Storage(getContext()));
storage.setPermissionsDialog(this, Storage.PERMISSIONS_RW, RESULT_PERMS_STOR);
storage.setPermissionsDialog(this, PERMISSIONS_STORAGE, RESULT_PERMS_STOR);
if (Build.VERSION.SDK_INT >= 21)
storage.setStorageAccessFramework(this, RESULT_PERMS_STOR);
}
......
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