导航菜单

页面标题

页面副标题

Fix Locker v1.5 - UserIconContentProvider.java 源代码

正在查看: Fix Locker v1.5 应用的 UserIconContentProvider.java JAVA 源代码文件

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


package com.user.a4keygen;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.webkit.MimeTypeMap;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public final class UserIconContentProvider extends ContentProvider {
    static final String AUTHORITY = "com.user.a4keygen.usericoncontentprovider";
    private static final String TAG = "UserIconContentProvider";
    private static final String USER_ICONS_DIR = "UserIcons";
    private final Map<Uri, ContentValues> mFileTracker = new HashMap();
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_ABSOLUTE_PATH = "absolute_path";
    private static final String COLUMN_DIRECTORY = "is_directory";
    private static final String COLUMN_MIME_TYPE = "mime_type";
    private static final String COLUMN_METADATA = "metadata";
    private static final String[] COLUMNS = {COLUMN_NAME, COLUMN_ABSOLUTE_PATH, COLUMN_DIRECTORY, COLUMN_MIME_TYPE, COLUMN_METADATA};
    private static final MimeTypeMap MIME_MAP = MimeTypeMap.getSingleton();

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

    @Override
    public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        File fileForUri = getFileForUri(uri);
        String str3 = TAG;
        Log.v(str3, "Query: " + uri);
        if ("/".equals(fileForUri.getAbsolutePath())) {
            MatrixCursor matrixCursor = new MatrixCursor(COLUMNS, this.mFileTracker.size());
            for (Map.Entry<Uri, ContentValues> entry : this.mFileTracker.entrySet()) {
                Log.v(TAG, "Adding path " + entry);
                matrixCursor.addRow(getRow(COLUMNS, getFileForUri(entry.getKey()), entry.getValue().getAsString(COLUMN_METADATA)));
            }
            return matrixCursor;
        }
        if (!fileForUri.exists()) {
            Log.e(str3, "Query - File from uri: '" + uri + "' doesn't exists");
            return null;
        }
        if (!fileForUri.isDirectory()) {
            String[] strArr3 = COLUMNS;
            MatrixCursor matrixCursor2 = new MatrixCursor(strArr3, 1);
            matrixCursor2.addRow(getRow(strArr3, fileForUri, null));
            return matrixCursor2;
        }
        File[] listFiles = fileForUri.listFiles();
        sortFilesByAbsolutePath(listFiles);
        MatrixCursor matrixCursor3 = new MatrixCursor(COLUMNS, listFiles.length + 1);
        for (File file : listFiles) {
            matrixCursor3.addRow(getRow(COLUMNS, file, null));
        }
        return matrixCursor3;
    }

    @Override
    public String getType(Uri uri) {
        return getType(getFileForUri(uri));
    }

    @Override
    public Uri insert(Uri uri, ContentValues contentValues) {
        File fileForUri = getFileForUri(uri);
        String str = TAG;
        Log.v(str, "insert(): uri=" + uri + ", file=" + fileForUri);
        if (!fileForUri.exists()) {
            Log.e(str, "Insert - File from uri: '" + uri + "' doesn't exist");
            return null;
        }
        if (this.mFileTracker.get(uri) != null) {
            Log.e(str, "Insert - File from uri: '" + uri + "' already exists, ignoring");
            return null;
        }
        this.mFileTracker.put(uri, contentValues);
        return uri;
    }

    @Override
    public int delete(Uri uri, String str, String[] strArr) {
        Log.v(TAG, "delete(): uri=" + uri);
        this.mFileTracker.remove(uri);
        return recursiveDelete(getFileForUri(uri));
    }

    @Override
    public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) {
        if (!getFileForUri(uri).exists()) {
            Log.e(TAG, "Update - File from uri: '" + uri + "' doesn't exist");
            return 0;
        }
        if (this.mFileTracker.get(uri) == null) {
            Log.e(TAG, "Update - File from uri: '" + uri + "' isn't tracked yet, use insert");
            return 0;
        }
        this.mFileTracker.put(uri, contentValues);
        return 1;
    }

    @Override
    public ParcelFileDescriptor openFile(Uri uri, String str) throws FileNotFoundException {
        File fileForUri = getFileForUri(uri);
        int modeToMode = modeToMode(str);
        String str2 = TAG;
        Log.v(str2, "openFile(): uri=" + uri + ", mode=" + str + "(" + modeToMode + ")");
        if ((modeToMode & 134217728) == 134217728) {
            Log.v(str2, "Creating file " + fileForUri);
            File parentFile = fileForUri.getParentFile();
            if (!parentFile.exists()) {
                Log.v(str2, "Creating parents for " + fileForUri);
                if (!parentFile.mkdirs()) {
                    throw new FileNotFoundException("Could not created parent dirs for " + fileForUri);
                }
            }
            if (!this.mFileTracker.containsKey(uri)) {
                this.mFileTracker.put(uri, new ContentValues());
            }
        }
        ParcelFileDescriptor open = ParcelFileDescriptor.open(fileForUri, modeToMode);
        Log.v(str2, "Returning FD " + open.getFd() + " for " + fileForUri.getAbsoluteFile());
        return open;
    }

    private Object[] getRow(String[] strArr, File file, String str) {
        Object[] objArr = new Object[strArr.length];
        for (int i = 0; i < strArr.length; i++) {
            objArr[i] = getColumnValue(strArr[i], file, str);
        }
        return objArr;
    }

    private Object getColumnValue(String str, File file, String str2) {
        if (COLUMN_NAME.equals(str)) {
            return file.getName();
        }
        if (COLUMN_ABSOLUTE_PATH.equals(str)) {
            return file.getAbsolutePath();
        }
        if (COLUMN_DIRECTORY.equals(str)) {
            return Boolean.valueOf(file.isDirectory());
        }
        if (COLUMN_METADATA.equals(str)) {
            return str2;
        }
        if (!COLUMN_MIME_TYPE.equals(str) || file.isDirectory()) {
            return null;
        }
        return getType(file);
    }

    private String getType(File file) {
        int lastIndexOf = file.getName().lastIndexOf(46);
        if (lastIndexOf < 0) {
            return "application/octet-stream";
        }
        String mimeTypeFromExtension = MIME_MAP.getMimeTypeFromExtension(file.getName().substring(lastIndexOf + 1));
        return mimeTypeFromExtension != null ? mimeTypeFromExtension : "application/octet-stream";
    }

    static File getFile(Context context, String str) {
        File file = new File(getStorageDirectory(context), new File(str).getName());
        Log.v(TAG, "getFile(" + str + "): returning " + file);
        return file;
    }

    static File getStorageDirectory(Context context) {
        return new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), USER_ICONS_DIR);
    }

    private File getFileForUri(Uri uri) {
        File file = getFile(getContext(), uri.getPath());
        Log.v(TAG, "getFileForUri(" + uri + "): returning " + file);
        return file;
    }

    private static int modeToMode(String str) {
        if ("r".equals(str)) {
            return 268435456;
        }
        if ("w".equals(str) || "wt".equals(str)) {
            return 738197504;
        }
        if ("wa".equals(str)) {
            return 704643072;
        }
        if ("rw".equals(str)) {
            return 939524096;
        }
        if ("rwt".equals(str)) {
            return 1006632960;
        }
        throw new IllegalArgumentException("Invalid mode: " + str);
    }

    private int recursiveDelete(File file) {
        File[] listFiles;
        Log.v(TAG, "recursiveDelete(): rootDir=" + file);
        int i = 0;
        if (file == null) {
            return 0;
        }
        if (file.isDirectory() && (listFiles = file.listFiles()) != null) {
            int length = listFiles.length;
            int i2 = 0;
            while (i < length) {
                i2 += recursiveDelete(listFiles[i]);
                i++;
            }
            i = i2;
        }
        file.delete();
        return i + 1;
    }

    private static void sortFilesByAbsolutePath(File[] fileArr) {
        Arrays.sort(fileArr, new Comparator() {
            @Override
            public final int compare(Object obj, Object obj2) {
                int compareTo;
                compareTo = ((File) obj).getAbsolutePath().compareTo(((File) obj2).getAbsolutePath());
                return compareTo;
            }
        });
    }
}