2022-05-11 18:03:58 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2024-01-01 07:50:49 +00:00
|
|
|
Copyright 2018-2024 by Marcel Bokhorst (M66B)
|
2022-05-11 18:03:58 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-17 06:22:42 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.pm.ProviderInfo;
|
2023-01-05 20:53:22 +00:00
|
|
|
import android.net.Uri;
|
2023-11-20 07:51:22 +00:00
|
|
|
import android.text.TextUtils;
|
2023-01-05 20:53:22 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2022-05-11 18:03:58 +00:00
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
|
2023-11-20 07:51:22 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
2022-05-11 18:03:58 +00:00
|
|
|
public class FileProviderEx extends FileProvider {
|
|
|
|
// https://android-review.googlesource.com/c/platform/frameworks/support/+/1978527
|
|
|
|
public FileProviderEx() {
|
|
|
|
super(R.xml.fileprovider_paths);
|
|
|
|
}
|
2023-01-05 20:53:22 +00:00
|
|
|
|
2023-04-17 06:22:42 +00:00
|
|
|
@Override
|
|
|
|
public void attachInfo(@NonNull Context context, @NonNull ProviderInfo info) {
|
|
|
|
try {
|
|
|
|
super.attachInfo(context, info);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
/*
|
|
|
|
OSCAL C80 (C80) Android 12 (SDK 31)
|
|
|
|
Exception java.lang.RuntimeException:
|
|
|
|
at android.app.ActivityThread.installProvider (ActivityThread.java:7537)
|
|
|
|
at android.app.ActivityThread.installContentProviders (ActivityThread.java:7044)
|
|
|
|
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6811)
|
|
|
|
at android.app.ActivityThread.access$1500 (ActivityThread.java:268)
|
|
|
|
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2100)
|
|
|
|
at android.os.Handler.dispatchMessage (Handler.java:106)
|
|
|
|
at android.os.Looper.loopOnce (Looper.java:201)
|
|
|
|
at android.os.Looper.loop (Looper.java:288)
|
|
|
|
at android.app.ActivityThread.main (ActivityThread.java:7953)
|
|
|
|
at java.lang.reflect.Method.invoke
|
|
|
|
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:553)
|
|
|
|
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
|
|
|
|
Caused by java.lang.IllegalArgumentException:
|
|
|
|
at androidx.core.content.FileProvider$SimplePathStrategy.addRoot (FileProvider.java:798)
|
|
|
|
at androidx.core.content.FileProvider.parsePathStrategy (FileProvider.java:734)
|
|
|
|
at androidx.core.content.FileProvider.getPathStrategy (FileProvider.java:645)
|
|
|
|
at androidx.core.content.FileProvider.attachInfo (FileProvider.java:424)
|
|
|
|
at android.app.ActivityThread.installProvider (ActivityThread.java:7531)
|
|
|
|
Caused by java.io.IOException: Invalid argument
|
|
|
|
at java.io.UnixFileSystem.canonicalize0
|
|
|
|
at java.io.UnixFileSystem.canonicalize (UnixFileSystem.java:153)
|
|
|
|
at java.io.File.getCanonicalPath (File.java:611)
|
|
|
|
at java.io.File.getCanonicalFile (File.java:636)
|
|
|
|
at androidx.core.content.FileProvider$SimplePathStrategy.addRoot (FileProvider.java:796)
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:51:22 +00:00
|
|
|
public static Uri getUri(@NonNull Context context, @NonNull String authority, @NonNull File file) {
|
|
|
|
return getUri(context, authority, file, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Uri getUri(@NonNull Context context, @NonNull String authority, @NonNull File file, @NonNull String name) {
|
|
|
|
Uri uri;
|
|
|
|
if (TextUtils.isEmpty(name))
|
|
|
|
uri = getUriForFile(context, authority, file);
|
|
|
|
else
|
|
|
|
uri = getUriForFile(context, authority, file, name);
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2023-01-05 20:53:22 +00:00
|
|
|
@Override
|
|
|
|
public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
|
|
|
|
throw new UnsupportedOperationException("No external updates");
|
|
|
|
}
|
2022-05-11 18:03:58 +00:00
|
|
|
}
|