public class AndroidHack {
    private static Object _mLoadedApk;
    private static Object _sActivityThread;

    final class AnonymousClass_1 implements Callback {
        final /* synthetic */ Object val$activityThread;
        final /* synthetic */ Handler val$handler;

        AnonymousClass_1(Handler handler, Object obj) {
            this.val$handler = handler;
            this.val$activityThread = obj;
        }

        public boolean handleMessage(Message message) {
            try {
                AndroidHack.ensureLoadedApk();
                this.val$handler.handleMessage(message);
                AndroidHack.ensureLoadedApk();
            } catch (Throwable th) {
                Throwable th2 = th;
                RuntimeException runtimeException;
                if ((th2 instanceof ClassNotFoundException) || th2.toString().contains("ClassNotFoundException")) {
                    if (message.what != 113) {
                        Object loadedApk = AndroidHack.getLoadedApk(RuntimeVariables.androidApplication, this.val$activityThread, RuntimeVariables.androidApplication.getPackageName());
                        if (loadedApk == null) {
                            runtimeException = new RuntimeException("loadedapk is null");
                        } else {
                            ClassLoader classLoader = (ClassLoader) AtlasHacks.LoadedApk_mClassLoader.get(loadedApk);
                            if (classLoader instanceof DelegateClassLoader) {
                                runtimeException = new RuntimeException("From Atlas:classNotFound ---", th2);
                            } else {
                                RuntimeException runtimeException2 = new RuntimeException("wrong classloader in loadedapk---" + classLoader.getClass().getName(), th2);
                            }
                        }
                    }
                } else if ((th2 instanceof ClassCastException) || th2.toString().contains("ClassCastException")) {
                    Process.killProcess(Process.myPid());
                } else {
                    runtimeException = new RuntimeException(th2);
                }
            }
            return true;
        }
    }

    static class ActvityThreadGetter implements Runnable {
        ActvityThreadGetter() {
        }

        public void run() {
            try {
                AndroidHack._sActivityThread = AtlasHacks.ActivityThread_currentActivityThread.invoke(AtlasHacks.ActivityThread.getmClass(), new Object[0]);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (AtlasHacks.ActivityThread_currentActivityThread) {
                AtlasHacks.ActivityThread_currentActivityThread.notify();
            }
        }
    }

    static {
        _sActivityThread = null;
        _mLoadedApk = null;
    }

    public static Object getActivityThread() throws Exception {
        if (_sActivityThread == null) {
            if (Thread.currentThread().getId() == Looper.getMainLooper().getThread().getId()) {
                _sActivityThread = AtlasHacks.ActivityThread_currentActivityThread.invoke(null, new Object[0]);
            } else {
                Handler handler = new Handler(Looper.getMainLooper());
                synchronized (AtlasHacks.ActivityThread_currentActivityThread) {
                    handler.post(new ActvityThreadGetter());
                    AtlasHacks.ActivityThread_currentActivityThread.wait();
                }
            }
        }
        return _sActivityThread;
    }

    public static Handler hackH() throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        try {
            Handler handler = (Handler) AtlasHacks.ActivityThread.field("mH").ofType(Hack.into("android.app.ActivityThread$H").getmClass()).get(activityThread);
            Field declaredField = Handler.class.getDeclaredField("mCallback");
            declaredField.setAccessible(true);
            declaredField.set(handler, new AnonymousClass_1(handler, activityThread));
        } catch (HackAssertionException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void ensureLoadedApk() throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        Object loadedApk = getLoadedApk(RuntimeVariables.androidApplication, activityThread, RuntimeVariables.androidApplication.getPackageName());
        if (loadedApk == null) {
            loadedApk = createNewLoadedApk(RuntimeVariables.androidApplication, activityThread);
            if (loadedApk == null) {
                throw new RuntimeException("can't create loadedApk");
            }
        }
        activityThread = loadedApk;
        if (!(((ClassLoader) AtlasHacks.LoadedApk_mClassLoader.get(activityThread)) instanceof DelegateClassLoader)) {
            AtlasHacks.LoadedApk_mClassLoader.set(activityThread, RuntimeVariables.delegateClassLoader);
            AtlasHacks.LoadedApk_mResources.set(activityThread, RuntimeVariables.delegateResources);
        }
    }

    public static Object getLoadedApk(Application application, Object obj, String str) {
        WeakReference weakReference = (WeakReference) ((Map) AtlasHacks.ActivityThread_mPackages.get(obj)).get(str);
        if (weakReference == null || weakReference.get() == null) {
            return null;
        }
        _mLoadedApk = weakReference.get();
        return weakReference.get();
    }

    public static Object createNewLoadedApk(Application application, Object obj) {
        try {
            Method declaredMethod;
            ApplicationInfo applicationInfo = application.getPackageManager().getApplicationInfo(application.getPackageName(), 1152);
            application.getPackageManager();
            Resources resources = application.getResources();
            if (resources instanceof DelegateResources) {
                declaredMethod = resources.getClass().getSuperclass().getDeclaredMethod("getCompatibilityInfo", new Class[0]);
            } else {
                declaredMethod = resources.getClass().getDeclaredMethod("getCompatibilityInfo", new Class[0]);
            }
            declaredMethod.setAccessible(true);
            Class cls = Class.forName("android.content.res.CompatibilityInfo");
            Object invoke = declaredMethod.invoke(application.getResources(), new Object[0]);
            Method declaredMethod2 = AtlasHacks.ActivityThread.getmClass().getDeclaredMethod("getPackageInfoNoCheck", new Class[]{ApplicationInfo.class, cls});
            declaredMethod2.setAccessible(true);
            invoke = declaredMethod2.invoke(obj, new Object[]{applicationInfo, invoke});
            _mLoadedApk = invoke;
            return invoke;
        } catch (Throwable e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static void injectClassLoader(String str, ClassLoader classLoader) throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        Object loadedApk = getLoadedApk(RuntimeVariables.androidApplication, activityThread, str);
        if (loadedApk == null) {
            loadedApk = createNewLoadedApk(RuntimeVariables.androidApplication, activityThread);
        }
        if (loadedApk == null) {
            throw new Exception("Failed to get ActivityThread.mLoadedApk");
        }
        AtlasHacks.LoadedApk_mClassLoader.set(loadedApk, classLoader);
    }

    public static void injectApplication(String str, Application application) throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        Object loadedApk = getLoadedApk(application, activityThread, application.getPackageName());
        if (loadedApk == null) {
            throw new Exception("Failed to get ActivityThread.mLoadedApk");
        }
        AtlasHacks.LoadedApk_mApplication.set(loadedApk, application);
        AtlasHacks.ActivityThread_mInitialApplication.set(activityThread, application);
    }

    public static void injectResources(Application application, Resources resources) throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        Object loadedApk = getLoadedApk(application, activityThread, application.getPackageName());
        if (loadedApk == null) {
            activityThread = createNewLoadedApk(application, activityThread);
            if (activityThread == null) {
                throw new RuntimeException("Failed to get ActivityThread.mLoadedApk");
            }
            if (!(((ClassLoader) AtlasHacks.LoadedApk_mClassLoader.get(activityThread)) instanceof DelegateClassLoader)) {
                AtlasHacks.LoadedApk_mClassLoader.set(activityThread, RuntimeVariables.delegateClassLoader);
            }
            loadedApk = activityThread;
        }
        AtlasHacks.LoadedApk_mResources.set(loadedApk, resources);
        AtlasHacks.ContextImpl_mResources.set(application.getBaseContext(), resources);
        AtlasHacks.ContextImpl_mTheme.set(application.getBaseContext(), null);
    }

