拿 MTK JB2(android 4.2.1)源码包编译出来的卡刷,然后“设置”中发现内置存储空间和外置 sd 卡可用空间都为 0 ,其他任何应用也反映可用空间 0 。但 adb shell 进去均可正常访问, df 也显示正常。
看了看 /etc/permissions/platform.xml 是正常的, sdcard_rw media_rw 都在。无奈只有简单调试了一下,我在“设置”->"存储"的代码加了log:
private void measureApproximateStorage(IMediaContainerService imcs) {
/*final String path = mVolume != null ? mVolume.getPath()
: Environment.getDataDirectory().getPath();*/
final String path;
if(mVolume != null) {
path = mVolume.getPath();
} else {
if(FeatureOption.MTK_SHARED_SDCARD) {
path = Environment.getLegacyExternalStorageDirectory().getPath();
} else {
path = Environment.getDataDirectory().getPath();
}
}
Log.d(TAG, "measureApproximateStorage, path is " + path);
try {
final long[] stats = imcs.getFileSystemStats(path);
mTotalSize = stats[0];
mAvailSize = stats[1];
Log.d(TAG, "total size:" + mTotalSize + " path:" + path);
} catch (Exception e) {
Log.w(TAG, "Problem in container service", e);
}
sendInternalApproximateUpdate();
}
结果:
D/StorageMeasurement( 1454): ## total size:2142347264 path:/data
D/StorageMeasurement( 1454): ## total size:0 path:/storage/sdcard1
D/StorageMeasurement( 1454): ## total size:0 path:/storage/sdcard0
再往下追踪直到 native 层: libcore/luni/src/main/native/libcore_io_Posix.cpp ,我也加了 log
static jobject Posix_statfs(JNIEnv* env, jobject, jstring javaPath) {
ScopedUtfChars path(env, javaPath);
if (path.c_str() == NULL) {
return NULL;
}
struct statfs sb;
int rc = TEMP_FAILURE_RETRY(statfs(path.c_str(), &sb));
ALOGE("[My Debug]##path:%s blocks:%llu rc:%d uid:%d gid:%d", path.c_str(), sb.f_blocks, rc, getuid(), getgid());
if (rc == -1) {
throwErrnoException(env, "statfs");
return NULL;
}
return makeStructStatFs(env, sb);
}
结果:
E/Posix ( 1524): [My Debug]## path:/storage/sdcard1 blocks:0 rc:0 uid:10018 gid:10018
E/Posix ( 1524): [My Debug]## path:/storage/sdcard0 blocks:0 rc:0 uid:10018 gid:10018
我觉得很可能还是权限问题,就把 /storage/sdcard1 和 0 都 mount -o fmask=0000,dmask=0000 这样 /storage/sdcard0 和 1 权限就是 777 了,试了一下还是不行。
另外,如果 APP 打开这些存储设备会有 log :
I/DefContainer-JNI( 1884): error opening: /storage/sdcard0: Permission denied
I/DefContainer-JNI( 1884): error opening: /storage/sdcard1: Permission denied
代码在 frameworks/base/packages/DefaultContainerService/jni/com_android_defcontainer_MeasurementUtils.cpp
static jlong native_measureDirectory(JNIEnv* env, jobject clazz, jstring directory) {
jlong ret = 0L;
const char* path = env->GetStringUTFChars(directory, NULL);
if (path == NULL) {
return ret;
}
int dirfd = open(path, O_DIRECTORY, O_RDONLY);
if (dirfd < 0) {
ALOGI("error opening: %s: %s", path, strerror(errno));
} else {
ret = calculate_dir_size(dirfd);
close(dirfd);
}
env->ReleaseStringUTFChars(directory, path);
return ret;
}
看来就是调用底层的系统 API 访问文件没权限,但文件系统都已经 777 了还是不行,现在没有其他思路了,希望大伙帮我出出主意。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.