diff options
author | Piotr Mikolajczyk <piotr.mikolajczyk@qt.io> | 2020-11-30 12:27:26 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-12-04 09:18:34 +0000 |
commit | 1fa5245b274fb37cbadd99a6adb2ebbcae038a10 (patch) | |
tree | 9c0d7367704720853b32c04b8a01d0b11727796f /src/corelib/io | |
parent | 0b4adb5b63221d423e4bdd6d07b3460d3d5cc6fe (diff) |
Android: Kill calls to deprecated func in API 29
Since API 29 functions:
- getExternalStoragePublicDirectory
- getExternalStorageDirectory
are deprecated and no longer return directly accessible path.
This patch replaces calls to those with suggested call to
Context.getExternalFilesDir(String)
Task-number: QTBUG-87803
Change-Id: I36bc5d5b72a80017996445af0d577aacf5e112d3
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
(cherry picked from commit e1440dd7bc1a5da9a536f88b9733d04ec8fa6e61)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qstandardpaths_android.cpp | 62 |
1 files changed, 7 insertions, 55 deletions
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp index 1f4e0de1e7..dd7101ad52 100644 --- a/src/corelib/io/qstandardpaths_android.cpp +++ b/src/corelib/io/qstandardpaths_android.cpp @@ -86,51 +86,6 @@ static inline QString getAbsolutePath(const QJNIObjectPrivate &file) } /* - * The root of the external storage - * - */ -static QString getExternalStorageDirectory() -{ - QString &path = (*androidDirCache)[QStringLiteral("EXT_ROOT")]; - if (!path.isEmpty()) - return path; - - QJNIObjectPrivate file = QJNIObjectPrivate::callStaticObjectMethod("android/os/Environment", - "getExternalStorageDirectory", - "()Ljava/io/File;"); - if (!file.isValid()) - return QString(); - - return (path = getAbsolutePath(file)); -} - -/* - * Locations where applications can place user files (public). - * E.g., /storage/Music - */ -static QString getExternalStoragePublicDirectory(const char *directoryField) -{ - QString &path = (*androidDirCache)[QLatin1String(directoryField)]; - if (!path.isEmpty()) - return path; - - QJNIObjectPrivate dirField = QJNIObjectPrivate::getStaticObjectField("android/os/Environment", - directoryField, - "Ljava/lang/String;"); - if (!dirField.isValid()) - return QString(); - - QJNIObjectPrivate file = QJNIObjectPrivate::callStaticObjectMethod("android/os/Environment", - "getExternalStoragePublicDirectory", - "(Ljava/lang/String;)Ljava/io/File;", - dirField.object()); - if (!file.isValid()) - return QString(); - - return (path = getAbsolutePath(file)); -} - -/* * Locations where applications can place persistent files it owns. * E.g., /storage/org.app/Music */ @@ -145,7 +100,7 @@ static QString getExternalFilesDir(const char *directoryField = 0) return QString(); QJNIObjectPrivate dirField = QJNIObjectPrivate::fromString(QLatin1String("")); - if (directoryField) { + if (directoryField && strlen(directoryField) > 0) { dirField = QJNIObjectPrivate::getStaticObjectField("android/os/Environment", directoryField, "Ljava/lang/String;"); @@ -233,21 +188,21 @@ QString QStandardPaths::writableLocation(StandardLocation type) { switch (type) { case QStandardPaths::MusicLocation: - return getExternalStoragePublicDirectory("DIRECTORY_MUSIC"); + return getExternalFilesDir("DIRECTORY_MUSIC"); case QStandardPaths::MoviesLocation: - return getExternalStoragePublicDirectory("DIRECTORY_MOVIES"); + return getExternalFilesDir("DIRECTORY_MOVIES"); case QStandardPaths::PicturesLocation: - return getExternalStoragePublicDirectory("DIRECTORY_PICTURES"); + return getExternalFilesDir("DIRECTORY_PICTURES"); case QStandardPaths::DocumentsLocation: - return getExternalStoragePublicDirectory("DIRECTORY_DOCUMENTS"); + return getExternalFilesDir("DIRECTORY_DOCUMENTS"); case QStandardPaths::DownloadLocation: - return getExternalStoragePublicDirectory("DIRECTORY_DOWNLOADS"); + return getExternalFilesDir("DIRECTORY_DOWNLOADS"); case QStandardPaths::GenericConfigLocation: case QStandardPaths::ConfigLocation: case QStandardPaths::AppConfigLocation: return getFilesDir() + testDir() + QLatin1String("/settings"); case QStandardPaths::GenericDataLocation: - return getExternalStorageDirectory() + testDir(); + return getExternalFilesDir() + testDir(); case QStandardPaths::AppDataLocation: case QStandardPaths::AppLocalDataLocation: return getFilesDir() + testDir(); @@ -273,11 +228,8 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) if (type == MusicLocation) { return QStringList() << writableLocation(type) << getExternalFilesDir("DIRECTORY_MUSIC") - << getExternalStoragePublicDirectory("DIRECTORY_PODCASTS") << getExternalFilesDir("DIRECTORY_PODCASTS") - << getExternalStoragePublicDirectory("DIRECTORY_NOTIFICATIONS") << getExternalFilesDir("DIRECTORY_NOTIFICATIONS") - << getExternalStoragePublicDirectory("DIRECTORY_ALARMS") << getExternalFilesDir("DIRECTORY_ALARMS"); } |