static jobject createScanResult(JNIEnv *env, wifi_scan_result *result) {

    // ALOGD("creating scan result");

    jobject scanResult = createObject(env, "android/net/wifi/ScanResult");
    if (scanResult == NULL) {
        ALOGE("Error in creating scan result");
        return NULL;
    }

    // ALOGD("setting SSID to %s", result.ssid);
    setStringField(env, scanResult, "SSID", result->ssid);

    char bssid[32];
    sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result->bssid[0], result->bssid[1],
        result->bssid[2], result->bssid[3], result->bssid[4], result->bssid[5]);

    setStringField(env, scanResult, "BSSID", bssid);

    setIntField(env, scanResult, "level", result->rssi);
    setIntField(env, scanResult, "frequency", result->channel);
    setLongField(env, scanResult, "timestamp", result->ts);

    return scanResult;
}
static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
{
    setBooleanField(env, obj, gPaths.acOnlinePath, gFieldIds.mAcOnline);
    setBooleanField(env, obj, gPaths.usbOnlinePath, gFieldIds.mUsbOnline);
    setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent);
    
    setIntField(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel);
    setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage);
    setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature);
    
    const int SIZE = 128;
    char buf[SIZE];
    
    if (readFromFile(gPaths.batteryStatusPath, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf));
    else
        env->SetIntField(obj, gFieldIds.mBatteryStatus,
                         gConstants.statusUnknown);
    
    if (readFromFile(gPaths.batteryHealthPath, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf));

    if (readFromFile(gPaths.batteryTechnologyPath, buf, SIZE) > 0)
        env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf));
}
コード例 #3
0
JNIEXPORT jint Java_com_mediatek_effect_filterpacks_Stereo3D2Dto3DFilter_init(JNIEnv* env, jobject thiz,
        jint inputWidth, jint inputHeight)
{
    jint result = 0;
    jclass cls;
    MTKTo3d *MyTo3d;
    TO3D_SET_ENV_INFO_STRUCT *MyTo3dInitInfo;
    TO3D_SET_PROC_INFO_STRUCT *MyTo3dProcInfo;

    XLOGD("Stereo3D 2Dto3D init()");

    cls = env->GetObjectClass(thiz);
    MyTo3d = (MTKTo3d *)getIntField(env, cls, thiz, "mNativeMyTo3d");
    MyTo3dInitInfo = (TO3D_SET_ENV_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeInitInfo");
    MyTo3dProcInfo = (TO3D_SET_PROC_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeProcInfo");

    XLOGD("get MyTo3d: 0x%x", MyTo3d);
    XLOGD("get MyTo3dInitInfo: 0x%x", MyTo3dInitInfo);
    XLOGD("get MyTo3dProcInfo: 0x%x", MyTo3dProcInfo);

    if (NULL == MyTo3d)
    {
        MyTo3d = MTKTo3d::createInstance();
        setIntField(env, cls, thiz, "mNativeMyTo3d", (int)MyTo3d);
    }

    if (NULL ==MyTo3dInitInfo)
    {
        MyTo3dInitInfo = (TO3D_SET_ENV_INFO_STRUCT *)malloc(sizeof(TO3D_SET_ENV_INFO_STRUCT));
        memset(MyTo3dInitInfo, 0, sizeof(TO3D_SET_ENV_INFO_STRUCT));
        setIntField(env, cls, thiz, "mNativeInitInfo", (int)MyTo3dInitInfo);
    }

    if (NULL == MyTo3dProcInfo)
    {
        MyTo3dProcInfo = (TO3D_SET_PROC_INFO_STRUCT *)malloc(sizeof(TO3D_SET_PROC_INFO_STRUCT));
        memset(MyTo3dProcInfo, 0, sizeof(TO3D_SET_PROC_INFO_STRUCT));
        setIntField(env, cls, thiz, "mNativeProcInfo", (int)MyTo3dProcInfo);
    }

    XLOGD("set MyTo3d: 0x%x", MyTo3d);
    XLOGD("set MyTo3dInitInfo: 0x%x", MyTo3dInitInfo);
    XLOGD("set MyTo3dProcInfo: 0x%x", MyTo3dProcInfo);

    MyTo3dInitInfo->large_image_format = TO3D_IMAGE_FORMAT_RGBA8888;
    MyTo3dInitInfo->small_image_format = TO3D_IMAGE_FORMAT_LUMA;
    MyTo3dInitInfo->to3d_scenario = TO3D_STILL_IMAGE_PLAYBACK;
    MyTo3dInitInfo->to3d_tuning_data.baseline = TUNE_BASE_LINE;
    MyTo3dInitInfo->to3d_tuning_data.global_thr_ratio = TUNE_GLOBAL_THR_RATIO;
    MyTo3dInitInfo->to3d_tuning_data.global_weighting = TUNE_GLOBAL_WEIGHTING;
    MyTo3dInitInfo->to3d_tuning_data.scene_change_thr = TUNE_SCENE_CHANGE_THR;
    MyTo3dInitInfo->large_image_height = inputHeight; // input height = output height
    MyTo3dInitInfo->large_image_width = inputWidth; // input width = output width
    MyTo3dInitInfo->small_image_width = 0;  // gMyTo3dInitInfo.large_image_width /10;
    MyTo3dInitInfo->small_image_height = 0; // gMyTo3dInitInfo.large_image_height/10;

    return result;
}
static jobject android_net_wifi_getScanResults(
        JNIEnv *env, jclass cls, jint iface, jboolean flush)  {
    
    wifi_scan_result results[256];
    int num_results = 256;
    
    wifi_interface_handle handle = getIfaceHandle(env, cls, iface);
    ALOGD("getting scan results on interface[%d] = %p", iface, handle);
    
    int result = wifi_get_cached_gscan_results(handle, 1, num_results, results, &num_results);
    if (result == WIFI_SUCCESS) {
        jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult");
        if (clsScanResult == NULL) {
            ALOGE("Error in accessing class");
            return NULL;
        }

        jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL);
        if (scanResults == NULL) {
            ALOGE("Error in allocating array");
            return NULL;
        }

        for (int i = 0; i < num_results; i++) {

            jobject scanResult = createObject(env, "android/net/wifi/ScanResult");
            if (scanResult == NULL) {
                ALOGE("Error in creating scan result");
                return NULL;
            }

            setStringField(env, scanResult, "SSID", results[i].ssid);

            char bssid[32];
            sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0],
                    results[i].bssid[1], results[i].bssid[2], results[i].bssid[3],
                    results[i].bssid[4], results[i].bssid[5]);

            setStringField(env, scanResult, "BSSID", bssid);

            setIntField(env, scanResult, "level", results[i].rssi);
            setIntField(env, scanResult, "frequency", results[i].channel);
            setLongField(env, scanResult, "timestamp", results[i].ts);

            env->SetObjectArrayElement(scanResults, i, scanResult);
            env->DeleteLocalRef(scanResult);
        }

        return scanResults;
    } else {
        return NULL;
    }
}
static void onHotlistApFound(wifi_request_id id,
        unsigned num_results, wifi_scan_result *results) {

    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onHotlistApFound called, vm = %p, obj = %p, env = %p, num_results = %d",
            mVM, mCls, env, num_results);

    jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult");
    if (clsScanResult == NULL) {
        ALOGE("Error in accessing class");
        return;
    }

    jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL);
    if (scanResults == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    for (unsigned i = 0; i < num_results; i++) {

        jobject scanResult = createObject(env, "android/net/wifi/ScanResult");
        if (scanResult == NULL) {
            ALOGE("Error in creating scan result");
            return;
        }

        setStringField(env, scanResult, "SSID", results[i].ssid);

        char bssid[32];
        sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1],
            results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]);

        setStringField(env, scanResult, "BSSID", bssid);

        setIntField(env, scanResult, "level", results[i].rssi);
        setIntField(env, scanResult, "frequency", results[i].channel);
        setLongField(env, scanResult, "timestamp", results[i].ts);

        env->SetObjectArrayElement(scanResults, i, scanResult);

        ALOGD("Found AP %32s %s", results[i].ssid, bssid);
    }

    reportEvent(env, mCls, "onHotlistApFound", "(I[Landroid/net/wifi/ScanResult;)V",
        id, scanResults);
}
static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
{
    setBooleanField(env, obj, ACO, gFieldIds.mAcOnline);
    setBooleanField(env, obj, USBO, gFieldIds.mUsbOnline);
    setBooleanField(env, obj, BPRS, gFieldIds.mBatteryPresent);
    
    setPercentageField(env, obj, BCAP, gFieldIds.mBatteryLevel);
    setVoltageField(env, obj, BVOL, gFieldIds.mBatteryVoltage);
    setIntField(env, obj, BTMP, gFieldIds.mBatteryTemperature);
    
    const int SIZE = 128;
    char buf[SIZE];
    
    if (readFromFile(BSTS, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf));
    else
        env->SetIntField(obj, gFieldIds.mBatteryStatus,
                         gConstants.statusUnknown);
    
    if (readFromFile(BHTH, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf));

    if (readFromFile(BTECH, buf, SIZE) > 0)
        env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf));
}
static jboolean android_net_wifi_getScanCapabilities(
        JNIEnv *env, jclass cls, jint iface, jobject capabilities) {

    wifi_interface_handle handle = getIfaceHandle(env, cls, iface);
    ALOGD("getting scan capabilities on interface[%d] = %p", iface, handle);

    wifi_gscan_capabilities c;
    memset(&c, 0, sizeof(c));
    int result = wifi_get_gscan_capabilities(handle, &c);
    if (result != WIFI_SUCCESS) {
        ALOGD("failed to get capabilities : %d", result);
        return JNI_FALSE;
    }

    setIntField(env, capabilities, "max_scan_cache_size", c.max_scan_cache_size);
    setIntField(env, capabilities, "max_scan_buckets", c.max_scan_buckets);
    setIntField(env, capabilities, "max_ap_cache_per_scan", c.max_ap_cache_per_scan);
    setIntField(env, capabilities, "max_rssi_sample_size", c.max_rssi_sample_size);
    setIntField(env, capabilities, "max_scan_reporting_threshold", c.max_scan_reporting_threshold);
    setIntField(env, capabilities, "max_hotlist_aps", c.max_hotlist_aps);
    setIntField(env, capabilities, "max_significant_wifi_change_aps",
                c.max_significant_wifi_change_aps);

    return JNI_TRUE;
}
static void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result results[]) {
    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onRttResults called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    jclass clsRttResult = (env)->FindClass("android/net/wifi/RttManager$RttResult");
    if (clsRttResult == NULL) {
        ALOGE("Error in accessing class");
        return;
    }

    jobjectArray rttResults = env->NewObjectArray(num_results, clsRttResult, NULL);
    if (rttResults == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    for (unsigned i = 0; i < num_results; i++) {

        wifi_rtt_result& result = results[i];

        jobject rttResult = createObject(env, "android/net/wifi/RttManager$RttResult");
        if (rttResult == NULL) {
            ALOGE("Error in creating rtt result");
            return;
        }

        char bssid[32];
        sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.addr[0], result.addr[1],
            result.addr[2], result.addr[3], result.addr[4], result.addr[5]);

        setStringField(env, rttResult, "bssid", bssid);
        setIntField(env,  rttResult, "status",               result.status);
        setIntField(env,  rttResult, "requestType",          result.type);
        setLongField(env, rttResult, "ts",                   result.ts);
        setIntField(env,  rttResult, "rssi",                 result.rssi);
        setIntField(env,  rttResult, "rssi_spread",          result.rssi_spread);
        setIntField(env,  rttResult, "tx_rate",              result.tx_rate.bitrate);
        setLongField(env, rttResult, "rtt_ns",               result.rtt);
        setLongField(env, rttResult, "rtt_sd_ns",            result.rtt_sd);
        setLongField(env, rttResult, "rtt_spread_ns",        result.rtt_spread);
        setIntField(env,  rttResult, "distance_cm",          result.distance);
        setIntField(env,  rttResult, "distance_sd_cm",       result.distance_sd);
        setIntField(env,  rttResult, "distance_spread_cm",   result.distance_spread);

        env->SetObjectArrayElement(rttResults, i, rttResult);
    }

    reportEvent(env, mCls, "onRttResults", "(I[Landroid/net/wifi/RttManager$RttResult;)V",
        id, rttResults);
}
コード例 #9
0
JNIEXPORT jint Java_com_mediatek_effect_filterpacks_Stereo3D2Dto3DFilter_close(JNIEnv* env, jobject thiz)
{
    jint result = 0;
    jclass cls;
    MTKTo3d *MyTo3d;
    TO3D_SET_ENV_INFO_STRUCT *MyTo3dInitInfo;
    TO3D_SET_PROC_INFO_STRUCT *MyTo3dProcInfo;

    XLOGD("Stereo3D 2Dto3D close()");

    cls = env->GetObjectClass(thiz);
    MyTo3d = (MTKTo3d *)getIntField(env, cls, thiz, "mNativeMyTo3d");
    MyTo3dInitInfo = (TO3D_SET_ENV_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeInitInfo");
    MyTo3dProcInfo = (TO3D_SET_PROC_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeProcInfo");

    XLOGD("get MyTo3d: 0x%x", MyTo3d);
    XLOGD("get MyTo3dInitInfo: 0x%x", MyTo3dInitInfo);
    XLOGD("get MyTo3dProcInfo: 0x%x", MyTo3dProcInfo);

    if (NULL != MyTo3dInitInfo)
    {
        free(MyTo3dInitInfo);
        setIntField(env, cls, thiz, "mNativeInitInfo", 0);
    }

    if (NULL != MyTo3dProcInfo)
    {
        free(MyTo3dProcInfo);
        setIntField(env, cls, thiz, "mNativeProcInfo", 0);
    }

    if (NULL != MyTo3d)
    {
        MyTo3d->To3dReset();
        MyTo3d->destroyInstance();
        MyTo3d = NULL;
        setIntField(env, cls, thiz, "mNativeMyTo3d", 0);
    }
    return result;
}
コード例 #10
0
ファイル: FUSE26Util.cpp プロジェクト: unsound/jfuse
/**
 * Fills in the fields of target (Java class Timespec) from the fields of source
 * (struct timespec).
 */
bool FUSE26Util::fillTimespec(JNIEnv *env, const struct timespec *source, jobject target) {
    CSLogTraceEnter("bool FUSE26Util::fillTimespec(%p, %p, %p)", env, source, target);

    bool ret = false;
    do {
        jclass clazz = env->GetObjectClass(target);
        if(clazz == NULL || env->ExceptionCheck() == JNI_TRUE) {
            CSLogError("Could not get object class!");
            if(env->ExceptionCheck())
                env->ExceptionDescribe();
            break;
        }

        if(!setIntField(env, clazz, target, "sec", source->tv_sec))
            break;
        if(!setIntField(env, clazz, target, "nsec", source->tv_nsec))
            break;
        
        ret = true;
    } while(0);

    CSLogTraceLeave("bool FUSE26Util::fillTimespec(%p, %p, %p): %d", env, source, target, ret);
    return ret;
}
コード例 #11
0
ファイル: FUSE26Util.cpp プロジェクト: unsound/jfuse
bool FUSE26Util::fillFUSEFileInfo(JNIEnv *env, const struct fuse_file_info *fi, jobject ffiObject) {
    CSLogTraceEnter("bool FUSE26Util::fillFUSEFileInfo(%p, %p, %p)", env, fi, ffiObject);

    bool ret = false;
    do {
        jclass ffiClass = env->GetObjectClass(ffiObject);
        if(ffiClass == NULL || env->ExceptionCheck() == JNI_TRUE) {
            CSLogError("Could not get object class!");
            if(env->ExceptionCheck())
                env->ExceptionDescribe();
            break;
        }

        if(!setIntField(env, ffiClass, ffiObject, "flags", fi->flags))
            break;
        if(!setLongField(env, ffiClass, ffiObject, "fh_old", fi->fh_old))
            break;
        if(!setIntField(env, ffiClass, ffiObject, "writepage", fi->writepage))
            break;
        if(!setBooleanField(env, ffiClass, ffiObject, "direct_io", (fi->direct_io == 0 ? JNI_FALSE : JNI_TRUE)))
            break;
        if(!setBooleanField(env, ffiClass, ffiObject, "keep_cache", (fi->keep_cache == 0 ? JNI_FALSE : JNI_TRUE)))
            break;
        if(!setBooleanField(env, ffiClass, ffiObject, "flush", (fi->flush == 0 ? JNI_FALSE : JNI_TRUE)))
            break;
        if(!setLongField(env, ffiClass, ffiObject, "fh", fi->fh))
            break;
        if(!setLongField(env, ffiClass, ffiObject, "lock_owner", fi->lock_owner))
            break;

        ret = true;
    } while(0);

    CSLogTraceLeave("bool FUSE26Util::fillFUSEFileInfo(%p, %p, %p): %d", env, fi, ffiObject, ret);
    return ret;
}
static jobject android_net_wifi_getLinkLayerStats (JNIEnv *env, jclass cls, jint iface)  {

    wifi_stats_result_handler handler;
    memset(&handler, 0, sizeof(handler));
    handler.on_link_stats_results = &onLinkStatsResults;
    wifi_interface_handle handle = getIfaceHandle(env, cls, iface);
    int result = wifi_get_link_stats(0, handle, handler);
    if (result < 0) {
        ALOGE("android_net_wifi_getLinkLayerStats: failed to get link statistics\n");
        return NULL;
    }

    jobject wifiLinkLayerStats = createObject(env, "android/net/wifi/WifiLinkLayerStats");
    if (wifiLinkLayerStats == NULL) {
       ALOGE("Error in allocating wifiLinkLayerStats");
       return NULL;
    }

    setIntField(env, wifiLinkLayerStats, "beacon_rx", link_stat.beacon_rx);
    setIntField(env, wifiLinkLayerStats, "rssi_mgmt", link_stat.rssi_mgmt);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_be", link_stat.ac[WIFI_AC_BE].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_bk", link_stat.ac[WIFI_AC_BK].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_vi", link_stat.ac[WIFI_AC_VI].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "rxmpdu_vo", link_stat.ac[WIFI_AC_VO].rx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_be", link_stat.ac[WIFI_AC_BE].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_bk", link_stat.ac[WIFI_AC_BK].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_vi", link_stat.ac[WIFI_AC_VI].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "txmpdu_vo", link_stat.ac[WIFI_AC_VO].tx_mpdu);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_be", link_stat.ac[WIFI_AC_BE].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_bk", link_stat.ac[WIFI_AC_BK].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_vi",  link_stat.ac[WIFI_AC_VI].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "lostmpdu_vo", link_stat.ac[WIFI_AC_VO].mpdu_lost);
    setLongField(env, wifiLinkLayerStats, "retries_be", link_stat.ac[WIFI_AC_BE].retries);
    setLongField(env, wifiLinkLayerStats, "retries_bk", link_stat.ac[WIFI_AC_BK].retries);
    setLongField(env, wifiLinkLayerStats, "retries_vi", link_stat.ac[WIFI_AC_VI].retries);
    setLongField(env, wifiLinkLayerStats, "retries_vo", link_stat.ac[WIFI_AC_VO].retries);


    setIntField(env, wifiLinkLayerStats, "on_time", radio_stat.on_time);
    setIntField(env, wifiLinkLayerStats, "tx_time", radio_stat.tx_time);
    setIntField(env, wifiLinkLayerStats, "rx_time", radio_stat.rx_time);
    setIntField(env, wifiLinkLayerStats, "on_time_scan", radio_stat.on_time_scan);

    return wifiLinkLayerStats;
}
static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
{
    setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent);

    setIntFieldMax(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel, 100);
    setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage);
    setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature);

    const int SIZE = 128;
    char buf[SIZE];

    if (readFromFile(gPaths.batteryStatusPath, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf));
    else
        env->SetIntField(obj, gFieldIds.mBatteryStatus,
                         gConstants.statusUnknown);

    if (readFromFile(gPaths.batteryHealthPath, buf, SIZE) > 0)
        env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf));

    if (readFromFile(gPaths.batteryTechnologyPath, buf, SIZE) > 0)
        env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf));

    unsigned int i;
    String8 path;
    jboolean acOnline = false;
    jboolean usbOnline = false;
    jboolean wirelessOnline = false;

    for (i = 0; i < gChargerNames.size(); i++) {
        path.clear();
        path.appendFormat("%s/%s/online", POWER_SUPPLY_PATH,
                          gChargerNames[i].string());

        if (readFromFile(path, buf, SIZE) > 0) {
            if (buf[0] != '0') {
                path.clear();
                path.appendFormat("%s/%s/type", POWER_SUPPLY_PATH,
                                  gChargerNames[i].string());
                switch(readPowerSupplyType(path)) {
                case ANDROID_POWER_SUPPLY_TYPE_AC:
                    acOnline = true;
                    break;
                case ANDROID_POWER_SUPPLY_TYPE_USB:
                    usbOnline = true;
                    break;
                case ANDROID_POWER_SUPPLY_TYPE_WIRELESS:
                    wirelessOnline = true;
                    break;
                default:
                    ALOGW("%s: Unknown power supply type",
                          gChargerNames[i].string());
                }
            }
        }
    }

    env->SetBooleanField(obj, gFieldIds.mAcOnline, acOnline);
    env->SetBooleanField(obj, gFieldIds.mUsbOnline, usbOnline);
    env->SetBooleanField(obj, gFieldIds.mWirelessOnline, wirelessOnline);
}
コード例 #14
0
/*
 * Class:     com_ibm_opencard_terminal_pcsc10_OCFPCSC1
 * Method:    SCardGetStatusChange
 * Signature: (II[Lcom/ibm/opencard/terminal/pcsc10/PcscReaderState;)V
 */
