导航菜单

页面标题

页面副标题

Plus 12 v10.13.1.1 - ModuleContentProvider.java 源代码

正在查看: Plus 12 v10.13.1.1 应用的 ModuleContentProvider.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.telegram.messenger;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
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 java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.Theme;

public class ModuleContentProvider extends ContentProvider {
    private static final String AUTHORITY = "org.telegram.plus.android.provider.content";
    private static final String AUTHORITY_BETA = "org.telegram.plus.beta.android.provider.content";
    private static final String TAG = "ModuleContentProvider";
    private String themeName;
    public static Uri THEME_URI = Uri.parse("content://org.telegram.plus.android.provider.content/theme");
    public static Uri THEME_NEW_RI = Uri.parse("content://org.telegram.plus.android.provider.content/uri");
    public static Uri GET_NAME = Uri.parse("content://org.telegram.plus.android.provider.content/name");
    public static Uri SET_NAME = Uri.parse("content://org.telegram.plus.android.provider.content/newname");

    @Override
    public boolean onCreate() {
        return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String orderBy) {
        return null;
    }

    @Override
    public String getType(Uri uri) {
        if (BuildVars.BETA) {
            GET_NAME = Uri.parse("content://org.telegram.plus.beta.android.provider.content/name");
        }
        if (uri.equals(GET_NAME)) {
            return ApplicationLoader.applicationContext.getSharedPreferences("theme", 0).getString("themeName", "empty");
        }
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        if (BuildVars.BETA) {
            SET_NAME = Uri.parse("content://org.telegram.plus.beta.android.provider.content/newname");
        }
        if (uri.toString().contains(SET_NAME.toString())) {
            AndroidUtilities.themeUpdated = true;
            return uri;
        }
        throw new UnsupportedOperationException();
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        if (BuildVars.BETA) {
            THEME_URI = Uri.parse("content://org.telegram.plus.beta.android.provider.content/theme");
            THEME_NEW_RI = Uri.parse("content://org.telegram.plus.beta.android.provider.content/uri:");
        }
        boolean contains = uri.toString().contains(THEME_NEW_RI.toString());
        if (uri.toString().contains(THEME_URI.toString()) || contains) {
            String uri2 = uri.toString();
            String substring = uri2.substring(uri2.lastIndexOf(":") + 1, uri2.length());
            if (!"mounted".equals(Environment.getExternalStorageState())) {
                return 30;
            }
            if (!contains) {
                final File file = new File(substring);
                if (!file.exists()) {
                    return 20;
                }
                try {
                    this.themeName = file.getName();
                    if (file.getAbsolutePath().contains(".attheme")) {
                        if (!AndroidUtilities.copyFile(file, new File(ApplicationLoader.getFilesDirFixed(), file.getName()))) {
                            return 25;
                        }
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                ModuleContentProvider.lambda$update$0(file);
                            }
                        });
                    } else {
                        applyTheme(substring);
                    }
                    return file.getAbsolutePath().contains(".attheme") ? 11 : 10;
                } catch (Exception e) {
                    e.printStackTrace();
                    return 25;
                }
            }
            try {
                InputStream openInputStream = ApplicationLoader.applicationContext.getContentResolver().openInputStream(uri);
                File file2 = new File(ApplicationLoader.getFilesDirFixed(), this.themeName);
                if (!AndroidUtilities.copyFile(openInputStream, file2)) {
                    return 20;
                }
                Theme.setUsePlusThemeKey(false);
                Theme.applyThemeFile(file2, file2.getName(), (TLRPC.TL_theme) null, false);
                return 20;
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
                return 20;
            } catch (IOException e3) {
                e3.printStackTrace();
                return 20;
            }
        }
        throw new UnsupportedOperationException();
    }

    public static void lambda$update$0(File file) {
        Theme.setUsePlusThemeKey(false);
        file.getName();
        Theme.applyThemeFile(file, file.getName(), (TLRPC.TL_theme) null, false);
        Theme.needRebuild = true;
    }

    public String getRealPathFromURI(Uri contentURI) {
        String str;
        Cursor query = ApplicationLoader.applicationContext.getContentResolver().query(contentURI, null, null, null, null);
        if (query == null) {
            return contentURI.getPath();
        }
        query.moveToFirst();
        try {
            str = query.getString(query.getColumnIndex("_data"));
        } catch (Exception unused) {
            str = BuildConfig.APP_CENTER_HASH;
        }
        query.close();
        return str;
    }

    @Override
    public int delete(Uri uri, String where, String[] selectionArgs) {
        StringBuilder sb = new StringBuilder();
        sb.append("delete uri: ");
        sb.append(uri.toString());
        throw new UnsupportedOperationException();
    }

    private void applyTheme(final String xmlFile) {
        String str = xmlFile.substring(0, xmlFile.lastIndexOf(".")) + "_wallpaper.jpg";
        File file = new File(str);
        if (file.exists()) {
            SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
            if (sharedPreferences.getInt("selectedBackground", 1000001) == 1000001) {
                SharedPreferences.Editor edit = sharedPreferences.edit();
                edit.putInt("selectedBackground", R.styleable.AppCompatTheme_toolbarStyle);
                edit.putInt("selectedColor", 0);
                edit.putBoolean("overrideThemeWallpaper", true);
                edit.commit();
            }
        }
        if (Utilities.loadPrefFromSD(ApplicationLoader.applicationContext, xmlFile) == 4) {
            Theme.selectedAutoNightType = 0;
            Theme.saveAutoNightThemeConfig();
            Utilities.applyWallpaper(str);
            Theme.setPlusWallpaper(file);
            Theme.setUsePlusThemeKey(true);
            Utilities.restartApp(500);
        }
    }

    public static String getPath(final Context context, final Uri uri) {
        Uri uri2 = null;
        if (Build.VERSION.SDK_INT >= 19 && DocumentsContract.isDocumentUri(context, uri)) {
            if (isExternalStorageDocument(uri)) {
                String[] split = DocumentsContract.getDocumentId(uri).split(":");
                String str = split[0];
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }
            if (isDownloadsDocument(uri)) {
                try {
                    String documentId = DocumentsContract.getDocumentId(uri);
                    StringBuilder sb = new StringBuilder();
                    sb.append("getPath: id= ");
                    sb.append(documentId);
                    return getDataColumn(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId).longValue()), null, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    List<String> pathSegments = uri.getPathSegments();
                    if (pathSegments.size() > 1) {
                        String str2 = pathSegments.get(1);
                        return !str2.startsWith("/") ? str2.substring(str2.indexOf("/")) : str2;
                    }
                }
            } else if (isMediaDocument(uri)) {
                String[] split2 = DocumentsContract.getDocumentId(uri).split(":");
                String str3 = split2[0];
                if ("image".equals(str3)) {
                    uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(str3)) {
                    uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(str3)) {
                    uri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                return getDataColumn(context, uri2, "_id=?", new String[]{split2[1]});
            }
        } else {
            if ("content".equalsIgnoreCase(uri.getScheme())) {
                if (isGooglePhotosUri(uri)) {
                    return uri.getLastPathSegment();
                }
                return getDataColumn(context, uri, null, null);
            }
            if ("file".equalsIgnoreCase(uri.getScheme())) {
                return uri.getPath();
            }
        }
        return null;
    }

    public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
        Cursor cursor = null;
        try {
            try {
                cursor = context.getContentResolver().query(uri, new String[]{"_data"}, selection, selectionArgs, null);
            } catch (Exception e) {
                e.printStackTrace();
                if (cursor == null) {
                    return "nodata";
                }
            }
            if (cursor != null && cursor.moveToFirst()) {
                String string = cursor.getString(cursor.getColumnIndexOrThrow("_data"));
                cursor.close();
                return string;
            }
            if (cursor == null) {
                return "nodata";
            }
            cursor.close();
            return "nodata";
        } catch (Throwable th) {
            if (cursor != null) {
                cursor.close();
            }
            throw th;
        }
    }

    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());
    }
}