Let users disable command confirmations over SMS
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 1 Sep 2014 21:49:14 +0000 (00:49 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 1 Sep 2014 21:49:14 +0000 (00:49 +0300)
Most FonBot commands confirm their execution with a short message, but
this can be wasteful is SMS messages are used. This commit adds a new
preference that disables confirmation messages if the command was sent
over SMS. Thanks to Valerio Bozzolan for the suggestion in bug 14.

res/xml/prefs.xml
src/ro/ieval/fonbot/Heavy.java
src/ro/ieval/fonbot/SmsStatusReceiver.java
src/ro/ieval/fonbot/Utils.java

index 6d90c6aca888de51b649e1f69a39d0e9c3df03a9..3ed8b4f156760221fd7ced9ce44cca2cf222f3d7 100644 (file)
@@ -4,6 +4,7 @@
     <EditTextPreference android:dialogTitle="Password" android:dialogMessage="Enter your password" android:inputType="textPassword" android:title="Password" android:key="password"/>
     <EditTextPreference android:dialogTitle="SMS Password" android:dialogMessage="Enter the password required to send SMS commands. Leave empty to disable SMS commands" android:title="SMS Password" android:key="smspassword"/>
        <CheckBoxPreference android:title="Show ongoing events" android:summaryOn="Ongoing events are shown" android:summaryOff="Ongoing events are not shown" android:key="ongoing"/>
     <EditTextPreference android:dialogTitle="Password" android:dialogMessage="Enter your password" android:inputType="textPassword" android:title="Password" android:key="password"/>
     <EditTextPreference android:dialogTitle="SMS Password" android:dialogMessage="Enter the password required to send SMS commands. Leave empty to disable SMS commands" android:title="SMS Password" android:key="smspassword"/>
        <CheckBoxPreference android:title="Show ongoing events" android:summaryOn="Ongoing events are shown" android:summaryOff="Ongoing events are not shown" android:key="ongoing"/>
+       <CheckBoxPreference android:title="SMS messages are expensive" android:summaryOn="Commands sent via SMS do not confirm their execution." android:summaryOff="All commands confirm their execution." android:key="expensive_sms"/>
     <CheckBoxPreference android:title="Device administration" android:summaryOn="Device administration is enabled." android:key="admin" android:summaryOff="Device administration is disabled. Some commands require device administration."/>
        <CheckBoxPreference android:key="foreground" android:title="Run service in foreground" android:summaryOn="The FonBot service is kept in foreground. " android:summaryOff="The FonBot service is not kept in foreground."/>
     <CheckBoxPreference android:key="system" android:summaryOff="FonBot is not a system app. Changing this requires root and busybox" android:title="System App" android:summaryOn="FonBot is a system app. Changing this requires root and busybox"/>
     <CheckBoxPreference android:title="Device administration" android:summaryOn="Device administration is enabled." android:key="admin" android:summaryOff="Device administration is disabled. Some commands require device administration."/>
        <CheckBoxPreference android:key="foreground" android:title="Run service in foreground" android:summaryOn="The FonBot service is kept in foreground. " android:summaryOff="The FonBot service is not kept in foreground."/>
     <CheckBoxPreference android:key="system" android:summaryOff="FonBot is not a system app. Changing this requires root and busybox" android:title="System App" android:summaryOn="FonBot is a system app. Changing this requires root and busybox"/>
index 3eb17a875685c1fe75ac9881bdd6a29b7109883f..f87f3f5457e69aa4ac0357b2a60ebb23a319e1bb 100644 (file)
@@ -290,7 +290,7 @@ final class Heavy {
                                Utils.sendMessage(toNonNull(context), toNonNull(replyTo), cannot_connect_to_host_on_port, hostname, Integer.valueOf(port));
                                return null;
                        }
                                Utils.sendMessage(toNonNull(context), toNonNull(replyTo), cannot_connect_to_host_on_port, hostname, Integer.valueOf(port));
                                return null;
                        }
-                       Utils.sendMessage(toNonNull(context), toNonNull(replyTo), photo_sent);
+                       Utils.sendConfirmMessage(toNonNull(context), toNonNull(replyTo), photo_sent);
                        return null;
                }
        }
                        return null;
                }
        }
@@ -362,7 +362,7 @@ final class Heavy {
                                        //ignored
                                }
                        }
                                        //ignored
                                }
                        }
-                       Utils.sendMessage(context, replyTo, file_sent);
+                       Utils.sendConfirmMessage(context, replyTo, file_sent);
                }
        }
 
                }
        }
 
@@ -438,7 +438,7 @@ final class Heavy {
                                        //ignored
                                }
                        }
                                        //ignored
                                }
                        }
-                       Utils.sendMessage(context, replyTo, file_received);
+                       Utils.sendConfirmMessage(context, replyTo, file_received);
                }
        }
 
                }
        }
 
@@ -479,7 +479,7 @@ final class Heavy {
                                return;
                        camera.stopPreview();
                        stopCamera();
                                return;
                        camera.stopPreview();
                        stopCamera();
-                       Utils.sendMessage(toNonNull(context), toNonNull(replyTo), sending_photo);
+                       Utils.sendConfirmMessage(toNonNull(context), toNonNull(replyTo), sending_photo);
                        new SendDataAsyncTask(toNonNull(context), toNonNull(replyTo), toNonNull(hostname), port, data).execute();
                }
        }
                        new SendDataAsyncTask(toNonNull(context), toNonNull(replyTo), toNonNull(hostname), port, data).execute();
                }
        }
@@ -514,7 +514,7 @@ final class Heavy {
                        }
 
                        if(exitCode == 0 && new File(filename).exists())
                        }
 
                        if(exitCode == 0 && new File(filename).exists())
-                               Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_successful);
+                               Utils.sendConfirmMessage(toNonNull(context), toNonNull(replyTo), screencap_successful);
                        else
                                Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
                }
                        else
                                Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
                }
@@ -799,7 +799,7 @@ final class Heavy {
                man.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                savedRingVolume=man.getStreamVolume(AudioManager.STREAM_RING);
                man.setStreamVolume(AudioManager.STREAM_RING, man.getStreamMaxVolume(AudioManager.STREAM_RING), 0);
                man.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                savedRingVolume=man.getStreamVolume(AudioManager.STREAM_RING);
                man.setStreamVolume(AudioManager.STREAM_RING, man.getStreamMaxVolume(AudioManager.STREAM_RING), 0);
-               Utils.sendMessage(context, replyTo, ringing);
+               Utils.sendConfirmMessage(context, replyTo, ringing);
                ringtone.play();
        }
 
                ringtone.play();
        }
 
@@ -832,7 +832,7 @@ final class Heavy {
        private static void stopAlarm(final Context context, final Address replyTo){
                Utils.unregisterOngoing(context, toNonNull(OngoingEvent.RING));
                final AudioManager man=(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        private static void stopAlarm(final Context context, final Address replyTo){
                Utils.unregisterOngoing(context, toNonNull(OngoingEvent.RING));
                final AudioManager man=(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
-               Utils.sendMessage(context, replyTo, no_longer_ringing);
+               Utils.sendConfirmMessage(context, replyTo, no_longer_ringing);
                ringtone.stop();
                man.setStreamVolume(AudioManager.STREAM_RING, savedRingVolume, 0);
                man.setRingerMode(savedRingerMode);
                ringtone.stop();
                man.setStreamVolume(AudioManager.STREAM_RING, savedRingVolume, 0);
                man.setRingerMode(savedRingerMode);
@@ -897,11 +897,11 @@ final class Heavy {
 
                if(on) {
                        adapter.enable();
 
                if(on) {
                        adapter.enable();
-                       Utils.sendMessage(context, replyTo, enabling_bluetooth);
+                       Utils.sendConfirmMessage(context, replyTo, enabling_bluetooth);
                }
                else {
                        adapter.disable();
                }
                else {
                        adapter.disable();
-                       Utils.sendMessage(context, replyTo, disabling_bluetooth);
+                       Utils.sendConfirmMessage(context, replyTo, disabling_bluetooth);
                }
        }
 
                }
        }
 
@@ -1093,9 +1093,9 @@ final class Heavy {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                final String name=Utils.callerId(context, nr);
                if(name==null)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                final String name=Utils.callerId(context, nr);
                if(name==null)
-                       Utils.sendMessage(context, replyTo, dialing, nr);
+                       Utils.sendConfirmMessage(context, replyTo, dialing, nr);
                else
                else
-                       Utils.sendMessage(context, replyTo, dialing, nr+" ("+name+")");
+                       Utils.sendConfirmMessage(context, replyTo, dialing, nr+" ("+name+")");
                context.startActivity(intent);
        }
 
                context.startActivity(intent);
        }
 
@@ -1117,7 +1117,7 @@ final class Heavy {
                                Intent.FLAG_ACTIVITY_NEW_TASK|
                                Intent.FLAG_ACTIVITY_NO_USER_ACTION|
                                Intent.FLAG_FROM_BACKGROUND);
                                Intent.FLAG_ACTIVITY_NEW_TASK|
                                Intent.FLAG_ACTIVITY_NO_USER_ACTION|
                                Intent.FLAG_FROM_BACKGROUND);
-               Utils.sendMessage(context, toNonNull(replyTo), showing_dialog);
+               Utils.sendConfirmMessage(context, toNonNull(replyTo), showing_dialog);
                context.startActivity(intent);
        }
 
                context.startActivity(intent);
        }
 
