Loading core/api/current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -23033,10 +23033,12 @@ package android.media { method @Deprecated public int getStreamType(); method public String getTitle(android.content.Context); method public float getVolume(); method public boolean isHapticGeneratorEnabled(); method public boolean isLooping(); method public boolean isPlaying(); method public void play(); method public void setAudioAttributes(android.media.AudioAttributes) throws java.lang.IllegalArgumentException; method public boolean setHapticGeneratorEnabled(boolean); method public void setLooping(boolean); method @Deprecated public void setStreamType(int); method public void setVolume(float); media/java/android/media/IRingtonePlayer.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ interface IRingtonePlayer { float volume, boolean looping, in @nullable VolumeShaper.Configuration volumeShaperConfig); oneway void stop(IBinder token); boolean isPlaying(IBinder token); oneway void setPlaybackProperties(IBinder token, float volume, boolean looping); oneway void setPlaybackProperties(IBinder token, float volume, boolean looping, boolean hapticGeneratorEnabled); /** Used for Notification sound playback. */ oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); Loading media/java/android/media/Ringtone.java +43 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.media.audiofx.HapticGenerator; import android.net.Uri; import android.os.Binder; import android.os.Build; Loading Loading @@ -77,6 +78,7 @@ public class Ringtone { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private MediaPlayer mLocalPlayer; private final MyOnCompletionListener mCompletionListener = new MyOnCompletionListener(); private HapticGenerator mHapticGenerator; @UnsupportedAppUsage private Uri mUri; Loading @@ -89,6 +91,7 @@ public class Ringtone { // playback properties, use synchronized with mPlaybackSettingsLock private boolean mIsLooping = false; private float mVolume = 1.0f; private boolean mHapticGeneratorEnabled = false; private final Object mPlaybackSettingsLock = new Object(); /** {@hide} */ Loading Loading @@ -196,6 +199,34 @@ public class Ringtone { } } /** * Enable or disable the {@link android.media.audiofx.HapticGenerator} effect. The effect can * only be enabled on devices that support the effect. * * @return true if the HapticGenerator effect is successfully enabled. Otherwise, return false. * @see android.media.audiofx.HapticGenerator#isAvailable() */ public boolean setHapticGeneratorEnabled(boolean enabled) { if (!HapticGenerator.isAvailable()) { return false; } synchronized (mPlaybackSettingsLock) { mHapticGeneratorEnabled = enabled; applyPlaybackProperties_sync(); } return true; } /** * Return whether the {@link android.media.audiofx.HapticGenerator} effect is enabled or not. * @return true if the HapticGenerator is enabled. */ public boolean isHapticGeneratorEnabled() { synchronized (mPlaybackSettingsLock) { return mHapticGeneratorEnabled; } } /** * Must be called synchronized on mPlaybackSettingsLock */ Loading @@ -203,9 +234,16 @@ public class Ringtone { if (mLocalPlayer != null) { mLocalPlayer.setVolume(mVolume); mLocalPlayer.setLooping(mIsLooping); if (mHapticGenerator == null && mHapticGeneratorEnabled) { mHapticGenerator = HapticGenerator.create(mLocalPlayer.getAudioSessionId()); } if (mHapticGenerator != null) { mHapticGenerator.setEnabled(mHapticGeneratorEnabled); } } else if (mAllowRemote && (mRemotePlayer != null)) { try { mRemotePlayer.setPlaybackProperties(mRemoteToken, mVolume, mIsLooping); mRemotePlayer.setPlaybackProperties( mRemoteToken, mVolume, mIsLooping, mHapticGeneratorEnabled); } catch (RemoteException e) { Log.w(TAG, "Problem setting playback properties: ", e); } Loading Loading @@ -413,6 +451,10 @@ public class Ringtone { private void destroyLocalPlayer() { if (mLocalPlayer != null) { if (mHapticGenerator != null) { mHapticGenerator.release(); mHapticGenerator = null; } mLocalPlayer.setOnCompletionListener(null); mLocalPlayer.reset(); mLocalPlayer.release(); Loading packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +3 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,8 @@ public class RingtonePlayer extends SystemUI { } @Override public void setPlaybackProperties(IBinder token, float volume, boolean looping) { public void setPlaybackProperties(IBinder token, float volume, boolean looping, boolean hapticGeneratorEnabled) { Client client; synchronized (mClients) { client = mClients.get(token); Loading @@ -171,6 +172,7 @@ public class RingtonePlayer extends SystemUI { if (client != null) { client.mRingtone.setVolume(volume); client.mRingtone.setLooping(looping); client.mRingtone.setHapticGeneratorEnabled(hapticGeneratorEnabled); } // else no client for token when setting playback properties but will be set at play() } Loading Loading
core/api/current.txt +2 −0 Original line number Diff line number Diff line Loading @@ -23033,10 +23033,12 @@ package android.media { method @Deprecated public int getStreamType(); method public String getTitle(android.content.Context); method public float getVolume(); method public boolean isHapticGeneratorEnabled(); method public boolean isLooping(); method public boolean isPlaying(); method public void play(); method public void setAudioAttributes(android.media.AudioAttributes) throws java.lang.IllegalArgumentException; method public boolean setHapticGeneratorEnabled(boolean); method public void setLooping(boolean); method @Deprecated public void setStreamType(int); method public void setVolume(float);
media/java/android/media/IRingtonePlayer.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ interface IRingtonePlayer { float volume, boolean looping, in @nullable VolumeShaper.Configuration volumeShaperConfig); oneway void stop(IBinder token); boolean isPlaying(IBinder token); oneway void setPlaybackProperties(IBinder token, float volume, boolean looping); oneway void setPlaybackProperties(IBinder token, float volume, boolean looping, boolean hapticGeneratorEnabled); /** Used for Notification sound playback. */ oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa); Loading
media/java/android/media/Ringtone.java +43 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.media.audiofx.HapticGenerator; import android.net.Uri; import android.os.Binder; import android.os.Build; Loading Loading @@ -77,6 +78,7 @@ public class Ringtone { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private MediaPlayer mLocalPlayer; private final MyOnCompletionListener mCompletionListener = new MyOnCompletionListener(); private HapticGenerator mHapticGenerator; @UnsupportedAppUsage private Uri mUri; Loading @@ -89,6 +91,7 @@ public class Ringtone { // playback properties, use synchronized with mPlaybackSettingsLock private boolean mIsLooping = false; private float mVolume = 1.0f; private boolean mHapticGeneratorEnabled = false; private final Object mPlaybackSettingsLock = new Object(); /** {@hide} */ Loading Loading @@ -196,6 +199,34 @@ public class Ringtone { } } /** * Enable or disable the {@link android.media.audiofx.HapticGenerator} effect. The effect can * only be enabled on devices that support the effect. * * @return true if the HapticGenerator effect is successfully enabled. Otherwise, return false. * @see android.media.audiofx.HapticGenerator#isAvailable() */ public boolean setHapticGeneratorEnabled(boolean enabled) { if (!HapticGenerator.isAvailable()) { return false; } synchronized (mPlaybackSettingsLock) { mHapticGeneratorEnabled = enabled; applyPlaybackProperties_sync(); } return true; } /** * Return whether the {@link android.media.audiofx.HapticGenerator} effect is enabled or not. * @return true if the HapticGenerator is enabled. */ public boolean isHapticGeneratorEnabled() { synchronized (mPlaybackSettingsLock) { return mHapticGeneratorEnabled; } } /** * Must be called synchronized on mPlaybackSettingsLock */ Loading @@ -203,9 +234,16 @@ public class Ringtone { if (mLocalPlayer != null) { mLocalPlayer.setVolume(mVolume); mLocalPlayer.setLooping(mIsLooping); if (mHapticGenerator == null && mHapticGeneratorEnabled) { mHapticGenerator = HapticGenerator.create(mLocalPlayer.getAudioSessionId()); } if (mHapticGenerator != null) { mHapticGenerator.setEnabled(mHapticGeneratorEnabled); } } else if (mAllowRemote && (mRemotePlayer != null)) { try { mRemotePlayer.setPlaybackProperties(mRemoteToken, mVolume, mIsLooping); mRemotePlayer.setPlaybackProperties( mRemoteToken, mVolume, mIsLooping, mHapticGeneratorEnabled); } catch (RemoteException e) { Log.w(TAG, "Problem setting playback properties: ", e); } Loading Loading @@ -413,6 +451,10 @@ public class Ringtone { private void destroyLocalPlayer() { if (mLocalPlayer != null) { if (mHapticGenerator != null) { mHapticGenerator.release(); mHapticGenerator = null; } mLocalPlayer.setOnCompletionListener(null); mLocalPlayer.reset(); mLocalPlayer.release(); Loading
packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +3 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,8 @@ public class RingtonePlayer extends SystemUI { } @Override public void setPlaybackProperties(IBinder token, float volume, boolean looping) { public void setPlaybackProperties(IBinder token, float volume, boolean looping, boolean hapticGeneratorEnabled) { Client client; synchronized (mClients) { client = mClients.get(token); Loading @@ -171,6 +172,7 @@ public class RingtonePlayer extends SystemUI { if (client != null) { client.mRingtone.setVolume(volume); client.mRingtone.setLooping(looping); client.mRingtone.setHapticGeneratorEnabled(hapticGeneratorEnabled); } // else no client for token when setting playback properties but will be set at play() } Loading