2021-02-21 17:18:37 +01:00
|
|
|
package app.fedilab.android.helper;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2021-02-24 00:52:44 +01:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2021-02-21 17:18:37 +01:00
|
|
|
import android.util.Base64;
|
2021-02-24 00:52:44 +01:00
|
|
|
import android.util.Log;
|
2021-02-23 18:34:58 +01:00
|
|
|
|
|
|
|
import org.unifiedpush.android.connector.Registration;
|
|
|
|
|
2021-02-26 19:03:36 +01:00
|
|
|
import java.util.ArrayList;
|
2021-02-23 18:34:58 +01:00
|
|
|
import java.util.List;
|
2021-02-21 17:18:37 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2021-02-23 18:34:58 +01:00
|
|
|
import app.fedilab.android.activities.BaseMainActivity;
|
2021-02-24 00:52:44 +01:00
|
|
|
import app.fedilab.android.asynctasks.PostSubscriptionAsyncTask;
|
|
|
|
import app.fedilab.android.client.APIResponse;
|
2021-02-23 19:08:45 +01:00
|
|
|
import app.fedilab.android.client.Entities.Account;
|
2021-02-24 00:52:44 +01:00
|
|
|
import app.fedilab.android.interfaces.OnPostSubscription;
|
|
|
|
import app.fedilab.android.sqlite.AccountDAO;
|
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
2021-02-23 18:34:58 +01:00
|
|
|
|
2021-02-24 00:52:44 +01:00
|
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
|
|
|
|
|
|
public class PushNotifications implements OnPostSubscription {
|
2021-02-21 17:18:37 +01:00
|
|
|
|
2021-02-24 00:52:44 +01:00
|
|
|
private Context context;
|
2021-02-21 17:18:37 +01:00
|
|
|
|
2021-02-24 00:52:44 +01:00
|
|
|
public void registerPushNotifications(Context context, String endpoint) {
|
|
|
|
this.context = context;
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
List<Account> accountPush = new AccountDAO(context, db).getPushNotificationAccounts();
|
|
|
|
for (Account account : accountPush) {
|
|
|
|
new PostSubscriptionAsyncTask(context, account, endpoint, this);
|
|
|
|
}
|
2021-02-21 17:18:37 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 18:34:58 +01:00
|
|
|
public static void getDistributors(Context context) {
|
|
|
|
List<String> distributors = new Registration().getDistributors(context);
|
|
|
|
if (distributors.isEmpty()) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:03:36 +01:00
|
|
|
public void displayNotification(Context context, String ciphered) {
|
2021-02-21 17:18:37 +01:00
|
|
|
ECDH ecdh = new ECDH();
|
2021-02-26 19:03:36 +01:00
|
|
|
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
List<Account> accountPush = new AccountDAO(context, db).getPushNotificationAccounts();
|
|
|
|
List<byte[]> trousseau = new ArrayList<>();
|
|
|
|
for (Account account : accountPush) {
|
|
|
|
byte[] secret = ecdh.getSecret(context, account);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-21 17:18:37 +01:00
|
|
|
//process with the event
|
|
|
|
// https://openacs.org/webpush-demo/report.html
|
|
|
|
// decrypt using AES 128 GCM
|
2021-02-24 00:52:44 +01:00
|
|
|
}
|
2021-02-21 17:18:37 +01:00
|
|
|
|
2021-02-24 00:52:44 +01:00
|
|
|
@Override
|
|
|
|
public void onSubscription(APIResponse apiResponse) {
|
|
|
|
//TODO je ne sais pas si c'est toujours utile
|
2021-02-21 17:18:37 +01:00
|
|
|
}
|
|
|
|
}
|