Skip to content

Commit ffbe2f2

Browse files
schfan-1Android Build Coastguard Worker
authored andcommitted
[SettingsProvider] verify ringtone URI before setting
Similar to ag/24422287, but the same URI verification should be done in SettingsProvider as well, which can be called by apps via Settings.System API or ContentProvider APIs without using RingtoneManager. BUG: 227201030 Test: manual with a test app. Will add a CTS test. (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1b234678ec122994ccbfc52ac48aafdad7fdb1ed) Merged-In: Ic0ffa1db14b5660d02880b632a7f2ad9e6e5d84b Change-Id: Ic0ffa1db14b5660d02880b632a7f2ad9e6e5d84b
1 parent bcf54ce commit ffbe2f2

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,9 @@ private boolean mutateSystemSetting(String name, String value, int runAsUserId,
19281928
cacheName = Settings.System.ALARM_ALERT_CACHE;
19291929
}
19301930
if (cacheName != null) {
1931+
if (!isValidAudioUri(name, value)) {
1932+
return false;
1933+
}
19311934
final File cacheFile = new File(
19321935
getRingtoneCacheDir(owningUserId), cacheName);
19331936
cacheFile.delete();
@@ -1960,6 +1963,34 @@ private boolean mutateSystemSetting(String name, String value, int runAsUserId,
19601963
}
19611964
}
19621965

1966+
private boolean isValidAudioUri(String name, String uri) {
1967+
if (uri != null) {
1968+
Uri audioUri = Uri.parse(uri);
1969+
if (Settings.AUTHORITY.equals(
1970+
ContentProvider.getAuthorityWithoutUserId(audioUri.getAuthority()))) {
1971+
// Don't accept setting the default uri to self-referential URIs like
1972+
// Settings.System.DEFAULT_RINGTONE_URI, which is an alias to the value of this
1973+
// setting.
1974+
return false;
1975+
}
1976+
final String mimeType = getContext().getContentResolver().getType(audioUri);
1977+
if (mimeType == null) {
1978+
Slog.e(LOG_TAG,
1979+
"mutateSystemSetting for setting: " + name + " URI: " + audioUri
1980+
+ " ignored: failure to find mimeType (no access from this context?)");
1981+
return false;
1982+
}
1983+
if (!(mimeType.startsWith("audio/") || mimeType.equals("application/ogg")
1984+
|| mimeType.equals("application/x-flac"))) {
1985+
Slog.e(LOG_TAG,
1986+
"mutateSystemSetting for setting: " + name + " URI: " + audioUri
1987+
+ " ignored: associated mimeType: " + mimeType + " is not an audio type");
1988+
return false;
1989+
}
1990+
}
1991+
return true;
1992+
}
1993+
19631994
private boolean hasWriteSecureSettingsPermission() {
19641995
// Write secure settings is a more protected permission. If caller has it we are good.
19651996
return getContext().checkCallingOrSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS)

0 commit comments

Comments
 (0)