我需要在android native jni中更改文件名(/system/etc/asound.conf) 。我可以通过运行 shell cmd 在串口中执行此操作:
mount -o remount rw /system
busybox mv /system/etc/asound.conf /system/etc/asoundback.conf
mount -o remount r /system
首先,我通过调用 Runtime.getRuntiem(String) 在 java 中运行上面的 shell 脚本。这将导致所有 android 系统服务重新加载。所以我没有这样做。
我通过像这样调用 system() 在 jni 中运行 shell 脚本:
android_media_AudioSystem_changeFileName(JNIEnv *env, jobject thiz, jstring from, jstring to)
{
const jchar* c_from = env->GetStringCritical(from, 0);
String8 c_from8;
if (from) {
c_from8 = String8(c_from, env->GetStringLength(from));
env->ReleaseStringCritical(from, c_from);
}
const jchar* c_to = env->GetStringCritical(to, 0);
String8 c_to8;
if (to) {
c_to8 = String8(c_to, env->GetStringLength(to));
env->ReleaseStringCritical(to, c_to);
}
LOGV("*********** android_media_AudioSystem_changeFileName from: %s ,to: %s" ,c_from8 ,c_to8);
char buff[4096];
sprintf(buff ,"mount -o remount rw /system;busybox mv %s %s;mount -o remount r /system" ,c_from8 ,c_to8);
if(system(buff) == -1) return -1;
return 0;
}
这没用。日志是:
[ 197.520000] mclkdiv = 2, bitclkdiv = 12
D/ALSAModule( 1160): open called for devices 00000002 in mode 0...
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker_normal
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback_Speaker
E/ALSALib ( 1160): external/alsa-lib/src/pcm/pcm.c:2203:(snd_pcm_open_noupdate) Unknown PCM AndroidPlayback
I/ALSAModule( 1160): Initialized ALSA PLAYBACK device defaul
D/SoundSettings( 2041): ******* audio channel: codec
D/SoundSettings( 2041): ******* before asound-----> asoundback
I/AudioSystem( 2041): *********** android_media_AudioSystem_changeFileName
F/libc ( 2041): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
I/DEBUG ( 1155): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 1155): Build fingerprint: 'android:4.0.3/IML74K/eng.android.20120717.210618:eng/test-keys'
I/DEBUG ( 1155): pid: 2041, tid: 2041 >>> com.android.settings <<<
I/DEBUG ( 1155): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaadI/DEBUG ( 1155): r0 deadbaad r1 00000001 r2 40000000 r3 00000000
I/DEBUG ( 1155): r4 00000000 r5 00000027 r6 62100021 r7 411afa18
I/DEBUG ( 1155): r8 be9b8644 r9 be9b864c 10 4786445b fp be9b8684
I/DEBUG ( 1155): ip ffffffff sp be9b8618 lr 40068f01 pc 40065660 cpsr 60000030
I/DEBUG ( 1155): #00 pc 00017660 /system/lib/libc.so
I/DEBUG ( 1155): #01 pc 0006f9de /system/lib/libandroid_runtime.so
I/DEBUG ( 1155): #02 pc 0001ebf0 /system/lib/libdvm.so (dvmPlatformInvoke)
I/DEBUG ( 1155): #03 pc 00058c38 /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread)
I/DEBUG ( 1155):
I/DEBUG ( 1155): code around pc:
I/DEBUG ( 1155): 40065640 4623b15c 2c006824 e026d1fb b12368db \.#F$h.,..&..h#.
I/DEBUG ( 1155): 40065650 21014a17 6011447a 48124798 24002527 .J.!zD.`.G.H'%.$
I/DEBUG ( 1155): 40065660 f7f47005 2106ef70 effef7f5 460aa901 .p..p..!.......F
I/DEBUG ( 1155): 40065670 f04f2006 94015380 94029303 ebc8f7f5 . O..S..........
I/DEBUG ( 1155): 40065680 4622a905 f7f52002 f7f4ebd2 2106ef5c .."F. ......\..!
I/DEBUG ( 1155):
I/DEBUG ( 1155): code around lr:
I/DEBUG ( 1155): 40068ee0 41f0e92d 46804c0c 447c2600 68a56824 -..A.L.F.&|D$h.h
I/DEBUG ( 1155): 40068ef0 e0076867 300cf9b5 dd022b00 47c04628 gh.....0.+..(F.G
I/DEBUG ( 1155): 40068f00 35544306 37fff117 6824d5f4 d1ee2c00 .CT5...7..$h.,..
I/DEBUG ( 1155): 40068f10 e8bd4630 bf0081f0 000285fa 41f0e92d 0F..........-..A
I/DEBUG ( 1155): 40068f20 fb01b086 9004f602 461f4815 4615460c .........H.F.F.F
I/DEBUG ( 1155):
I/DEBUG ( 1155): memory map around addr deadbaad:
有人可以帮助我吗?非常感谢!!!