java media_unmount file_Android 恢复系统调用流程

com.android.settings.MasterClear

private void showFinalConfirmation() {

Preference preference = new Preference(getActivity());

preference.setFragment(MasterClearConfirm.class.getName());

preference.setTitle(R.string.master_clear_confirm_title);

preference.getExtras().putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());

((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);

}

MasterClearConfirm.java

Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);

private void doMasterClear() {

if (mEraseSdCard) {

Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);

intent.putExtra(Intent.EXTRA_REASON, "WipeAllFlash");

intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);

getActivity().startService(intent);

} else {

Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);

intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);

intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm");

getActivity().sendBroadcast(intent);

// Intent handling is asynchronous -- assume it will happen soon.

}

}

core/res/AndroidManifest.xml:

系统注册一个receiver

android:permission="android.permission.MASTER_CLEAR">

android:priority="100" >

services/core/java/com/android/server/MasterClearReceiver.java

Thread thr = new Thread("Reboot") {

@Override

public void run() {

try {

RecoverySystem.rebootWipeUserData(context, shutdown, reason);

Log.wtf(TAG, "Still running after master clear?!");

} catch (IOException e) {

Slog.e(TAG, "Can't perform master clear/factory reset", e);

} catch (SecurityException e) {

Slog.e(TAG, "Can't perform master clear/factory reset", e);

}

}

};

thr.start();

格式化sdcard,执行umount命令

core/res/AndroidManifest.xml:

android:permission="android.permission.MASTER_CLEAR"

android:exported="true" />

services/core/java/com/android/server/MountService.java

public void unmountVolume(String path, boolean force, boolean removeEncryption) {

validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);

waitForReady();

String volState = getVolumeState(path);

if (DEBUG_UNMOUNT) {

Slog.i(TAG, "Unmounting " + path

+ " force = " + force

+ " removeEncryption = " + removeEncryption);

}

if (Environment.MEDIA_UNMOUNTED.equals(volState) ||

Environment.MEDIA_REMOVED.equals(volState) ||

Environment.MEDIA_SHARED.equals(volState) ||

Environment.MEDIA_UNMOUNTABLE.equals(volState)) {

// Media already unmounted or cannot be unmounted.

// TODO return valid return code when adding observer call back.

return;

}

UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption);

mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));

}

private int doUnmountVolume(String path, boolean force, boolean removeEncryption) {

if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {

return VoldResponseCode.OpFailedVolNotMounted;

}

/*

* Force a GC to make sure AssetManagers in other threads of the

* system_server are cleaned up. We have to do this since AssetManager

* instances are kept as a WeakReference and it's possible we have files

* open on the external storage.

*/

Runtime.getRuntime().gc();

// Redundant probably. But no harm in updating state again.

if (path.equals(mExternalStoragePath)) //only flash

{

mPms.updateExternalMediaStatus(false, false);

}

try {

final Command cmd = new Command("volume", "unmount", path);

if (removeEncryption) {

cmd.appendArg("force_and_revert");

} else if (force) {

cmd.appendArg("force");

}

mConnector.execute(cmd);

// We unmounted the volume. None of the asec containers are available now.

synchronized (mAsecMountSet) {

mAsecMountSet.clear();

}

return StorageResultCode.OperationSucceeded;

} catch (NativeDaemonConnectorException e) {

// Don't worry about mismatch in PackageManager since the

// call back will handle the status changes any way.

int code = e.getCode();

if (code == VoldResponseCode.OpFailedVolNotMounted) {

return StorageResultCode.OperationFailedStorageNotMounted;

} else if (code == VoldResponseCode.OpFailedStorageBusy) {

return StorageResultCode.OperationFailedStorageBusy;

} else {

return StorageResultCode.OperationFailedInternalError;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值