From 4f840b57462f952f500d84a2b16f61951d7e3ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 19 Aug 2015 21:26:57 -0700 Subject: [PATCH] Replace endlessjabbersdk jar with source Pulled from https://github.com/celeronpm/YappySDK at commit 07f41007613b98ddc8765984f6e7189e30a63a75 --- QKSMS/build.gradle | 1 - QKSMS/libs/endlessjabbersdk.jar | Bin 9282 -> 0 bytes .../sdk/EndlessJabberInterface.java | 105 ++++++++++++++ .../sdk/EndlessJabberReceiver.java | 22 +++ .../sdk/EndlessJabberWakefulService.java | 78 ++++++++++ .../sdk/IEndlessJabberImplementation.java | 50 +++++++ .../mariussoft/endlessjabber/sdk/MMSPart.java | 57 ++++++++ .../sdk/WakefulBroadcastReceiver.java | 135 ++++++++++++++++++ 8 files changed, 447 insertions(+), 1 deletion(-) delete mode 100644 QKSMS/libs/endlessjabbersdk.jar create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberInterface.java create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberReceiver.java create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberWakefulService.java create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/IEndlessJabberImplementation.java create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/MMSPart.java create mode 100644 QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/WakefulBroadcastReceiver.java diff --git a/QKSMS/build.gradle b/QKSMS/build.gradle index b6ece62a..241209fe 100644 --- a/QKSMS/build.gradle +++ b/QKSMS/build.gradle @@ -55,5 +55,4 @@ dependencies { // External services compile 'com.crittercism:crittercism-android-agent:5.0.3' - compile files('libs/endlessjabbersdk.jar') } diff --git a/QKSMS/libs/endlessjabbersdk.jar b/QKSMS/libs/endlessjabbersdk.jar deleted file mode 100644 index 55a014e7a2b5cc6fe1d99389ae3d7743a181e94f..0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kUoZM!aE3wq`_umd==hwB diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberInterface.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberInterface.java new file mode 100644 index 00000000..df4c5c26 --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberInterface.java @@ -0,0 +1,105 @@ +package com.mariussoft.endlessjabber.sdk; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.net.Uri; + +public class EndlessJabberInterface { + + /** Checks whether or not EndlessJabber is installed */ + public static boolean IsInstalled(Context ctx) { + + PackageManager pm = ctx.getPackageManager(); + try { + pm.getPackageInfo("com.mariussoft.endlessjabber", PackageManager.GET_ACTIVITIES); + return true; + } catch (NameNotFoundException e) { + return false; + } + } + + /** Opens up GooglePlay and redirects it to the EndlessJabber app */ + public static void OpenGooglePlayLink(Context ctx) { + final String appPackageName = "com.mariussoft.endlessjabber"; + try { + ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); + } catch (android.content.ActivityNotFoundException anfe) { + ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName))); + } + } + + /** Launches EndlessJabber */ + public static void LaunchEndlessJabber(Context ctx) { + Intent intent = ctx.getPackageManager().getLaunchIntentForPackage("com.mariussoft.endlessjabber"); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ctx.startActivity(intent); + } + + /** + * Enables integration by specifying which class to call + * + * @param context + * The context to use + * @param concreteImplementation + * The concrete implementation to call on events + * @param sendSMS + * If true, your app will be responsible for sending SMS messages + * as well as presisting them to the SMS repository + * @param sendMMS + * If true, your app will be responsible for sending & persisting + * MMS messages to the MMS repository + * @throws Exception + */ + @SuppressWarnings("rawtypes") + public static void EnableIntegration(Context context, Class concreteImplementation, boolean sendSMS, boolean sendMMS) throws Exception { + Class clazz = concreteImplementation; + if (!IEndlessJabberImplementation.class.isAssignableFrom(clazz)) { + throw new Exception("Class must implement IEndlessJabberImplementation"); + } + + SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit(); + editor.putString("InterfaceClass", concreteImplementation.getName()); + editor.putBoolean("SendSMS", sendSMS); + editor.putBoolean("SendMMS", sendMMS); + editor.commit(); + + SendInfoToEndlessJabber(context); + } + + /** Disables integration */ + @SuppressWarnings("rawtypes") + public static void DisableIntegration(Context context, Class nameOfImplementation) { + SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit(); + editor.clear(); + editor.commit(); + + SendInfoToEndlessJabber(context); + } + + /** + * Refresh integration info with EndlessJabber + * + * @param ctx + * Context to use + */ + static void SendInfoToEndlessJabber(Context context) { + String EndlessJabber_INTENT = "com.mariussoft.endlessjabber.action.extendResponse"; + SharedPreferences prefs = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE); + + Intent i = new Intent(); + i.setAction(EndlessJabber_INTENT); + i.putExtra("Action", "UpdateInfo"); + i.putExtra("PackageName", context.getPackageName()); + i.putExtra("Enabled", prefs.contains("InterfaceClass")); + + if (prefs.contains("InterfaceClass")) { + i.putExtra("SendSMS", prefs.getBoolean("SendSMS", false)); + i.putExtra("SendMMS", prefs.getBoolean("SendMMS", false)); + } + + context.sendBroadcast(i); + } +} diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberReceiver.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberReceiver.java new file mode 100644 index 00000000..9eebc92c --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberReceiver.java @@ -0,0 +1,22 @@ +package com.mariussoft.endlessjabber.sdk; + +import android.content.Context; +import android.content.Intent; + +public class EndlessJabberReceiver extends WakefulBroadcastReceiver { + + public static final String EndlessJabber_INTENT = "com.mariussoft.endlessjabber.action.extend"; + + @Override + public void onReceive(Context context, Intent intent) { + + if (intent.getAction().equals(EndlessJabber_INTENT)) { + + // This is the Intent to deliver to our service. + Intent service = new Intent(context, EndlessJabberWakefulService.class); + service.putExtras(intent.getExtras()); + + startWakefulService(context, service); + } + } +} diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberWakefulService.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberWakefulService.java new file mode 100644 index 00000000..dbe22a51 --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/EndlessJabberWakefulService.java @@ -0,0 +1,78 @@ +package com.mariussoft.endlessjabber.sdk; + +import android.app.IntentService; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +public class EndlessJabberWakefulService extends IntentService { + + public EndlessJabberWakefulService() { + super("EndlessJabberWakefulService"); + } + + @Override + protected void onHandleIntent(Intent intent) { + Context context = getApplicationContext(); + + // Get the class to call + String implemenationClass = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).getString("InterfaceClass", null); + + if (implemenationClass == null) { + return; + } + + IEndlessJabberImplementation instanceOfMyClass; + try { + instanceOfMyClass = (IEndlessJabberImplementation) Class.forName(implemenationClass).newInstance(); + + Bundle extras = intent.getExtras(); + + switch (extras.getString("Action")) { + case "UpdateRead": { + long time = extras.getLong("Time"); + int conversationID = extras.getInt("ConversationID"); + instanceOfMyClass.UpdateReadMessages(context, time, conversationID); + break; + } + case "DeleteThread": { + + int conversationID = extras.getInt("ConversationID"); + instanceOfMyClass.DeleteThread(context, conversationID); + break; + } + case "SendMMS": { + + boolean save = extras.getBoolean("Save"); + boolean send = extras.getBoolean("Send"); + String[] Recipients = extras.getStringArray("Recipients"); + + MMSPart[] parts = new MMSPart[extras.getParcelableArray("Parts").length]; + + for (int i = 0; i < parts.length; i++) { + parts[i] = (MMSPart) extras.getParcelableArray("Parts")[i]; + } + + instanceOfMyClass.SendMMS(context, Recipients, parts, extras.getString("Subject"), save, send); + break; + } + case "SendSMS": { + boolean send = extras.getBoolean("Send"); + String[] Recipients = extras.getStringArray("Recipients"); + String message = extras.getString("Message"); + + instanceOfMyClass.SendSMS(context, Recipients, message, send); + break; + } + case "UpdateInfo": { + EndlessJabberInterface.SendInfoToEndlessJabber(context); + break; + } + } + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + + } + + EndlessJabberReceiver.completeWakefulIntent(intent); + } +} diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/IEndlessJabberImplementation.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/IEndlessJabberImplementation.java new file mode 100644 index 00000000..eddd832c --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/IEndlessJabberImplementation.java @@ -0,0 +1,50 @@ +package com.mariussoft.endlessjabber.sdk; + +import android.content.Context; + +/** + * + * Interface to implement EndlessJabber integration + * + */ +public interface IEndlessJabberImplementation { + + /** + * Update all messages in the SMS/MMS repositories as read where the time <= the provided time as well as where the threadID matches the provided ID + * @param context The context to utilize + * @param time The 'time' in the SMS database to use when marking messages as read + * (NOTE* for MMS divide by 1000 as MMS repository stores times as 1/1000th of the SMS) + * @param threadID The ID of the thread in the SMS/MMS repositories to update + */ + void UpdateReadMessages(Context context, long time, int threadID); + + /** + * Delete any messages/conversations in the SMS/MMS repositories where the threadID matches the provided ID + * @param context The context to utilize + * @param threadID The ID of the thread in the SMS/MMS repositories to delete + */ + void DeleteThread(Context context,int threadID); + + /** + * Method gets called when EndlessJabber is requested to send an MMS message via the web app + * @param context The context to utilize + * @param recipients List of recipients to send message to + * @param parts The message parts to send along with message + * @param subject The MMS subject of the message + * @param save Whether or not to save the MMS to the MMS repository + * @param send If true, send the message along with saving it to the MMS repository + * NOTE: On KitKat save will be true only when enabled in the SDK & your app is the default messaging app on the system + * + * If both save & send are false, this call is only for informational purposes (e.g. modify notifications, update UI, etc...) + */ + void SendMMS(Context context, String[] recipients, MMSPart[] parts, String subject, boolean save, boolean send); + + /** + * Method gets called when EndlessJabber is requested to send an SMS message via the web app + * @param context The context to utilize + * @param recipients List of recipients to send message to + * @param message The message to send + * @param send If true, send the message along with saving it to the SMS repository, otherwise this is only for informational purposes (e.g. modify notifications, update UI, etc...) + */ + void SendSMS(Context context, String[] recipients, String message, boolean send); +} diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/MMSPart.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/MMSPart.java new file mode 100644 index 00000000..278aa6d5 --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/MMSPart.java @@ -0,0 +1,57 @@ +package com.mariussoft.endlessjabber.sdk; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * + * An MMS attachment + * + */ +public class MMSPart implements Parcelable { + /** + * The name of the MMS attachment + */ + public String Name = ""; + /** + * The MimeType of the MMS attachment + */ + public String MimeType = ""; + /** + * The byte[] of the MMS attachment + */ + public byte[] Data; + + public MMSPart() { + } + + public MMSPart(Parcel parcel) { + Name = parcel.readString(); + MimeType = parcel.readString(); + Data = new byte[parcel.readInt()]; + parcel.readByteArray(Data); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int arg1) { + dest.writeString(Name); + dest.writeString(MimeType); + dest.writeInt(Data.length); + dest.writeByteArray(Data); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public MMSPart createFromParcel(Parcel in) { + return new MMSPart(in); + } + + public MMSPart[] newArray(int size) { + return new MMSPart[size]; + } + }; +} \ No newline at end of file diff --git a/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/WakefulBroadcastReceiver.java b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/WakefulBroadcastReceiver.java new file mode 100644 index 00000000..d75f50a5 --- /dev/null +++ b/QKSMS/src/main/java/com/mariussoft/endlessjabber/sdk/WakefulBroadcastReceiver.java @@ -0,0 +1,135 @@ +package com.mariussoft.endlessjabber.sdk; + +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.os.PowerManager; +import android.util.Log; +import android.util.SparseArray; + +/** + * Helper for the common pattern of implementing a {@link BroadcastReceiver} + * that receives a device wakeup event and then passes the work off + * to a {@link android.app.Service}, while ensuring that the + * device does not go back to sleep during the transition. + * + *

