Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7773a42b authored by Songchun Fan's avatar Songchun Fan Committed by Song Chun Fan
Browse files

[SettingsProvider] clear binder identity when updating the ringtone cache

Otherwise non-system callers can set the ringtone but cannot update the
ringtone cache. This doesn't affect a normal user journey (user setting Ringtone via the Settings app). It only affects CTS tests and third-party apps that tries to update the system ringtone.

BUG: 297847899
Test: atest android.media.audio.cts.RingtoneManagerTest

Change-Id: I15ed4bd3f9d49b0edeea0c752f37ad8b8e421473
parent bd33753f
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -2034,12 +2034,14 @@ public class SettingsProvider extends ContentProvider {
            final Uri ringtoneUri = Uri.parse(value);
            // Stream selected ringtone into cache, so it's available for playback
            // when CE storage is still locked
            Binder.withCleanCallingIdentity(() -> {
                try (InputStream in = openRingtone(getContext(), ringtoneUri);
                         OutputStream out = new FileOutputStream(cacheFile)) {
                    FileUtils.copy(in, out);
                } catch (IOException e) {
                    Slog.w(LOG_TAG, "Failed to cache ringtone: " + e);
                }
            });
        }
        return true;
    }