Merge "Rename fast-scroll sound effects to navigation repeat" into sc-dev

This commit is contained in:
Philip Junker
2021-02-22 13:22:50 +00:00
committed by Android (Google) Code Review
4 changed files with 62 additions and 53 deletions

View File

@@ -3123,52 +3123,57 @@ public class AudioManager {
/** /**
* @hide Home sound * @hide Home sound
* Played by the framework when the home app becomes active if config_enableHomeSound is set to * <p>
* true. This is currently only used on TV devices. * To be played by the framework when the home app becomes active if config_enableHomeSound is
* set to true. This is currently only used on TV devices.
* Note that this sound is only available if a sound file is specified in audio_assets.xml. * Note that this sound is only available if a sound file is specified in audio_assets.xml.
* @see #playSoundEffect(int) * @see #playSoundEffect(int)
*/ */
public static final int FX_HOME = 11; public static final int FX_HOME = 11;
/** /**
* @hide Fast scroll sound 1 * @hide Navigation repeat sound 1
* To be by the framework when a fast-scrolling is performed and * <p>
* {@link #areFastScrollSoundEffectsEnabled()} is true. * To be played by the framework when a focus navigation is repeatedly triggered
* (e.g. due to long-pressing) and {@link #areNavigationRepeatSoundEffectsEnabled()} is true.
* This is currently only used on TV devices. * This is currently only used on TV devices.
* Note that this sound is only available if a sound file is specified in audio_assets.xml * Note that this sound is only available if a sound file is specified in audio_assets.xml
* @see #playSoundEffect(int) * @see #playSoundEffect(int)
*/ */
public static final int FX_FAST_SCROLL_1 = 12; public static final int FX_FOCUS_NAVIGATION_REPEAT_1 = 12;
/** /**
* @hide Fast scroll sound 2 * @hide Navigation repeat sound 2
* To be by the framework when a fast-scrolling is performed and * <p>
* {@link #areFastScrollSoundEffectsEnabled()} is true. * To be played by the framework when a focus navigation is repeatedly triggered
* (e.g. due to long-pressing) and {@link #areNavigationRepeatSoundEffectsEnabled()} is true.
* This is currently only used on TV devices. * This is currently only used on TV devices.
* Note that this sound is only available if a sound file is specified in audio_assets.xml * Note that this sound is only available if a sound file is specified in audio_assets.xml
* @see #playSoundEffect(int) * @see #playSoundEffect(int)
*/ */
public static final int FX_FAST_SCROLL_2 = 13; public static final int FX_FOCUS_NAVIGATION_REPEAT_2 = 13;
/** /**
* @hide Fast scroll sound 3 * @hide Navigation repeat sound 3
* To be by the framework when a fast-scrolling is performed and * <p>
* {@link #areFastScrollSoundEffectsEnabled()} is true. * To be played by the framework when a focus navigation is repeatedly triggered
* (e.g. due to long-pressing) and {@link #areNavigationRepeatSoundEffectsEnabled()} is true.
* This is currently only used on TV devices. * This is currently only used on TV devices.
* Note that this sound is only available if a sound file is specified in audio_assets.xml * Note that this sound is only available if a sound file is specified in audio_assets.xml
* @see #playSoundEffect(int) * @see #playSoundEffect(int)
*/ */
public static final int FX_FAST_SCROLL_3 = 14; public static final int FX_FOCUS_NAVIGATION_REPEAT_3 = 14;
/** /**
* @hide Fast scroll sound 4 * @hide Navigation repeat sound 4
* To be by the framework when a fast-scrolling is performed and * <p>
* {@link #areFastScrollSoundEffectsEnabled()} is true. * To be played by the framework when a focus navigation is repeatedly triggered
* (e.g. due to long-pressing) and {@link #areNavigationRepeatSoundEffectsEnabled()} is true.
* This is currently only used on TV devices. * This is currently only used on TV devices.
* Note that this sound is only available if a sound file is specified in audio_assets.xml * Note that this sound is only available if a sound file is specified in audio_assets.xml
* @see #playSoundEffect(int) * @see #playSoundEffect(int)
*/ */
public static final int FX_FAST_SCROLL_4 = 15; public static final int FX_FOCUS_NAVIGATION_REPEAT_4 = 15;
/** /**
* @hide Number of sound effects * @hide Number of sound effects
@@ -3177,27 +3182,27 @@ public class AudioManager {
public static final int NUM_SOUND_EFFECTS = 16; public static final int NUM_SOUND_EFFECTS = 16;
/** /**
* @hide Number of fast scroll sound effects * @hide Number of FX_FOCUS_NAVIGATION_REPEAT_* sound effects
*/ */
public static final int NUM_FAST_SCROLL_SOUND_EFFECTS = 4; public static final int NUM_NAVIGATION_REPEAT_SOUND_EFFECTS = 4;
/** /**
* @hide * @hide
* @param n a value in [0, {@link #NUM_FAST_SCROLL_SOUND_EFFECTS}[ * @param n a value in [0, {@link #NUM_NAVIGATION_REPEAT_SOUND_EFFECTS}[
* @return The id of a fast scroll sound effect or -1 if out of bounds * @return The id of a navigation repeat sound effect or -1 if out of bounds
*/ */
public static int getNthFastScrollSoundEffectId(int n) { public static int getNthNavigationRepeatSoundEffect(int n) {
switch (n) { switch (n) {
case 0: case 0:
return FX_FAST_SCROLL_1; return FX_FOCUS_NAVIGATION_REPEAT_1;
case 1: case 1:
return FX_FAST_SCROLL_2; return FX_FOCUS_NAVIGATION_REPEAT_2;
case 2: case 2:
return FX_FAST_SCROLL_3; return FX_FOCUS_NAVIGATION_REPEAT_3;
case 3: case 3:
return FX_FAST_SCROLL_4; return FX_FOCUS_NAVIGATION_REPEAT_4;
default: default:
Log.w(TAG, "Invalid fast-scroll sound effect id: " + n); Log.w(TAG, "Invalid navigation repeat sound effect id: " + n);
return -1; return -1;
} }
} }
@@ -3205,9 +3210,9 @@ public class AudioManager {
/** /**
* @hide * @hide
*/ */
public void setFastScrollSoundEffectsEnabled(boolean enabled) { public void setNavigationRepeatSoundEffectsEnabled(boolean enabled) {
try { try {
getService().setFastScrollSoundEffectsEnabled(enabled); getService().setNavigationRepeatSoundEffectsEnabled(enabled);
} catch (RemoteException e) { } catch (RemoteException e) {
} }
@@ -3215,11 +3220,11 @@ public class AudioManager {
/** /**
* @hide * @hide
* @return true if the fast scroll sound effects are enabled * @return true if the navigation repeat sound effects are enabled
*/ */
public boolean areFastScrollSoundEffectsEnabled() { public boolean areNavigationRepeatSoundEffectsEnabled() {
try { try {
return getService().areFastScrollSoundEffectsEnabled(); return getService().areNavigationRepeatSoundEffectsEnabled();
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }

View File

@@ -351,9 +351,9 @@ interface IAudioService {
oneway void unregisterCommunicationDeviceDispatcher( oneway void unregisterCommunicationDeviceDispatcher(
ICommunicationDeviceDispatcher dispatcher); ICommunicationDeviceDispatcher dispatcher);
boolean areFastScrollSoundEffectsEnabled(); boolean areNavigationRepeatSoundEffectsEnabled();
oneway void setFastScrollSoundEffectsEnabled(boolean enabled); oneway void setNavigationRepeatSoundEffectsEnabled(boolean enabled);
boolean isHomeSoundEffectEnabled(); boolean isHomeSoundEffectEnabled();

View File

@@ -726,7 +726,7 @@ public class AudioService extends IAudioService.Stub
// caches the value returned by AudioSystem.isMicrophoneMuted() // caches the value returned by AudioSystem.isMicrophoneMuted()
private boolean mMicMuteFromSystemCached; private boolean mMicMuteFromSystemCached;
private boolean mFastScrollSoundEffectsEnabled; private boolean mNavigationRepeatSoundEffectsEnabled;
private boolean mHomeSoundEffectEnabled; private boolean mHomeSoundEffectEnabled;
@GuardedBy("mSettingsLock") @GuardedBy("mSettingsLock")
@@ -2325,15 +2325,15 @@ public class AudioService extends IAudioService.Stub
VOL_ADJUST_NORMAL); VOL_ADJUST_NORMAL);
} }
public void setFastScrollSoundEffectsEnabled(boolean enabled) { public void setNavigationRepeatSoundEffectsEnabled(boolean enabled) {
mFastScrollSoundEffectsEnabled = enabled; mNavigationRepeatSoundEffectsEnabled = enabled;
} }
/** /**
* @return true if the fast scroll sound effects are enabled * @return true if the fast scroll sound effects are enabled
*/ */
public boolean areFastScrollSoundEffectsEnabled() { public boolean areNavigationRepeatSoundEffectsEnabled() {
return mFastScrollSoundEffectsEnabled; return mNavigationRepeatSoundEffectsEnabled;
} }
public void setHomeSoundEffectEnabled(boolean enabled) { public void setHomeSoundEffectEnabled(boolean enabled) {

View File

@@ -52,6 +52,7 @@ import java.util.Map;
* used by AudioService. As its methods are called on the message handler thread * used by AudioService. As its methods are called on the message handler thread
* of AudioService, the actual work is offloaded to a dedicated thread. * of AudioService, the actual work is offloaded to a dedicated thread.
* This helps keeping AudioService responsive. * This helps keeping AudioService responsive.
*
* @hide * @hide
*/ */
class SoundEffectsHelper { class SoundEffectsHelper {
@@ -89,15 +90,18 @@ class SoundEffectsHelper {
final String mFileName; final String mFileName;
int mSampleId; int mSampleId;
boolean mLoaded; // for effects in SoundPool boolean mLoaded; // for effects in SoundPool
Resource(String fileName) { Resource(String fileName) {
mFileName = fileName; mFileName = fileName;
mSampleId = EFFECT_NOT_IN_SOUND_POOL; mSampleId = EFFECT_NOT_IN_SOUND_POOL;
} }
void unload() { void unload() {
mSampleId = EFFECT_NOT_IN_SOUND_POOL; mSampleId = EFFECT_NOT_IN_SOUND_POOL;
mLoaded = false; mLoaded = false;
} }
} }
// All the fields below are accessed by the worker thread exclusively // All the fields below are accessed by the worker thread exclusively
private final List<Resource> mResources = new ArrayList<Resource>(); private final List<Resource> mResources = new ArrayList<Resource>();
private final int[] mEffects = new int[AudioManager.NUM_SOUND_EFFECTS]; // indexes in mResources private final int[] mEffects = new int[AudioManager.NUM_SOUND_EFFECTS]; // indexes in mResources
@@ -116,9 +120,9 @@ class SoundEffectsHelper {
} }
/** /**
* Unloads samples from the sound pool. * Unloads samples from the sound pool.
* This method can be called to free some memory when * This method can be called to free some memory when
* sound effects are disabled. * sound effects are disabled.
*/ */
/*package*/ void unloadSoundEffects() { /*package*/ void unloadSoundEffects() {
sendMsg(MSG_UNLOAD_EFFECTS, 0, 0, null, 0); sendMsg(MSG_UNLOAD_EFFECTS, 0, 0, null, 0);
@@ -385,12 +389,12 @@ class SoundEffectsHelper {
} }
} }
boolean fastScrollSoundEffectsParsed = allFastScrollSoundsParsed(parserCounter); boolean navigationRepeatFxParsed = allNavigationRepeatSoundsParsed(parserCounter);
boolean homeSoundParsed = parserCounter.getOrDefault(AudioManager.FX_HOME, 0) > 0; boolean homeSoundParsed = parserCounter.getOrDefault(AudioManager.FX_HOME, 0) > 0;
if (fastScrollSoundEffectsParsed || homeSoundParsed) { if (navigationRepeatFxParsed || homeSoundParsed) {
AudioManager audioManager = mContext.getSystemService(AudioManager.class); AudioManager audioManager = mContext.getSystemService(AudioManager.class);
if (audioManager != null && fastScrollSoundEffectsParsed) { if (audioManager != null && navigationRepeatFxParsed) {
audioManager.setFastScrollSoundEffectsEnabled(true); audioManager.setNavigationRepeatSoundEffectsEnabled(true);
} }
if (audioManager != null && homeSoundParsed) { if (audioManager != null && homeSoundParsed) {
audioManager.setHomeSoundEffectEnabled(true); audioManager.setHomeSoundEffectEnabled(true);
@@ -410,13 +414,13 @@ class SoundEffectsHelper {
} }
} }
private boolean allFastScrollSoundsParsed(Map<Integer, Integer> parserCounter) { private boolean allNavigationRepeatSoundsParsed(Map<Integer, Integer> parserCounter) {
int numFastScrollSoundEffectsParsed = int numFastScrollSoundEffectsParsed =
parserCounter.getOrDefault(AudioManager.FX_FAST_SCROLL_1, 0) parserCounter.getOrDefault(AudioManager.FX_FOCUS_NAVIGATION_REPEAT_1, 0)
+ parserCounter.getOrDefault(AudioManager.FX_FAST_SCROLL_2, 0) + parserCounter.getOrDefault(AudioManager.FX_FOCUS_NAVIGATION_REPEAT_2, 0)
+ parserCounter.getOrDefault(AudioManager.FX_FAST_SCROLL_3, 0) + parserCounter.getOrDefault(AudioManager.FX_FOCUS_NAVIGATION_REPEAT_3, 0)
+ parserCounter.getOrDefault(AudioManager.FX_FAST_SCROLL_4, 0); + parserCounter.getOrDefault(AudioManager.FX_FOCUS_NAVIGATION_REPEAT_4, 0);
return numFastScrollSoundEffectsParsed == AudioManager.NUM_FAST_SCROLL_SOUND_EFFECTS; return numFastScrollSoundEffectsParsed == AudioManager.NUM_NAVIGATION_REPEAT_SOUND_EFFECTS;
} }
private int findOrAddResourceByFileName(String fileName) { private int findOrAddResourceByFileName(String fileName) {