Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5268f553
Commit
5268f553
authored
Mar 01, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
java/File: add method ToAbsolutePath() returning AllocatedPath
parent
e44c9a00
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
60 deletions
+67
-60
Environment.cxx
src/android/Environment.cxx
+19
-47
Environment.hxx
src/android/Environment.hxx
+8
-4
StandardDirectory.cxx
src/fs/StandardDirectory.cxx
+1
-7
File.cxx
src/java/File.cxx
+26
-1
File.hxx
src/java/File.hxx
+13
-1
No files found.
src/android/Environment.cxx
View file @
5268f553
...
...
@@ -17,18 +17,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Environment.hxx"
#include "java/Class.hxx"
#include "java/String.hxx"
#include "java/File.hxx"
#include "util/StringUtil.hxx"
#include "fs/AllocatedPath.hxx"
namespace
Environment
{
static
Java
::
TrivialClass
cls
;
static
jmethodID
getExternalStorageDirectory_method
;
static
jmethodID
getExternalStoragePublicDirectory_method
;
static
jstring
getExternalStorageDirectory
(
JNIEnv
*
env
);
};
void
...
...
@@ -51,63 +51,35 @@ Environment::Deinitialise(JNIEnv *env)
cls
.
Clear
(
env
);
}
static
jstring
ToAbsolutePathChecked
(
JNIEnv
*
env
,
jobject
file
)
{
if
(
file
==
nullptr
)
return
nullptr
;
jstring
path
=
Java
::
File
::
getAbsolutePath
(
env
,
file
);
env
->
DeleteLocalRef
(
file
);
return
path
;
}
static
jstring
Environment
::
getExternalStorageDirectory
(
JNIEnv
*
env
)
{
jobject
file
=
env
->
CallStaticObjectMethod
(
cls
,
getExternalStorageDirectory_method
);
return
ToAbsolutePathChecked
(
env
,
file
);
}
char
*
Environment
::
getExternalStorageDirectory
(
char
*
buffer
,
size_t
max_size
)
AllocatedPath
Environment
::
getExternalStorageDirectory
()
{
JNIEnv
*
env
=
Java
::
GetEnv
();
jstring
value
=
getExternalStorageDirectory
(
env
);
if
(
value
==
nullptr
)
return
nullptr
;
jobject
file
=
env
->
CallStaticObjectMethod
(
cls
,
getExternalStorageDirectory_method
);
if
(
file
==
nullptr
)
return
AllocatedPath
::
Null
();
Java
::
String
value2
(
env
,
value
);
value2
.
CopyTo
(
env
,
buffer
,
max_size
);
return
buffer
;
return
Java
::
File
::
ToAbsolutePath
(
env
,
file
);
}
static
jstring
getExternalStoragePublicDirectory
(
JNIEnv
*
env
,
const
char
*
type
)
AllocatedPath
Environment
::
getExternalStoragePublicDirectory
(
const
char
*
type
)
{
if
(
Environment
::
getExternalStoragePublicDirectory_method
==
nullptr
)
if
(
getExternalStoragePublicDirectory_method
==
nullptr
)
/* needs API level 8 */
return
nullptr
;
return
AllocatedPath
::
Null
();
JNIEnv
*
env
=
Java
::
GetEnv
();
Java
::
String
type2
(
env
,
type
);
jobject
file
=
env
->
CallStaticObjectMethod
(
Environment
::
cls
,
Environment
::
getExternalStoragePublicDirectory_method
,
type2
.
Get
());
return
ToAbsolutePathChecked
(
env
,
file
);
}
char
*
Environment
::
getExternalStoragePublicDirectory
(
char
*
buffer
,
size_t
max_size
,
const
char
*
type
)
{
JNIEnv
*
env
=
Java
::
GetEnv
();
jstring
path
=
::
getExternalStoragePublicDirectory
(
env
,
type
);
if
(
path
==
nullptr
)
return
nullptr
;
if
(
file
==
nullptr
)
return
AllocatedPath
::
Null
();
Java
::
String
path2
(
env
,
path
);
path2
.
CopyTo
(
env
,
buffer
,
max_size
);
return
buffer
;
return
Java
::
File
::
ToAbsolutePath
(
env
,
file
);
}
src/android/Environment.hxx
View file @
5268f553
...
...
@@ -20,8 +20,11 @@
#ifndef MPD_ANDROID_ENVIRONMENT_HXX
#define MPD_ANDROID_ENVIRONMENT_HXX
#include "Compiler.h"
#include <jni.h>
#include <stddef.h>
class
AllocatedPath
;
namespace
Environment
{
void
Initialise
(
JNIEnv
*
env
);
...
...
@@ -30,10 +33,11 @@ namespace Environment {
/**
* Determine the mount point of the external SD card.
*/
char
*
getExternalStorageDirectory
(
char
*
buffer
,
size_t
max_size
);
gcc_pure
AllocatedPath
getExternalStorageDirectory
();
char
*
getExternalStoragePublicDirectory
(
char
*
buffer
,
size_t
max_size
,
const
char
*
type
);
gcc_pure
AllocatedPath
getExternalStoragePublicDirectory
(
const
char
*
type
);
};
#endif
src/fs/StandardDirectory.cxx
View file @
5268f553
...
...
@@ -246,13 +246,7 @@ AllocatedPath GetUserMusicDir()
#elif defined(USE_XDG)
return
GetUserDir
(
"XDG_MUSIC_DIR"
);
#elif defined(ANDROID)
char
buffer
[
1024
];
if
(
Environment
::
getExternalStoragePublicDirectory
(
buffer
,
sizeof
(
buffer
),
"Music"
)
==
nullptr
)
return
AllocatedPath
::
Null
();
return
AllocatedPath
::
FromUTF8
(
buffer
);
return
Environment
::
getExternalStoragePublicDirectory
(
"Music"
);
#else
return
AllocatedPath
::
Null
();
#endif
...
...
src/java/File.cxx
View file @
5268f553
/*
* Copyright (C) 2010-201
2
Max Kellermann <max@duempel.org>
* Copyright (C) 2010-201
4
Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -27,8 +27,13 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "File.hxx"
#include "Class.hxx"
#include "String.hxx"
#include "Object.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/Limits.hxx"
jmethodID
Java
::
File
::
getAbsolutePath_method
;
...
...
@@ -40,3 +45,23 @@ Java::File::Initialise(JNIEnv *env)
getAbsolutePath_method
=
env
->
GetMethodID
(
cls
,
"getAbsolutePath"
,
"()Ljava/lang/String;"
);
}
AllocatedPath
Java
::
File
::
ToAbsolutePath
(
JNIEnv
*
env
,
jobject
_file
)
{
assert
(
env
!=
nullptr
);
assert
(
_file
!=
nullptr
);
LocalObject
file
(
env
,
_file
);
const
jstring
path
=
getAbsolutePath
(
env
,
file
);
if
(
path
==
nullptr
)
{
env
->
ExceptionClear
();
return
AllocatedPath
::
Null
();
}
Java
::
String
path2
(
env
,
path
);
char
buffer
[
MPD_PATH_MAX
];
path2
.
CopyTo
(
env
,
buffer
,
sizeof
(
buffer
));
return
AllocatedPath
::
FromUTF8
(
buffer
);
}
src/java/File.hxx
View file @
5268f553
/*
* Copyright (C) 2010-201
2
Max Kellermann <max@duempel.org>
* Copyright (C) 2010-201
4
Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -34,6 +34,8 @@
#include <jni.h>
class
AllocatedPath
;
namespace
Java
{
/**
* Wrapper for a java.io.File object.
...
...
@@ -42,12 +44,22 @@ namespace Java {
static
jmethodID
getAbsolutePath_method
;
public
:
gcc_nonnull_all
static
void
Initialise
(
JNIEnv
*
env
);
gcc_nonnull_all
static
jstring
getAbsolutePath
(
JNIEnv
*
env
,
jobject
file
)
{
return
(
jstring
)
env
->
CallObjectMethod
(
file
,
getAbsolutePath_method
);
}
/**
* Invoke File.getAbsolutePath() and release the
* specified File reference.
*/
gcc_pure
gcc_nonnull_all
static
AllocatedPath
ToAbsolutePath
(
JNIEnv
*
env
,
jobject
file
);
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment