Androidリスニングアプリケーションのアンインストール
5347 ワード
, , 360 360 , Service log , , Service 。 Stackoverflow , , 。
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* begin */
// 0
#define MEM_ZERO(pDest, destSize) memset(pDest, 0, destSize)
//LOG
#define LOG_INFO(tag, msg) __android_log_write(ANDROID_LOG_INFO, tag, msg)
#define LOG_DEBUG(tag, msg) __android_log_write(ANDROID_LOG_DEBUG, tag, msg)
#define LOG_WARN(tag, msg) __android_log_write(ANDROID_LOG_WARN, tag, msg)
#define LOG_ERROR(tag, msg) __android_log_write(ANDROID_LOG_ERROR, tag, msg)
/* begin */
static char c_TAG[] = "onEvent";
static jboolean b_IS_COPY = JNI_TRUE;
jstring
Java_com_example_untitled_MyActivity_init( JNIEnv* env,
jobject thiz )
{
jstring tag = (*env)->NewStringUTF(env, c_TAG);
// log
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "init OK"), &b_IS_COPY));
//fork ,
pid_t pid = fork();
if (pid < 0)
{
// log
LOG_ERROR((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "fork failed !!!"), &b_IS_COPY));
}
else if (pid == 0)
{
// "/data/data/pym.test.uninstalledobserver"
int fileDescriptor = inotify_init();
if (fileDescriptor < 0)
{
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "inotify_init failed !!!"), &b_IS_COPY));
exit(1);
}
int watchDescriptor;
watchDescriptor = inotify_add_watch(fileDescriptor, "/data/data/com.example.untitled", IN_DELETE);
if (watchDescriptor < 0)
{
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "inotify_add_watch failed !!!"), &b_IS_COPY));
exit(1);
}
// , event, = struct inotify_event , event
void *p_buf = malloc(sizeof(struct inotify_event));
if (p_buf == NULL)
{
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "malloc failed !!!"), &b_IS_COPY));
exit(1);
}
//
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "start observer"), &b_IS_COPY));
size_t readBytes = read(fileDescriptor, p_buf, sizeof(struct inotify_event));
//read , ,
free(p_buf);
inotify_rm_watch(fileDescriptor, IN_DELETE);
// log
LOG_DEBUG((*env)->GetStringUTFChars(env, tag, &b_IS_COPY)
, (*env)->GetStringUTFChars(env, (*env)->NewStringUTF(env, "uninstalled"), &b_IS_COPY));
// am start -a android.intent.action.VIEW -d http://shouji.360.cn/web/uninstall/uninstall.html
// execlp("am", "am", "start", "-a", "android.intent.action.VIEW", "-d", "http://shouji.360.cn/web/uninstall/uninstall.html", (char *)NULL);
//4.2 , --user 0
execlp("am", "am", "start","--user", "0" ,"-a", "android.intent.action.VIEW", "-d", "https://www.google.com", (char *)NULL);
}
else
{
// , init ,
}
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
次はmkファイルです
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
// Log
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
SOファイルをコンパイルするのは多くなくて、コンパイルに成功した後にコンパイルしたsoファイルをlibsディレクトリの下に置きます
Initメソッドを呼び出すことで