Skip to content
Snippets Groups Projects
Commit 134aa98a authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Update Medialibrary JNI to match new API

parent 0502fcfd
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ AndroidMediaLibrary::~AndroidMediaLibrary()
delete p_ml;
}
bool
medialibrary::InitializeResult
AndroidMediaLibrary::initML(const std::string& dbPath, const std::string& thumbsPath)
{
p_DeviceListerCb = p_ml->setDeviceLister(p_lister);
......
......@@ -28,7 +28,7 @@ public:
AndroidMediaLibrary(JavaVM *vm, fields *ref_fields, jobject thiz);
~AndroidMediaLibrary();
bool initML(const std::string& dbPath, const std::string& thumbsPath);
medialibrary::InitializeResult initML(const std::string& dbPath, const std::string& thumbsPath);
void start();
bool addDevice(const std::string& uuid, const std::string& path, bool removable);
std::vector<std::tuple<std::string, std::string, bool>> devices();
......
......@@ -22,17 +22,18 @@ AndroidMediaLibrary *MediaLibrary_getInstance(JNIEnv *env, jobject thiz);
static void
MediaLibrary_setInstance(JNIEnv *env, jobject thiz, AndroidMediaLibrary *p_obj);
jboolean
jint
init(JNIEnv* env, jobject thiz, jstring dbPath, jstring thumbsPath)
{
AndroidMediaLibrary *aml = new AndroidMediaLibrary(myVm, &ml_fields, thiz);
MediaLibrary_setInstance(env, thiz, aml);
const char *db_utfchars = env->GetStringUTFChars(dbPath, JNI_FALSE);
const char *thumbs_utfchars = env->GetStringUTFChars(thumbsPath, JNI_FALSE);
m_IsInitialized = aml->initML(db_utfchars, thumbs_utfchars);
medialibrary::InitializeResult initCode = aml->initML(db_utfchars, thumbs_utfchars);
m_IsInitialized = initCode != medialibrary::InitializeResult::Failed;
env->ReleaseStringUTFChars(dbPath, db_utfchars);
env->ReleaseStringUTFChars(thumbsPath, thumbs_utfchars);
return m_IsInitialized;
return (int) initCode;
}
void
......@@ -756,7 +757,7 @@ playlistDelete(JNIEnv* env, jobject thiz, jobject medialibrary, jlong playlistId
* JNI stuff
*/
static JNINativeMethod methods[] = {
{"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)init },
{"nativeInit", "(Ljava/lang/String;Ljava/lang/String;)I", (void*)init },
{"nativeStart", "()V", (void*)start },
{"nativeRelease", "()V", (void*)release },
{"nativeAddDevice", "(Ljava/lang/String;Ljava/lang/String;Z)Z", (void*)addDevice },
......
......@@ -46,6 +46,11 @@ public class Medialibrary {
public static final int FLAG_MEDIA_ADDED_AUDIO_EMPTY = 1 << 4;
public static final int FLAG_MEDIA_ADDED_VIDEO = 1 << 5;
public static final int ML_INIT_SUCCESS = 0;
public static final int ML_INIT_ALREADY_INITIALIZED = 1;
public static final int ML_INIT_FAILED = 2;
public static final int ML_INIT_DB_RESET = 3;
public static final String ACTION_IDLE = "action_idle";
public static final String STATE_IDLE = "state_idle";
......@@ -74,17 +79,18 @@ public class Medialibrary {
return sContext;
}
public boolean init(Context context) {
public int init(Context context) {
if (context == null)
return false;
return ML_INIT_FAILED;
sContext = context;
File extFilesDir = context.getExternalFilesDir(null);
File dbDirectory = context.getDir("db", Context.MODE_PRIVATE);
if (extFilesDir == null || !extFilesDir.exists()
|| dbDirectory == null || !dbDirectory.canWrite())
return false;
mIsInitiated = nativeInit(dbDirectory+ VLC_MEDIA_DB_NAME, extFilesDir+ THUMBS_FOLDER_NAME);
return mIsInitiated;
return ML_INIT_FAILED;
int initCode = nativeInit(dbDirectory+ VLC_MEDIA_DB_NAME, extFilesDir+ THUMBS_FOLDER_NAME);
mIsInitiated = initCode != ML_INIT_FAILED;
return initCode;
}
public void start() {
......@@ -585,7 +591,7 @@ public class Medialibrary {
// Native methods
private native boolean nativeInit(String dbPath, String thumbsPath);
private native int nativeInit(String dbPath, String thumbsPath);
private native void nativeStart();
private native void nativeRelease();
private native void nativeBanFolder(String path);
......
......@@ -215,24 +215,27 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
if (mMedialibrary.isInitiated()) {
mMedialibrary.resumeBackgroundOperations();
exitCommand();
} else
} else {
final Context context = getApplicationContext();
mCallsExecutor.execute(new Runnable() {
Handler handler = null;
@Override
public void run() {
boolean shouldInit = !(new File(MediaParsingService.this.getDir("db", Context.MODE_PRIVATE)+Medialibrary.VLC_MEDIA_DB_NAME).exists());
if (mMedialibrary.init(getApplicationContext())) {
boolean shouldInit = !(new File(MediaParsingService.this.getDir("db", Context.MODE_PRIVATE) + Medialibrary.VLC_MEDIA_DB_NAME).exists());
int initCode = mMedialibrary.init(context);
shouldInit |= initCode == Medialibrary.ML_INIT_DB_RESET;
if (initCode != Medialibrary.ML_INIT_FAILED) {
final List<String> devices = new ArrayList<>();
devices.add(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
devices.addAll(AndroidDevices.getExternalStorageDirectories());
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MediaParsingService.this);
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
for (final String device : devices) {
final boolean isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY);
final String uuid = FileUtils.getFileNameFromPath(device);
if (TextUtils.isEmpty(device) || TextUtils.isEmpty(uuid))
continue;
final boolean isNew = mMedialibrary.addDevice(isMainStorage ? "main-storage" : uuid, device, !isMainStorage);
final boolean isIgnored = sharedPreferences.getBoolean("ignore_"+ uuid, false);
final boolean isIgnored = sharedPreferences.getBoolean("ignore_" + uuid, false);
if (!isMainStorage && isNew && !isIgnored)
showStorageNotification(device);
}
......@@ -265,6 +268,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
}, 2000);
}
});
}
}
private boolean wasWorking;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment