导航菜单

页面标题

页面副标题

哔哩哔哩 v1.6.6 - XprefProvider.java 源代码

正在查看: 哔哩哔哩 v1.6.6 应用的 XprefProvider.java JAVA 源代码文件

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


package com.bilibili.xpref;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RestrictTo;
import android.support.annotation.VisibleForTesting;
import android.util.ArrayMap;
import android.util.Log;
import bl.agh;
import bl.bbi;
import bl.bcl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestrictTo({RestrictTo.Scope.LIBRARY})
public final class XprefProvider extends ContentProvider {
    private final Map<String, a> a = a();

    @Override
    public int delete(Uri uri, String str, String[] strArr) {
        bbi.b(uri, "uri");
        return 0;
    }

    @Override
    public String getType(Uri uri) {
        bbi.b(uri, "uri");
        return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues contentValues) {
        bbi.b(uri, "uri");
        return null;
    }

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

    @Override
    public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        bbi.b(uri, "uri");
        return null;
    }

    @Override
    public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) {
        bbi.b(uri, "uri");
        return 0;
    }

    @Override
    public void shutdown() {
        this.a.clear();
    }

    @Override
    public Bundle call(String str, String str2, Bundle bundle) {
        String string;
        a a2;
        bbi.b(str, "method");
        if (bundle == null || (string = bundle.getString("$xpref.name")) == null || (a2 = a(string)) == null) {
            Log.w("XprefProvider", "What work?");
            return null;
        }
        switch (str.hashCode()) {
            case 1165:
                if (str.equals("$1")) {
                    return agh.a(a2.getAll());
                }
                return null;
            case 1166:
                if (str.equals("$2")) {
                    return agh.a(a2.a(str2));
                }
                return null;
            case 1167:
                if (str.equals("$3")) {
                    return agh.a(a2.getStringSet(str2, null));
                }
                return null;
            case 1168:
                if (str.equals("$4")) {
                    return agh.a(a2.b(str2));
                }
                return null;
            case 1169:
                if (str.equals("$5")) {
                    return agh.a(a2.c(str2));
                }
                return null;
            case 1170:
                if (str.equals("$6")) {
                    return agh.a(a2.d(str2));
                }
                return null;
            case 1171:
                if (str.equals("$7")) {
                    return agh.a(a2.e(str2));
                }
                return null;
            case 1172:
                if (str.equals("$8") && a2.contains(str2)) {
                    return Bundle.EMPTY;
                }
                return null;
            case 1173:
                if (!str.equals("$9")) {
                    return null;
                }
                bundle.remove("$xpref.name");
                return a(bundle, a2);
            default:
                return null;
        }
    }

    private final Bundle a(Bundle bundle, SharedPreferences sharedPreferences) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        if (bundle.getBoolean("$xpref.clear", false)) {
            edit.clear();
        } else {
            for (String str : bundle.keySet()) {
                Object obj = bundle.get(str);
                if (obj == null) {
                    edit.remove(str);
                } else if (obj instanceof Integer) {
                    edit.putInt(str, ((Number) obj).intValue());
                } else if (obj instanceof Long) {
                    edit.putLong(str, ((Number) obj).longValue());
                } else if (obj instanceof Float) {
                    edit.putFloat(str, ((Number) obj).floatValue());
                } else if (obj instanceof String) {
                    edit.putString(str, (String) obj);
                } else if (obj instanceof Boolean) {
                    edit.putBoolean(str, ((Boolean) obj).booleanValue());
                } else if (obj instanceof ArrayList) {
                    edit.putStringSet(str, agh.a((ArrayList<?>) obj));
                }
            }
        }
        edit.apply();
        return null;
    }

    private final Map<String, a> a() {
        if (Build.VERSION.SDK_INT >= 19) {
            return b();
        }
        return new HashMap();
    }

    @TargetApi(19)
    private final Map<String, a> b() {
        return new ArrayMap();
    }

    private final a a(String str) {
        a aVar;
        Context context = getContext();
        if (context == null) {
            throw new IllegalStateException();
        }
        synchronized (this) {
            Map<String, a> map = this.a;
            a aVar2 = map.get(str);
            if (aVar2 == null) {
                SharedPreferences sharedPreferences = context.getSharedPreferences(str, 0);
                bbi.a((Object) sharedPreferences, "context.getSharedPrefere…me, Context.MODE_PRIVATE)");
                aVar2 = new a(sharedPreferences, new b(str, context));
                map.put(str, aVar2);
            }
            aVar = aVar2;
        }
        return aVar;
    }

    static final class b implements SharedPreferences.OnSharedPreferenceChangeListener {
        final String b;
        final Context c;

        b(String str, Context context) {
            this.b = str;
            this.c = context;
        }

        @Override
        public final void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
            XprefProvider.this.a(this.b, str);
        }
    }

    public final void a(String str, String str2) {
        Context context = getContext();
        if (context != null) {
            Uri.Builder appendPath = agh.a(context).buildUpon().appendPath(str);
            if (str2 == null) {
                str2 = "$xpref.NULL";
            }
            context.getContentResolver().notifyChange(appendPath.appendPath(str2).build(), (ContentObserver) null, false);
        }
    }

    @VisibleForTesting(otherwise = 3)
    public static final class a implements SharedPreferences, SharedPreferences.OnSharedPreferenceChangeListener {
        private Map<String, ?> a;
        private final SharedPreferences b;
        private final SharedPreferences.OnSharedPreferenceChangeListener c;

        @Override
        public boolean contains(String str) {
            return this.b.contains(str);
        }

        @Override
        public boolean getBoolean(String str, boolean z) {
            return this.b.getBoolean(str, z);
        }

        @Override
        public float getFloat(String str, float f) {
            return this.b.getFloat(str, f);
        }

        @Override
        public int getInt(String str, int i) {
            return this.b.getInt(str, i);
        }

        @Override
        public long getLong(String str, long j) {
            return this.b.getLong(str, j);
        }

        @Override
        public String getString(String str, String str2) {
            return this.b.getString(str, str2);
        }

        @Override
        public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
        }

        @Override
        public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
        }

        public a(SharedPreferences sharedPreferences, SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
            bbi.b(sharedPreferences, "delegate");
            bbi.b(onSharedPreferenceChangeListener, "listener");
            this.b = sharedPreferences;
            this.c = onSharedPreferenceChangeListener;
            this.b.registerOnSharedPreferenceChangeListener(this);
        }

        @Override
        public synchronized Map<String, ?> getAll() {
            Map<String, ?> map;
            map = this.a;
            if (map == null) {
                map = this.b.getAll();
            }
            this.a = map;
            bbi.a((Object) map, "c");
            return map;
        }

        public final String a(String str) {
            try {
                return this.b.getString(str, null);
            } catch (ClassCastException unused) {
                Object obj = getAll().get(str);
                return obj != null ? obj.toString() : null;
            }
        }

        @Override
        public Set<String> getStringSet(String str, Set<String> set) {
            try {
                return this.b.getStringSet(str, set);
            } catch (ClassCastException unused) {
                return set;
            }
        }

        @Override
        @SuppressLint({"CommitPrefEdits"})
        public SharedPreferences.Editor edit() {
            SharedPreferences.Editor edit = this.b.edit();
            bbi.a((Object) edit, "delegate.edit()");
            return new SharedPreferencesEditorC0033a(this, edit);
        }

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
            bbi.b(sharedPreferences, "ignored");
            a();
            this.c.onSharedPreferenceChanged(this, str);
        }

        final class SharedPreferencesEditorC0033a implements SharedPreferences.Editor {
            final a a;
            private final SharedPreferences.Editor b;

            @Override
            public SharedPreferences.Editor clear() {
                return this.b.clear();
            }

            @Override
            public SharedPreferences.Editor putBoolean(String str, boolean z) {
                return this.b.putBoolean(str, z);
            }

            @Override
            public SharedPreferences.Editor putFloat(String str, float f) {
                return this.b.putFloat(str, f);
            }

            @Override
            public SharedPreferences.Editor putInt(String str, int i) {
                return this.b.putInt(str, i);
            }

            @Override
            public SharedPreferences.Editor putLong(String str, long j) {
                return this.b.putLong(str, j);
            }

            @Override
            public SharedPreferences.Editor putString(String str, String str2) {
                return this.b.putString(str, str2);
            }

            @Override
            public SharedPreferences.Editor putStringSet(String str, Set<String> set) {
                return this.b.putStringSet(str, set);
            }

            @Override
            public SharedPreferences.Editor remove(String str) {
                return this.b.remove(str);
            }

            public SharedPreferencesEditorC0033a(a aVar, SharedPreferences.Editor editor) {
                bbi.b(editor, "delegate");
                this.a = aVar;
                this.b = editor;
            }

            @Override
            public boolean commit() {
                try {
                    return this.b.commit();
                } finally {
                    this.a.a();
                }
            }

            @Override
            public void apply() {
                this.b.apply();
                this.a.a();
            }
        }

        public final synchronized void a() {
            this.a = (Map) null;
        }

        public final Integer b(String str) {
            Object obj = getAll().get(str);
            if (!(obj instanceof Integer)) {
                obj = obj instanceof String ? bcl.b((String) obj) : null;
            }
            return (Integer) obj;
        }

        public final Long c(String str) {
            Object obj = getAll().get(str);
            if (!(obj instanceof Long)) {
                obj = obj instanceof String ? bcl.c((String) obj) : null;
            }
            return (Long) obj;
        }

        public final Float d(String str) {
            Object obj = getAll().get(str);
            if (!(obj instanceof Float)) {
                obj = obj instanceof String ? bcl.a((String) obj) : null;
            }
            return (Float) obj;
        }

        public final Boolean e(String str) {
            Object obj = getAll().get(str);
            if (!(obj instanceof Boolean)) {
                obj = obj instanceof String ? Boolean.valueOf(Boolean.parseBoolean((String) obj)) : null;
            }
            return (Boolean) obj;
        }
    }
}