diff --git a/proguard.config b/proguard.config index 551b9211..89717e9c 100644 --- a/proguard.config +++ b/proguard.config @@ -3,6 +3,7 @@ -printseeds seeds.txt -printusage unused.txt -optimizationpasses 5 +-repackageclasses -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify @@ -32,11 +33,6 @@ public void *(android.view.View); } --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } @@ -55,3 +51,5 @@ -assumenosideeffects class junit.framework.Assert { ; } + +-keep public class org.kreed.vanilla.Compat* diff --git a/src/org/kreed/vanilla/CompatFroyo.java b/src/org/kreed/vanilla/CompatFroyo.java new file mode 100644 index 00000000..472ddf67 --- /dev/null +++ b/src/org/kreed/vanilla/CompatFroyo.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011 Christopher Eby + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.kreed.vanilla; + +import android.app.backup.BackupManager; +import android.content.ComponentName; +import android.content.Context; +import android.media.AudioManager; + +/** + * Framework methods only in Froyo or above go here. + */ +public class CompatFroyo { + public static void registerMediaButtonEventReceiver(AudioManager manager, ComponentName receiver) + { + manager.registerMediaButtonEventReceiver(receiver); + } + + public static void unregisterMediaButtonEventReceiver(AudioManager manager, ComponentName receiver) + { + manager.unregisterMediaButtonEventReceiver(receiver); + } + + public static void dataChanged(Context context) + { + new BackupManager(context).dataChanged(); + } +} diff --git a/src/org/kreed/vanilla/MediaButtonReceiver.java b/src/org/kreed/vanilla/MediaButtonReceiver.java index 0116516d..2f123ce7 100644 --- a/src/org/kreed/vanilla/MediaButtonReceiver.java +++ b/src/org/kreed/vanilla/MediaButtonReceiver.java @@ -33,6 +33,10 @@ import android.os.SystemClock; import android.telephony.TelephonyManager; import android.view.KeyEvent; +/** + * Receives media button events and calls to PlaybackService to respond + * appropriately. + */ public class MediaButtonReceiver extends BroadcastReceiver { /** * If another button event is received before this time in milliseconds @@ -175,7 +179,7 @@ public class MediaButtonReceiver extends BroadcastReceiver { AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName()); - audioManager.registerMediaButtonEventReceiver(receiver); + CompatFroyo.registerMediaButtonEventReceiver(audioManager, receiver); } /** @@ -190,7 +194,7 @@ public class MediaButtonReceiver extends BroadcastReceiver { AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName()); - audioManager.unregisterMediaButtonEventReceiver(receiver); + CompatFroyo.unregisterMediaButtonEventReceiver(audioManager, receiver); } @Override diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java index 5c3f83be..9f8f1cff 100644 --- a/src/org/kreed/vanilla/PlaybackService.java +++ b/src/org/kreed/vanilla/PlaybackService.java @@ -22,7 +22,6 @@ package org.kreed.vanilla; -import android.app.backup.BackupManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -60,7 +59,16 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; -public final class PlaybackService extends Service implements Handler.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, SharedPreferences.OnSharedPreferenceChangeListener, SongTimeline.Callback { +/** + * Handles music playback and pretty much all the other work. + */ +public final class PlaybackService extends Service + implements Handler.Callback + , MediaPlayer.OnCompletionListener + , MediaPlayer.OnErrorListener + , SharedPreferences.OnSharedPreferenceChangeListener + , SongTimeline.Callback +{ /** * Name of the state file. */ @@ -443,8 +451,9 @@ public final class PlaybackService extends Service implements Handler.Callback, mHeadsetPlay = settings.getBoolean(key, false); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) - new BackupManager(this).dataChanged(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { + CompatFroyo.dataChanged(this); + } } /** @@ -892,6 +901,7 @@ public final class PlaybackService extends Service implements Handler.Callback, } + @Override public void onSharedPreferenceChanged(SharedPreferences settings, String key) { loadPreference(key); @@ -937,6 +947,7 @@ public final class PlaybackService extends Service implements Handler.Callback, private static final int PROCESS_SONG = 13; private static final int PROCESS_STATE = 14; + @Override public boolean handleMessage(Message message) { switch (message.what) {