package epson.provider; import android.content.ContentValues; import android.content.Context; import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; import android.os.ParcelFileDescriptor; import androidx.core.content.FileProvider; import java.io.File; import java.io.FileNotFoundException; public abstract class IAFileProvider extends FileProvider { private static String mAuthority; public boolean onCreate() { return true; } public void attachInfo(Context context, ProviderInfo providerInfo) { super.attachInfo(context, providerInfo); mAuthority = providerInfo.authority; } public ParcelFileDescriptor openFile(Uri uri, String str) throws FileNotFoundException { if (checkUriPath(uri)) { return super.openFile(uri, str); } throw new FileNotFoundException(); } public static Uri getUriForFile(Context context, File file) throws FileNotFoundException { return getUriForFile(context, mAuthority, file); } public String getType(Uri uri) { if (!checkUriPath(uri)) { return null; } return super.getType(uri); } public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) { if (!checkUriPath(uri)) { return null; } return super.query(uri, strArr, str, strArr2, str2); } static boolean checkUriPath(Uri uri) { if (uri == null) { return true; } String path = uri.getPath(); if (path.contains("/../") || path.endsWith("/..")) { return false; } return true; } public Uri insert(Uri uri, ContentValues contentValues) { throw new UnsupportedOperationException("No external insert"); } public int delete(Uri uri, String str, String[] strArr) { throw new UnsupportedOperationException("No external delete"); } public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) { throw new UnsupportedOperationException("No external updates"); } }