編輯:關於Android編程
需要下載ntfs-3g驅動包,並做相應修改,這個網上已經可以下載到修改好的包,本文最後也會附加。
在Android原生代碼中,只支持了FAT格式的掛載,並未支持NTFS格式的存儲設備掛載。一般來說,在手機上並不需要實現這種功能,但是在機頂盒上,USB掛載卻是必須的。那為了達到這種目的,一種比較便捷的解決辦法就是移植現有的驅動以支持當前的系統,NTFS-3G在Android上無疑是一個可以使用的方案。
【疑問】如果我們不移植,有沒有辦法使用NTFS功能?其實也是可以的,或者說部分可以,我們在源碼中進入Kernel目錄下去執行Make menuconfig(海思平台在:Hi3796MV100-2015-2-3-CP058\device\hisilicon\bigfish\sdk\source\kernel\linux-3.10.y,Broadcom平台:kernel位於源碼根目錄下android\kernel\private\97xxx-bcm\linux),
make menuconfig界面如下:
繼續:
把這些功能打開:
然後打開ntfs支持選項,重新編譯內核,會生成一個ko文件,將編譯的內核文件重新燒寫到盒子中,在進入到device目錄下去使用Mount命令手動掛在插入的usb節點同樣可以達到掛在上的目的,但是這個也只能說試試而已,實際離開串口調試沒法用。
我們將下載的這個驅動源碼放到Android系統源碼的external目錄下(Broadcom\android\external\ntfs-3g),然後執行mm編譯會生成ntfs-3g和ntfsfix兩個bin文件,我們把它拷貝到/system/bin下並修改相應權限重啟機頂盒,即可以使用該功能(只是有了驅動基礎,具體要實現當U盤掛載,仍然需要修改系統源碼,主要是VOLD模塊,後面說明)。
1.在Broadcom\android-5.1\system\vold添加Ntfs.h
#ifndef _NTFS_H #define _NTFS_H #includeclass Ntfs { public: static int check(const char *fsPath); static int doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount, int ownerUid, int ownerGid, int permMask, bool createLost); static int format(const char *fsPath, unsigned int numSectors); }; #endif
2.接著實現頭文件:
#include#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOG_TAG "Vold" #include #include #include #include "Ntfs.h" extern "C" int logwrap(int argc, const char **argv, int background); extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *); #define NTFS_3G_PATH "/system/bin/ntfs-3g" int Ntfs::check(const char *fsPath) { // no NTFS file system check is performed, always return true SLOGI("Ntfs filesystem: Skipping fs checks\n"); return 0; } int Ntfs::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount, int ownerUid, int ownerGid, int permMask, bool createLost) { int rc; unsigned long flags; char mountData[255]; flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC; flags |= (ro ? MS_RDONLY : 0); flags |= (remount ? MS_REMOUNT : 0); #if 0 /* * Note: This is a temporary hack. If the sampling profiler is enabled, * we make the SD card world-writable so any process can write snapshots. * * TODO: Remove this code once we have a drop box in system_server. */ char value[PROPERTY_VALUE_MAX]; property_get("persist.sampling_profiler", value, ""); if (value[0] == '1') { SLOGW("The SD card is world-writable because the" " 'persist.sampling_profiler' system property is set to '1'."); permMask = 0; } sprintf(mountData, "uid=%d,gid=%d,fmask=%o,dmask=%o,nls=utf8", ownerUid, ownerGid, permMask, permMask); rc = mount(fsPath, mountPoint, "ntfs", flags, ""); #else SLOGE("mount ntfs block by ntfs-3g", fsPath); sprintf(mountData, "uid=%d,gid=%d,fmask=%o,dmask=%o,nls=utf8", ownerUid, ownerGid, permMask, permMask); const char* args[16]; args[0] = NTFS_3G_PATH; args[1] = fsPath; args[2] = mountPoint; args[3] = "-o"; args[4] = mountData; args[5] = NULL; rc = logwrap(5, args, 1); #endif if(rc) { SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath); flags |= MS_RDONLY; rc = mount(fsPath, mountPoint, "ntfs", flags, ""); } return rc; } int Ntfs::format(const char *fsPath, unsigned int numSectors) { SLOGE("Format ntfs filesystem not supported\n"); errno = EIO; return -1; }
在上面的代碼中,我們指定了ntfs-3g支持文件的目錄:#define NTFS_3G_PATH "/system/bin/ntfs-3g"這個在前面已經說過了。
3.在Volume.cpp中添加:#include "Ntfs.h"
修改掛載和卸載的幾個函數:
int Volume::mountVol(const char* devName) {//modify by dongqiang add param
dev_t deviceNodes[4];
int n, i, rc = 0;
char errmsg[255];
int flags = getFlags();
bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
// TODO: handle "bind" style mounts, for emulated storage
char decrypt_state[PROPERTY_VALUE_MAX];
char crypto_state[PROPERTY_VALUE_MAX];
char encrypt_progress[PROPERTY_VALUE_MAX];
property_get("vold.decrypt", decrypt_state, "");
property_get("vold.encrypt_progress", encrypt_progress, "");
/* Don't try to mount the volumes if we have not yet entered the disk password
* or are in the process of encrypting.
*/
if ((getState() == Volume::State_NoMedia) ||
((!strcmp(decrypt_state, "1") || encrypt_progress[0]) && providesAsec)) {
snprintf(errmsg, sizeof(errmsg),
"Volume %s %s mount failed - no media",
getLabel(), getFuseMountpoint());
mVm->getBroadcaster()->sendBroadcast(
ResponseCode::VolumeMountFailedNoMedia,
errmsg, false);
errno = ENODEV;
return -1;
} else if (getState() != Volume::State_Idle) {
errno = EBUSY;
if (getState() == Volume::State_Pending) {
mRetryMount = true;
}
return -1;
}
n = getDeviceNodes((dev_t *) &deviceNodes, 4);
if (!n) {
SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
return -1;
}
/* If we're running encrypted, and the volume is marked as encryptable and nonremovable,
* and also marked as providing Asec storage, then we need to decrypt
* that partition, and update the volume object to point to it's new decrypted
* block device
*/
property_get("ro.crypto.state", crypto_state, "");
if (providesAsec &&
((flags & (VOL_NONREMOVABLE | VOL_ENCRYPTABLE))==(VOL_NONREMOVABLE | VOL_ENCRYPTABLE)) &&
!strcmp(crypto_state, "encrypted") && !isDecrypted()) {
char new_sys_path[MAXPATHLEN];
char nodepath[256];
int new_major, new_minor;
if (n != 1) {
/* We only expect one device node returned when mounting encryptable volumes */
SLOGE("Too many device nodes returned when mounting %s\n", getMountpoint());
return -1;
}
if (cryptfs_setup_volume(getLabel(), MAJOR(deviceNodes[0]), MINOR(deviceNodes[0]),
new_sys_path, sizeof(new_sys_path),
&new_major, &new_minor)) {
SLOGE("Cannot setup encryption mapping for %s\n", getMountpoint());
return -1;
}
/* We now have the new sysfs path for the decrypted block device, and the
* majore and minor numbers for it. So, create the device, update the
* path to the new sysfs path, and continue.
*/
snprintf(nodepath,
sizeof(nodepath), "/dev/block/vold/%d:%d",
new_major, new_minor);
if (createDeviceNode(nodepath, new_major , new_minor)) {
SLOGE("Error making device node '%s' (%s)", nodepath,
strerror(errno));
}
// Todo: Either create sys filename from nodepath, or pass in bogus path so
// vold ignores state changes on this internal device.
updateDeviceInfo(nodepath, new_major , new_minor);
/* Get the device nodes again, because they just changed */
n = getDeviceNodes((dev_t *) &deviceNodes, 4);
if (!n) {
SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
return -1;
}
}
char finalPath[32] = {0x00};//add by dongqiang
for (i = 0; i < n; i++) {
char devicePath[255];
sprintf(devicePath, "/dev/block/vold/%d:%d", /*major(deviceNodes[i])*/g_major,
/*minor(deviceNodes[i])*/g_minor);//modify by dongqiang
//add by dongqiang begin 2015-12-09
const char * path_prefix = "/mnt/media_rw/";
const size_t len = strlen(path_prefix) + strlen(devName);
char * path = new char[len+1];
strcpy(path, path_prefix);
strcat(path, devName);
int errCode = mkdir(path, 0777);
if(g_major == 179) {
rmdir(path);
}
memset(finalPath, 0x00, sizeof(finalPath));
if(strstr(devicePath, "179") != NULL) {
strcpy(finalPath, "/mnt/media_rw/sdcard1/");
} else {
strcpy(finalPath, path);
}
delete(path);
//add by dongqiang end
SLOGI("%s being considered for volume %s\n", devicePath, getLabel());
SLOGI("current mountpoint is %s, fuseMountPoint is %s", getMountpoint(), getFuseMountpoint());
errno = 0;
setState(Volume::State_Checking);
//add by dongqiang begin
int permMask = providesAsec ? 0007 : 0002;
bool isNtfsFS = true;
bool isFatFs = true;
bool isExtFs = true;
bool isExfatFs = true;
if (isNtfsFS) {
SLOGI("devicePath:%s ,mountpoint:%s\n", devicePath, getMountpoint());
if (Ntfs::doMount(devicePath, finalPath, false, false,
AID_MEDIA_RW, AID_MEDIA_RW, permMask, true)) {
SLOGE("%s failed to mount via NTFS (%s)\n", devicePath, strerror(errno));
isNtfsFS = false;
} else {
isFatFs = false;
isExtFs = false;
isExfatFs = false;
}
}
if (isFatFs) {
if (Fat::doMount(devicePath, finalPath, false, false, false,
AID_MEDIA_RW, AID_MEDIA_RW, permMask, true)) {
SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
isFatFs = false;
} else {
isExtFs = false;
isExfatFs = false;
}
}
//add by dongqiang end
errno = 0;
int gid;
extractMetadata(devicePath);
if (providesAsec && mountAsecExternal() != 0) {
SLOGE("Failed to mount secure area (%s)", strerror(errno));
umount(/*getMountpoint()*/finalPath);
setState(Volume::State_Idle);
return -1;
}
char service[64];
snprintf(service, 64, "fuse_%s", getLabel());
property_set("ctl.start", service);
setState(Volume::State_Mounted);
mCurrentlyMountedKdev = deviceNodes[i];
return 0;
}
SLOGE("Volume %s found no suitable devices for mounting :(\n", getLabel());
setState(Volume::State_Idle);
return -1;
}
int Volume::doUnmount(const char *path, bool force) {
int retries = 10;
if (mDebug) {
SLOGD("Unmounting {%s}, force = %d", path, force);
}
while (retries--) {
if (!umount(path) || errno == EINVAL || errno == ENOENT) {
SLOGI("%s sucessfully unmounted", path);
return 0;
}
int action = 0;
if (force) {
if (retries == 1) {
action = 2; // SIGKILL
} else if (retries == 2) {
action = 1; // SIGHUP
}
}
SLOGW("Failed to unmount %s (%s, retries %d, action %d)",
path, strerror(errno), retries, action);
Process::killProcessesWithOpenFiles(path, action);
usleep(1000*1000);
}
errno = EBUSY;
SLOGE("Giving up on unmount %s (%s)", path, strerror(errno));
return -1;
}
移除掛載函數:
int Volume::unmountVol(bool force, bool revert, const char* devName) {//add the third param by dongqiang
int i, rc;
int flags = getFlags();
bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
/*
if (getState() != Volume::State_Mounted) {
SLOGE("Volume %s unmount request when not mounted", getLabel());
errno = EINVAL;
return UNMOUNT_NOT_MOUNTED_ERR;
}
*/
setState(Volume::State_Unmounting);
usleep(1000 * 1000); // Give the framework some time to react
char service[64];
snprintf(service, 64, "fuse_%s", getLabel());
property_set("ctl.stop", service);
/* Give it a chance to stop. I wish we had a synchronous way to determine this... */
sleep(3);
// TODO: determine failure mode if FUSE times out
if (providesAsec && doUnmount(Volume::SEC_ASECDIR_EXT, force) != 0) {
SLOGE("Failed to unmount secure area on %s (%s)", getMountpoint(), strerror(errno));
goto out_mounted;
}
//add by dongqiang begin
if(strstr(devName, "mmcb")) {
if (doUnmount(getFuseMountpoint(), force) != 0) {
SLOGE("Failed to unmount %s (%s)", getFuseMountpoint(), strerror(errno));
goto fail_remount_secure;
}
const char* path_pre = "/mnt/media_rw/";
char* path = new char[strlen(path_pre) + strlen(devName)];
strcpy(path, path_pre);
strcat(path, devName);
rmdir(path);
delete(path);
} else {
const char* path_pre = "/mnt/media_rw/";
char* path = new char[strlen(path_pre) + strlen(devName)];
strcpy(path, path_pre);
strcat(path, devName);
if (doUnmount(path, force) != 0) {
SLOGE("Failed to unmount %s (%s)", getFuseMountpoint(), strerror(errno));
if(path != NULL) {
delete(path);
}
goto fail_remount_secure;
}
int rtCode = rmdir(path);
delete(path);
}
//add by dongqiang end
if(strstr(devName, "mmcb")) {
if (doUnmount(getMountpoint(), force) != 0) {
SLOGE("Failed to unmount %s (%s)", getMountpoint(), strerror(errno));
goto fail_remount_secure;
}
sleep(3);
const char* path_pre = "/mnt/media_rw/";
char* path = new char[strlen(path_pre) + strlen(devName)];
strcpy(path, path_pre);
strcat(path, devName);
SLOGD("dq-------unmount333, path=%s", path);
rmdir(path);
delete(path);
} else {
const char* path_pre = "/mnt/media_rw/";
char* path = new char[strlen(path_pre) + strlen(devName)];
strcpy(path, path_pre);
strcat(path, devName);
if (doUnmount(path, force) != 0) {
SLOGE("Failed to unmount %s (%s)", getMountpoint(), strerror(errno));
if(path != NULL) {
delete(path);
}
goto fail_remount_secure;
}
if(path != NULL) {
rmdir(path);
delete(path);
}
}
SLOGI("%s unmounted successfully", getMountpoint());
/* If this is an encrypted volume, and we've been asked to undo
* the crypto mapping, then revert the dm-crypt mapping, and revert
* the device info to the original values.
*/
if (revert && isDecrypted()) {
cryptfs_revert_volume(getLabel());
revertDeviceInfo();
SLOGI("Encrypted volume %s reverted successfully", getMountpoint());
}
setUuid(NULL);
setUserLabel(NULL);
setState(Volume::State_Idle);
mCurrentlyMountedKdev = -1;
return 0;
fail_remount_secure:
if (providesAsec && mountAsecExternal() != 0) {
SLOGE("Failed to remount secure area (%s)", strerror(errno));
goto out_nomedia;
}
out_mounted:
setState(Volume::State_Mounted);
return -1;
out_nomedia:
setState(Volume::State_NoMedia);
return -1;
}
如下函數中主要對全局變量g_major和g_minor進行初始化。
int Volume::createDeviceNode(const char *path, int major, int minor) {
//add by dongqiang begin
g_major = major;
g_minor = minor;
//add by dongqiang end
mode_t mode = 0660 | S_IFBLK;
dev_t dev = (major << 8) | minor;
if (mknod(path, mode, dev) < 0) {
if (errno != EEXIST) {
return -1;
}
}
return 0;
}
4.在VolumeManager.cpp中做如下修改(2處):
int VolumeManager::mountVolume(const char *label) {
Volume *v = lookupVolume(label);
if (!v) {
errno = ENOENT;
return -1;
}
return v->mountVol(devName);//modify by dongqiang ---add param
}
int VolumeManager::unmountVolume(const char *label, bool force, bool revert) {
Volume *v = lookupVolume(label);
if (!v) {
errno = ENOENT;
return -1;
}
if (v->getState() == Volume::State_NoMedia) {
errno = ENODEV;
return -1;
}
if (v->getState() != Volume::State_Mounted) {
SLOGW("Attempt to unmount volume which isn't mounted (%d)\n",
v->getState());
errno = EBUSY;
return UNMOUNT_NOT_MOUNTED_ERR;
}
cleanupAsec(v, force);
return v->unmountVol(force, revert, NULL);//add the third param by dongqiang
}
5.在DirectVolume.cpp中修改如下:
①定義全局變量數組char nameForRm[32] = {0x00};
②
int DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
const char *dp = evt->findParam("DEVPATH");
PathCollection::iterator it;
for (it = mPaths->begin(); it != mPaths->end(); ++it) {
if ((*it)->match(dp)) {
/* We can handle this disk */
int action = evt->getAction();
const char *devtype = evt->findParam("DEVTYPE");
if (action == NetlinkEvent::NlActionAdd) {
int major = atoi(evt->findParam("MAJOR"));
int minor = atoi(evt->findParam("MINOR"));
char nodepath[255];
snprintf(nodepath,
sizeof(nodepath), "/dev/block/vold/%d:%d",
major, minor);
if (createDeviceNode(nodepath, major, minor)) {
SLOGE("Error making device node '%s' (%s)", nodepath,
strerror(errno));
}
if (!strcmp(devtype, "disk")) {
handleDiskAdded(dp, evt);
} else
handlePartitionAdded(dp, evt);
}
/* Send notification iff disk is ready (ie all partitions found) */
if (getState() == Volume::State_Idle) {
char msg[255];
snprintf(msg, sizeof(msg),
"Volume %s %s disk inserted (%d:%d)", getLabel(),
getFuseMountpoint(), mDiskMajor, mDiskMinor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted,
msg, false);
}
} else if (action == NetlinkEvent::NlActionRemove) {
if (!strcmp(devtype, "disk")) {
handleDiskRemoved(dp, evt);
} else {
handlePartitionRemoved(dp, evt);
}
} else if (action == NetlinkEvent::NlActionChange) {
if (!strcmp(devtype, "disk")) {
handleDiskChanged(dp, evt);
} else {
handlePartitionChanged(dp, evt);
}
} else {
SLOGW("Ignoring non add/remove/change event");
}
return 0;
}
}
errno = ENODEV;
return -1;
}
處理分區添加:
void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {
int major = atoi(evt->findParam("MAJOR"));
int minor = atoi(evt->findParam("MINOR"));
int part_num;
const char *tmp = evt->findParam("PARTN");
if (tmp) {
part_num = atoi(tmp);
} else {
SLOGW("Kernel block uevent missing 'PARTN'");
part_num = 1;
}
if (part_num > MAX_PARTITIONS || part_num < 1) {
SLOGE("Invalid 'PARTN' value");
return;
}
if (part_num > mDiskNumParts) {
mDiskNumParts = part_num;
}
if (major != mDiskMajor) {
SLOGE("Partition '%s' has a different major than its disk!", devpath);
return;
}
#ifdef PARTITION_DEBUG
SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor);
#endif
if (part_num >= MAX_PARTITIONS) {
SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
} else {
if ((mPartMinors[part_num - 1] == -1) && mPendingPartCount)
mPendingPartCount--;
mPartMinors[part_num -1] = minor;
}
if (!mPendingPartCount) {
#ifdef PARTITION_DEBUG
SLOGD("Dv:partAdd: Got all partitions - ready to rock!");
#endif
if (getState() != Volume::State_Formatting) {
setState(Volume::State_Idle);
if (mRetryMount == true) {
mRetryMount = false;
mountVol(evt->findParam("DEVNAME"));//modify by dongqiang ----add param
}
}
} else {
#ifdef PARTITION_DEBUG
SLOGD("Dv:partAdd: pending %d disk", mPendingPartCount);
#endif
}
}
處理disk移除:
void DirectVolume::handleDiskRemoved(const char * /*devpath*/,
NetlinkEvent *evt) {
int major = atoi(evt->findParam("MAJOR"));
int minor = atoi(evt->findParam("MINOR"));
char msg[255];
bool enabled;
if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
mVm->unshareVolume(getLabel(), "ums");
}
SLOGD("handleDiskRemoved, volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)",
getLabel(), getFuseMountpoint(), major, minor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
msg, false);
setState(Volume::State_NoMedia);
if(strstr(nameForRm, evt->findParam("DEVNAME"))) {
const char * path_prefix = "/mnt/media_rw/";
const size_t len = strlen(path_prefix) + strlen(nameForRm);
char * path = new char[len+1];
strcpy(path, path_prefix);
strcat(path, nameForRm);
SLOGD("dq>---------handleDiskRemoved-----path to remove: %s, name=%s", path, nameForRm);
Volume::unmountVol(true, false, nameForRm);
sleep(3);
int code = rmdir(path);
SLOGD("handleDiskRemoved, now remove path: %s, error: %s", path, strerror(code));
}
}
處理分區移除:
void DirectVolume::handlePartitionRemoved(const char * /*devpath*/,
NetlinkEvent *evt) {
int major = atoi(evt->findParam("MAJOR"));
int minor = atoi(evt->findParam("MINOR"));
char msg[255];
int state;
const char* devName = evt->findParam("DEVNAME");
//modify by dongqiang begin
const char * path_prefix = "/mnt/media_rw/";
const size_t len = strlen(path_prefix) + strlen(devName);
char * path = new char[len+1];
strcpy(path, path_prefix);
strcat(path, devName);
memset(nameForRm, 0x00, sizeof(nameForRm));
strcpy(nameForRm, devName);
if(major == 179) {
//179 sdcard
SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
} else {
//usb
SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), /*getMountpoint()*/path, major, minor);
}
//modify by dongqiang end
/*
* The framework doesn't need to get notified of
* partition removal unless it's mounted. Otherwise
* the removal notification will be sent on the Disk
* itself
*/
state = getState();
SLOGD("dq------current state: %d",state);
if (state != Volume::State_Mounted && state != Volume::State_Shared) {
SLOGE("state !=State_Mounted && state != State_Shared");
Volume::unmountVol(true, false, devName);
sleep(3);
int code = rmdir(path);
SLOGD("we now remove path: %s, error: %s", path, strerror(code));
delete(path);
return;
}
//add by dongqiang begin
if(path != NULL) {
delete(path);
}
//add by dongqiang end
if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
/*
* Yikes, our mounted partition is going away!
*/
bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
if (providesAsec && mVm->cleanupAsec(this, true)) {
SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
}
snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
getLabel(), getFuseMountpoint(), major, minor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
msg, false);
if (Volume::unmountVol(true, false, evt->findParam("DEVNAME"))) {//add the third param by dongqiang
SLOGE("Failed to unmount volume on bad removal (%s)",
strerror(errno));
// XXX: At this point we're screwed for now
} else {
SLOGD("Crisis averted");
}
} else if (state == Volume::State_Shared) {
/* removed during mass storage */
snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)",
getLabel(), major, minor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
msg, false);
if (mVm->unshareVolume(getLabel(), "ums")) {
SLOGE("Failed to unshare volume on bad removal (%s)",
strerror(errno));
} else {
SLOGD("Crisis averted");
}
}
}
6.在Volume.h中修改如下:
//modify by dongqiang, add parameter
int mountVol(const char* devName);
//modify by dongqiang
int unmountVol(bool force, bool revert, const char* devName);//add the third param by dongqiang
然後對代碼進行重新編譯,將生成的vold文件拷貝到/system/bin下運行。
這篇博客我們來介紹一下建造者模式(Builder Pattern),建造者模式又被稱為生成器模式,是創造性模式之一,與工廠方法模式和抽象工廠模式不同,後兩者的目的是為了實
今天自定義了一個簡單的Android菜單控件。實現方式是:PopupWindow和ListView。現在來給大家分享一下源碼: SHContextMenu.java核心代
今天因為要做一個設置開機畫面的功能,主要是讓用戶可以設置自己的開機畫面,應用層需要做讓用戶選擇開機畫面圖片的功能。所以需要做一個簡單的圖片浏覽選擇程序。最後選用Galle
Android系統根據生命周期的不同階段喚起對應的回調函數來執行代碼。系統存在啟動與銷毀一個activity的一套有序的回調函數。本節來討論下不同生命周期的回調函數裡都該