JNIEXPORT void JNICALL Java_com_ibm_opencard_terminal_pcsc10_OCFPCSC1_SCardGetStatusChange
(JNIEnv *env, jobject obj, jint context, jint timeout, jobjectArray jReaderState) {

    SCARD_READERSTATE   *readerState;
    int         numReaderState;
    int         ii;
    long        returnCode;
    jobject     objReaderState;
    jbyteArray  jATR;

    /* First access the PcscReaderState structure to initialize the return       */
    /* value. Allocate a reader state array for each java ReaderState structure. */

    numReaderState = env->GetArrayLength(jReaderState);
    if (numReaderState < 1) {
        throwPcscException(env, obj, "SCardGetStatusChange",
                           "size of ReaderState array must be greater than 0 elements", 0);
        return;
    }

    readerState = (SCARD_READERSTATE *)malloc(numReaderState * sizeof(SCARD_READERSTATE));
    if (readerState == NULL) {
        throwPcscException(env, obj, "SCardGetStatusChange", "error allocating memory for the readerState buffer", 0);
        return;
    }

    /* clear the allocated memory */
    memset(readerState, 0x00, numReaderState * sizeof(SCARD_READERSTATE));

    /* Now get each Java reader state structure and translate it into C++ */
    for (ii=0; ii<numReaderState; ii++) {
        objReaderState = env->GetObjectArrayElement(jReaderState, ii);
        if (env->ExceptionOccurred() != NULL) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting elements from the readerState array", 0);
            return;
        }

        returnCode = getIntField(env, objReaderState, "CurrentState", (long *)&readerState[ii].dwCurrentState);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting CurrentState field from the readerState record", 0);
            return;
        }

        returnCode = getIntField(env, objReaderState, "EventState", (long*)&readerState[ii].dwEventState);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting EventState field from the readerState record", 0);
            return;
        }

        readerState[ii].szReader = (const char *)accessStringField(env, objReaderState, "Reader");
        if (readerState[ii].szReader == NULL) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting Reader field from readerState record", 0);
            return;
        }

        int maxSize;
        returnCode = accessByteArray(env, objReaderState, "UserData", (unsigned char **)&readerState[ii].pvUserData, &maxSize);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting UserData field from readerState record", 0);
            return;
        }
    }

    /* set the response timeout to 1000ms */

    returnCode =  SCardGetStatusChange((SCARDCONTEXT)context, 1000, readerState, numReaderState);
    if (returnCode != SCARD_S_SUCCESS) {
        free(readerState);
        throwPcscException(env, obj, "SCardGetStatusChange", "error executing SCardGetStatusChange", returnCode);
        return;
    }

    readerState[0].dwCurrentState = readerState[0].dwEventState;

    /* write back the informations from the readerStatus to the java structures */
    for (ii=0; ii<numReaderState; ii++) {
        objReaderState = env->GetObjectArrayElement(jReaderState, ii);
        if (env->ExceptionOccurred() != NULL) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error getting array elements", returnCode);
            return;
        }

        returnCode = setIntField(env, objReaderState, "EventState", readerState[ii].dwEventState);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error setting the EventState field", returnCode);
            return;
        }

        returnCode = releaseStringField(env, objReaderState, "Reader", (const char *)readerState[ii].szReader);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error setting the Reader field", returnCode);
            return;
        }

        returnCode = releaseByteArray(env, objReaderState, "UserData", (unsigned char *)readerState[ii].pvUserData);
        if (returnCode) {
            free(readerState);
            throwPcscException(env, obj, "SCardGetStatusChange", "error setting the UserData", returnCode);
            return;
        }

        // buffer for length of ATR
        jsize lenATR = (jsize)readerState[0].cbAtr;

        // check the length of the ATR in the PCSC ReaderState
        // if > 0 copy ATR to java ReaderState

        if (lenATR > 0) {

            // create new java bytearray with length of current ATR
            jATR = env->NewByteArray(lenATR);

            // copy PCSC ATR to jATR
            env->SetByteArrayRegion(jATR, 0, lenATR, (jbyte *)readerState[ii].rgbAtr);

            // find the ReaderState-Class
            jclass clsReaderState = env->GetObjectClass(objReaderState);

            // get the field ID from ATR-field
            jfieldID fldATR = env->GetFieldID(clsReaderState, "ATR", "[B");

            // set the ATR-field within the ReaderStateObject
            env->SetObjectField(objReaderState, fldATR, jATR);
        }
    }

    free(readerState);

    return;
}
コード例 #15
0
JNIEXPORT void JNICALL Java_shmem_Constant_setConstant(JNIEnv *env, jobject obj)
{
    jclass c = (*env)->GetObjectClass(env, obj);
    setIntField(env, c, obj, "CMP_EQ", SHMEM_CMP_EQ);
    setIntField(env, c, obj, "CMP_GE", SHMEM_CMP_GE);
    setIntField(env, c, obj, "CMP_GT", SHMEM_CMP_GT);
    setIntField(env, c, obj, "CMP_LE", SHMEM_CMP_LE);
    setIntField(env, c, obj, "CMP_LT", SHMEM_CMP_LT);
    setIntField(env, c, obj, "CMP_NE", SHMEM_CMP_NE);

    setIntField(env, c, obj, "BARRIER_SYNC_SIZE",
                        SHMEM_BARRIER_SYNC_SIZE);
    setIntField(env, c, obj, "BCAST_SYNC_SIZE",
                        SHMEM_BCAST_SYNC_SIZE);
    setIntField(env, c, obj, "COLLECT_SYNC_SIZE",
                        SHMEM_COLLECT_SYNC_SIZE);
    setIntField(env, c, obj, "REDUCE_SYNC_SIZE",
                        SHMEM_REDUCE_SYNC_SIZE);
    setIntField(env, c, obj, "REDUCE_MIN_WRKDATA_SIZE",
                        SHMEM_REDUCE_MIN_WRKDATA_SIZE);
    setIntField(env, c, obj, "SYNC_VALUE",
                        SHMEM_SYNC_VALUE);
}