+ * This program is free software: you can redistribute it and/or modify it under the terms of + * the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * This program 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 Affero General Public License for more details. + *
+ * You should have received a copy of the GNU Affero General Public License along with this + * program. If not, see https://www.gnu.org/licenses/. + *
+ * Source code: https://github.com/openvk/mobile-android-refresh + */ + +public class AccountAuthentificator extends AbstractAccountAuthenticator { + + private final Context ctx; + + public AccountAuthentificator(Context ctx) { + super(ctx); + this.ctx = ctx; + } + + @Override + public Bundle addAccount(AccountAuthenticatorResponse accountAuthenticatorResponse, + String s, String s2, String[] strings, Bundle bundle) + throws NetworkErrorException { + Intent i = new Intent(this.ctx, AuthActivity.class); + i.putExtra("accountAuthenticatorResponse", accountAuthenticatorResponse); + bundle.putParcelable("intent", i); + return bundle; + } + + @Override + public Bundle editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse, String s) { + return null; + } + + @Override + public Bundle confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, + Account account, Bundle bundle) + throws NetworkErrorException { + return null; + } + + @Override + public Bundle getAuthToken(AccountAuthenticatorResponse accountAuthenticatorResponse, + Account account, String s, Bundle bundle) + throws NetworkErrorException { + return null; + } + + @Override + public String getAuthTokenLabel(String s) { + return null; + } + + @Override + public Bundle updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, + Account account, String s, Bundle bundle) + throws NetworkErrorException { + return null; + } + + @Override + public Bundle hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse, + Account account, String[] strings) throws NetworkErrorException { + return null; + } +} diff --git a/app/src/main/java/uk/openvk/android/refresh/utils/LibraryLoader.java b/app/src/main/java/uk/openvk/android/refresh/utils/LibraryLoader.java new file mode 100644 index 0000000..92313b2 --- /dev/null +++ b/app/src/main/java/uk/openvk/android/refresh/utils/LibraryLoader.java @@ -0,0 +1,24 @@ +package uk.openvk.android.refresh.utils; + +import android.content.Context; + +/** + * Copyleft © 2022, 2023 OpenVK Team + * Copyleft © 2022, 2023 Dmitry Tretyakov (aka. Tinelix) + * + * This program is free software: you can redistribute it and/or modify it under the terms of + * the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License along with this + * program. If not, see https://www.gnu.org/licenses/. + * + * Source code: https://github.com/openvk/mobile-android-refresh + */ + +public interface LibraryLoader { + void loadSharedLibrary(Context ctx, String library_name) throws UnsatisfiedLinkError, SecurityException, Exception; +} diff --git a/app/src/main/java/uk/openvk/android/refresh/utils/RealPathUtil.java b/app/src/main/java/uk/openvk/android/refresh/utils/RealPathUtil.java new file mode 100644 index 0000000..ab63c8d --- /dev/null +++ b/app/src/main/java/uk/openvk/android/refresh/utils/RealPathUtil.java @@ -0,0 +1,107 @@ +package uk.openvk.android.refresh.utils; + +import android.annotation.SuppressLint; +import android.content.ContentUris; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.util.Log; + +import uk.openvk.android.refresh.OvkApplication; + +/** + * Copyleft © 2022, 2023 OpenVK Team + * Copyleft © 2022, 2023 Dmitry Tretyakov (aka. Tinelix) + * + * This program is free software: you can redistribute it and/or modify it under the terms of + * the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License along with this + * program. If not, see https://www.gnu.org/licenses/. + * + * Source code: https://github.com/openvk/mobile-android-refresh + */ + +@SuppressLint("Recycle") +public class RealPathUtil { + public static String getRealPathFromURI(Context context, Uri uri) { + String selection = null; + String[] selectionArgs = null; + // Uri is different in versions after KITKAT (Android 4.4), we need to + if (Build.VERSION.SDK_INT >= 19 && DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) { + if (isExternalStorageDocument(uri)) { + final String docId = DocumentsContract.getDocumentId(uri); + final String[] split = docId.split(":"); + return Environment.getExternalStorageDirectory() + "/" + split[1]; + } else if (isDownloadsDocument(uri)) { + final String id = DocumentsContract.getDocumentId(uri); + uri = ContentUris.withAppendedId( + Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + } else if (isMediaDocument(uri)) { + final String docId = DocumentsContract.getDocumentId(uri); + final String[] split = docId.split(":"); + final String type = split[0]; + if ("image".equals(type)) { + uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + } else if ("video".equals(type)) { + uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + } else if ("audio".equals(type)) { + uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; + } + selection = "_id=?"; + selectionArgs = new String[]{ + split[1] + }; + } + } + if ("content".equalsIgnoreCase(uri.getScheme())) { + + + if (isGooglePhotosUri(uri)) { + return uri.getLastPathSegment(); + } + + String[] projection = { + MediaStore.Images.Media.DATA + }; + Cursor cursor = null; + try { + cursor = context.getContentResolver() + .query(uri, projection, selection, selectionArgs, null); + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + if (cursor.moveToFirst()) { + return cursor.getString(column_index); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else if ("file".equalsIgnoreCase(uri.getScheme())) { + return uri.getPath(); + } + return null; + } + + public static boolean isExternalStorageDocument(Uri uri) { + return "com.android.externalstorage.documents".equals(uri.getAuthority()); + } + + public static boolean isDownloadsDocument(Uri uri) { + return "com.android.providers.downloads.documents".equals(uri.getAuthority()); + } + + public static boolean isMediaDocument(Uri uri) { + return "com.android.providers.media.documents".equals(uri.getAuthority()); + } + + public static boolean isGooglePhotosUri(Uri uri) { + return "com.google.android.apps.photos.content".equals(uri.getAuthority()); + } +}