diff --git a/.gitignore b/.gitignore
index 34b89654..6208a99c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,8 @@ local.properties
proguard/
# Log Files
*.log
+pushfish-android.iml
+/pushfish-android.iml
+/app/app.iml
+/pushjet-android.iml
+/Pushjet-Android.iml
diff --git a/Pushjet-Android.iml b/Pushjet-Android.iml
deleted file mode 100644
index b3109a9e..00000000
--- a/Pushjet-Android.iml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/app.iml b/app/app.iml
index 3086841b..3e6799a1 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -9,7 +9,6 @@
-
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bf2ef7f1..4245136e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -44,18 +44,6 @@
android:value="io.Pushfish.api.PushListActivity" />
-
-
-
-
-
-
-
-
-
-
{
-
- @Override
- protected Void doInBackground(Boolean... params) {
- if(asyncAlreadyRunning) {
- return null;
- }
-
- asyncAlreadyRunning = true;
- boolean force = params.length > 0 && params[0];
- if (!force && shouldRegister()) {
- Log.i(TAG, "Already registered, no need to re-register");
- asyncAlreadyRunning = false;
- return null; // No need to re-register
- }
-
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
- String url = SettingsActivity.getRegisterUrl(mContext) + "/gcm";
- String senderId = SettingsActivity.getSenderId(mContext);
- Looper.prepare();
-
- try {
- if (gcm == null) {
- gcm = GoogleCloudMessaging.getInstance(mContext);
- }
- String regid = gcm.register(senderId);
-
- Map data = new HashMap<>();
- data.put("regId", regid);
- data.put("uuid", new DeviceUuidFactory(mContext).getDeviceUuid().toString());
-
- // Should we be doing crypto magic?
- if(preferences.getBoolean("general_encrypt_gcm", true)) {
- KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
- kpg.initialize(1024, new SecureRandom());
- KeyPair kp = kpg.genKeyPair();
- PublicKey publicKey = kp.getPublic();
- PrivateKey privateKey = kp.getPrivate();
-
- String B64DerPublicKey = Base64.encodeToString(publicKey.getEncoded(), Base64.NO_WRAP);
- String B64DerPrivateKey = Base64.encodeToString(privateKey.getEncoded(), Base64.NO_WRAP);
- data.put("pubkey", B64DerPublicKey);
-
- SharedPreferences.Editor editor = getGcmPreferences(mContext).edit();
- editor.putString(PROPERTY_PRIVATE_KEY, B64DerPrivateKey);
- editor.commit();
- }
-
- for (int i = 1; i <= 10; i++) {
- Log.i(TAG, "Attempt #" + i + " to register device");
- try {
- HttpUtil.Post(url, data);
- break;
- } catch (Exception ignore) {
- Log.e(TAG, ignore.getMessage());
- if (i == 10)
- throw new IOException();
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- break;
- }
- }
- }
-
- storeRegistrationId(regid);
- } catch (IOException ignore) {
- Toast.makeText(mContext, "Could not register with GCM server", Toast.LENGTH_SHORT).show();
- } catch (NoSuchAlgorithmException e) {
- Toast.makeText(mContext, "Could not build crypto keypair. Disabling encryption...", Toast.LENGTH_LONG).show();
- SharedPreferences.Editor prefEditor = preferences.edit();
- prefEditor.putBoolean("general_encrypt_gcm", false);
- prefEditor.commit();
-
- return this.doInBackground(params);
- }
-
- Log.i(TAG, "Registered!");
- if (force) {
- Toast.makeText(mContext, "Registered to " + url, Toast.LENGTH_SHORT).show();
- }
-
- Log.i(TAG, "Registered to " + url);
- asyncAlreadyRunning = false;
- return null;
- }
- }
-}
diff --git a/app/src/main/java/io/Pushfish/api/GcmBroadcastReceiver.java b/app/src/main/java/io/Pushfish/api/GcmBroadcastReceiver.java
deleted file mode 100644
index 674f6df4..00000000
--- a/app/src/main/java/io/Pushfish/api/GcmBroadcastReceiver.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package io.Pushfish.api;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.support.v4.content.WakefulBroadcastReceiver;
-
-public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- // Explicitly specify that GcmIntentService will handle the intent.
- ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
- // Start the service, keeping the device awake while it is launching.
- startWakefulService(context, (intent.setComponent(comp)));
- setResultCode(Activity.RESULT_OK);
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/io/Pushfish/api/GcmIntentService.java b/app/src/main/java/io/Pushfish/api/GcmIntentService.java
deleted file mode 100644
index 98687748..00000000
--- a/app/src/main/java/io/Pushfish/api/GcmIntentService.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package io.Pushfish.api;
-
-import android.annotation.TargetApi;
-import android.app.IntentService;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.support.v4.app.NotificationCompat;
-import android.util.Log;
-
-import com.google.android.gms.gcm.GoogleCloudMessaging;
-
-import io.Pushfish.api.PushfishApi.PushfishService;
-import io.Pushfish.api.PushfishApi.PushfishMessage;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.util.Date;
-
-public class GcmIntentService extends IntentService {
- private static int NOTIFICATION_ID = 0;
-
- public GcmIntentService() {
- super("GcmIntentService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- Bundle extras = intent.getExtras();
- GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
- String messageType = gcm.getMessageType(intent);
-
- if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
- String rawJson = extras.getString("message");
-
- try {
- JSONObject Msg = new JSONObject(rawJson);
- JSONObject Srv = Msg.getJSONObject("service");
- PushfishService srv = new PushfishService(
- Srv.getString("public"),
- Srv.getString("name"),
- new Date((long) Srv.getInt("created") * 1000)
- );
- srv.setIcon(Srv.getString("icon"));
-
- PushfishMessage msg = new PushfishMessage(
- srv,
- Msg.getString("message"),
- Msg.getString("title"),
- Msg.getInt("timestamp")
- );
- msg.setLevel(Msg.getInt("level"));
- msg.setLink(Msg.getString("link"));
- DatabaseHandler db = new DatabaseHandler(this);
- db.addMessage(msg);
- sendNotification(msg);
- } catch (JSONException ignore) {
- Log.e("PushfishJson", ignore.getMessage());
- }
- }
- GcmBroadcastReceiver.completeWakefulIntent(intent);
- sendBroadcast(new Intent("PushfishMessageRefresh"));
- }
-
- private void sendNotification(PushfishMessage msg) {
- NOTIFICATION_ID++;
- NotificationManager mNotificationManager = (NotificationManager)
- this.getSystemService(Context.NOTIFICATION_SERVICE);
-
- Intent intent = new Intent(this, PushListActivity.class);
- if (msg.hasLink()) {
- try {
- intent = new Intent(Intent.ACTION_VIEW, Uri.parse(msg.getLink()));
- } catch (Exception ignore) {
- }
- }
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
-
- NotificationCompat.Builder mBuilder =
- new NotificationCompat.Builder(this)
- .setSmallIcon(R.drawable.ic_stat_notif)
- .setContentTitle(msg.getTitleOrName())
- .setStyle(new NotificationCompat.BigTextStyle()
- .bigText(msg.getMessage()))
- .setContentText(msg.getMessage())
- .setAutoCancel(true);
-
- if (msg.getService().hasIcon()) {
- try {
- Bitmap icon = msg.getService().getIconBitmap(getApplicationContext());
- Resources res = getApplicationContext().getResources();
-
- int nHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
- int nWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
-
- mBuilder.setLargeIcon(MiscUtil.scaleBitmap(icon, nWidth, nHeight));
- } catch (IOException ignore) {
- ignore.printStackTrace();
- }
- }
-
- setPriority(mBuilder, msg);
- mBuilder.setDefaults(Notification.DEFAULT_ALL);
-
- mBuilder.setContentIntent(contentIntent);
- mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
- }
-
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- private void setPriority(NotificationCompat.Builder mBuilder, PushfishMessage msg) {
- int priority = msg.getLevel() - 3;
- if(Math.abs(priority) > 2) {
- priority = 0;
- }
-
- mBuilder.setPriority(priority);
- }
-}
-
diff --git a/app/src/main/java/io/Pushfish/api/SettingsActivity.java b/app/src/main/java/io/Pushfish/api/SettingsActivity.java
index a333614d..6c293459 100644
--- a/app/src/main/java/io/Pushfish/api/SettingsActivity.java
+++ b/app/src/main/java/io/Pushfish/api/SettingsActivity.java
@@ -15,7 +15,6 @@
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
-import io.Pushfish.api.Async.GCMRegistrar;
import io.Pushfish.api.Async.RefreshServiceAsync;
import io.Pushfish.api.PushfishApi.PushfishApi;
@@ -71,13 +70,8 @@ public void onClick(DialogInterface dialog, int which) {
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- GCMRegistrar gcm = new GCMRegistrar(context);
-
- gcm.forgetRegistration();
db.truncateMessages();
db.truncateServices();
- gcm.registerInBackground(true);
-
PushfishApi api = new PushfishApi(context, getRegisterUrl(context));
new RefreshServiceAsync(api, db).execute();