unifiedpush - first changes
This commit is contained in:
parent
cb9f31787c
commit
17d4325303
|
@ -35,7 +35,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -77,6 +76,7 @@ import com.google.android.material.navigation.NavigationView;
|
|||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.unifiedpush.android.connector.Registration;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -114,7 +114,6 @@ import app.fedilab.android.client.Entities.Error;
|
|||
import app.fedilab.android.client.Entities.Filters;
|
||||
import app.fedilab.android.client.Entities.Instance;
|
||||
import app.fedilab.android.client.Entities.ManageTimelines;
|
||||
import app.fedilab.android.client.Entities.PushSubscription;
|
||||
import app.fedilab.android.client.Entities.Relationship;
|
||||
import app.fedilab.android.client.Entities.Results;
|
||||
import app.fedilab.android.client.Entities.Status;
|
||||
|
@ -424,9 +423,14 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
main_app_container = findViewById(R.id.main_app_container);
|
||||
|
||||
|
||||
Log.v(Helper.TAG, "social: " + social);
|
||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
String serverKey = sharedpreferences.getString(Helper.SERVER_KEY + userId + instance, null);
|
||||
if (serverKey == null) {
|
||||
new PostSubscriptionAsyncTask(BaseMainActivity.this, this);
|
||||
}
|
||||
new PostSubscriptionAsyncTask(BaseMainActivity.this, this);
|
||||
// Registration registration = new Registration();
|
||||
new Registration().registerAppWithDialog(BaseMainActivity.this);
|
||||
}
|
||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
new SyncTimelinesAsyncTask(BaseMainActivity.this, 0, Helper.canFetchList(BaseMainActivity.this, account), BaseMainActivity.this);
|
||||
|
@ -1703,6 +1707,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
new Registration().unregisterApp(BaseMainActivity.this);
|
||||
}
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
boolean clearCacheExit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false);
|
||||
WeakReference<Context> contextReference = new WeakReference<>(BaseMainActivity.this);
|
||||
|
@ -2434,7 +2442,14 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
@Override
|
||||
public void onSubscription(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse != null && apiResponse.getPushSubscription() != null) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(BaseMainActivity.this));
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.SERVER_KEY + userId + instance, apiResponse.getPushSubscription().getServer_key());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
public enum iconLauncher {
|
||||
|
|
|
@ -23,7 +23,6 @@ import android.os.Bundle;
|
|||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
|
@ -5811,10 +5810,8 @@ public class API {
|
|||
String auth = Base64.encodeToString(randBytes, Base64.DEFAULT);
|
||||
params.put("subscription[keys][p256dh]", pubKey);
|
||||
params.put("subscription[keys][auth]", auth);
|
||||
Log.v(Helper.TAG, "params: " + params);
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/push/subscription"), 10, params, prefKeyOauthTokenT);
|
||||
Log.v(Helper.TAG, "response: " + response);
|
||||
pushSubscription = parsePushNotifications(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
|
|
|
@ -277,6 +277,7 @@ public class BaseHelper {
|
|||
//Some definitions
|
||||
public static final String CLIENT_NAME = "client_name";
|
||||
public static final String APP_PREFS = "app_prefs";
|
||||
public static final String SERVER_KEY = "server_key";
|
||||
public static final String ID = "id";
|
||||
public static final String CLIENT_ID = "client_id";
|
||||
public static final String CLIENT_SECRET = "client_secret";
|
||||
|
|
|
@ -140,7 +140,7 @@ public class ECDH {
|
|||
String strPub = prefs.getString(kp_public, "");
|
||||
String strPriv = prefs.getString(kp_private, "");
|
||||
|
||||
if (strPub.isEmpty() || strPriv.isEmpty() || 1 == 1) {
|
||||
if (strPub.isEmpty() || strPriv.isEmpty()) {
|
||||
return newPair(context);
|
||||
}
|
||||
try {
|
||||
|
@ -152,8 +152,6 @@ public class ECDH {
|
|||
}
|
||||
|
||||
public String getPublicKey(Context context) {
|
||||
Log.v(Helper.TAG, "getPair(context): " + getPair(context));
|
||||
Log.v(Helper.TAG, "getPair(context).getPublic(): " + getPair(context).getPublic());
|
||||
return base64Encode(getPair(context).getPublic().getEncoded());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +1,40 @@
|
|||
package app.fedilab.android.services;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.unifiedpush.android.connector.MessagingReceiver;
|
||||
import org.unifiedpush.android.connector.MessagingReceiverHandler;
|
||||
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.PushNotifications;
|
||||
|
||||
class handler implements MessagingReceiverHandler {
|
||||
@Override
|
||||
public void onNewEndpoint(@Nullable Context context, @NotNull String s) {
|
||||
Log.v(Helper.TAG, "onNewEndpoint: " + s);
|
||||
PushNotifications push = new PushNotifications();
|
||||
push.registerPushNotifications(context, s);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationFailed(@Nullable Context context) {
|
||||
Log.v(Helper.TAG, "onRegistrationFailed: ");
|
||||
// Toast ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationRefused(@Nullable Context context) {
|
||||
// Toast ?
|
||||
Log.v(Helper.TAG, "onRegistrationRefused: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnregistered(@Nullable Context context) {
|
||||
Log.v(Helper.TAG, "onUnregistered: ");
|
||||
// Remove endpoint & ServerKey
|
||||
}
|
||||
|
||||
|
@ -35,6 +42,7 @@ class handler implements MessagingReceiverHandler {
|
|||
public void onMessage(@Nullable Context context, @NotNull String s) {
|
||||
PushNotifications push = new PushNotifications();
|
||||
push.displayNotification(context, s);
|
||||
Log.v(Helper.TAG, "onMessage: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue