From 62b9aec7a0a4e1cf8cfec7e39ea3103ab510d72e Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Mon, 7 Nov 2011 11:10:16 -0800 Subject: Don't check return value of new for being == null new either succeeds or throws an exception Change-Id: I1615e10c4f6730495c49e56b64714a00141ea8ff --- media/java/android/media/AudioService.java | 54 +++++++++++++--------------- media/java/android/media/SoundPool.java | 10 +++--- media/java/android/media/ThumbnailUtils.java | 4 +-- 3 files changed, 29 insertions(+), 39 deletions(-) (limited to 'media/java') diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 2f32bd8..459b145 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -1015,10 +1015,6 @@ public class AudioService extends IAudioService.Stub { return true; } mSoundPool = new SoundPool(NUM_SOUNDPOOL_CHANNELS, AudioSystem.STREAM_SYSTEM, 0); - if (mSoundPool == null) { - Log.w(TAG, "loadSoundEffects() could not allocate sound pool"); - return false; - } try { mSoundPoolCallBack = null; @@ -2093,32 +2089,30 @@ public class AudioService extends IAudioService.Stub { mSoundPool.play(SOUND_EFFECT_FILES_MAP[effectType][1], volFloat, volFloat, 0, 0, 1.0f); } else { MediaPlayer mediaPlayer = new MediaPlayer(); - if (mediaPlayer != null) { - try { - String filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH + SOUND_EFFECT_FILES[SOUND_EFFECT_FILES_MAP[effectType][0]]; - mediaPlayer.setDataSource(filePath); - mediaPlayer.setAudioStreamType(AudioSystem.STREAM_SYSTEM); - mediaPlayer.prepare(); - mediaPlayer.setVolume(volFloat, volFloat); - mediaPlayer.setOnCompletionListener(new OnCompletionListener() { - public void onCompletion(MediaPlayer mp) { - cleanupPlayer(mp); - } - }); - mediaPlayer.setOnErrorListener(new OnErrorListener() { - public boolean onError(MediaPlayer mp, int what, int extra) { - cleanupPlayer(mp); - return true; - } - }); - mediaPlayer.start(); - } catch (IOException ex) { - Log.w(TAG, "MediaPlayer IOException: "+ex); - } catch (IllegalArgumentException ex) { - Log.w(TAG, "MediaPlayer IllegalArgumentException: "+ex); - } catch (IllegalStateException ex) { - Log.w(TAG, "MediaPlayer IllegalStateException: "+ex); - } + try { + String filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH + SOUND_EFFECT_FILES[SOUND_EFFECT_FILES_MAP[effectType][0]]; + mediaPlayer.setDataSource(filePath); + mediaPlayer.setAudioStreamType(AudioSystem.STREAM_SYSTEM); + mediaPlayer.prepare(); + mediaPlayer.setVolume(volFloat, volFloat); + mediaPlayer.setOnCompletionListener(new OnCompletionListener() { + public void onCompletion(MediaPlayer mp) { + cleanupPlayer(mp); + } + }); + mediaPlayer.setOnErrorListener(new OnErrorListener() { + public boolean onError(MediaPlayer mp, int what, int extra) { + cleanupPlayer(mp); + return true; + } + }); + mediaPlayer.start(); + } catch (IOException ex) { + Log.w(TAG, "MediaPlayer IOException: "+ex); + } catch (IllegalArgumentException ex) { + Log.w(TAG, "MediaPlayer IllegalArgumentException: "+ex); + } catch (IllegalStateException ex) { + Log.w(TAG, "MediaPlayer IllegalStateException: "+ex); } } } diff --git a/media/java/android/media/SoundPool.java b/media/java/android/media/SoundPool.java index 5e9c018..0f68e98 100644 --- a/media/java/android/media/SoundPool.java +++ b/media/java/android/media/SoundPool.java @@ -161,12 +161,10 @@ public class SoundPool int id = 0; try { File f = new File(path); - if (f != null) { - ParcelFileDescriptor fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY); - if (fd != null) { - id = _load(fd.getFileDescriptor(), 0, f.length(), priority); - fd.close(); - } + ParcelFileDescriptor fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY); + if (fd != null) { + id = _load(fd.getFileDescriptor(), 0, f.length(), priority); + fd.close(); } } catch (java.io.IOException e) { Log.e(TAG, "error loading " + path); diff --git a/media/java/android/media/ThumbnailUtils.java b/media/java/android/media/ThumbnailUtils.java index 078d4af..b320515 100644 --- a/media/java/android/media/ThumbnailUtils.java +++ b/media/java/android/media/ThumbnailUtils.java @@ -472,9 +472,7 @@ public class ThumbnailUtils { byte [] thumbData = null; try { exif = new ExifInterface(filePath); - if (exif != null) { - thumbData = exif.getThumbnail(); - } + thumbData = exif.getThumbnail(); } catch (IOException ex) { Log.w(TAG, ex); } -- cgit v1.1