Code example for DexClassLoader

Methods: loadClass

0
    public static final int eAM_STATUS_USURP_FAILURE = 13;
 
    private AuthentecHelper(Context ctx)
    { 
        try { 
            AuthentecMobile = sAuthentecClassLoader.loadClass("com.authentec.amjni.AuthentecMobile");
            TSM = sAuthentecClassLoader.loadClass("com.authentec.amjni.TSM");
            Constructor ctor = AuthentecMobile.getDeclaredConstructors()[0];
            am = ctor.newInstance(ctx);
        } catch (Exception ex) {
            ex.printStackTrace();
            return; 
        } 
    } 
 
    public int fingerprintUnlock(String sScreen, Context ctx) {
        int iResult = 0;
 
        try { 
            if (! (Boolean) AuthentecMobile.getMethod("AM2ClientLibraryLoaded").invoke(am)) {
                return eAM_STATUS_LIBRARY_NOT_AVAILABLE;
            } 
 
            if(null == ctx) {
                return eAM_STATUS_INVALID_PARAMETER;
            } 
 
            //int iResult = TSM.LAP(ctx).verify().viaGfxScreen(sScreen).exec(); 
            Class partTypes[] = new Class[1];
            Object argList[] = new Object[1];
 
            partTypes[0] = Context.class;
            argList[0] = ctx;
            Object TSMi = TSM.getMethod("LAP", partTypes).invoke(null, argList);
 
            TSM.getMethod("verify").invoke(TSMi);
 
            partTypes[0] = String.class;
            argList[0] = sScreen;
            TSM.getMethod("viaGfxScreen", partTypes).invoke(TSMi, argList);
 
            iResult = (Integer) TSM.getMethod("exec").invoke(TSMi);
            TSMi = null;
 
            try { 
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } 
        } catch (Exception e) {
            e.printStackTrace();
        } 
 
        return iResult;
    } 
 
    public int startEnrollmentWizard(Context choosefinger, String msTempPasscode)
    { 
        int miResult = eAM_STATUS_LIBRARY_NOT_AVAILABLE;
 
        try { 
            Class partTypes[] = new Class[1];
            Object argList[] = new Object[1];
 
            partTypes[0] = Context.class;
            argList[0] = choosefinger;
            Object TSMi = TSM.getMethod("LAP", partTypes).invoke(null, argList);
 
            if (msTempPasscode != null) {
                partTypes[0] = String.class;
                argList[0] = msTempPasscode;
                argList[0] = (String) TSM.getMethod("Hexify", partTypes).invoke(null, argList);
 
                TSM.getMethod("usingPasscode", partTypes).invoke(TSMi, argList);
 
                TSM.getMethod("enroll").invoke(TSMi);
                //miResult = TSM.LAP(ChooseLockFinger.this).usingPasscode(TSM.Hexify(msTempPasscode)).enroll().exec(); 
            } else { 
                partTypes[0] = String.class;
                argList[0] = "_classicEnroll";
                TSM.getMethod("addFunction", partTypes).invoke(TSMi, argList);
                //miResult = TSM.LAP(ChooseLockFinger.this).addFunction("_classicEnroll").exec(); 
            } 
 
            miResult = (Integer) TSM.getMethod("exec").invoke(TSMi);
            TSMi = null;
 
        } catch (Exception e) {
            e.printStackTrace();
        } 
 
        return miResult;
    } 
 
    public int startVerification(Context choosefinger)
    { 
        int miResult = eAM_STATUS_LIBRARY_NOT_AVAILABLE;
 
        try { 
            //miResult = TSM.LAP(ChooseLockFinger.this).verify().viaGfxScreen("lap-verify").exec(); 
            Class partTypes[] = new Class[1];
            Object argList[] = new Object[1];
 
            partTypes[0] = Context.class;
            argList[0] = choosefinger;
            Object TSMi = TSM.getMethod("LAP", partTypes).invoke(null, argList);
 
            TSM.getMethod("verify").invoke(TSMi);
 
            partTypes[0] = String.class;
            argList[0] = "lap-verify";
            TSM.getMethod("viaGfxScreen", partTypes).invoke(TSMi, argList);
 
            miResult = (Integer) TSM.getMethod("exec").invoke(TSMi);
            TSMi = null;
 
        } catch (Exception e) {
            e.printStackTrace();
        } 
 
        return miResult;
    } 
 
    public int verifyPolicy(Context ctx)
    { 
        int iResult = eAM_STATUS_LIBRARY_NOT_AVAILABLE;
 
        try { 
            //iResult = TSM.LAP(m_Context).waitForUI().verify().exec(); 
            Class partTypes[] = new Class[1];
            Object argList[] = new Object[1];
 
            partTypes[0] = Context.class;
            argList[0] = ctx;
            Object TSMi = TSM.getMethod("LAP", partTypes).invoke(null, argList);
 
            TSM.getMethod("waitForUI").invoke(TSMi, (Object[]) null);
 
            TSM.getMethod("verify").invoke(TSMi, (Object[]) null);
 
            iResult = (Integer) TSM.getMethod("exec").invoke(TSMi, (Object[]) null);
            TSMi = null;
 
        } catch (Exception e) {
            e.printStackTrace();
        } 
 
        return iResult;
    } 
 
    public static AuthentecHelper getInstance(Context ctx)
    { 
        ensureClassLoader(ctx);
        return new AuthentecHelper(ctx);
    } 
 
    public static void ensureClassLoader(Context ctx)
    { 
        if (sAuthentecClassLoader != null) {
            return; 
        } 
 
        String authentecJarLocation = SystemProperties.get("ro.authentec.fingerprint.jar","");
        String authentecSoLocation = SystemProperties.get("ro.authentec.fingerprint.so","");
 
        if ("".equals(authentecJarLocation) || "".equals(authentecSoLocation))
            return; 
 
        sAuthentecClassLoader =  new DexClassLoader(authentecJarLocation,
                new ContextWrapper(ctx).getCacheDir().getAbsolutePath(),
                authentecSoLocation,ClassLoader.getSystemClassLoader());
    } 
}