@@ -1166,7 +1166,7 @@ final class Heavy {
                        Utils.sendMessage(context, replyTo, last_known_location);
                        locationListener.onLocationChanged(lastKnownLocation);
                }
                        Utils.sendMessage(context, replyTo, last_known_location);
                        locationListener.onLocationChanged(lastKnownLocation);
                }
-               Utils.sendMessage(context, replyTo, listening_for_location_updates);
+               Utils.sendConfirmMessage(context, replyTo, listening_for_location_updates);
                man.requestLocationUpdates(provider, minTime, minDistance, locationListener);
        }
 
                man.requestLocationUpdates(provider, minTime, minDistance, locationListener);
        }
 
@@ -1179,7 +1179,7 @@ final class Heavy {
        public static void lock(final Context context, final Address replyTo) {
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
                dpm.lockNow();
        public static void lock(final Context context, final Address replyTo) {
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
                dpm.lockNow();
-               Utils.sendMessage(context, replyTo, device_locked);
+               Utils.sendConfirmMessage(context, replyTo, device_locked);
        }
 
        /**
        }
 
        /**
@@ -1193,7 +1193,7 @@ final class Heavy {
                final Intent intent=new Intent("com.android.music.musicservicecommand");
                intent.putExtra("command", command);
                context.sendBroadcast(intent);
                final Intent intent=new Intent("com.android.music.musicservicecommand");
                intent.putExtra("command", command);
                context.sendBroadcast(intent);
-               Utils.sendMessage(context, replyTo, command_sent);
+               Utils.sendConfirmMessage(context, replyTo, command_sent);
        }
 
        /**
        }
 
        /**
@@ -1220,7 +1220,7 @@ final class Heavy {
                final LocationManager man=(LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
                man.removeUpdates(locationListener);
                locationListener=null;
                final LocationManager man=(LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
                man.removeUpdates(locationListener);
                locationListener=null;
-               Utils.sendMessage(context, replyTo, no_longer_listening_for_location_updates);
+               Utils.sendConfirmMessage(context, replyTo, no_longer_listening_for_location_updates);
        }
 
        /**
        }
 
        /**
@@ -1379,7 +1379,7 @@ final class Heavy {
         */
        public static void rm(final Context context, final Address replyTo, final String filename){
                if(new File(filename).delete())
         */
        public static void rm(final Context context, final Address replyTo, final String filename){
                if(new File(filename).delete())
-                       Utils.sendMessage(context, replyTo, file_deleted);
+                       Utils.sendConfirmMessage(context, replyTo, file_deleted);
                else
                        Utils.sendMessage(context, replyTo, error_while_deleting_file);
        }
                else
                        Utils.sendMessage(context, replyTo, error_while_deleting_file);
        }
@@ -1395,7 +1395,7 @@ final class Heavy {
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
 
                dpm.resetPassword("", 0);
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
 
                dpm.resetPassword("", 0);
-               Utils.sendMessage(context, replyTo, password_cleared);
+               Utils.sendConfirmMessage(context, replyTo, password_cleared);
        }
 
        /**
        }
 
        /**
@@ -1410,7 +1410,7 @@ final class Heavy {
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
 
                dpm.resetPassword(password, 0);
                final DevicePolicyManager dpm=(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
 
                dpm.resetPassword(password, 0);
-               Utils.sendMessage(context, replyTo, password_set);
+               Utils.sendConfirmMessage(context, replyTo, password_set);
        }
 
        /**
        }
 
        /**
@@ -1425,7 +1425,7 @@ final class Heavy {
                final SmsManager manager=SmsManager.getDefault();
                final ArrayList<String> messages=manager.divideMessage(text);
                if(messages.size() > 1)
                final SmsManager manager=SmsManager.getDefault();
                final ArrayList<String> messages=manager.divideMessage(text);
                if(messages.size() > 1)
-                       Utils.sendMessage(context, replyTo, message_was_split_into_parts, Integer.valueOf(messages.size()));
+                       Utils.sendConfirmMessage(context, replyTo, message_was_split_into_parts, Integer.valueOf(messages.size()));
 
                final ArrayList<PendingIntent> sents=new ArrayList<PendingIntent>(messages.size());
                final ArrayList<PendingIntent> delivereds=new ArrayList<PendingIntent>(messages.size());
 
                final ArrayList<PendingIntent> sents=new ArrayList<PendingIntent>(messages.size());
                final ArrayList<PendingIntent> delivereds=new ArrayList<PendingIntent>(messages.size());
@@ -1519,7 +1519,7 @@ final class Heavy {
                        @Override
                        public void onInit(final int status) {
                                if(status==TextToSpeech.SUCCESS){
                        @Override
                        public void onInit(final int status) {
                                if(status==TextToSpeech.SUCCESS){
-                                       Utils.sendMessage(context, replyTo, speaking);
+                                       Utils.sendConfirmMessage(context, replyTo, speaking);
                                        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                                } else
                                        Utils.sendMessage(context, replyTo, tts_engine_not_available);
                                        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                                } else
                                        Utils.sendMessage(context, replyTo, tts_engine_not_available);
@@ -1548,7 +1548,7 @@ final class Heavy {
         */
        public static void toast(final Context context, final Address replyTo, final String text, final int duration){
                Toast.makeText(context,text,duration).show();
         */
        public static void toast(final Context context, final Address replyTo, final String text, final int duration){
                Toast.makeText(context,text,duration).show();
-               Utils.sendMessage(context, replyTo, toast_shown);
+               Utils.sendConfirmMessage(context, replyTo, toast_shown);
        }
 
        /**
        }
 
        /**
@@ -1560,7 +1560,7 @@ final class Heavy {
         */
        public static void vibrate(final Context context, final Address replyTo, final long ms){
                final Vibrator v=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
         */
        public static void vibrate(final Context context, final Address replyTo, final long ms){
                final Vibrator v=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
-               Utils.sendMessage(context, replyTo, vibrating);
+               Utils.sendConfirmMessage(context, replyTo, vibrating);
                v.vibrate(ms);
        }
 
                v.vibrate(ms);
        }
 
@@ -1577,7 +1577,7 @@ final class Heavy {
                        intent.setData(uri);
                        intent.setFlags(Intent.FLAG_FROM_BACKGROUND|Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(intent);
                        intent.setData(uri);
                        intent.setFlags(Intent.FLAG_FROM_BACKGROUND|Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(intent);
-                       Utils.sendMessage(context, replyTo, url_opened);
+                       Utils.sendConfirmMessage(context, replyTo, url_opened);
                } catch(ActivityNotFoundException e){
                        Utils.sendMessage(context, replyTo, no_activity_found_for_this_url);
                } catch(Exception e){
                } catch(ActivityNotFoundException e){
                        Utils.sendMessage(context, replyTo, no_activity_found_for_this_url);
                } catch(Exception e){
@@ -1610,9 +1610,9 @@ final class Heavy {
                final WifiManager man=(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                man.setWifiEnabled(on);
                if(on)
                final WifiManager man=(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                man.setWifiEnabled(on);
                if(on)
-                       Utils.sendMessage(context, replyTo, enabling_wifi);
+                       Utils.sendConfirmMessage(context, replyTo, enabling_wifi);
                else
                else
-                       Utils.sendMessage(context, replyTo, disabling_wifi);
+                       Utils.sendConfirmMessage(context, replyTo, disabling_wifi);
        }
 
        /**
        }
 
        /**
@@ -1646,7 +1646,7 @@ final class Heavy {
        public static void disable(final Context context, final Address replyTo, final Command command){
                PreferenceManager.getDefaultSharedPreferences(context).edit()
                .putBoolean(command+"disabled", true).commit();
        public static void disable(final Context context, final Address replyTo, final Command command){
                PreferenceManager.getDefaultSharedPreferences(context).edit()
                .putBoolean(command+"disabled", true).commit();
-               Utils.sendMessage(context, replyTo, command_disabled, command);
+               Utils.sendConfirmMessage(context, replyTo, command_disabled, command);
        }
 
        /**
        }
 
        /**
@@ -1659,7 +1659,7 @@ final class Heavy {
        public static void enable(final Context context, final Address replyTo, final Command command){
                PreferenceManager.getDefaultSharedPreferences(context).edit()
                .remove(command+"disabled").commit();
        public static void enable(final Context context, final Address replyTo, final Command command){
                PreferenceManager.getDefaultSharedPreferences(context).edit()
                .remove(command+"disabled").commit();
-               Utils.sendMessage(context, replyTo, command_enabled, command);
+               Utils.sendConfirmMessage(context, replyTo, command_enabled, command);
 
        }
 
 
        }
 
@@ -1681,7 +1681,7 @@ final class Heavy {
         * @param replyTo reply Address
         */
        public static void poll(final Context context, final Address replyTo) {
         * @param replyTo reply Address
         */
        public static void poll(final Context context, final Address replyTo) {
-               Utils.sendMessage(context, replyTo, starting_long_polling_if_stopped);
+               Utils.sendConfirmMessage(context, replyTo, starting_long_polling_if_stopped);
                context.startService(new Intent(context, FonBotMainService.class));
        }
 
                context.startService(new Intent(context, FonBotMainService.class));
        }
 
@@ -1746,7 +1746,7 @@ final class Heavy {
                        return;
                }
                context.startActivity(intent);
                        return;
                }
                context.startActivity(intent);
-               Utils.sendMessage(context, replyTo, app_launched);
+               Utils.sendConfirmMessage(context, replyTo, app_launched);
        }
 
        /**
        }
 
        /**
@@ -1781,10 +1781,10 @@ final class Heavy {
                try{
                        if(enable){
                                getITelephony(context).enableDataConnectivity();
                try{
                        if(enable){
                                getITelephony(context).enableDataConnectivity();
-                               Utils.sendMessage(context, replyTo, enabling_data);
+                               Utils.sendConfirmMessage(context, replyTo, enabling_data);
                        } else {
                                getITelephony(context).disableDataConnectivity();
                        } else {
                                getITelephony(context).disableDataConnectivity();
-                               Utils.sendMessage(context, replyTo, disabling_data);
+                               Utils.sendConfirmMessage(context, replyTo, disabling_data);
                        }
                } catch(Exception e){
                        Utils.sendMessage(context, replyTo, exception_while_getting_itelephony,
                        }
                } catch(Exception e){
                        Utils.sendMessage(context, replyTo, exception_while_getting_itelephony,
@@ -1815,9 +1815,9 @@ final class Heavy {
        public static void gps(final Context context, final Address replyTo, final boolean enabled) {
                Secure.setLocationProviderEnabled(context.getContentResolver(), LocationManager.GPS_PROVIDER, enabled);
                if(enabled)
        public static void gps(final Context context, final Address replyTo, final boolean enabled) {
                Secure.setLocationProviderEnabled(context.getContentResolver(), LocationManager.GPS_PROVIDER, enabled);
                if(enabled)
-                       Utils.sendMessage(context, replyTo, enabling_gps);
+                       Utils.sendConfirmMessage(context, replyTo, enabling_gps);
                else
                else
-                       Utils.sendMessage(context, replyTo, disabling_gps);
+                       Utils.sendConfirmMessage(context, replyTo, disabling_gps);
        }
 
        /**
        }
 
        /**
@@ -1843,9 +1843,9 @@ final class Heavy {
        public static void glocation(final Context context, final Address replyTo, final boolean enabled) {
                Secure.setLocationProviderEnabled(context.getContentResolver(), LocationManager.NETWORK_PROVIDER, enabled);
                if(enabled)
        public static void glocation(final Context context, final Address replyTo, final boolean enabled) {
                Secure.setLocationProviderEnabled(context.getContentResolver(), LocationManager.NETWORK_PROVIDER, enabled);
                if(enabled)
-                       Utils.sendMessage(context, replyTo, enabling_network_location);
+                       Utils.sendConfirmMessage(context, replyTo, enabling_network_location);
                else
                else
-                       Utils.sendMessage(context, replyTo, disabling_network_location);
+                       Utils.sendConfirmMessage(context, replyTo, disabling_network_location);
        }
 
        /**
        }
 
        /**
@@ -1859,7 +1859,7 @@ final class Heavy {
         */
        public static void reboot(final Context context, final Address replyTo, final @Nullable String reason) {
                final PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
         */
        public static void reboot(final Context context, final Address replyTo, final @Nullable String reason) {
                final PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
-               Utils.sendMessage(context, replyTo, rebooting);
+               Utils.sendConfirmMessage(context, replyTo, rebooting);
                try {
                        pm.reboot(reason);
                } catch (final Exception e){
                try {
                        pm.reboot(reason);
                } catch (final Exception e){
@@ -1887,7 +1887,7 @@ final class Heavy {
        public static void notify(final Context context, final Address replyTo, final int id) {
                final NotificationManager man=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                man.cancel(id);
        public static void notify(final Context context, final Address replyTo, final int id) {
                final NotificationManager man=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                man.cancel(id);
-               Utils.sendMessage(context, replyTo, notification_canceled);
+               Utils.sendConfirmMessage(context, replyTo, notification_canceled);
        }
 
        /**
        }
 
        /**
@@ -1906,7 +1906,7 @@ final class Heavy {
                                setContentText(text).
                                setSmallIcon(android.R.drawable.stat_notify_sync_noanim).
                                build());
                                setContentText(text).
                                setSmallIcon(android.R.drawable.stat_notify_sync_noanim).
                                build());
-               Utils.sendMessage(context, replyTo, notification_shown);
+               Utils.sendConfirmMessage(context, replyTo, notification_shown);
        }
 
        /**
        }
 
        /**
@@ -1928,7 +1928,7 @@ final class Heavy {
         */
        public static void torch(final Context context, final Address replyTo){
                context.sendBroadcast(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"));
         */
        public static void torch(final Context context, final Address replyTo){
                context.sendBroadcast(new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT"));
-               Utils.sendMessage(context, replyTo, toggling_torch_state);
+               Utils.sendConfirmMessage(context, replyTo, toggling_torch_state);
        }
 
        /**
        }
 
        /**
index 59a96a56a54a3247d4ff72f9eaa53a900d95b901..8ae964357728743b2d704917eb4c5246cfe40ac1 100644 (file)
@@ -78,7 +78,7 @@ public final class SmsStatusReceiver extends BroadcastReceiver {
                if(intent.getAction().startsWith(SENT_ACTION))
                        switch(getResultCode()){
                        case Activity.RESULT_OK:
                if(intent.getAction().startsWith(SENT_ACTION))
                        switch(getResultCode()){
                        case Activity.RESULT_OK:
-                               Utils.sendMessage(context, replyTo, sms_sent, describeSMS(intent));
+                               Utils.sendConfirmMessage(context, replyTo, sms_sent, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                Utils.sendMessage(context, replyTo, sms_not_sent_generic_failure, describeSMS(intent));
                                break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                Utils.sendMessage(context, replyTo, sms_not_sent_generic_failure, describeSMS(intent));
index 37049c566a75fb4e2fdc8fc2299c9c78b29bc01f..40a5e57dfbf66a93a52b772b4de9fe7201544647 100644 (file)
@@ -271,6 +271,22 @@ public final class Utils {
                sendMessage(context, address, toNonNull(context.getString(resource, args)));
        }
 
                sendMessage(context, address, toNonNull(context.getString(resource, args)));
        }
 
+       /**
+        * Send a confirmation message to a certain Address. A confirm message is a message that:
+        * 1) Confers no information (except for confirming that the command was executed).
+        * 2) May be dropped if the user asked so.
+        *
+        * @param context Context instance
+        * @param address destination Address
+        * @param resource String resource for the message text
+        * @param args format parameters for the resource
+        */
+       public static void sendConfirmMessage(final Context context, final Address address, final int resource, final Object... args){
+               final SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(context);
+               if(address.protocol != Protocol.SMS || !sp.getBoolean("expensive_sms", false))
+                       sendMessage(context, address, resource, args);
+       }
+
        /**
         * Send a notification to the user.
         * 
        /**
         * Send a notification to the user.
         * 
@@ -688,7 +704,7 @@ public final class Utils {
                                PreferenceManager.getDefaultSharedPreferences(context).edit()
                                .putString(MessageType.valueOf(args[0].toUpperCase(Locale.ENGLISH)).toString(), replyTo.toString())
                                .commit();
                                PreferenceManager.getDefaultSharedPreferences(context).edit()
                                .putString(MessageType.valueOf(args[0].toUpperCase(Locale.ENGLISH)).toString(), replyTo.toString())
                                .commit();
-                               sendMessage(context, replyTo, notification_enabled);
+                               sendConfirmMessage(context, replyTo, notification_enabled);
                        } catch (IllegalArgumentException e){
                                sendMessage(context, replyTo, messagetype_should_be_one_of, join(", ",toNonNull(MessageType.values())));
                                break;
                        } catch (IllegalArgumentException e){
                                sendMessage(context, replyTo, messagetype_should_be_one_of, join(", ",toNonNull(MessageType.values())));
                                break;
@@ -706,7 +722,7 @@ public final class Utils {
                                PreferenceManager.getDefaultSharedPreferences(context).edit()
                                .remove(MessageType.valueOf(args[0].toUpperCase(Locale.ENGLISH)).toString())
                                .commit();
                                PreferenceManager.getDefaultSharedPreferences(context).edit()
                                .remove(MessageType.valueOf(args[0].toUpperCase(Locale.ENGLISH)).toString())
                                .commit();
-                               sendMessage(context, replyTo,  notification_disabled);
+                               sendConfirmMessage(context, replyTo,  notification_disabled);
                        } catch (IllegalArgumentException e){
                                sendMessage(context, replyTo,  messagetype_should_be_one_of, join(", ",toNonNull(MessageType.values())));
                                break;
                        } catch (IllegalArgumentException e){
                                sendMessage(context, replyTo,  messagetype_should_be_one_of, join(", ",toNonNull(MessageType.values())));
                                break;
@@ -726,7 +742,7 @@ public final class Utils {
                                else
                                        Heavy.setPassword(context, replyTo, toNonNull(args[0]));
                        } catch (SecurityException e){
                                else
                                        Heavy.setPassword(context, replyTo, toNonNull(args[0]));
                        } catch (SecurityException e){
-                               sendMessage(context, replyTo,  security_exception+e.getMessage());
+                               sendMessage(context, replyTo,  security_exceptione.getMessage());
                        }
                        break;
 
                        }
                        break;
 
This page took 0.025928 seconds and 4 git commands to generate.