android: Replace deprecated FileObserver() constructor with newer SDKs
This commit is contained in:
parent
dc351a30e1
commit
c976165533
|
@ -16,6 +16,7 @@
|
|||
package org.strongswan.android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.FileObserver;
|
||||
import android.os.Handler;
|
||||
|
@ -37,6 +38,7 @@ import java.io.StringReader;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class LogFragment extends Fragment
|
||||
|
@ -58,7 +60,15 @@ public class LogFragment extends Fragment
|
|||
|
||||
mLogHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
mDirectoryObserver = new LogDirectoryObserver(getActivity().getFilesDir().getAbsolutePath());
|
||||
File logdir = getActivity().getFilesDir();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
{
|
||||
mDirectoryObserver = new LogDirectoryObserver(logdir);
|
||||
}
|
||||
else
|
||||
{
|
||||
mDirectoryObserver = new LogDirectoryObserver(logdir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -224,14 +234,20 @@ public class LogFragment extends Fragment
|
|||
*/
|
||||
private class LogDirectoryObserver extends FileObserver
|
||||
{
|
||||
private final File mFile;
|
||||
private long mSize;
|
||||
private static final int mMask = FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE;
|
||||
private final File mFile = new File(mLogFilePath);
|
||||
private long mSize = mFile.length();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public LogDirectoryObserver(String path)
|
||||
{
|
||||
super(path, FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE);
|
||||
mFile = new File(mLogFilePath);
|
||||
mSize = mFile.length();
|
||||
super(path, mMask);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.Q)
|
||||
public LogDirectoryObserver(File path)
|
||||
{
|
||||
super(path, mMask);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue