Search in sources :

Example 16 with DexClassLoader

use of dalvik.system.DexClassLoader in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindowManager method init.

/** {@inheritDoc} */
@Override
public void init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs) {
    mContext = context;
    mWindowManager = windowManager;
    mWindowManagerFuncs = windowManagerFuncs;
    mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
    if (!mHeadless) {
        // don't create KeyguardViewMediator if headless
        mKeyguardMediator = new KeyguardViewMediator(context, null);
    }
    mHandler = new PolicyHandler();
    mOrientationListener = new MyOrientationListener(mContext, mHandler);
    try {
        mOrientationListener.setCurrentRotation(windowManager.getRotation());
    } catch (RemoteException ex) {
    }
    updateHybridLayout();
    mSettingsObserver = new SettingsObserver(mHandler);
    mSettingsObserver.observe();
    // SystemUI reboot
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.USER_INTERFACE_STATE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            // Return for reset triggers
            if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0) == 0) {
                return;
            }
            // Update layout
            update(true);
            // Reset trigger
            Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0);
        }
    });
    // Expanded desktop
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.EXPANDED_DESKTOP_STATE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHybridLayout();
            update(false);
        }
    });
    mShortcutManager = new ShortcutManager(context, mHandler);
    mShortcutManager.observe();
    mUiMode = context.getResources().getInteger(com.android.internal.R.integer.config_defaultUiModeType);
    mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
    mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
    mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
    mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
    mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PhoneWindowManager.mBroadcastWakeLock");
    mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
    mLidOpenRotation = readRotation(com.android.internal.R.integer.config_lidOpenRotation);
    mCarDockRotation = readRotation(com.android.internal.R.integer.config_carDockRotation);
    mDeskDockRotation = readRotation(com.android.internal.R.integer.config_deskDockRotation);
    mUndockedHdmiRotation = readRotation(com.android.internal.R.integer.config_undockedHdmiRotation);
    mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_carDockEnablesAccelerometer);
    mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
    mLidKeyboardAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidKeyboardAccessibility);
    mLidNavigationAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidNavigationAccessibility);
    mLidControlsSleep = mContext.getResources().getBoolean(com.android.internal.R.bool.config_lidControlsSleep);
    mHasRemovableLid = mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasRemovableLid);
    mDeviceHardwareKeys = mContext.getResources().getInteger(com.android.internal.R.integer.config_deviceHardwareKeys);
    mHasHomeKey = ((mDeviceHardwareKeys & KEY_MASK_HOME) != 0);
    mHasMenuKey = ((mDeviceHardwareKeys & KEY_MASK_MENU) != 0);
    mHasAssistKey = ((mDeviceHardwareKeys & KEY_MASK_ASSIST) != 0);
    mHasAppSwitchKey = ((mDeviceHardwareKeys & KEY_MASK_APP_SWITCH) != 0);
    // register for dock events
    IntentFilter filter = new IntentFilter();
    filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
    filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
    filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
    filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
    filter.addAction(Intent.ACTION_DOCK_EVENT);
    Intent intent = context.registerReceiver(mDockReceiver, filter);
    if (intent != null) {
        // Retrieve current sticky dock event broadcast.
        mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
    }
    // register for dream-related broadcasts
    filter = new IntentFilter();
    filter.addAction(Intent.ACTION_DREAMING_STARTED);
    filter.addAction(Intent.ACTION_DREAMING_STOPPED);
    context.registerReceiver(mDreamReceiver, filter);
    // register for multiuser-relevant broadcasts
    filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
    context.registerReceiver(mMultiuserReceiver, filter);
    mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    mLongPressVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_longPressVibePattern);
    mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_virtualKeyVibePattern);
    mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_keyboardTapVibePattern);
    mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeDisabledVibePattern);
    mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeEnabledVibePattern);
    mScreenshotChordEnabled = mContext.getResources().getBoolean(com.android.internal.R.bool.config_enableScreenshotChord);
    mGlobalKeyManager = new GlobalKeyManager(mContext);
    // Controls rotation and the like.
    initializeHdmiState();
    // Match current screen state.
    if (mPowerManager.isScreenOn()) {
        screenTurningOn(null);
    } else {
        screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
    }
    String deviceKeyHandlerLib = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerLib);
    String deviceKeyHandlerClass = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerClass);
    if (!deviceKeyHandlerLib.equals("") && !deviceKeyHandlerClass.equals("")) {
        DexClassLoader loader = new DexClassLoader(deviceKeyHandlerLib, new ContextWrapper(mContext).getCacheDir().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
        try {
            Class<?> klass = loader.loadClass(deviceKeyHandlerClass);
            Constructor<?> constructor = klass.getConstructor(Context.class);
            mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(mContext);
            if (DEBUG)
                Slog.d(TAG, "Device key handler loaded");
        } catch (Exception e) {
            Slog.w(TAG, "Could not instantiate device key handler " + deviceKeyHandlerClass + " from class " + deviceKeyHandlerLib, e);
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) KeyguardViewMediator(com.android.internal.policy.impl.keyguard.KeyguardViewMediator) DexClassLoader(dalvik.system.DexClassLoader) Handler(android.os.Handler) DeviceKeyHandler(com.android.internal.os.DeviceKeyHandler) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) RemoteException(android.os.RemoteException) ContextWrapper(android.content.ContextWrapper) ContentObserver(android.database.ContentObserver)

Example 17 with DexClassLoader

use of dalvik.system.DexClassLoader in project freeline by alibaba.

the class NativeUtils method injectHackNativeLib.

public static void injectHackNativeLib(String libraryDir, PathClassLoader classLoader) {
    try {
        Log.i(TAG, "native lib inject process start...");
        String refFieldName = "nativeLibraryPathElements";
        if (Build.VERSION.SDK_INT < 23) {
            refFieldName = "nativeLibraryDirectories";
        }
        Object pathListObject = ReflectUtil.getField(classLoader, "pathList");
        Object nativeLibraryPathElementsObject = ReflectUtil.getField(pathListObject, refFieldName);
        Field nativeLibraryPathElementsFiled = ReflectUtil.fieldGetOrg(pathListObject, refFieldName);
        DexClassLoader dumbDexClassLoader = new DexClassLoader("", libraryDir, libraryDir, classLoader.getParent());
        Object dynamicNativeLibraryPathElements = ReflectUtil.getField(ReflectUtil.getField(dumbDexClassLoader, "pathList"), refFieldName);
        Object dynamicNativeLibraryPathElement = Array.get(dynamicNativeLibraryPathElements, 0);
        int lengthOfNewNativeLibraryPathElements = Array.getLength(nativeLibraryPathElementsObject) + 1;
        Object newNativeLibraryPathElements = Array.newInstance(nativeLibraryPathElementsFiled.getType().getComponentType(), lengthOfNewNativeLibraryPathElements);
        Array.set(newNativeLibraryPathElements, 0, dynamicNativeLibraryPathElement);
        for (int i = 1; i < lengthOfNewNativeLibraryPathElements; i++) {
            Object object = Array.get(nativeLibraryPathElementsObject, i - 1);
            Array.set(newNativeLibraryPathElements, i, object);
        }
        ReflectUtil.setField(pathListObject, refFieldName, newNativeLibraryPathElements);
        Log.i(TAG, "inject native lib success " + newNativeLibraryPathElements);
    } catch (Exception ex) {
        Log.e(TAG, "inject native lib failed", ex);
    }
}
Also used : Field(java.lang.reflect.Field) DexClassLoader(dalvik.system.DexClassLoader)

Example 18 with DexClassLoader

use of dalvik.system.DexClassLoader in project dynamic-load-apk by singwhatiwanna.

the class DLPluginManager method preparePluginEnv.

/**
     * prepare plugin runtime env, has DexClassLoader, Resources, and so on.
     * 
     * @param packageInfo
     * @param dexPath
     * @return
     */
private DLPluginPackage preparePluginEnv(PackageInfo packageInfo, String dexPath) {
    DLPluginPackage pluginPackage = mPackagesHolder.get(packageInfo.packageName);
    if (pluginPackage != null) {
        return pluginPackage;
    }
    DexClassLoader dexClassLoader = createDexClassLoader(dexPath);
    AssetManager assetManager = createAssetManager(dexPath);
    Resources resources = createResources(assetManager);
    // create pluginPackage
    pluginPackage = new DLPluginPackage(dexClassLoader, resources, packageInfo);
    mPackagesHolder.put(packageInfo.packageName, pluginPackage);
    return pluginPackage;
}
Also used : AssetManager(android.content.res.AssetManager) DexClassLoader(dalvik.system.DexClassLoader) Resources(android.content.res.Resources)

Example 19 with DexClassLoader

use of dalvik.system.DexClassLoader in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DimmableIZatIconPreference method load.

private static void load(Context context) {
    if (mLoader == null) {
        try {
            if (mXtProxyClz == null || mNotifierClz == null) {
                mLoader = new DexClassLoader("/system/framework/izat.xt.srv.jar", context.getFilesDir().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
                mXtProxyClz = Class.forName("com.qti.izat.XTProxy", true, mLoader);
                mNotifierClz = Class.forName("com.qti.izat.XTProxy$Notifier", true, mLoader);
                mIzatPackage = (String) mXtProxyClz.getField("IZAT_XT_PACKAGE").get(null);
                mGetXtProxyMethod = mXtProxyClz.getMethod("getXTProxy", Context.class, mNotifierClz);
                mGetConsentMethod = mXtProxyClz.getMethod("getUserConsent");
                mShowIzatMethod = mXtProxyClz.getMethod("showIzat", Context.class, String.class);
            }
        } catch (NoSuchMethodException | NullPointerException | SecurityException | NoSuchFieldException | LinkageError | IllegalAccessException | ClassNotFoundException e) {
            mXtProxyClz = null;
            mNotifierClz = null;
            mIzatPackage = null;
            mGetXtProxyMethod = null;
            mGetConsentMethod = null;
            mShowIzatMethod = null;
            e.printStackTrace();
        }
    }
}
Also used : Context(android.content.Context) LinkageError(java.lang.LinkageError) NullPointerException(java.lang.NullPointerException) DexClassLoader(dalvik.system.DexClassLoader) SecurityException(java.lang.SecurityException) NoSuchFieldException(java.lang.NoSuchFieldException) ClassNotFoundException(java.lang.ClassNotFoundException) NoSuchMethodException(java.lang.NoSuchMethodException) IllegalAccessException(java.lang.IllegalAccessException)

Aggregations

DexClassLoader (dalvik.system.DexClassLoader)19 File (java.io.File)7 DexFile (dalvik.system.DexFile)4 Resources (android.content.res.Resources)3 RemoteException (android.os.RemoteException)3 FileOutputStream (java.io.FileOutputStream)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ContextWrapper (android.content.ContextWrapper)2 Intent (android.content.Intent)2 AssetManager (android.content.res.AssetManager)2 PathClassLoader (dalvik.system.PathClassLoader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Field (java.lang.reflect.Field)2 ZipFile (java.util.zip.ZipFile)2 TargetApi (android.annotation.TargetApi)1 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Context (android.content.Context)1