Merge "Refactor Ringtone.playFallbackRingtone" am: 2f56b3ab02 am: cbba151c10 am: 010e3ddc5f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1931765

Change-Id: I4d17fdf6a29cc66fce523c227f82a19366ca5636
This commit is contained in:
Kevin Rocard
2022-01-20 05:48:14 +00:00
committed by Automerger Merge Worker

View File

@@ -504,16 +504,24 @@ public class Ringtone {
} }
private boolean playFallbackRingtone() { private boolean playFallbackRingtone() {
if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) int streamType = AudioAttributes.toLegacyStreamType(mAudioAttributes);
!= 0) { if (mAudioManager.getStreamVolume(streamType) == 0) {
return false;
}
int ringtoneType = RingtoneManager.getDefaultType(mUri); int ringtoneType = RingtoneManager.getDefaultType(mUri);
if (ringtoneType == -1 || if (ringtoneType != -1 &&
RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) { RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) == null) {
Log.w(TAG, "not playing fallback for " + mUri);
return false;
}
// Default ringtone, try fallback ringtone. // Default ringtone, try fallback ringtone.
try { try {
AssetFileDescriptor afd = mContext.getResources().openRawResourceFd( AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(
com.android.internal.R.raw.fallbackring); com.android.internal.R.raw.fallbackring);
if (afd != null) { if (afd == null) {
Log.e(TAG, "Could not load fallback ringtone");
return false;
}
mLocalPlayer = new MediaPlayer(); mLocalPlayer = new MediaPlayer();
if (afd.getDeclaredLength() < 0) { if (afd.getDeclaredLength() < 0) {
mLocalPlayer.setDataSource(afd.getFileDescriptor()); mLocalPlayer.setDataSource(afd.getFileDescriptor());
@@ -532,22 +540,16 @@ public class Ringtone {
mLocalPlayer.prepare(); mLocalPlayer.prepare();
startLocalPlayer(); startLocalPlayer();
afd.close(); afd.close();
return true;
} else {
Log.e(TAG, "Could not load fallback ringtone");
}
} catch (IOException ioe) { } catch (IOException ioe) {
destroyLocalPlayer(); destroyLocalPlayer();
Log.e(TAG, "Failed to open fallback ringtone"); Log.e(TAG, "Failed to open fallback ringtone");
return false;
} catch (NotFoundException nfe) { } catch (NotFoundException nfe) {
Log.e(TAG, "Fallback ringtone does not exist"); Log.e(TAG, "Fallback ringtone does not exist");
}
} else {
Log.w(TAG, "not playing fallback for " + mUri);
}
}
return false; return false;
} }
return true;
}
void setTitle(String title) { void setTitle(String title) {
mTitle = title; mTitle = title;