    public static Instrumentation getInstrumentation() throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread != null) {
            return (Instrumentation) AtlasHacks.ActivityThread_mInstrumentation.get(activityThread);
        }
        throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
    }

    public static void injectInstrumentationHook(Instrumentation instrumentation) throws Exception {
        Object activityThread = getActivityThread();
        if (activityThread == null) {
            throw new Exception("Failed to get ActivityThread.sCurrentActivityThread");
        }
        AtlasHacks.ActivityThread_mInstrumentation.set(activityThread, instrumentation);
    }

    public static void injectContextHook(ContextWrapper contextWrapper, ContextWrapper contextWrapper2) {
        AtlasHacks.ContextWrapper_mBase.set(contextWrapper, contextWrapper2);
    }
} public class AssertionArrayException extends Exception {
    private static final long serialVersionUID = 1;
    private List<HackAssertionException> mAssertionErr;

    public AssertionArrayException(String str) {
        super(str);
        this.mAssertionErr = new ArrayList();
    }

    public void addException(HackAssertionException hackAssertionException) {
        this.mAssertionErr.add(hackAssertionException);
    }

    public void addException(List<HackAssertionException> list) {
        this.mAssertionErr.addAll(list);
    }

    public List<HackAssertionException> getExceptions() {
        return this.mAssertionErr;
    }

    public static AssertionArrayException mergeException(AssertionArrayException assertionArrayException, AssertionArrayException assertionArrayException2) {
        if (assertionArrayException == null) {
            return assertionArrayException2;
        }
        if (assertionArrayException2 == null) {
            return assertionArrayException;
        }
        AssertionArrayException assertionArrayException3 = new AssertionArrayException(assertionArrayException.getMessage() + SymbolExpUtil.SYMBOL_SEMICOLON + assertionArrayException2.getMessage());
        assertionArrayException3.addException(assertionArrayException.getExceptions());
        assertionArrayException3.addException(assertionArrayException2.getExceptions());
        return assertionArrayException3;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        for (HackAssertionException hackAssertionException : this.mAssertionErr) {
            stringBuilder.append(hackAssertionException.toString()).append(SymbolExpUtil.SYMBOL_SEMICOLON);
            try {
                if (hackAssertionException.getCause() instanceof NoSuchFieldException) {
                    Field[] declaredFields = hackAssertionException.getHackedClass().getDeclaredFields();
                    stringBuilder.append(hackAssertionException.getHackedClass().getName()).append(".").append(hackAssertionException.getHackedFieldName()).append(SymbolExpUtil.SYMBOL_SEMICOLON);
                    for (Field name : declaredFields) {
                        stringBuilder.append(name.getName()).append(FilePathGenerator.ANDROID_DIR_SEP);
                    }
                } else if (hackAssertionException.getCause() instanceof NoSuchMethodException) {
                    Method[] declaredMethods = hackAssertionException.getHackedClass().getDeclaredMethods();
                    stringBuilder.append(hackAssertionException.getHackedClass().getName()).append("->").append(hackAssertionException.getHackedMethodName()).append(SymbolExpUtil.SYMBOL_SEMICOLON);
                    for (int i = 0; i < declaredMethods.length; i++) {
                        if (hackAssertionException.getHackedMethodName().equals(declaredMethods[i].getName())) {
                            stringBuilder.append(declaredMethods[i].toGenericString()).append(FilePathGenerator.ANDROID_DIR_SEP);
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            stringBuilder.append("@@@@");
        }
        return stringBuilder.toString();
    }
} public class AtlasHacks extends HackDeclaration implements AssertionFailureHandler {
    public static HackedClass<Object> ActivityThread;
    public static HackedMethod ActivityThread_currentActivityThread;
    public static HackedField<Object, ArrayList<Application>> ActivityThread_mAllApplications;
    public static HackedField<Object, Application> ActivityThread_mInitialApplication;
    public static HackedField<Object, Instrumentation> ActivityThread_mInstrumentation;
    public static HackedField<Object, Map<String, Object>> ActivityThread_mPackages;
    public static HackedField<Object, Object> ActivityThread_sPackageManager;
    public static HackedClass<Application> Application;
    public static HackedMethod Application_attach;
    public static HackedClass<AssetManager> AssetManager;
    public static HackedMethod AssetManager_addAssetPath;
    public static HackedClass<ClassLoader> ClassLoader;
    public static HackedMethod ClassLoader_findLibrary;
    public static HackedClass<Object> ContextImpl;
    public static HackedField<Object, Resources> ContextImpl_mResources;
    public static HackedField<Object, Theme> ContextImpl_mTheme;
    public static HackedClass<ContextThemeWrapper> ContextThemeWrapper;
    public static HackedField<ContextThemeWrapper, Context> ContextThemeWrapper_mBase;
    public static HackedField<ContextThemeWrapper, Resources> ContextThemeWrapper_mResources;
    public static HackedField<ContextThemeWrapper, Theme> ContextThemeWrapper_mTheme;
    public static HackedClass<ContextWrapper> ContextWrapper;
    public static HackedField<ContextWrapper, Context> ContextWrapper_mBase;
    public static HackedClass<DexClassLoader> DexClassLoader;
    public static HackedMethod DexClassLoader_findClass;
    public static ArrayList<HackedMethod> GeneratePackageInfoList;
    public static ArrayList<HackedMethod> GetPackageInfoList;
    public static HackedClass<Object> IPackageManager;
    public static HackedClass<Object> LexFile;
    public static HackedMethod LexFile_close;
    public static HackedMethod LexFile_loadClass;
    public static HackedMethod LexFile_loadLex;
    public static HackedClass<Object> LoadedApk;
    public static HackedField<Object, String> LoadedApk_mAppDir;
    public static HackedField<Object, Application> LoadedApk_mApplication;
    public static HackedField<Object, ClassLoader> LoadedApk_mBaseClassLoader;
    public static HackedField<Object, ClassLoader> LoadedApk_mClassLoader;
    public static HackedField<Object, String> LoadedApk_mResDir;
    public static HackedField<Object, Resources> LoadedApk_mResources;
    public static HackedClass<Resources> Resources;
    public static HackedField<Resources, Object> Resources_mAssets;
    public static HackedClass<Service> Service;
    protected static final Logger log;
    public static boolean sIsIgnoreFailure;
    public static boolean sIsReflectAvailable;
    public static boolean sIsReflectChecked;
    private AssertionArrayException mExceptionArray;

    public AtlasHacks() {
        this.mExceptionArray = null;
    }

    static {
        log = LoggerFactory.getInstance(AtlasHacks.class);
        sIsReflectAvailable = false;
        sIsReflectChecked = false;
        sIsIgnoreFailure = false;
        GeneratePackageInfoList = new ArrayList();
        GetPackageInfoList = new ArrayList();
    }

    public static boolean defineAndVerify() throws AssertionArrayException {
        if (sIsReflectChecked) {
            return sIsReflectAvailable;
        }
        AtlasHacks atlasHacks = new AtlasHacks();
        try {
            Hack.setAssertionFailureHandler(atlasHacks);
            if (VERSION.SDK_INT == 11) {
                atlasHacks.onAssertionFailure(new HackAssertionException("Hack Assertion Failed: Android OS Version 11"));
            }
            allClasses();
            allConstructors();
            allFields();
            allMethods();
            if (atlasHacks.mExceptionArray != null) {
                sIsReflectAvailable = false;
                throw atlasHacks.mExceptionArray;
            }
            sIsReflectAvailable = true;
            return sIsReflectAvailable;
        } catch (Throwable e) {
            sIsReflectAvailable = false;
            log.error("HackAssertionException", e);
        } finally {
            Hack.setAssertionFailureHandler(null);
            sIsReflectChecked = true;
        }
    }

    public static void allClasses() throws HackAssertionException {
        if (VERSION.SDK_INT <= 8) {
            LoadedApk = Hack.into("android.app.ActivityThread$PackageInfo");
        } else {
            LoadedApk = Hack.into("android.app.LoadedApk");
        }
        ActivityThread = Hack.into("android.app.ActivityThread");
        Resources = Hack.into(Resources.class);
        Application = Hack.into(Application.class);
        AssetManager = Hack.into(AssetManager.class);
        IPackageManager = Hack.into("android.content.pm.IPackageManager");
        Service = Hack.into(Service.class);
        ContextImpl = Hack.into("android.app.ContextImpl");
        ContextThemeWrapper = Hack.into(ContextThemeWrapper.class);
        ContextWrapper = Hack.into("android.content.ContextWrapper");
        sIsIgnoreFailure = true;
        ClassLoader = Hack.into(ClassLoader.class);
        DexClassLoader = Hack.into(DexClassLoader.class);
        LexFile = Hack.into("dalvik.system.LexFile");
        sIsIgnoreFailure = false;
    }

    public static void allFields() throws HackAssertionException {
        ActivityThread_mInstrumentation = ActivityThread.field("mInstrumentation").ofType(Instrumentation.class);
        ActivityThread_mAllApplications = ActivityThread.field("mAllApplications").ofGenericType(ArrayList.class);
        ActivityThread_mInitialApplication = ActivityThread.field("mInitialApplication").ofType(Application.class);
        ActivityThread_mPackages = ActivityThread.field("mPackages").ofGenericType(Map.class);
        ActivityThread_sPackageManager = ActivityThread.staticField("sPackageManager").ofType(IPackageManager.getmClass());
        LoadedApk_mApplication = LoadedApk.field("mApplication").ofType(Application.class);
        LoadedApk_mResources = LoadedApk.field("mResources").ofType(Resources.class);
        LoadedApk_mResDir = LoadedApk.field("mResDir").ofType(String.class);
        LoadedApk_mClassLoader = LoadedApk.field("mClassLoader").ofType(ClassLoader.class);
        LoadedApk_mBaseClassLoader = LoadedApk.field("mBaseClassLoader").ofType(ClassLoader.class);
        LoadedApk_mAppDir = LoadedApk.field("mAppDir").ofType(String.class);
        ContextImpl_mResources = ContextImpl.field("mResources").ofType(Resources.class);
        ContextImpl_mTheme = ContextImpl.field("mTheme").ofType(Theme.class);
        sIsIgnoreFailure = true;
        ContextThemeWrapper_mBase = ContextThemeWrapper.field("mBase").ofType(Context.class);
        sIsIgnoreFailure = false;
        ContextThemeWrapper_mTheme = ContextThemeWrapper.field("mTheme").ofType(Theme.class);
        try {
            if (VERSION.SDK_INT >= 17 && ContextThemeWrapper.getmClass().getDeclaredField("mResources") != null) {
                ContextThemeWrapper_mResources = ContextThemeWrapper.field("mResources").ofType(Resources.class);
            }
        } catch (NoSuchFieldException e) {
            log.warn("Not found ContextThemeWrapper.mResources on VERSION " + VERSION.SDK_INT);
        }
        ContextWrapper_mBase = ContextWrapper.field("mBase").ofType(Context.class);
        Resources_mAssets = Resources.field("mAssets");
    }

    public static void allMethods() throws HackAssertionException {
        ActivityThread_currentActivityThread = ActivityThread.method("currentActivityThread", new Class[0]);
        AssetManager_addAssetPath = AssetManager.method("addAssetPath", String.class);
        Application_attach = Application.method("attach", Context.class);
        ClassLoader_findLibrary = ClassLoader.method("findLibrary", String.class);
        if (LexFile != null && LexFile.getmClass() != null) {
            LexFile_loadLex = LexFile.method("loadLex", String.class, Integer.TYPE);
            LexFile_loadClass = LexFile.method("loadClass", String.class, ClassLoader.class);
            LexFile_close = LexFile.method("close", new Class[0]);
            DexClassLoader_findClass = DexClassLoader.method("findClass", String.class);
        }
    }

    public static void allConstructors() throws HackAssertionException {
    }

    public boolean onAssertionFailure(HackAssertionException hackAssertionException) {
        if (!sIsIgnoreFailure) {
            if (this.mExceptionArray == null) {
                this.mExceptionArray = new AssertionArrayException("atlas hack assert failed");
            }
            this.mExceptionArray.addException(hackAssertionException);
        }
        return true;
    }
} public interface Logger {
    void debug(String str);

    void error(String str);

    void error(String str, Throwable th);

    void error(StringBuffer stringBuffer, Throwable th);

    void fatal(String str);

    void fatal(String str, Throwable th);

    void info(String str);

    boolean isDebugEnabled();

    boolean isErrorEnabled();

    boolean isFatalEnabled();

    boolean isInfoEnabled();

    boolean isVerboseEnabled();

    boolean isWarnEnabled();

    void verbose(String str);

    void warn(String str);

    void warn(String str, Throwable th);

    void warn(StringBuffer stringBuffer, Throwable th);
} public class LoggerFactory {
    public static int logLevel;

    static {
        logLevel = 3;
    }

    public static Logger getInstance(String str) {
        return getInstance(str, null);
    }

    public static Logger getInstance(Class<?> cls) {
        return getInstance(null, cls);
    }

    private static Logger getInstance(String str, Class<?> cls) {
        if (cls != null) {
            return new AndroidLogger((Class) cls);
        }
        return new AndroidLogger(str);
    }
} public class BundleLifecycleHandler implements SynchronousBundleListener {
    static final Logger log;

    private class BundleStartTask extends AsyncTask<Bundle, Void, Void> {
        private BundleStartTask() {
        }

        protected Void doInBackground(Bundle... bundleArr) {
            BundleLifecycleHandler.this.started(bundleArr[0]);
            return null;
        }
    }

    static {
        log = LoggerFactory.getInstance("BundleLifecycleHandler");
    }

    @SuppressLint({"NewApi"})
    public void bundleChanged(BundleEvent bundleEvent) {
        switch (bundleEvent.getType()) {
            case DeviceSecuritySDK.ENVIRONMENT_ONLINE /*0*/:
                loaded(bundleEvent.getBundle());
            case OpenBase.OAUTH_CREATE /*1*/:
                installed(bundleEvent.getBundle());
            case StaticDataStore.SECURITY_KEY_TYPE /*2*/:
                if (isLewaOS()) {
                    if (Looper.myLooper() == null) {
                        Looper.prepare();
                    }
                    started(bundleEvent.getBundle());
                } else if (Framework.isFrameworkStartupShutdown()) {
                    BundleStartTask bundleStartTask = new BundleStartTask();
                    if (VERSION.SDK_INT > 11) {
                        bundleStartTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Bundle[]{bundleEvent.getBundle()});
                        return;
                    }
                    bundleStartTask.execute(new Bundle[]{bundleEvent.getBundle()});
                } else {
                    started(bundleEvent.getBundle());
                }
            case StaticDataStore.INVALID_KEY_TYPE /*4*/:
                stopped(bundleEvent.getBundle());
            case IStaticDataEncryptComponent.GCRY_CIPHER_SERPENT128 /*8*/:
                updated(bundleEvent.getBundle());
            case IStaticDataEncryptComponent.GCRY_CIPHER_AES128 /*16*/:
                uninstalled(bundleEvent.getBundle());
            default:
        }
    }

    private void loaded(Bundle bundle) {
        long currentTimeMillis = System.currentTimeMillis();
        BundleImpl bundleImpl = (BundleImpl) bundle;
        try {
            DelegateResources.newDelegateResources(RuntimeVariables.androidApplication, RuntimeVariables.delegateResources);
        } catch (Throwable e) {
            log.error("Could not load resource in bundle " + bundleImpl.getLocation(), e);
        }
        if (DelegateComponent.getPackage(bundle.getLocation()) == null) {
            PackageLite parse = PackageLite.parse(bundleImpl.getArchive().getArchiveFile());
            log.info("Bundle installation info " + bundle.getLocation() + ":" + parse.components);
            DelegateComponent.putPackage(bundle.getLocation(), parse);
        }
        log.info("loaded() spend " + (System.currentTimeMillis() - currentTimeMillis) + " milliseconds");
    }

    private void installed(Bundle bundle) {
    }

    private void updated(Bundle bundle) {
    }

    private void uninstalled(Bundle bundle) {
        DelegateComponent.removePackage(bundle.getLocation());
    }

    private void started(Bundle bundle) {
        BundleImpl bundleImpl = (BundleImpl) bundle;
        long currentTimeMillis = System.currentTimeMillis();
        String str = (String) bundleImpl.getHeaders().get("Bundle-Application");
        if (StringUtils.isNotEmpty(str)) {
            String[] strArr;
            String[] split = StringUtils.split(str, SymbolExpUtil.SYMBOL_COMMA);
            if (split == null || split.length == 0) {
                strArr = new String[]{str};
            } else {
                strArr = split;
            }
            if (strArr != null) {
                for (String str2 : strArr) {
                    String trim = StringUtils.trim(str2);
                    if (StringUtils.isNotEmpty(trim)) {
                        try {
                            Application newApplication;
                            int i;
                            for (Application newApplication2 : DelegateComponent.apkApplications.values()) {
                                if (newApplication2.getClass().getName().equals(trim)) {
                                    i = 1;
                                    break;
                                }
                            }
                            i = 0;
                            if (i == 0) {
                                newApplication2 = newApplication(trim, bundleImpl.getClassLoader());
                                newApplication2.onCreate();
                                DelegateComponent.apkApplications.put("system:" + trim, newApplication2);
                            }
                        } catch (Throwable th) {
                            log.error("Error to start application", th);
                        }
                    }
                }
            }
        } else {
            PackageLite packageLite = DelegateComponent.getPackage(bundleImpl.getLocation());
            if (packageLite != null) {
                str2 = packageLite.applicationClassName;
                if (StringUtils.isNotEmpty(str2)) {
                    try {
                        newApplication(str2, bundleImpl.getClassLoader()).onCreate();
                    } catch (Throwable th2) {
                        log.error("Error to start application >>>", th2);
                    }
                }
            }
        }
        log.info("started() spend " + (System.currentTimeMillis() - currentTimeMillis) + " milliseconds");
    }

    protected static Application newApplication(String str, ClassLoader classLoader) throws Exception {
        Class loadClass = classLoader.loadClass(str);
        if (loadClass == null) {
            throw new ClassNotFoundException(str);
        }
        Application application = (Application) loadClass.newInstance();
        AtlasHacks.Application_attach.invoke(application, RuntimeVariables.androidApplication);
        return application;
    }

    private void stopped(Bundle bundle) {
        Application application = (Application) DelegateComponent.apkApplications.get(bundle.getLocation());
        if (application != null) {
            application.onTerminate();
            DelegateComponent.apkApplications.remove(bundle.getLocation());
        }
    }

    public void handleLowMemory() {
    }

    private boolean isLewaOS() {
        try {
            return StringUtils.isNotEmpty((String) Class.forName("android.os.SystemProperties").getDeclaredMethod(ServicePermission.GET, new Class[]{String.class}).invoke(null, new Object[]{"ro.lewa.version"}));
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
} public interface ClassNotFoundInterceptorCallback {
    Intent returnIntent(Intent intent);
} public class DelegateClassLoader extends ClassLoader {
    public DelegateClassLoader(ClassLoader classLoader) {
        super(classLoader);
    }

    public Class<?> loadClass(String str) throws ClassNotFoundException {
        return super.loadClass(str);
    }

    protected Class<?> findClass(String str) throws ClassNotFoundException {
        Class<?> loadFromInstalledBundles = ClassLoadFromBundle.loadFromInstalledBundles(str);
        if (loadFromInstalledBundles == null) {
            loadFromInstalledBundles = ClassLoadFromBundle.loadFromUninstalledBundles(str);
        }
        if (loadFromInstalledBundles != null) {
            return loadFromInstalledBundles;
        }
        throw new ClassNotFoundException("Can't find class " + str + printExceptionInfo() + " " + ClassLoadFromBundle.getClassNotFoundReason(str));
    }

    private String printExceptionInfo() {
        StringBuilder stringBuilder = new StringBuilder("installed bundles: ");
        List bundles = Framework.getBundles();
        if (!(bundles == null || bundles.isEmpty())) {
            for (Bundle bundle : Framework.getBundles()) {
                if (bundle.getLocation().contains("com.ut")) {
                    stringBuilder.append(bundle.getLocation().toUpperCase());
                } else {
                    stringBuilder.append(bundle.getLocation());
                }
                stringBuilder.append(":");
            }
        }
        return stringBuilder.toString();
    }
} public class DelegateComponent {
    static Map<String, Application> apkApplications;
    private static Map<String, PackageLite> apkPackages;
    static final Logger log;

    static {
        log = LoggerFactory.getInstance("DelegateComponent");
        apkPackages = new ConcurrentHashMap();
        apkApplications = new HashMap();
    }

    public static PackageLite getPackage(String str) {
        return (PackageLite) apkPackages.get(str);
    }

    public static void putPackage(String str, PackageLite packageLite) {
        apkPackages.put(str, packageLite);
    }

    public static void removePackage(String str) {
        apkPackages.remove(str);
    }

    public static String locateComponent(String str) {
        for (Entry entry : apkPackages.entrySet()) {
            if (((PackageLite) entry.getValue()).components.contains(str)) {
                return (String) entry.getKey();
            }
        }
        return null;
    }
} public class FrameworkLifecycleHandler implements FrameworkListener {
    static final Logger log;

    static {
        log = LoggerFactory.getInstance("FrameworkLifecycleHandler");
    }

    public void frameworkEvent(FrameworkEvent frameworkEvent) {
        switch (frameworkEvent.getType()) {
            case DeviceSecuritySDK.ENVIRONMENT_ONLINE /*0*/:
                starting();
            case OpenBase.OAUTH_CREATE /*1*/:
                started();
            default:
        }
    }

    private void starting() {
        Bundle bundle;
        long currentTimeMillis = System.currentTimeMillis();
        try {
            bundle = RuntimeVariables.androidApplication.getPackageManager().getApplicationInfo(RuntimeVariables.androidApplication.getPackageName(), TBImageQuailtyStrategy.CDN_SIZE_128).metaData;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            bundle = null;
        }
        if (bundle != null) {
            String string = bundle.getString("application");
            if (StringUtils.isNotEmpty(string)) {
                if (log.isDebugEnabled()) {
                    log.debug("Found extra application: " + string);
                }
                String[] split = StringUtils.split(string, SymbolExpUtil.SYMBOL_COMMA);
                if (split == null || split.length == 0) {
                    split = new String[]{string};
                }
                for (String str : r0) {
                    try {
                        Application newApplication = BundleLifecycleHandler.newApplication(str, Framework.getSystemClassLoader());
                        newApplication.onCreate();
                        DelegateComponent.apkApplications.put("system:" + str, newApplication);
                    } catch (Throwable e2) {
                        log.error("Error to start application", e2);
                    }
                }
            }
        }
        log.info("starting() spend " + (System.currentTimeMillis() - currentTimeMillis) + " milliseconds");
    }

    private void started() {
        long currentTimeMillis = System.currentTimeMillis();
        try {
            DelegateResources.newDelegateResources(RuntimeVariables.androidApplication, RuntimeVariables.delegateResources);
        } catch (Throwable e) {
            log.error("Failed to newDelegateResources", e);
        }
        log.info("started() spend " + (System.currentTimeMillis() - currentTimeMillis) + " milliseconds");
    }
} public class InstrumentationHook extends Instrumentation {
    static final Logger log;
    private Context context;
    private Instrumentation mBase;

    private static interface ExecStartActivityCallback {
        ActivityResult execStartActivity();
    }

    class AnonymousClass_1 implements ExecStartActivityCallback {
        final /* synthetic */ IBinder val$contextThread;
        final /* synthetic */ Intent val$intent;
        final /* synthetic */ int val$requestCode;
        final /* synthetic */ Activity val$target;
        final /* synthetic */ IBinder val$token;
        final /* synthetic */ Context val$who;

        AnonymousClass_1(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i) {
            this.val$who = context;
            this.val$contextThread = iBinder;
            this.val$token = iBinder2;
            this.val$target = activity;
            this.val$intent = intent;
            this.val$requestCode = i;
        }

        public ActivityResult execStartActivity() {
            return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode);
        }
    }

    class AnonymousClass_2 implements ExecStartActivityCallback {
        final /* synthetic */ IBinder val$contextThread;
        final /* synthetic */ Intent val$intent;
        final /* synthetic */ Bundle val$options;
        final /* synthetic */ int val$requestCode;
        final /* synthetic */ Activity val$target;
        final /* synthetic */ IBinder val$token;
        final /* synthetic */ Context val$who;

        AnonymousClass_2(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i, Bundle bundle) {
            this.val$who = context;
            this.val$contextThread = iBinder;
            this.val$token = iBinder2;
            this.val$target = activity;
            this.val$intent = intent;
            this.val$requestCode = i;
            this.val$options = bundle;
        }

        public ActivityResult execStartActivity() {
            return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode, this.val$options);
        }
    }

    class AnonymousClass_3 implements ExecStartActivityCallback {
        final /* synthetic */ IBinder val$contextThread;
        final /* synthetic */ Intent val$intent;
        final /* synthetic */ int val$requestCode;
        final /* synthetic */ Fragment val$target;
        final /* synthetic */ IBinder val$token;
        final /* synthetic */ Context val$who;

        AnonymousClass_3(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i) {
            this.val$who = context;
            this.val$contextThread = iBinder;
            this.val$token = iBinder2;
            this.val$target = fragment;
            this.val$intent = intent;
            this.val$requestCode = i;
        }

        public ActivityResult execStartActivity() {
            return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode);
        }
    }

    class AnonymousClass_4 implements ExecStartActivityCallback {
        final /* synthetic */ IBinder val$contextThread;
        final /* synthetic */ Intent val$intent;
        final /* synthetic */ Bundle val$options;
        final /* synthetic */ int val$requestCode;
        final /* synthetic */ Fragment val$target;
        final /* synthetic */ IBinder val$token;
        final /* synthetic */ Context val$who;

        AnonymousClass_4(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i, Bundle bundle) {
            this.val$who = context;
            this.val$contextThread = iBinder;
            this.val$token = iBinder2;
            this.val$target = fragment;
            this.val$intent = intent;
            this.val$requestCode = i;
            this.val$options = bundle;
        }

        public ActivityResult execStartActivity() {
            return InstrumentationHook.this.mBase.execStartActivity(this.val$who, this.val$contextThread, this.val$token, this.val$target, this.val$intent, this.val$requestCode, this.val$options);
        }
    }

    static {
        log = LoggerFactory.getInstance("InstrumentationHook");
    }

    public InstrumentationHook(Instrumentation instrumentation, Context context) {
        this.context = context;
        this.mBase = instrumentation;
    }

    public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i) {
        return execStartActivityInternal(this.context, intent, new AnonymousClass_1(context, iBinder, iBinder2, activity, intent, i));
    }

    @TargetApi(16)
    public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i, Bundle bundle) {
        return execStartActivityInternal(this.context, intent, new AnonymousClass_2(context, iBinder, iBinder2, activity, intent, i, bundle));
    }

    @TargetApi(14)
    public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i) {
        return execStartActivityInternal(this.context, intent, new AnonymousClass_3(context, iBinder, iBinder2, fragment, intent, i));
    }

    @TargetApi(16)
    public ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Fragment fragment, Intent intent, int i, Bundle bundle) {
        return execStartActivityInternal(this.context, intent, new AnonymousClass_4(context, iBinder, iBinder2, fragment, intent, i, bundle));
    }

    private ActivityResult execStartActivityInternal(Context context, Intent intent, ExecStartActivityCallback execStartActivityCallback) {
        String packageName;
        Object className;
        if (intent.getComponent() != null) {
            packageName = intent.getComponent().getPackageName();
            className = intent.getComponent().getClassName();
        } else {
            ResolveInfo resolveActivity = context.getPackageManager().resolveActivity(intent, 0);
            if (resolveActivity == null || resolveActivity.activityInfo == null) {
                className = null;
                packageName = null;
            } else {
                packageName = resolveActivity.activityInfo.packageName;
                className = resolveActivity.activityInfo.name;
            }
        }
        if (!StringUtils.equals(context.getPackageName(), packageName)) {
            return execStartActivityCallback.execStartActivity();
        }
        if (DelegateComponent.locateComponent(className) != null) {
            return execStartActivityCallback.execStartActivity();
        }
        try {
            if (ClassLoadFromBundle.loadFromUninstalledBundles(className) != null) {
                return execStartActivityCallback.execStartActivity();
            }
        } catch (ClassNotFoundException e) {
            log.info("Can't find class " + className + " in all bundles.");
        }
        try {
            if (Framework.getSystemClassLoader().loadClass(className) != null) {
                return execStartActivityCallback.execStartActivity();
            }
            return null;
        } catch (ClassNotFoundException e2) {
            log.error("Can't find class " + className);
            if (Framework.getClassNotFoundCallback() == null) {
                return null;
            }
            if (intent.getComponent() == null && !TextUtils.isEmpty(className)) {
                intent.setClassName(context, className);
            }
            if (intent.getComponent() == null) {
                return null;
            }
            Framework.getClassNotFoundCallback().returnIntent(intent);
            return null;
        }
    }

    public Activity newActivity(Class<?> cls, Context context, IBinder iBinder, Application application, Intent intent, ActivityInfo activityInfo, CharSequence charSequence, Activity activity, String str, Object obj) throws InstantiationException, IllegalAccessException {
        Activity newActivity = this.mBase.newActivity(cls, context, iBinder, application, intent, activityInfo, charSequence, activity, str, obj);
        if (RuntimeVariables.androidApplication.getPackageName().equals(activityInfo.packageName) && AtlasHacks.ContextThemeWrapper_mResources != null) {
            AtlasHacks.ContextThemeWrapper_mResources.set(newActivity, RuntimeVariables.delegateResources);
        }
        return newActivity;
    }

    public Activity newActivity(ClassLoader classLoader, String str, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Activity newActivity;
        String str2;
        try {
            newActivity = this.mBase.newActivity(classLoader, str, intent);
        } catch (ClassNotFoundException e) {
            ClassNotFoundException classNotFoundException = e;
            CharSequence property = Framework.getProperty("android.taobao.atlas.welcome", "com.taobao.tao.welcome.Welcome");
            if (TextUtils.isEmpty(property)) {
                str2 = "com.taobao.tao.welcome.Welcome";
            } else {
                CharSequence charSequence = property;
            }
            if (TextUtils.isEmpty(str2)) {
                throw classNotFoundException;
            }
            List runningTasks = ((ActivityManager) this.context.getSystemService(DetailConstants.SECKILL_LIST_TYPE)).getRunningTasks(1);
            if (runningTasks != null && runningTasks.size() > 0 && ((RunningTaskInfo) runningTasks.get(0)).numActivities > 1 && Framework.getClassNotFoundCallback() != null) {
                if (intent.getComponent() == null) {
                    intent.setClassName(this.context, str);
                }
                Framework.getClassNotFoundCallback().returnIntent(intent);
            }
            log.warn("Could not find activity class: " + str);
            log.warn("Redirect to welcome activity: " + str2);
            newActivity = this.mBase.newActivity(classLoader, str2, intent);
        }
        if ((classLoader instanceof DelegateClassLoader) && AtlasHacks.ContextThemeWrapper_mResources != null) {
            AtlasHacks.ContextThemeWrapper_mResources.set(newActivity, RuntimeVariables.delegateResources);
        }
        return newActivity;
    }

    public void callActivityOnCreate(Activity activity, Bundle bundle) {
        if (RuntimeVariables.androidApplication.getPackageName().equals(activity.getPackageName())) {
            ContextImplHook contextImplHook = new ContextImplHook(activity.getBaseContext(), activity.getClass().getClassLoader());
            if (!(AtlasHacks.ContextThemeWrapper_mBase == null || AtlasHacks.ContextThemeWrapper_mBase.getField() == null)) {
                AtlasHacks.ContextThemeWrapper_mBase.set(activity, contextImplHook);
            }
            AtlasHacks.ContextWrapper_mBase.set(activity, contextImplHook);
            if (activity.getClass().getClassLoader() instanceof BundleClassLoader) {
                try {
                    ((BundleClassLoader) activity.getClass().getClassLoader()).getBundle().startBundle();
                } catch (BundleException e) {
                    log.error(e.getMessage() + " Caused by: ", e.getNestedException());
                }
            }
            Object property = Framework.getProperty("android.taobao.atlas.welcome", "com.taobao.tao.welcome.Welcome");
            if (TextUtils.isEmpty(property)) {
                property = "com.taobao.tao.welcome.Welcome";
            }
            if (activity.getClass().getName().equals(property)) {
                this.mBase.callActivityOnCreate(activity, null);
                return;
            } else {
                this.mBase.callActivityOnCreate(activity, bundle);
                return;
            }
        }
        this.mBase.callActivityOnCreate(activity, bundle);
    }

    @TargetApi(18)
    public UiAutomation getUiAutomation() {
        return this.mBase.getUiAutomation();
    }

    public void onCreate(Bundle bundle) {
        this.mBase.onCreate(bundle);
    }

    public void start() {
        this.mBase.start();
    }

    public void onStart() {
        this.mBase.onStart();
    }

    public boolean onException(Object obj, Throwable th) {
        return this.mBase.onException(obj, th);
    }

    public void sendStatus(int i, Bundle bundle) {
        this.mBase.sendStatus(i, bundle);
    }

    public void finish(int i, Bundle bundle) {
        this.mBase.finish(i, bundle);
    }

    public void setAutomaticPerformanceSnapshots() {
        this.mBase.setAutomaticPerformanceSnapshots();
    }

    public void startPerformanceSnapshot() {
        this.mBase.startPerformanceSnapshot();
    }

    public void endPerformanceSnapshot() {
        this.mBase.endPerformanceSnapshot();
    }

    public void onDestroy() {
        this.mBase.onDestroy();
    }

    public Context getContext() {
        return this.mBase.getContext();
    }

    public ComponentName getComponentName() {
        return this.mBase.getComponentName();
    }

    public Context getTargetContext() {
        return this.mBase.getTargetContext();
    }

    public boolean isProfiling() {
        return this.mBase.isProfiling();
    }

    public void startProfiling() {
        this.mBase.startProfiling();
    }

    public void stopProfiling() {
        this.mBase.stopProfiling();
    }

    public void setInTouchMode(boolean z) {
        this.mBase.setInTouchMode(z);
    }

    public void waitForIdle(Runnable runnable) {
        this.mBase.waitForIdle(runnable);
    }

    public void waitForIdleSync() {
        this.mBase.waitForIdleSync();
    }

    public void runOnMainSync(Runnable runnable) {
        this.mBase.runOnMainSync(runnable);
    }

    public Activity startActivitySync(Intent intent) {
        return this.mBase.startActivitySync(intent);
    }

    public void addMonitor(ActivityMonitor activityMonitor) {
        this.mBase.addMonitor(activityMonitor);
    }

    public ActivityMonitor addMonitor(IntentFilter intentFilter, ActivityResult activityResult, boolean z) {
        return this.mBase.addMonitor(intentFilter, activityResult, z);
    }

    public ActivityMonitor addMonitor(String str, ActivityResult activityResult, boolean z) {
        return this.mBase.addMonitor(str, activityResult, z);
    }

    public boolean checkMonitorHit(ActivityMonitor activityMonitor, int i) {
        return this.mBase.checkMonitorHit(activityMonitor, i);
    }

    public Activity waitForMonitor(ActivityMonitor activityMonitor) {
        return this.mBase.waitForMonitor(activityMonitor);
    }

    public Activity waitForMonitorWithTimeout(ActivityMonitor activityMonitor, long j) {
        return this.mBase.waitForMonitorWithTimeout(activityMonitor, j);
    }

    public void removeMonitor(ActivityMonitor activityMonitor) {
        this.mBase.removeMonitor(activityMonitor);
    }

    public boolean invokeMenuActionSync(Activity activity, int i, int i2) {
        return this.mBase.invokeMenuActionSync(activity, i, i2);
    }

    public boolean invokeContextMenuAction(Activity activity, int i, int i2) {
        return this.mBase.invokeContextMenuAction(activity, i, i2);
    }

    public void sendStringSync(String str) {
        this.mBase.sendStringSync(str);
    }

    public void sendKeySync(KeyEvent keyEvent) {
        this.mBase.sendKeySync(keyEvent);
    }

    public void sendKeyDownUpSync(int i) {
        this.mBase.sendKeyDownUpSync(i);
    }

    public void sendCharacterSync(int i) {
        this.mBase.sendCharacterSync(i);
    }

    public void sendPointerSync(MotionEvent motionEvent) {
        this.mBase.sendPointerSync(motionEvent);
    }

    public void sendTrackballEventSync(MotionEvent motionEvent) {
        this.mBase.sendTrackballEventSync(motionEvent);
    }

    public Application newApplication(ClassLoader classLoader, String str, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return this.mBase.newApplication(classLoader, str, context);
    }

    public void callApplicationOnCreate(Application application) {
        this.mBase.callApplicationOnCreate(application);
    }

    public void callActivityOnDestroy(Activity activity) {
        this.mBase.callActivityOnDestroy(activity);
    }

    public void callActivityOnRestoreInstanceState(Activity activity, Bundle bundle) {
        this.mBase.callActivityOnRestoreInstanceState(activity, bundle);
    }

    public void callActivityOnPostCreate(Activity activity, Bundle bundle) {
        this.mBase.callActivityOnPostCreate(activity, bundle);
    }

    public void callActivityOnNewIntent(Activity activity, Intent intent) {
        this.mBase.callActivityOnNewIntent(activity, intent);
    }

    public void callActivityOnStart(Activity activity) {
        this.mBase.callActivityOnStart(activity);
    }

    public void callActivityOnRestart(Activity activity) {
        this.mBase.callActivityOnRestart(activity);
    }

    public void callActivityOnResume(Activity activity) {
        this.mBase.callActivityOnResume(activity);
    }

    public void callActivityOnStop(Activity activity) {
        this.mBase.callActivityOnStop(activity);
    }

    public void callActivityOnSaveInstanceState(Activity activity, Bundle bundle) {
        this.mBase.callActivityOnSaveInstanceState(activity, bundle);
    }

    public void callActivityOnPause(Activity activity) {
        this.mBase.callActivityOnPause(activity);
    }

    public void callActivityOnUserLeaving(Activity activity) {
        this.mBase.callActivityOnUserLeaving(activity);
    }

    public void startAllocCounting() {
        this.mBase.startAllocCounting();
    }

    public void stopAllocCounting() {
        this.mBase.stopAllocCounting();
    }

    public Bundle getAllocCounts() {
        return this.mBase.getAllocCounts();
    }

    public Bundle getBinderCounts() {
        return this.mBase.getBinderCounts();
    }
} public class PackageLite {
    private static final String XMLDISABLECOMPONENT_SSO_ALIPAY_AUTHENTICATION_SERVICE = "com.taobao.android.sso.internal.AlipayAuthenticationService";
    private static final String XMLDISABLECOMPONENT_SSO_AUTHENTICATION_SERVICE = "com.taobao.android.sso.internal.AuthenticationService";
    static final Logger log;
    public String applicationClassName;
    public int applicationDescription;
    public int applicationIcon;
    public int applicationLabel;
    public final Set<String> components;
    public final Set<String> disableComponents;
    public Bundle metaData;
    public String packageName;
    public int versionCode;
    public String versionName;

    static {
        log = LoggerFactory.getInstance("PackageInfo");
    }

    PackageLite() {
        this.components = new HashSet();
        this.disableComponents = new HashSet();
    }

    public static PackageLite parse(File file) {
        Throwable e;
        XmlResourceParser xmlResourceParser = null;
        XmlResourceParser openXmlResourceParser;
        try {
            AssetManager assetManager = (AssetManager) AssetManager.class.newInstance();
            int intValue = ((Integer) AtlasHacks.AssetManager_addAssetPath.invoke(assetManager, file.getAbsolutePath())).intValue();
            if (intValue != 0) {
                openXmlResourceParser = assetManager.openXmlResourceParser(intValue, "AndroidManifest.xml");
            } else {
                openXmlResourceParser = assetManager.openXmlResourceParser(intValue, "AndroidManifest.xml");
            }
            if (openXmlResourceParser != null) {
                try {
                    PackageLite parse = parse(openXmlResourceParser);
                    if (parse == null) {
                        parse = new PackageLite();
                    }
                    if (openXmlResourceParser == null) {
                        return parse;
                    }
                    openXmlResourceParser.close();
                    return parse;
                } catch (Exception e2) {
                    e = e2;
                    try {
                        log.error("Exception while parse AndroidManifest.xml >>>", e);
                        if (openXmlResourceParser != null) {
                            openXmlResourceParser.close();
                        }
                        return null;
                    } catch (Throwable th) {
                        e = th;
                        xmlResourceParser = openXmlResourceParser;
                        if (xmlResourceParser != null) {
                            xmlResourceParser.close();
                        }
                        throw e;
                    }
                }
            }
            if (openXmlResourceParser != null) {
                openXmlResourceParser.close();
            }
            return null;
        } catch (Exception e3) {
            e = e3;
            openXmlResourceParser = null;
            log.error("Exception while parse AndroidManifest.xml >>>", e);
            if (openXmlResourceParser != null) {
                openXmlResourceParser.close();
            }
            return null;
        } catch (Throwable th2) {
            e = th2;
            if (xmlResourceParser != null) {
                xmlResourceParser.close();
            }
            throw e;
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    protected static android.taobao.atlas.runtime.PackageLite parse(android.content.res.XmlResourceParser r10) throws java.lang.Exception {
        /*
        r9 = 3;
        r8 = 1;
        r7 = 2;
        r1 = 0;
        r3 = 0;
        r4 = new android.taobao.atlas.runtime.PackageLite;
        r4.<init>();
    L_0x000a:
        r0 = r10.next();
        if (r0 == r7) goto L_0x0012;
    L_0x0010:
        if (r0 != r8) goto L_0x000a;
    L_0x0012:
        if (r0 == r7) goto L_0x001e;
    L_0x0014:
        r0 = log;
        r1 = "No start tag found";
        r0.error(r1);
        r0 = r3;
    L_0x001d:
        return r0;
    L_0x001e:
        r0 = r10.getName();
        r2 = "manifest";
        r0 = r0.equals(r2);
        if (r0 != 0) goto L_0x0035;
    L_0x002b:
        r0 = log;
        r1 = "No <manifest> tag";
        r0.error(r1);
        r0 = r3;
        goto L_0x001d;
    L_0x0035:
        r0 = "package";
        r0 = r10.getAttributeValue(r3, r0);
        r4.packageName = r0;
        r0 = r4.packageName;
        if (r0 == 0) goto L_0x004a;
    L_0x0042:
        r0 = r4.packageName;
        r0 = r0.length();
        if (r0 != 0) goto L_0x0054;
    L_0x004a:
        r0 = log;
        r1 = "<manifest> does not specify package";
        r0.error(r1);
        r0 = r3;
        goto L_0x001d;
    L_0x0054:
        r0 = r1;
        r2 = r1;
    L_0x0056:
        r5 = r10.getAttributeCount();
        if (r0 >= r5) goto L_0x0073;
    L_0x005c:
        r5 = r10.getAttributeName(r0);
        r6 = "versionCode";
        r6 = r5.equals(r6);
        if (r6 == 0) goto L_0x00a2;
    L_0x0069:
        r5 = r10.getAttributeIntValue(r0, r1);
        r4.versionCode = r5;
        r2 = r2 + 1;
    L_0x0071:
        if (r2 < r7) goto L_0x00b4;
    L_0x0073:
        r0 = r10.getDepth();
        r0 = r0 + 1;
    L_0x0079:
        r1 = r10.next();
        if (r1 == r8) goto L_0x00be;
    L_0x007f:
        if (r1 != r9) goto L_0x0087;
    L_0x0081:
        r2 = r10.getDepth();
        if (r2 < r0) goto L_0x00be;
    L_0x0087:
        if (r1 == r9) goto L_0x0079;
    L_0x0089:
        r2 = 4;
        if (r1 == r2) goto L_0x0079;
    L_0x008c:
        r1 = r10.getName();
        r2 = "application";
        r1 = r1.equals(r2);
        if (r1 == 0) goto L_0x00ba;
    L_0x0099:
        r0 = parseApplication(r4, r10, r10);
        if (r0 != 0) goto L_0x00b7;
    L_0x009f:
        r0 = r3;
        goto L_0x001d;
    L_0x00a2:
        r6 = "versionName";
        r5 = r5.equals(r6);
        if (r5 == 0) goto L_0x0071;
    L_0x00ab:
        r5 = r10.getAttributeValue(r0);
        r4.versionName = r5;
        r2 = r2 + 1;
        goto L_0x0071;
    L_0x00b4:
        r0 = r0 + 1;
        goto L_0x0056;
    L_0x00b7:
        r0 = r4;
        goto L_0x001d;
    L_0x00ba:
        skipCurrentTag(r10);
        goto L_0x0079;
    L_0x00be:
        r0 = r4;
        goto L_0x001d;
        */
        throw new UnsupportedOperationException("Method not decompiled: android.taobao.atlas.runtime.PackageLite.parse(android.content.res.XmlResourceParser):android.taobao.atlas.runtime.PackageLite");
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static boolean parseApplication(android.taobao.atlas.runtime.PackageLite r7, org.xmlpull.v1.XmlPullParser r8, android.util.AttributeSet r9) throws java.lang.Exception {
        /*
        r6 = 3;
        r5 = 1;
        r1 = 0;
        r2 = r7.packageName;
        r0 = r1;
    L_0x0006:
        r3 = r9.getAttributeCount();
        if (r0 >= r3) goto L_0x0056;
    L_0x000c:
        r3 = r9.getAttributeName(r0);
        r4 = "name";
        r4 = r3.equals(r4);
        if (r4 == 0) goto L_0x0026;
    L_0x0019:
        r3 = r9.getAttributeValue(r0);
        r3 = buildClassName(r2, r3);
        r7.applicationClassName = r3;
    L_0x0023:
        r0 = r0 + 1;
        goto L_0x0006;
    L_0x0026:
        r4 = "icon";
        r4 = r3.equals(r4);
        if (r4 == 0) goto L_0x0036;
    L_0x002f:
        r3 = r9.getAttributeResourceValue(r0, r1);
        r7.applicationIcon = r3;
        goto L_0x0023;
    L_0x0036:
        r4 = "label";
        r4 = r3.equals(r4);
        if (r4 == 0) goto L_0x0046;
    L_0x003f:
        r3 = r9.getAttributeResourceValue(r0, r1);
        r7.applicationLabel = r3;
        goto L_0x0023;
    L_0x0046:
        r4 = "description";
        r3 = r3.equals(r4);
        if (r3 == 0) goto L_0x0023;
    L_0x004f:
        r3 = r9.getAttributeResourceValue(r0, r1);
        r7.applicationDescription = r3;
        goto L_0x0023;
    L_0x0056:
        r0 = r8.getDepth();
    L_0x005a:
        r2 = r8.next();
        if (r2 == r5) goto L_0x00bb;
    L_0x0060:
        if (r2 != r6) goto L_0x0068;
    L_0x0062:
        r3 = r8.getDepth();
        if (r3 <= r0) goto L_0x00bb;
    L_0x0068:
        if (r2 == r6) goto L_0x005a;
    L_0x006a:
        r3 = 4;
        if (r2 == r3) goto L_0x005a;
    L_0x006d:
        r2 = r8.getName();
        r3 = "meta-data";
        r3 = r2.equals(r3);
        if (r3 == 0) goto L_0x0083;
    L_0x007a:
        r2 = r7.metaData;
        r2 = parseMetaData(r8, r9, r2);
        r7.metaData = r2;
        goto L_0x005a;
    L_0x0083:
        r3 = "activity";
        r3 = r2.equals(r3);
        if (r3 == 0) goto L_0x0090;
    L_0x008c:
        parseComponentData(r7, r8, r9, r1);
        goto L_0x005a;
    L_0x0090:
        r3 = "receiver";
        r3 = r2.equals(r3);
        if (r3 == 0) goto L_0x009d;
    L_0x0099:
        parseComponentData(r7, r8, r9, r5);
        goto L_0x005a;
    L_0x009d:
        r3 = "service";
        r3 = r2.equals(r3);
        if (r3 == 0) goto L_0x00aa;
    L_0x00a6:
        parseComponentData(r7, r8, r9, r5);
        goto L_0x005a;
    L_0x00aa:
        r3 = "provider";
        r2 = r2.equals(r3);
        if (r2 == 0) goto L_0x00b7;
    L_0x00b3:
        parseComponentData(r7, r8, r9, r1);
        goto L_0x005a;
    L_0x00b7:
        skipCurrentTag(r8);
        goto L_0x005a;
    L_0x00bb:
        return r5;
        */
        throw new UnsupportedOperationException("Method not decompiled: android.taobao.atlas.runtime.PackageLite.parseApplication(android.taobao.atlas.runtime.PackageLite, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet):boolean");
    }

    private static Bundle parseMetaData(XmlPullParser xmlPullParser, AttributeSet attributeSet, Bundle bundle) throws XmlPullParserException, IOException {
        int i = 0;
        if (bundle == null) {
            bundle = new Bundle();
        }
        String str = null;
        String str2 = null;
        int i2 = 0;
        while (i < attributeSet.getAttributeCount()) {
            String attributeName = attributeSet.getAttributeName(i);
            if (attributeName.equals(MtopResponse.KEY_NAME)) {
                str2 = attributeSet.getAttributeValue(i);
                i2++;
            } else if (attributeName.equals(C0271c.VALUE)) {
                str = attributeSet.getAttributeValue(i);
                i2++;
            }
            if (i2 >= 2) {
                break;
            }
            i++;
        }
        if (!(str2 == null || str == null)) {
            bundle.putString(str2, str);
        }
        return bundle;
    }

    private static String buildClassName(String str, CharSequence charSequence) {
        if (charSequence == null || charSequence.length() <= 0) {
            log.error("Empty class name in package " + str);
            return null;
        }
        String obj = charSequence.toString();
        char charAt = obj.charAt(0);
        if (charAt == ClassUtils.PACKAGE_SEPARATOR_CHAR) {
            return (str + obj).intern();
        }
        if (obj.indexOf(46) < 0) {
            StringBuilder stringBuilder = new StringBuilder(str);
            stringBuilder.append(ClassUtils.PACKAGE_SEPARATOR_CHAR);
            stringBuilder.append(obj);
            return stringBuilder.toString().intern();
        } else if (charAt >= 'a' && charAt <= 'z') {
            return obj.intern();
        } else {
            log.error("Bad class name " + obj + " in package " + str);
            return null;
        }
    }

    private static void skipCurrentTag(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        int depth = xmlPullParser.getDepth();
        while (true) {
            int next = xmlPullParser.next();
            if (next == 1) {
                return;
            }
            if (next == 3 && xmlPullParser.getDepth() <= depth) {
                return;
            }
        }
    }

    private static void parseComponentData(PackageLite packageLite, XmlPullParser xmlPullParser, AttributeSet attributeSet, boolean z) throws XmlPullParserException {
        int i = 0;
        String str = packageLite.packageName;
        int i2 = 0;
        while (i < attributeSet.getAttributeCount()) {
            if (attributeSet.getAttributeName(i).equals(MtopResponse.KEY_NAME)) {
                String attributeValue = attributeSet.getAttributeValue(i);
                if (attributeValue.startsWith(".")) {
                    attributeValue = str.concat(str);
                }
                packageLite.components.add(attributeValue);
                if (z && !(StringUtils.equals(attributeValue, XMLDISABLECOMPONENT_SSO_ALIPAY_AUTHENTICATION_SERVICE) && StringUtils.equals(attributeValue, XMLDISABLECOMPONENT_SSO_AUTHENTICATION_SERVICE))) {
                    packageLite.disableComponents.add(attributeValue);
                }
                i2++;
            }
            if (i2 < attributeSet.getAttributeCount()) {
                i++;
            } else {
                return;
            }
        }
    }
} public class RuntimeVariables {
    public static Application androidApplication;
    public static DelegateClassLoader delegateClassLoader;
    public static Resources delegateResources;
}
import android.app.Application;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.taobao.atlas.hack.AndroidHack;
import android.taobao.atlas.hack.AssertionArrayException;
import android.taobao.atlas.hack.AtlasHacks;
import android.taobao.atlas.log.Logger;
import android.taobao.atlas.log.LoggerFactory;
import android.taobao.atlas.runtime.BundleLifecycleHandler;
import android.taobao.atlas.runtime.ClassNotFoundInterceptorCallback;
import android.taobao.atlas.runtime.DelegateClassLoader;
import android.taobao.atlas.runtime.DelegateComponent;
import android.taobao.atlas.runtime.FrameworkLifecycleHandler;
import android.taobao.atlas.runtime.InstrumentationHook;
import android.taobao.atlas.runtime.PackageLite;
import android.taobao.atlas.runtime.RuntimeVariables;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkListener;
package android.taobao.atlas.framework;


public class Atlas {
    protected static Atlas instance;
    static final Logger log;
    private BundleLifecycleHandler bundleLifecycleHandler;
    private FrameworkLifecycleHandler frameworkLifecycleHandler;

    static {
        log = LoggerFactory.getInstance("Atlas");