This class takes care of creating and managing a partial wake lock + * for you; you must request the {@link android.Manifest.permission#WAKE_LOCK} + * permission to use it.

+ * + *

Example

+ * + *

A {@link WakefulBroadcastReceiver} uses the method + * {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()} + * to start the service that does the work. This method is comparable to + * {@link android.content.Context#startService startService()}, except that + * the {@link WakefulBroadcastReceiver} is holding a wake lock when the service + * starts. The intent that is passed with + * {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()} + * holds an extra identifying the wake lock.

+ * + * {@sample development/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulReceiver.java complete} + * + *

The service (in this example, an {@link android.app.IntentService}) does + * some work. When it is finished, it releases the wake lock by calling + * {@link WakefulBroadcastReceiver#completeWakefulIntent + * completeWakefulIntent(intent)}. The intent it passes as a parameter + * is the same intent that the {@link WakefulBroadcastReceiver} originally + * passed in.

+ * + * {@sample development/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulService.java complete} + */ +public abstract class WakefulBroadcastReceiver extends BroadcastReceiver { + private static final String EXTRA_WAKE_LOCK_ID = "android.support.content.wakelockid"; + + private static final SparseArray mActiveWakeLocks + = new SparseArray(); + private static int mNextId = 1; + + /** + * Do a {@link android.content.Context#startService(android.content.Intent) + * Context.startService}, but holding a wake lock while the service starts. + * This will modify the Intent to hold an extra identifying the wake lock; + * when the service receives it in {@link android.app.Service#onStartCommand + * Service.onStartCommand}, it should pass back the Intent it receives there to + * {@link #completeWakefulIntent(android.content.Intent)} in order to release + * the wake lock. + * + * @param context The Context in which it operate. + * @param intent The Intent with which to start the service, as per + * {@link android.content.Context#startService(android.content.Intent) + * Context.startService}. + */ + public static ComponentName startWakefulService(Context context, Intent intent) { + synchronized (mActiveWakeLocks) { + int id = mNextId; + mNextId++; + if (mNextId <= 0) { + mNextId = 1; + } + + intent.putExtra(EXTRA_WAKE_LOCK_ID, id); + ComponentName comp = context.startService(intent); + if (comp == null) { + return null; + } + + PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); + PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + "wake:" + comp.flattenToShortString()); + wl.setReferenceCounted(false); + wl.acquire(60*1000); + mActiveWakeLocks.put(id, wl); + return comp; + } + } + + /** + * Finish the execution from a previous {@link #startWakefulService}. Any wake lock + * that was being held will now be released. + * + * @param intent The Intent as originally generated by {@link #startWakefulService}. + * @return Returns true if the intent is associated with a wake lock that is + * now released; returns false if there was no wake lock specified for it. + */ + public static boolean completeWakefulIntent(Intent intent) { + final int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0); + if (id == 0) { + return false; + } + synchronized (mActiveWakeLocks) { + PowerManager.WakeLock wl = mActiveWakeLocks.get(id); + if (wl != null) { + wl.release(); + mActiveWakeLocks.remove(id); + return true; + } + // We return true whether or not we actually found the wake lock + // the return code is defined to indicate whether the Intent contained + // an identifier for a wake lock that it was supposed to match. + // We just log a warning here if there is no wake lock found, which could + // happen for example if this function is called twice on the same + // intent or the process is killed and restarted before processing the intent. + Log.w("WakefulBroadcastReceiver", "No active wake lock id #" + id); + return true; + } + } +} \ No newline at end of file