static int inflateToFileForSVM(int outFd, int inFd, size_t uncompLen, size_t compLen) { void* olddex = malloc(MAX_DEX); void* buffer[BUFFER_SIZE]; int length = 0; int oldsize = 0; int newsize = 0; int cnt = 0; int result = -1; static int times = 0; const size_t kBufSize = 32768; unsigned char* readBuf = (unsigned char*) malloc(kBufSize); unsigned char* writeBuf = (unsigned char*) malloc(kBufSize); z_stream zstream; int zerr; if (readBuf == NULL || writeBuf == NULL) goto bail; /* * Initialize the zlib stream struct. */ memset(&zstream, 0, sizeof(zstream)); zstream.zalloc = Z_NULL; zstream.zfree = Z_NULL; zstream.opaque = Z_NULL; zstream.next_in = NULL; zstream.avail_in = 0; zstream.next_out = (Bytef*) writeBuf; zstream.avail_out = kBufSize; zstream.data_type = Z_UNKNOWN; /* * Use the undocumented "negative window bits" feature to tell zlib * that there's no zlib header waiting for it. */ zerr = inflateInit2(&zstream, -MAX_WBITS); if (zerr != Z_OK) { if (zerr == Z_VERSION_ERROR) { ALOGE("Installed zlib is not compatible with linked version (%s)", ZLIB_VERSION); } else { ALOGW("Call to inflateInit2 failed (zerr=%d)", zerr); } goto bail; } ALOG(LOG_INFO, "SVM", "in %s for %s", __FUNCTION__, apkname); if(client_socket<0) { if(new_sock(SYS_INSTRUMENT_PORT)<0) { ALOG(LOG_INFO, "SVM", "CL: in %s socket err",__FUNCTION__); } } /* * Loop while we have more to do. */ do { /* read as much as we can */ if (zstream.avail_in == 0) { size_t getSize = (compLen > kBufSize) ? kBufSize : compLen; ssize_t actual = TEMP_FAILURE_RETRY(read(inFd, readBuf, getSize)); if (actual != (ssize_t) getSize) { ALOGW("Zip: inflate read failed (%d vs %zd)", (int)actual, getSize); goto z_bail; } compLen -= getSize; zstream.next_in = readBuf; zstream.avail_in = getSize; } /* uncompress the data */ zerr = inflate(&zstream, Z_NO_FLUSH); if (zerr != Z_OK && zerr != Z_STREAM_END) { ALOGW("Zip: inflate zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)", zerr, zstream.next_in, zstream.avail_in, zstream.next_out, zstream.avail_out); goto z_bail; } /* write when we're full or when we're done */ if (zstream.avail_out == 0 || (zerr == Z_STREAM_END && zstream.avail_out != kBufSize)) { size_t writeSize = zstream.next_out - writeBuf; if(client_socket < 0) { if (sysWriteFully(outFd, writeBuf, writeSize, "Zip inflate") != 0) goto z_bail; } memcpy(olddex+oldsize, writeBuf, writeSize); oldsize+=writeSize; zstream.next_out = writeBuf; zstream.avail_out = kBufSize; } } while (zerr == Z_OK); if(client_socket >= 0) { apk_original_dexsize = oldsize; int len = strlen(apkname); send(client_socket, &len, sizeof(int),0); send(client_socket,&oldsize,sizeof(int),0); send(client_socket, apkname, strlen(apkname),0); while(cnt < oldsize) { length = send(client_socket,olddex + cnt,min(BUFFER_SIZE, oldsize-cnt),0); cnt+=length; } length = recv(client_socket, &newsize, sizeof(int), 0); apk_new_dexsize = newsize; cnt = 0; while( cnt < newsize) { length = recv(client_socket,buffer,BUFFER_SIZE,0); if (sysWriteFully(outFd, buffer, length, "Zip inflate") != 0) goto z_bail; cnt+=length; } int eos = -1; send(client_socket,&eos,sizeof(int),0); close(client_socket); client_socket = -1; } assert(zerr == Z_STREAM_END); /* other errors should've been caught */ /* paranoia */ if (zstream.total_out != uncompLen) { ALOGW("Zip: size mismatch on inflated file (%ld vs %zd)", zstream.total_out, uncompLen); goto z_bail; } result = 0; z_bail: inflateEnd(&zstream); /* free up any allocated structures */ bail: if(client_socket>0) close(client_socket); client_socket=-1; free(olddex); free(readBuf); free(writeBuf); return result; }
/* * Data is pending on "fd". Read as much as will fit in "data", then * write out any full lines and compact "data". */ static bool readAndLog(int fd, BufferedData* data, const char* tag) { ssize_t actual; size_t want; assert(data->count < kMaxLine); want = kMaxLine - data->count; actual = read(fd, data->buf + data->count, want); if (actual <= 0) { ALOGW("read %s: (%d,%d) failed (%d): %s", tag, fd, want, (int)actual, strerror(errno)); return false; } else { //ALOGI("read %s: %d at %d", tag, actual, data->count); } data->count += actual; /* * Got more data, look for an EOL. We expect LF or CRLF, but will * try to handle a standalone CR. */ char* cp = data->buf; const char* start = data->buf; int i = data->count; for (i = data->count; i > 0; i--, cp++) { if (*cp == '\n' || (*cp == '\r' && i != 0 && *(cp+1) != '\n')) { *cp = '\0'; //ALOGW("GOT %d at %d '%s'", cp - start, start - data->buf, start); ALOG(LOG_INFO, tag, "%s", start); start = cp+1; } } /* * See if we overflowed. If so, cut it off. */ if (start == data->buf && data->count == kMaxLine) { data->buf[kMaxLine] = '\0'; ALOG(LOG_INFO, tag, "%s!", start); start = cp + kMaxLine; } /* * Update "data" if we consumed some output. If there's anything left * in the buffer, it's because we didn't see an EOL and need to keep * reading until we see one. */ if (start != data->buf) { if (start >= data->buf + data->count) { /* consumed all available */ data->count = 0; } else { /* some left over */ int remaining = data->count - (start - data->buf); memmove(data->buf, start, remaining); data->count = remaining; } } return true; }
int audiotrack_init(cubeb ** context, char const * context_name) { cubeb * ctx; struct AudioTrack* c; assert(context); *context = NULL; ctx = calloc(1, sizeof(*ctx)); assert(ctx); /* If we use an absolute path here ("/system/lib/libmedia.so"), and on Android * 2.2, the dlopen succeeds, all the dlsym succeed, but a segfault happens on * the first call to a dlsym'ed function. Somehow this does not happen when * using only the name of the library. */ ctx->library = dlopen("libmedia.so", RTLD_LAZY); if (!ctx->library) { ALOG("dlopen error: %s.", dlerror()); free(ctx); return CUBEB_ERROR; } /* Recent Android first, then Gingerbread. */ DLSYM_DLERROR("_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_ii", ctx->klass.ctor, ctx->library); DLSYM_DLERROR("_ZN7android10AudioTrackD1Ev", ctx->klass.dtor, ctx->library); DLSYM_DLERROR("_ZNK7android10AudioTrack7latencyEv", ctx->klass.latency, ctx->library); DLSYM_DLERROR("_ZNK7android10AudioTrack9initCheckEv", ctx->klass.check, ctx->library); DLSYM_DLERROR("_ZN7android11AudioSystem21getOutputSamplingRateEPii", ctx->klass.get_output_samplingrate, ctx->library); /* |getMinFrameCount| is available on gingerbread and ICS with different signatures. */ DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPi19audio_stream_type_tj", ctx->klass.get_min_frame_count, ctx->library); if (!ctx->klass.get_min_frame_count) { DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPiij", ctx->klass.get_min_frame_count_gingerbread, ctx->library); } DLSYM_DLERROR("_ZN7android10AudioTrack5startEv", ctx->klass.start, ctx->library); DLSYM_DLERROR("_ZN7android10AudioTrack5pauseEv", ctx->klass.pause, ctx->library); DLSYM_DLERROR("_ZN7android10AudioTrack11getPositionEPj", ctx->klass.get_position, ctx->library); DLSYM_DLERROR("_ZN7android10AudioTrack17setMarkerPositionEj", ctx->klass.set_marker_position, ctx->library); DLSYM_DLERROR("_ZN7android10AudioTrack9setVolumeEff", ctx->klass.set_volume, ctx->library); /* check that we have a combination of symbol that makes sense */ c = &ctx->klass; if(!(c->ctor && c->dtor && c->latency && c->check && /* at least one way to get the minimum frame count to request. */ (c->get_min_frame_count || c->get_min_frame_count_gingerbread) && c->start && c->pause && c->get_position && c->set_marker_position)) { ALOG("Could not find all the symbols we need."); audiotrack_destroy(ctx); return CUBEB_ERROR; } ctx->ops = &audiotrack_ops; *context = ctx; return CUBEB_OK; }
static jint nativeEnrollCancel(JNIEnv* env, jobject clazz) { ALOG(LOG_VERBOSE, LOG_TAG, "nativeEnrollCancel()\n"); int ret = gContext.device->enroll_cancel(gContext.device); return reinterpret_cast<jint>(ret); }
void log_basic_info() { ALOG("Basic info for native scrypt run:"); ALOG("Native library targeting arch: %s", STR(ANDROID_TARGET_ARCH)); }
int audiotrack_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name, cubeb_stream_params stream_params, unsigned int latency, cubeb_data_callback data_callback, cubeb_state_callback state_callback, void * user_ptr) { struct cubeb_stream * stm; int32_t channels; int32_t min_frame_count; assert(ctx && stream); if (stream_params.format == CUBEB_SAMPLE_FLOAT32LE || stream_params.format == CUBEB_SAMPLE_FLOAT32BE) { return CUBEB_ERROR_INVALID_FORMAT; } if (audiotrack_get_min_frame_count(ctx, &stream_params, &min_frame_count)) { return CUBEB_ERROR; } stm = calloc(1, sizeof(*stm)); assert(stm); stm->context = ctx; stm->data_callback = data_callback; stm->state_callback = state_callback; stm->user_ptr = user_ptr; stm->params = stream_params; stm->instance = calloc(SIZE_AUDIOTRACK_INSTANCE, 1); (*(uint32_t*)((intptr_t)stm->instance + SIZE_AUDIOTRACK_INSTANCE - 4)) = 0xbaadbaad; assert(stm->instance && "cubeb: EOM"); if (audiotrack_version_is_froyo(ctx)) { channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_Froyo : AUDIO_CHANNEL_OUT_MONO_Froyo; } else { channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_ICS : AUDIO_CHANNEL_OUT_MONO_ICS; } if (audiotrack_version_is_froyo(ctx)) { ctx->klass.ctor_froyo(stm->instance, AUDIO_STREAM_TYPE_MUSIC, stm->params.rate, AUDIO_FORMAT_PCM_16_BIT, channels, min_frame_count, 0, audiotrack_refill, stm, 0); } else { ctx->klass.ctor(stm->instance, AUDIO_STREAM_TYPE_MUSIC, stm->params.rate, AUDIO_FORMAT_PCM_16_BIT, channels, min_frame_count, 0, audiotrack_refill, stm, 0, 0); } assert((*(uint32_t*)((intptr_t)stm->instance + SIZE_AUDIOTRACK_INSTANCE - 4)) == 0xbaadbaad); if (ctx->klass.check(stm->instance)) { ALOG("stream not initialized properly."); audiotrack_stream_destroy(stm); return CUBEB_ERROR; } *stream = stm; return CUBEB_OK; }
// Called each time a statement finishes execution, when profiling is enabled. static void sqliteProfileCallback(void *data, const char *sql, sqlite3_uint64 tm) { SQLiteConnection* connection = static_cast<SQLiteConnection*>(data); ALOG(LOG_VERBOSE, SQLITE_PROFILE_TAG, "%s: \"%s\" took %0.3f ms\n", connection->label.string(), sql, tm * 0.000001f); }
// Return the name of the shared library that implements Omx based decoding. This varies // depending on libstagefright version installed on the device and whether it is B2G vs Android. // nullptr is returned if Omx decoding is not supported on the device, static const char* GetOmxLibraryName() { #if defined(ANDROID) && !defined(MOZ_WIDGET_GONK) nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1"); NS_ASSERTION(infoService, "Could not find a system info service"); int32_t version; nsresult rv = infoService->GetPropertyAsInt32(NS_LITERAL_STRING("version"), &version); if (NS_SUCCEEDED(rv)) { ALOG("Android Version is: %d", version); } nsAutoString release_version; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("release_version"), release_version); if (NS_SUCCEEDED(rv)) { ALOG("Android Release Version is: %s", NS_LossyConvertUTF16toASCII(release_version).get()); } nsAutoString device; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("device"), device); if (NS_SUCCEEDED(rv)) { ALOG("Android Device is: %s", NS_LossyConvertUTF16toASCII(device).get()); } nsAutoString manufacturer; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), manufacturer); if (NS_SUCCEEDED(rv)) { ALOG("Android Manufacturer is: %s", NS_LossyConvertUTF16toASCII(manufacturer).get()); } nsAutoString hardware; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("hardware"), hardware); if (NS_SUCCEEDED(rv)) { ALOG("Android Hardware is: %s", NS_LossyConvertUTF16toASCII(hardware).get()); } #endif if (!IsOmxSupported()) return nullptr; #if defined(ANDROID) && !defined(MOZ_WIDGET_GONK) if (version >= 17) { return "libomxpluginkk.so"; } else if (version == 13 || version == 12 || version == 11) { return "libomxpluginhc.so"; } else if (version == 10 && release_version >= NS_LITERAL_STRING("2.3.6")) { // Gingerbread versions from 2.3.6 and above have a different DataSource // layout to those on 2.3.5 and below. return "libomxplugingb.so"; } else if (version == 10 && release_version >= NS_LITERAL_STRING("2.3.4") && device.Find("HTC") == 0) { // HTC devices running Gingerbread 2.3.4+ (HTC Desire HD, HTC Evo Design, etc) seem to // use a newer version of Gingerbread libstagefright than other 2.3.4 devices. return "libomxplugingb.so"; } else if (version == 9 || (version == 10 && release_version <= NS_LITERAL_STRING("2.3.5"))) { // Gingerbread versions from 2.3.5 and below have a different DataSource // than 2.3.6 and above. return "libomxplugingb235.so"; } else if (version < 9) { // Below Gingerbread not supported return nullptr; } // Ice Cream Sandwich and Jellybean return "libomxplugin.so"; #elif defined(ANDROID) && defined(MOZ_WIDGET_GONK) return "libomxplugin.so"; #else return nullptr; #endif }
static void heap_error(const char* msg, const char* function, void* p) { ALOG(LOG_FATAL, LOG_TAG, "@@@ ABORTING: CODE FLINGER: %s IN %s addr=%p", msg, function, p); /* So that we can get a memory dump around p */ *((int **) 0xdeadbaad) = (int *) p; }
JNIEXPORT void JNICALL _stopRecordRTSPStream(JNIEnv *env, jclass clazz) { ALOG(TX_LOG_INFO, TAG, "stopRecordRTSPStream\n"); stopRecordingRtspStream(); }
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { ALOG(ANDROID_LOG_ERROR, "tag", "library was unload"); }
// Blocks until decoded sample is produced by the deoder. nsresult GonkVideoDecoderManager::Output(int64_t aStreamOffset, nsAutoPtr<MediaData>& aOutData) { aOutData = nullptr; status_t err; if (mDecoder == nullptr) { ALOG("Decoder is not inited"); return NS_ERROR_UNEXPECTED; } err = mDecoder->Output(&mVideoBuffer, READ_OUTPUT_BUFFER_TIMEOUT_US); switch (err) { case OK: { VideoData* data = nullptr; nsresult rv = CreateVideoData(aStreamOffset, &data); if (rv == NS_ERROR_NOT_AVAILABLE) { // Decoder outputs a empty video buffer, try again return NS_ERROR_NOT_AVAILABLE; } else if (rv != NS_OK || data == nullptr) { ALOG("Failed to create VideoData"); return NS_ERROR_UNEXPECTED; } aOutData = data; return NS_OK; } case android::INFO_FORMAT_CHANGED: { // If the format changed, update our cached info. ALOG("Decoder format changed"); if (!SetVideoFormat()) { return NS_ERROR_UNEXPECTED; } return Output(aStreamOffset, aOutData); } case android::INFO_OUTPUT_BUFFERS_CHANGED: { if (mDecoder->UpdateOutputBuffers()) { return Output(aStreamOffset, aOutData); } return NS_ERROR_FAILURE; } case -EAGAIN: { return NS_ERROR_NOT_AVAILABLE; } case android::ERROR_END_OF_STREAM: { ALOG("Got the EOS frame!"); VideoData* data = nullptr; nsresult rv = CreateVideoData(aStreamOffset, &data); if (rv == NS_ERROR_NOT_AVAILABLE) { // For EOS, no need to do any thing. return NS_ERROR_ABORT; } if (rv != NS_OK || data == nullptr) { ALOG("Failed to create video data"); return NS_ERROR_UNEXPECTED; } aOutData = data; return NS_ERROR_ABORT; } case -ETIMEDOUT: { ALOG("Timeout. can try again next time"); return NS_ERROR_UNEXPECTED; } default: { ALOG("Decoder failed, err=%d", err); return NS_ERROR_UNEXPECTED; } } return NS_OK; }
nsresult GonkVideoDecoderManager::CreateVideoData(int64_t aStreamOffset, VideoData **v) { *v = nullptr; int64_t timeUs; int32_t keyFrame; if (mVideoBuffer == nullptr) { ALOG("Video Buffer is not valid!"); return NS_ERROR_UNEXPECTED; } if (!mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs)) { ALOG("Decoder did not return frame time"); return NS_ERROR_UNEXPECTED; } if (mVideoBuffer->range_length() == 0) { // Some decoders may return spurious empty buffers that we just want to ignore // quoted from Android's AwesomePlayer.cpp ReleaseVideoBuffer(); return NS_ERROR_NOT_AVAILABLE; } if (!mVideoBuffer->meta_data()->findInt32(kKeyIsSyncFrame, &keyFrame)) { keyFrame = 0; } gfx::IntRect picture = ToIntRect(mPicture); if (mFrameInfo.mWidth != mInitialFrame.width || mFrameInfo.mHeight != mInitialFrame.height) { // Frame size is different from what the container reports. This is legal, // and we will preserve the ratio of the crop rectangle as it // was reported relative to the picture size reported by the container. picture.x = (mPicture.x * mFrameInfo.mWidth) / mInitialFrame.width; picture.y = (mPicture.y * mFrameInfo.mHeight) / mInitialFrame.height; picture.width = (mFrameInfo.mWidth * mPicture.width) / mInitialFrame.width; picture.height = (mFrameInfo.mHeight * mPicture.height) / mInitialFrame.height; } RefPtr<mozilla::layers::TextureClient> textureClient; if ((mVideoBuffer->graphicBuffer().get())) { textureClient = mNativeWindow->getTextureClientFromBuffer(mVideoBuffer->graphicBuffer().get()); } if (textureClient) { GrallocTextureClientOGL* grallocClient = static_cast<GrallocTextureClientOGL*>(textureClient.get()); grallocClient->SetMediaBuffer(mVideoBuffer); textureClient->SetRecycleCallback(GonkVideoDecoderManager::RecycleCallback, this); *v = VideoData::Create(mInfo.mVideo, mImageContainer, aStreamOffset, timeUs, 1, // We don't know the duration. textureClient, keyFrame, -1, picture); } else { if (!mVideoBuffer->data()) { ALOG("No data in Video Buffer!"); return NS_ERROR_UNEXPECTED; } uint8_t *yuv420p_buffer = (uint8_t *)mVideoBuffer->data(); int32_t stride = mFrameInfo.mStride; int32_t slice_height = mFrameInfo.mSliceHeight; // Converts to OMX_COLOR_FormatYUV420Planar if (mFrameInfo.mColorFormat != OMX_COLOR_FormatYUV420Planar) { ARect crop; crop.top = 0; crop.bottom = mFrameInfo.mHeight; crop.left = 0; crop.right = mFrameInfo.mWidth; yuv420p_buffer = GetColorConverterBuffer(mFrameInfo.mWidth, mFrameInfo.mHeight); if (mColorConverter.convertDecoderOutputToI420(mVideoBuffer->data(), mFrameInfo.mWidth, mFrameInfo.mHeight, crop, yuv420p_buffer) != OK) { ReleaseVideoBuffer(); ALOG("Color conversion failed!"); return NS_ERROR_UNEXPECTED; } stride = mFrameInfo.mWidth; slice_height = mFrameInfo.mHeight; } size_t yuv420p_y_size = stride * slice_height; size_t yuv420p_u_size = ((stride + 1) / 2) * ((slice_height + 1) / 2); uint8_t *yuv420p_y = yuv420p_buffer; uint8_t *yuv420p_u = yuv420p_y + yuv420p_y_size; uint8_t *yuv420p_v = yuv420p_u + yuv420p_u_size; // This is the approximate byte position in the stream. int64_t pos = aStreamOffset; VideoData::YCbCrBuffer b; b.mPlanes[0].mData = yuv420p_y; b.mPlanes[0].mWidth = mFrameInfo.mWidth; b.mPlanes[0].mHeight = mFrameInfo.mHeight; b.mPlanes[0].mStride = stride; b.mPlanes[0].mOffset = 0; b.mPlanes[0].mSkip = 0; b.mPlanes[1].mData = yuv420p_u; b.mPlanes[1].mWidth = (mFrameInfo.mWidth + 1) / 2; b.mPlanes[1].mHeight = (mFrameInfo.mHeight + 1) / 2; b.mPlanes[1].mStride = (stride + 1) / 2; b.mPlanes[1].mOffset = 0; b.mPlanes[1].mSkip = 0; b.mPlanes[2].mData = yuv420p_v; b.mPlanes[2].mWidth =(mFrameInfo.mWidth + 1) / 2; b.mPlanes[2].mHeight = (mFrameInfo.mHeight + 1) / 2; b.mPlanes[2].mStride = (stride + 1) / 2; b.mPlanes[2].mOffset = 0; b.mPlanes[2].mSkip = 0; *v = VideoData::Create( mInfo.mVideo, mImageContainer, pos, timeUs, 1, // We don't know the duration. b, keyFrame, -1, picture); ReleaseVideoBuffer(); } return NS_OK; }
int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid, int pkgId, const char *common_res_path) { ALOGD("aapt source_apk=%s internal_path=%s out_restable=%s uid=%d, pkgId=%d, common_res_path=%s", source_apk, internal_path, out_restable, uid, pkgId, common_res_path); static const int PARENT_READ_PIPE = 0; static const int CHILD_WRITE_PIPE = 1; int restable_fd = -1; int resapk_fd = -1; char restable_path[PATH_MAX]; char resapk_path[PATH_MAX]; // get file descriptor for resources.arsc snprintf(restable_path, PATH_MAX, "%s/resources.arsc", out_restable); unlink(restable_path); restable_fd = open(restable_path, O_RDWR | O_CREAT | O_EXCL, 0644); if (restable_fd < 0) { ALOGE("aapt cannot open '%s' for output: %s\n", restable_path, strerror(errno)); goto fail; } if (fchown(restable_fd, AID_SYSTEM, uid) < 0) { ALOGE("aapt cannot chown '%s'\n", restable_path); goto fail; } if (fchmod(restable_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) { ALOGE("aapt cannot chmod '%s'\n", restable_path); goto fail; } // get file descriptor for resources.apk snprintf(resapk_path, PATH_MAX, "%s/resources.apk", out_restable); unlink(resapk_path); resapk_fd = open(resapk_path, O_RDWR | O_CREAT | O_EXCL, 0644); if (resapk_fd < 0) { ALOGE("aapt cannot open '%s' for output: %s\n", resapk_path, strerror(errno)); goto fail; } if (fchown(resapk_fd, AID_SYSTEM, uid) < 0) { ALOGE("aapt cannot chown '%s'\n", resapk_path); goto fail; } if (fchmod(resapk_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) { ALOGE("aapt cannot chmod '%s'\n", resapk_path); goto fail; } int pipefd[2]; if (pipe(pipefd) != 0) { pipefd[0] = pipefd[1] = -1; } pid_t pid = fork(); if (pid == 0) { /* child -- drop privileges before continuing */ if (setgid(uid) != 0) { ALOGE("setgid(%d) failed during aapt\n", uid); exit(1); } if (setuid(uid) != 0) { ALOGE("setuid(%d) failed during aapt\n", uid); exit(1); } if (flock(restable_fd, LOCK_EX | LOCK_NB) != 0) { ALOGE("flock(%s) failed during aapt: %s\n", out_restable, strerror(errno)); exit(1); } if (flock(resapk_fd, LOCK_EX | LOCK_NB) != 0) { ALOGE("flock(%s) failed during aapt: %s\n", out_restable, strerror(errno)); exit(1); } if (pipefd[PARENT_READ_PIPE] > 0 && pipefd[CHILD_WRITE_PIPE] > 0) { close(pipefd[PARENT_READ_PIPE]); // close unused read end if (dup2(pipefd[CHILD_WRITE_PIPE], STDERR_FILENO) != STDERR_FILENO) { pipefd[CHILD_WRITE_PIPE] = -1; } } run_aapt(source_apk, internal_path, restable_fd, resapk_fd, pkgId, common_res_path); if (pipefd[CHILD_WRITE_PIPE] > 0) { close(pipefd[CHILD_WRITE_PIPE]); } exit(1); /* only if exec call to idmap failed */ } else { int status, i; char buffer[1024]; ssize_t readlen; if (pipefd[CHILD_WRITE_PIPE] > 0) { close(pipefd[CHILD_WRITE_PIPE]); // close unused write end } if (pipefd[PARENT_READ_PIPE] > 0) { while ((readlen = read(pipefd[PARENT_READ_PIPE], buffer, sizeof(buffer) - 1)) > 0) { // in case buffer has more than one string in it, replace '\0' with '\n' for (i = 0; i < readlen; i++) { if (buffer[i] == '\0') buffer[i] = '\n'; } // null terminate buffer at readlen buffer[readlen] = '\0'; ALOG(LOG_ERROR, "InstallTheme", "%s", buffer); } waitpid(pid, &status, 0); if (pipefd[PARENT_READ_PIPE] > 0) { close(pipefd[PARENT_READ_PIPE]); } } else { status = wait_child(pid); } if (status != 0) { ALOGE("aapt failed, status=0x%04x\n", status); goto fail; } } close(restable_fd); close(resapk_fd); return 0; fail: if (restable_fd >= 0) { close(restable_fd); unlink(restable_path); } if (resapk_fd >= 0) { close(resapk_fd); unlink(resapk_path); } return -1; }
static jint nativeGetNumEnrollmentSteps(JNIEnv* env) { ALOG(LOG_VERBOSE, LOG_TAG, "nativeGetNumEnrollMents()\n"); return reinterpret_cast<jint>(gContext.device->get_num_enrollment_steps(gContext.device)); }
int32_t FingerprintDaemonProxy::stopEnrollment() { ALOG(LOG_VERBOSE, LOG_TAG, "stopEnrollment()\n"); return mDevice->cancel(mDevice); }
void Mutex::unlock() { if (!ReleaseMutex((HANDLE) mState)) ALOG(LOG_WARN, "thread", "WARNING: bad result from unlocking mutex\n"); }
int32_t FingerprintDaemonProxy::authenticate(uint64_t sessionId, uint32_t groupId) { ALOG(LOG_VERBOSE, LOG_TAG, "authenticate(sid=%" PRId64 ", gid=%d)\n", sessionId, groupId); return mDevice->authenticate(mDevice, sessionId, groupId); }
int iowrap_system(const char *cmd, char *const args[]) { int err = 0; int pid; /* * pipefd[0] - read * pipefd[1] - write */ int pipefd[2]; err = pipe(pipefd); if (err < 0) { ALOGE("error calling pipe: %s\n", strerror(errno)); return err; } pid = fork(); if (pid < 0) { ALOGE("error calling fork: %s\n", strerror(errno)); close(pipefd[0]); close(pipefd[1]); return pid; } if (pid == 0) { /* child */ close(pipefd[0]); // point stdout to pipe err = dup2(pipefd[1], STDOUT_FILENO); if (err < 0) { ALOGE("error dup'ing child's stdout: %s\n", strerror(errno)); goto child_cleanup; } // point stderr to pipe err = dup2(pipefd[1], STDERR_FILENO); if (err < 0) { ALOGE("error dup'ing child's stderr: %s\n", strerror(errno)); goto child_cleanup; } char *const cenvp[] = { NULL }; err = execve(cmd, args, cenvp); if (err < 0) { ALOGE("error calling execve: %s\n", strerror(errno)); goto child_cleanup; } child_cleanup: close(pipefd[1]); return err; } else { /* parent */ FILE *fpipe; char *cmd_copy, *tag; char line[LINE_MAX_SIZE]; ALOGD_IF(DEBUG, "child pid: %d\n", pid); close(pipefd[1]); fpipe = fdopen(pipefd[0], "r"); if (fpipe == NULL) { ALOGE("error converting pipe to FILE*: %s\n", strerror(errno)); err = -1; goto parent_cleanup; } // create a copy since basename may modify its arg cmd_copy = strndup(cmd, TAG_MAX_SIZE); tag = basename(cmd_copy); while(fgets(line, sizeof(line), fpipe)) { ALOG(LOG_INFO, tag, "%s", line); } fclose(fpipe); pid = wait(NULL); if (pid < 0) { ALOGE("error waiting for child: %s\n", strerror(errno)); err = pid; goto parent_cleanup; } parent_cleanup: free(cmd_copy); close(pipefd[0]); return err; } // should never reach here return -1; }
int32_t FingerprintDaemonProxy::stopAuthentication() { ALOG(LOG_VERBOSE, LOG_TAG, "stopAuthentication()\n"); return mDevice->cancel(mDevice); }
// Called each time a statement begins execution, when tracing is enabled. static void sqliteTraceCallback(void *data, const char *sql) { SQLiteConnection* connection = static_cast<SQLiteConnection*>(data); ALOG(LOG_VERBOSE, SQLITE_TRACE_TAG, "%s: \"%s\"\n", connection->label.string(), sql); }
int32_t FingerprintDaemonProxy::remove(int32_t fingerId, int32_t groupId) { ALOG(LOG_VERBOSE, LOG_TAG, "remove(fid=%d, gid=%d)\n", fingerId, groupId); return mDevice->remove(mDevice, groupId, fingerId); }
static jint nativeRemove(JNIEnv* env, jobject clazz, jint fingerprintId) { ALOG(LOG_VERBOSE, LOG_TAG, "nativeRemove(%d)\n", fingerprintId); int ret = gContext.device->remove(gContext.device, fingerprintId); return reinterpret_cast<jint>(ret); }
static jclass findAppClass(JNIEnv *jenv,const char *apn){ //获取Loaders jclass clazzApplicationLoaders = jenv->FindClass("android/app/ApplicationLoaders"); jthrowable exception = jenv->ExceptionOccurred(); if (ClearException(jenv)) { ALOG("Exception","No class : %s", "android/app/ApplicationLoaders"); return NULL; } jfieldID fieldApplicationLoaders = jenv->GetStaticFieldID(clazzApplicationLoaders,"gApplicationLoaders","Landroid/app/ApplicationLoaders;"); if (ClearException(jenv)) { ALOG("Exception","No Static Field :%s","gApplicationLoaders"); return NULL; } jobject objApplicationLoaders = jenv->GetStaticObjectField(clazzApplicationLoaders,fieldApplicationLoaders); if (ClearException(jenv)) { ALOG("Exception","GetStaticObjectField is failed [%s","gApplicationLoaders"); return NULL; } jfieldID fieldLoaders = jenv->GetFieldID(clazzApplicationLoaders,"mLoaders","Ljava/util/Map;"); if (ClearException(jenv)) { ALOG("Exception","No Field :%s","mLoaders"); return NULL; } jobject objLoaders = jenv->GetObjectField(objApplicationLoaders,fieldLoaders); if (ClearException(jenv)) { ALOG("Exception","No object :%s","mLoaders"); return NULL; } //提取map中的values jclass clazzHashMap = jenv->GetObjectClass(objLoaders); jmethodID methodValues = jenv->GetMethodID(clazzHashMap,"values","()Ljava/util/Collection;"); jobject values = jenv->CallObjectMethod(objLoaders,methodValues); jclass clazzValues = jenv->GetObjectClass(values); jmethodID methodToArray = jenv->GetMethodID(clazzValues,"toArray","()[Ljava/lang/Object;"); if (ClearException(jenv)) { ALOG("Exception","No Method:%s","toArray"); return NULL; } jobjectArray classLoaders = (jobjectArray)jenv->CallObjectMethod(values,methodToArray); if (ClearException(jenv)) { ALOG("Exception","CallObjectMethod failed :%s","toArray"); return NULL; } int size = jenv->GetArrayLength(classLoaders); for(int i = 0 ; i < size ; i ++){ jobject classLoader = jenv->GetObjectArrayElement(classLoaders,i); jclass clazzCL = jenv->GetObjectClass(classLoader); jmethodID loadClass = jenv->GetMethodID(clazzCL,"loadClass","(Ljava/lang/String;)Ljava/lang/Class;"); jstring param = jenv->NewStringUTF(apn); jclass tClazz = (jclass)jenv->CallObjectMethod(classLoader,loadClass,param); if (ClearException(jenv)) { ALOG("Exception","No"); continue; } return tClazz; } ALOG("Exception","No"); return NULL; }
void log_params(JNIEnv *env, jbyteArray passwd, jbyteArray salt, jint N, jint r, jint p, jint dkLen) { ALOG("Parameters for native scrypt run:"); ALOG("passwd (summary): %s", get_byte_array_summary(env, passwd)); ALOG("salt (summary): %s", get_byte_array_summary(env, salt)); ALOG("N, r, p, dkLen: %d, %d, %d, %d", (int32_t) N, (int32_t) r, (int32_t) p, (int32_t) dkLen); }
void fatal(const char *msg) { fprintf(stderr, "%s", msg); ALOG(LOG_ERROR, "logwrapper", "%s", msg); exit(-1); }
// Return the name of the shared library that implements Omx based decoding. This varies // depending on libstagefright version installed on the device and whether it is B2G vs Android. // nullptr is returned if Omx decoding is not supported on the device, static const char* GetOmxLibraryName() { if (!IsOmxSupported()) return nullptr; #if defined(ANDROID) && !defined(MOZ_WIDGET_GONK) nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1"); NS_ASSERTION(infoService, "Could not find a system info service"); int32_t version; nsresult rv = infoService->GetPropertyAsInt32(NS_LITERAL_STRING("version"), &version); if (NS_SUCCEEDED(rv)) { ALOG("Android Version is: %d", version); } nsAutoString release_version; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("release_version"), release_version); if (NS_SUCCEEDED(rv)) { ALOG("Android Release Version is: %s", NS_LossyConvertUTF16toASCII(release_version).get()); } nsAutoString device; rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("device"), device); if (NS_SUCCEEDED(rv)) { ALOG("Android Device is: %s", NS_LossyConvertUTF16toASCII(device).get()); } if (version == 15 && (device.Find("LT28", false) == 0 || device.Find("LT26", false) == 0 || device.Find("LT22", false) == 0 || device.Find("IS12", false) == 0 || device.Find("MT27", false) == 0)) { // Sony Ericsson devices running ICS return "libomxpluginsony.so"; } else if (version == 13 || version == 12 || version == 11) { return "libomxpluginhc.so"; } else if (version == 10 && release_version >= NS_LITERAL_STRING("2.3.6")) { // Gingerbread versions from 2.3.6 and above have a different DataSource // layout to those on 2.3.5 and below. return "libomxplugingb.so"; } else if (version == 10 && release_version >= NS_LITERAL_STRING("2.3.4") && device.Find("HTC") == 0) { // HTC devices running Gingerbread 2.3.4+ (HTC Desire HD, HTC Evo Design, etc) seem to // use a newer version of Gingerbread libstagefright than other 2.3.4 devices. return "libomxplugingb.so"; } else if (version == 9 || (version == 10 && release_version <= NS_LITERAL_STRING("2.3.5"))) { // Gingerbread versions from 2.3.5 and below have a different DataSource // than 2.3.6 and above. return "libomxplugingb235.so"; } else if (version == 8) { // Froyo return "libomxpluginfroyo.so"; } else if (version < 8) { // Below Froyo not supported return nullptr; } // Default libomxplugin for non-gingerbread devices return "libomxplugin.so"; #elif defined(ANDROID) && defined(MOZ_WIDGET_GONK) return "libomxplugin.so"; #else return nullptr; #endif }
static jint nativeAuthenticate(JNIEnv* env, jobject clazz) { ALOG(LOG_VERBOSE, LOG_TAG, "nativeAuthenticate()\n"); int ret = gContext.device->authenticate(gContext.device); return reinterpret_cast<jint>(ret); }
int audiotrack_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name, cubeb_devid input_device, cubeb_stream_params * input_stream_params, cubeb_devid output_device, cubeb_stream_params * output_stream_params, unsigned int latency, cubeb_data_callback data_callback, cubeb_state_callback state_callback, void * user_ptr) { cubeb_stream * stm; int32_t channels; uint32_t min_frame_count; assert(ctx && stream); assert(!input_stream_params && "not supported"); if (input_device || output_device) { /* Device selection not yet implemented. */ return CUBEB_ERROR_DEVICE_UNAVAILABLE; } if (output_stream_params->format == CUBEB_SAMPLE_FLOAT32LE || output_stream_params->format == CUBEB_SAMPLE_FLOAT32BE) { return CUBEB_ERROR_INVALID_FORMAT; } if (audiotrack_get_min_frame_count(ctx, output_stream_params, (int *)&min_frame_count)) { return CUBEB_ERROR; } stm = calloc(1, sizeof(*stm)); assert(stm); stm->context = ctx; stm->data_callback = data_callback; stm->state_callback = state_callback; stm->user_ptr = user_ptr; stm->params = *output_stream_params; stm->instance = calloc(SIZE_AUDIOTRACK_INSTANCE, 1); (*(uint32_t*)((intptr_t)stm->instance + SIZE_AUDIOTRACK_INSTANCE - 4)) = 0xbaadbaad; assert(stm->instance && "cubeb: EOM"); /* gingerbread uses old channel layout enum */ if (audiotrack_version_is_gingerbread(ctx)) { channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_Legacy : AUDIO_CHANNEL_OUT_MONO_Legacy; } else { channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_ICS : AUDIO_CHANNEL_OUT_MONO_ICS; } ctx->klass.ctor(stm->instance, stm->params.stream_type, stm->params.rate, AUDIO_FORMAT_PCM_16_BIT, channels, min_frame_count, 0, audiotrack_refill, stm, 0, 0); assert((*(uint32_t*)((intptr_t)stm->instance + SIZE_AUDIOTRACK_INSTANCE - 4)) == 0xbaadbaad); if (ctx->klass.check(stm->instance)) { ALOG("stream not initialized properly."); audiotrack_stream_destroy(stm); return CUBEB_ERROR; } *stream = stm; return CUBEB_OK; }
int sa_stream_write(sa_stream_t *s, const void *data, size_t nbytes) { if (s == NULL || s->output_unit == NULL) { return SA_ERROR_NO_INIT; } if (nbytes == 0) { return SA_SUCCESS; } JNIEnv *jenv = GetJNIForThread(); if ((*jenv)->PushLocalFrame(jenv, 2)) { return SA_ERROR_OOM; } jbyteArray bytearray = (*jenv)->NewByteArray(jenv, nbytes); if (!bytearray) { (*jenv)->ExceptionClear(jenv); (*jenv)->PopLocalFrame(jenv, NULL); return SA_ERROR_OOM; } jbyte *byte = (*jenv)->GetByteArrayElements(jenv, bytearray, NULL); if (!byte) { (*jenv)->PopLocalFrame(jenv, NULL); return SA_ERROR_OOM; } memcpy(byte, data, nbytes); size_t wroteSoFar = 0; jint retval; do { retval = (*jenv)->CallIntMethod(jenv, s->output_unit, at.write, bytearray, wroteSoFar, nbytes - wroteSoFar); if (retval < 0) { ALOG("%x - Write failed %d", s, retval); break; } wroteSoFar += retval; if (wroteSoFar != nbytes) { /* android doesn't start playing until we explictly call play. */ if (!s->isPaused) sa_stream_resume(s); struct timespec ts = {0, 100000000}; /* .10s */ nanosleep(&ts, NULL); } } while(wroteSoFar < nbytes); s->amountWritten += nbytes; (*jenv)->ReleaseByteArrayElements(jenv, bytearray, byte, 0); (*jenv)->PopLocalFrame(jenv, NULL); return retval < 0 ? SA_ERROR_INVALID : SA_SUCCESS; }