From d245e81679ca4937ac5b411e19c7885c5beb8a89 Mon Sep 17 00:00:00 2001 From: Daniel Applebaum Date: Fri, 15 Jan 2010 05:02:27 +0000 Subject: [PATCH] Reorganize remote control pieces. Automatically build jar file for external applications. Create convenience functions in K9RemoteControl so that external applications do not need to know the details of handling the Intents and broadcasts. Send a permission string in the broadcasts so that unauthorized applications cannot intercept communication to authorized applications, such as K-9 Mail. --- build.xml | 14 +++++++- .../k9/remotecontrol/AccountReceiver.java | 33 +++++++++++++++++ .../k9/remotecontrol/K9AccountReceptor.java | 11 ++++++ .../{ => remotecontrol}/K9RemoteControl.java | 36 +++++++++++++++++-- 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/com/fsck/k9/remotecontrol/AccountReceiver.java create mode 100644 src/com/fsck/k9/remotecontrol/K9AccountReceptor.java rename src/com/fsck/k9/{ => remotecontrol}/K9RemoteControl.java (80%) diff --git a/build.xml b/build.xml index 29ef3a712..a51c20a4f 100644 --- a/build.xml +++ b/build.xml @@ -110,6 +110,9 @@ + + + @@ -201,6 +204,15 @@ + + Creating library ${rclib} for remote control + applications + + + + Converting compiled files and external libraries into ${out-folder}/${dex-file}... @@ -247,7 +259,7 @@ - + - * in their AndroidManifest.xml + * in their AndroidManifest.xml In addition, all applications sending remote control messages to K-9 Mail must * * An application that wishes to act on a particular Account in K-9 needs to fetch the list of configured Accounts by broadcasting an * {@link Intent} using K9_REQUEST_ACCOUNTS as the Action. The broadcast must be made using the {@link ContextWrapper} @@ -15,6 +24,11 @@ package com.fsck.k9; */ public class K9RemoteControl { + /** + * Permission that every application sending a broadcast to K-9 for Remote Control purposes should send on every broadcast. + * Prevent other applications from intercepting the broadcasts. + */ + public final static String K9_REMOTE_CONTROL_PERMISSION = "com.fsck.k9.permission.REMOTE_CONTROL"; /** * {@link Intent} Action to be sent to K-9 using {@link ContextWrapper.sendOrderedBroadcast} in order to fetch the list of configured Accounts. * The responseData will contain two String[] with keys K9_ACCOUNT_UUIDS and K9_ACCOUNT_DESCRIPTIONS @@ -105,4 +119,22 @@ public class K9RemoteControl public final static String K9_THEME_LIGHT = "LIGHT"; public final static String K9_THEME_DARK = "DARK"; + protected static String LOG_TAG = "K9RemoteControl"; + + public static void set(Context context, Intent broadcastIntent) + { + broadcastIntent.setAction(K9RemoteControl.K9_SET); + context.sendBroadcast(broadcastIntent, K9RemoteControl.K9_REMOTE_CONTROL_PERMISSION); + } + + public static void fetchAccounts(Context context, K9AccountReceptor receptor) + { + Intent accountFetchIntent = new Intent(); + accountFetchIntent.setAction(K9RemoteControl.K9_REQUEST_ACCOUNTS); + AccountReceiver receiver = new AccountReceiver(receptor); + context.sendOrderedBroadcast(accountFetchIntent, K9RemoteControl.K9_REMOTE_CONTROL_PERMISSION, receiver, null, Activity.RESULT_OK, null, null); + } + } + +