Loading media/java/android/media/IRingtonePlayer.aidl +2 −1 Original line number Original line Diff line number Diff line Loading @@ -25,9 +25,10 @@ import android.os.UserHandle; */ */ interface IRingtonePlayer { interface IRingtonePlayer { /** Used for Ringtone.java playback */ /** Used for Ringtone.java playback */ void play(IBinder token, in Uri uri, in AudioAttributes aa); void play(IBinder token, in Uri uri, in AudioAttributes aa, float volume, boolean looping); void stop(IBinder token); void stop(IBinder token); boolean isPlaying(IBinder token); boolean isPlaying(IBinder token); void setPlaybackProperties(IBinder token, float volume, boolean looping); /** Used for Notification sound playback. */ /** Used for Notification sound playback. */ void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); Loading media/java/android/media/Ringtone.java +63 −1 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,10 @@ public class Ringtone { .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); .build(); // playback properties, use synchronized with mPlaybackSettingsLock private boolean mIsLooping = false; private float mVolume = 1.0f; private final Object mPlaybackSettingsLock = new Object(); /** {@hide} */ /** {@hide} */ public Ringtone(Context context, boolean allowRemote) { public Ringtone(Context context, boolean allowRemote) { Loading Loading @@ -135,6 +139,52 @@ public class Ringtone { return mAudioAttributes; return mAudioAttributes; } } /** * @hide * Sets the player to be looping or non-looping. * @param looping whether to loop or not */ public void setLooping(boolean looping) { synchronized (mPlaybackSettingsLock) { mIsLooping = looping; applyPlaybackProperties_sync(); } } /** * @hide * Sets the volume on this player. * @param volume a raw scalar in range 0.0 to 1.0, where 0.0 mutes this player, and 1.0 * corresponds to no attenuation being applied. */ public void setVolume(float volume) { synchronized (mPlaybackSettingsLock) { if (volume < 0.0f) { volume = 0.0f; } if (volume > 1.0f) { volume = 1.0f; } mVolume = volume; applyPlaybackProperties_sync(); } } /** * Must be called synchronized on mPlaybackSettingsLock */ private void applyPlaybackProperties_sync() { if (mLocalPlayer != null) { mLocalPlayer.setVolume(mVolume); mLocalPlayer.setLooping(mIsLooping); } else if (mAllowRemote && (mRemotePlayer != null)) { try { mRemotePlayer.setPlaybackProperties(mRemoteToken, mVolume, mIsLooping); } catch (RemoteException e) { Log.w(TAG, "Problem setting playback properties: ", e); } } else { Log.w(TAG, "Neither local nor remote player available when applying playback properties"); } } /** /** * Returns a human-presentable title for ringtone. Looks in media * Returns a human-presentable title for ringtone. Looks in media * content provider. If not in either, uses the filename * content provider. If not in either, uses the filename Loading Loading @@ -221,6 +271,9 @@ public class Ringtone { try { try { mLocalPlayer.setDataSource(mContext, mUri); mLocalPlayer.setDataSource(mContext, mUri); mLocalPlayer.setAudioAttributes(mAudioAttributes); mLocalPlayer.setAudioAttributes(mAudioAttributes); synchronized (mPlaybackSettingsLock) { applyPlaybackProperties_sync(); } mLocalPlayer.prepare(); mLocalPlayer.prepare(); } catch (SecurityException | IOException e) { } catch (SecurityException | IOException e) { Loading Loading @@ -257,8 +310,14 @@ public class Ringtone { } } } else if (mAllowRemote && (mRemotePlayer != null)) { } else if (mAllowRemote && (mRemotePlayer != null)) { final Uri canonicalUri = mUri.getCanonicalUri(); final Uri canonicalUri = mUri.getCanonicalUri(); final boolean looping; final float volume; synchronized (mPlaybackSettingsLock) { looping = mIsLooping; volume = mVolume; } try { try { mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes); mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes, volume, looping); } catch (RemoteException e) { } catch (RemoteException e) { if (!playFallbackRingtone()) { if (!playFallbackRingtone()) { Log.w(TAG, "Problem playing ringtone: " + e); Log.w(TAG, "Problem playing ringtone: " + e); Loading Loading @@ -349,6 +408,9 @@ public class Ringtone { afd.getDeclaredLength()); afd.getDeclaredLength()); } } mLocalPlayer.setAudioAttributes(mAudioAttributes); mLocalPlayer.setAudioAttributes(mAudioAttributes); synchronized (mPlaybackSettingsLock) { applyPlaybackProperties_sync(); } mLocalPlayer.prepare(); mLocalPlayer.prepare(); startLocalPlayer(); startLocalPlayer(); afd.close(); afd.close(); Loading packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +17 −1 Original line number Original line Diff line number Diff line Loading @@ -92,7 +92,8 @@ public class RingtonePlayer extends SystemUI { private IRingtonePlayer mCallback = new IRingtonePlayer.Stub() { private IRingtonePlayer mCallback = new IRingtonePlayer.Stub() { @Override @Override public void play(IBinder token, Uri uri, AudioAttributes aa) throws RemoteException { public void play(IBinder token, Uri uri, AudioAttributes aa, float volume, boolean looping) throws RemoteException { if (LOGD) { if (LOGD) { Log.d(TAG, "play(token=" + token + ", uri=" + uri + ", uid=" Log.d(TAG, "play(token=" + token + ", uri=" + uri + ", uid=" + Binder.getCallingUid() + ")"); + Binder.getCallingUid() + ")"); Loading @@ -107,6 +108,8 @@ public class RingtonePlayer extends SystemUI { mClients.put(token, client); mClients.put(token, client); } } } } client.mRingtone.setLooping(looping); client.mRingtone.setVolume(volume); client.mRingtone.play(); client.mRingtone.play(); } } Loading Loading @@ -137,6 +140,19 @@ public class RingtonePlayer extends SystemUI { } } } } @Override public void setPlaybackProperties(IBinder token, float volume, boolean looping) { Client client; synchronized (mClients) { client = mClients.get(token); } if (client != null) { client.mRingtone.setVolume(volume); client.mRingtone.setLooping(looping); } // else no client for token when setting playback properties but will be set at play() } @Override @Override public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) { public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) { if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")"); if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")"); Loading Loading
media/java/android/media/IRingtonePlayer.aidl +2 −1 Original line number Original line Diff line number Diff line Loading @@ -25,9 +25,10 @@ import android.os.UserHandle; */ */ interface IRingtonePlayer { interface IRingtonePlayer { /** Used for Ringtone.java playback */ /** Used for Ringtone.java playback */ void play(IBinder token, in Uri uri, in AudioAttributes aa); void play(IBinder token, in Uri uri, in AudioAttributes aa, float volume, boolean looping); void stop(IBinder token); void stop(IBinder token); boolean isPlaying(IBinder token); boolean isPlaying(IBinder token); void setPlaybackProperties(IBinder token, float volume, boolean looping); /** Used for Notification sound playback. */ /** Used for Notification sound playback. */ void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); Loading
media/java/android/media/Ringtone.java +63 −1 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,10 @@ public class Ringtone { .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); .build(); // playback properties, use synchronized with mPlaybackSettingsLock private boolean mIsLooping = false; private float mVolume = 1.0f; private final Object mPlaybackSettingsLock = new Object(); /** {@hide} */ /** {@hide} */ public Ringtone(Context context, boolean allowRemote) { public Ringtone(Context context, boolean allowRemote) { Loading Loading @@ -135,6 +139,52 @@ public class Ringtone { return mAudioAttributes; return mAudioAttributes; } } /** * @hide * Sets the player to be looping or non-looping. * @param looping whether to loop or not */ public void setLooping(boolean looping) { synchronized (mPlaybackSettingsLock) { mIsLooping = looping; applyPlaybackProperties_sync(); } } /** * @hide * Sets the volume on this player. * @param volume a raw scalar in range 0.0 to 1.0, where 0.0 mutes this player, and 1.0 * corresponds to no attenuation being applied. */ public void setVolume(float volume) { synchronized (mPlaybackSettingsLock) { if (volume < 0.0f) { volume = 0.0f; } if (volume > 1.0f) { volume = 1.0f; } mVolume = volume; applyPlaybackProperties_sync(); } } /** * Must be called synchronized on mPlaybackSettingsLock */ private void applyPlaybackProperties_sync() { if (mLocalPlayer != null) { mLocalPlayer.setVolume(mVolume); mLocalPlayer.setLooping(mIsLooping); } else if (mAllowRemote && (mRemotePlayer != null)) { try { mRemotePlayer.setPlaybackProperties(mRemoteToken, mVolume, mIsLooping); } catch (RemoteException e) { Log.w(TAG, "Problem setting playback properties: ", e); } } else { Log.w(TAG, "Neither local nor remote player available when applying playback properties"); } } /** /** * Returns a human-presentable title for ringtone. Looks in media * Returns a human-presentable title for ringtone. Looks in media * content provider. If not in either, uses the filename * content provider. If not in either, uses the filename Loading Loading @@ -221,6 +271,9 @@ public class Ringtone { try { try { mLocalPlayer.setDataSource(mContext, mUri); mLocalPlayer.setDataSource(mContext, mUri); mLocalPlayer.setAudioAttributes(mAudioAttributes); mLocalPlayer.setAudioAttributes(mAudioAttributes); synchronized (mPlaybackSettingsLock) { applyPlaybackProperties_sync(); } mLocalPlayer.prepare(); mLocalPlayer.prepare(); } catch (SecurityException | IOException e) { } catch (SecurityException | IOException e) { Loading Loading @@ -257,8 +310,14 @@ public class Ringtone { } } } else if (mAllowRemote && (mRemotePlayer != null)) { } else if (mAllowRemote && (mRemotePlayer != null)) { final Uri canonicalUri = mUri.getCanonicalUri(); final Uri canonicalUri = mUri.getCanonicalUri(); final boolean looping; final float volume; synchronized (mPlaybackSettingsLock) { looping = mIsLooping; volume = mVolume; } try { try { mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes); mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes, volume, looping); } catch (RemoteException e) { } catch (RemoteException e) { if (!playFallbackRingtone()) { if (!playFallbackRingtone()) { Log.w(TAG, "Problem playing ringtone: " + e); Log.w(TAG, "Problem playing ringtone: " + e); Loading Loading @@ -349,6 +408,9 @@ public class Ringtone { afd.getDeclaredLength()); afd.getDeclaredLength()); } } mLocalPlayer.setAudioAttributes(mAudioAttributes); mLocalPlayer.setAudioAttributes(mAudioAttributes); synchronized (mPlaybackSettingsLock) { applyPlaybackProperties_sync(); } mLocalPlayer.prepare(); mLocalPlayer.prepare(); startLocalPlayer(); startLocalPlayer(); afd.close(); afd.close(); Loading
packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +17 −1 Original line number Original line Diff line number Diff line Loading @@ -92,7 +92,8 @@ public class RingtonePlayer extends SystemUI { private IRingtonePlayer mCallback = new IRingtonePlayer.Stub() { private IRingtonePlayer mCallback = new IRingtonePlayer.Stub() { @Override @Override public void play(IBinder token, Uri uri, AudioAttributes aa) throws RemoteException { public void play(IBinder token, Uri uri, AudioAttributes aa, float volume, boolean looping) throws RemoteException { if (LOGD) { if (LOGD) { Log.d(TAG, "play(token=" + token + ", uri=" + uri + ", uid=" Log.d(TAG, "play(token=" + token + ", uri=" + uri + ", uid=" + Binder.getCallingUid() + ")"); + Binder.getCallingUid() + ")"); Loading @@ -107,6 +108,8 @@ public class RingtonePlayer extends SystemUI { mClients.put(token, client); mClients.put(token, client); } } } } client.mRingtone.setLooping(looping); client.mRingtone.setVolume(volume); client.mRingtone.play(); client.mRingtone.play(); } } Loading Loading @@ -137,6 +140,19 @@ public class RingtonePlayer extends SystemUI { } } } } @Override public void setPlaybackProperties(IBinder token, float volume, boolean looping) { Client client; synchronized (mClients) { client = mClients.get(token); } if (client != null) { client.mRingtone.setVolume(volume); client.mRingtone.setLooping(looping); } // else no client for token when setting playback properties but will be set at play() } @Override @Override public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) { public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) { if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")"); if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")"); Loading