MountServiceの初期プローブ
36445 ワード
MountServiceはVoldのクライアントとしてvoldからのメッセージを受信し、内部定義には様々なVolume関連のステータス定義が保存されます:1、VolumeState
VoldResponseCode
1、MountServiceの構築方法:1.1、MountService静的オブジェクトsSelfの初期化、PackageManagerServiceの初期化、readStoregeListLockedの方法はシステムプロファイルを読み込み、mVolumesオブジェクトを初期化する.
readStorageListLockedメソッド、storage_を読み込むlist.xmlファイル.
こちらの携帯電話の読み取り結果は:
シミュレーションパーティションの場合:
すなわち、mEmulatedTemplateを初期化します.そうでない場合は、StorageVolumeを構築し、mVolumesに追加します.
1.2、MountServiceHandlerサブスレッドの開拓
1.3、登録ユーザー関連放送、マルチユーザー関連.
1.4.マスターVolumeデバイスがmassStorageを許可する場合、usb状態を傍受する:
1.5 NativeDaemonConnectorを構築し、ユーザーとvoldはsocket通信を行う.スレッドを個別に開きます.
NativeDaemonConnectorは、voldプロセスのCommandListenerと通信し、2番目のパラメータはvold、標識、voldで通信します.1番目のパラメータはINativeDaemonConnectorCallbackで、3つのコールバックがあります.
voldとの通信中にonEventメソッドがコールバックされます.
2、システム起動時に、また実行器systemReady方法:
handleSystemReadyでは、現在のストレージ・ブロック領域を巡回し、ステータスを更新します.
3.voldプロセスと通信し、MountServiceはそのonEventメソッドを実行する.
4、storate_を添付list.xmlファイルの内容:
ロゴの説明:
class VolumeState {
public static final int Init = -1;
public static final int NoMedia = 0;
public static final int Idle = 1;
public static final int Pending = 2;
public static final int Checking = 3;
public static final int Mounted = 4;
public static final int Unmounting = 5;
public static final int Formatting = 6;
public static final int Shared = 7;
public static final int SharedMnt = 8;
}
VoldResponseCode
class VoldResponseCode {
/* * 100 series - Requestion action was initiated; expect another reply * before proceeding with a new command. */
public static final int VolumeListResult = 110;
public static final int AsecListResult = 111;
public static final int StorageUsersListResult = 112;
public static final int CryptfsGetfieldResult = 113;
/* * 200 series - Requestion action has been successfully completed. */
public static final int ShareStatusResult = 210;
public static final int AsecPathResult = 211;
public static final int ShareEnabledResult = 212;
/* * 400 series - Command was accepted, but the requested action * did not take place. */
public static final int OpFailedNoMedia = 401;
public static final int OpFailedMediaBlank = 402;
public static final int OpFailedMediaCorrupt = 403;
public static final int OpFailedVolNotMounted = 404;
public static final int OpFailedStorageBusy = 405;
public static final int OpFailedStorageNotFound = 406;
/* * 600 series - Unsolicited broadcasts. */
public static final int VolumeStateChange = 605;
public static final int VolumeUuidChange = 613;
public static final int VolumeUserLabelChange = 614;
public static final int VolumeDiskInserted = 630;
public static final int VolumeDiskRemoved = 631;
public static final int VolumeBadRemoval = 632;
/* * 700 series - fstrim */
public static final int FstrimCompleted = 700;
}
1、MountServiceの構築方法:1.1、MountService静的オブジェクトsSelfの初期化、PackageManagerServiceの初期化、readStoregeListLockedの方法はシステムプロファイルを読み込み、mVolumesオブジェクトを初期化する.
sSelf = this;
mContext = context;
synchronized (mVolumesLock) {
readStorageListLocked();
}
// XXX: This will go away soon in favor of IMountServiceObserver
mPms = (PackageManagerService) ServiceManager.getService("package");
readStorageListLockedメソッド、storage_を読み込むlist.xmlファイル.
private void readStorageListLocked() {
mVolumes.clear();
mVolumeStates.clear();
Resources resources = mContext.getResources();
int id = com.android.internal.R.xml.storage_list;
XmlResourceParser parser = resources.getXml(id);
AttributeSet attrs = Xml.asAttributeSet(parser);
こちらの携帯電話の読み取り結果は:
04-21 21:50:36.230 D/MountService( 1269): got storage path: /storage/sdcard0 description: primary: true removable: false emulated: true mtpReserve: 100 allowMassStorage: false maxFileSize: 0 allowMtp: true
シミュレーションパーティションの場合:
if (emulated) {
// For devices with emulated storage, we create separate
// volumes for each known user.
mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false,
true, mtpReserve, false, maxFileSize, null, allowMtp);
final UserManagerService userManager = UserManagerService.getInstance();
for (UserInfo user : userManager.getUsers(false)) {
createEmulatedVolumeForUserLocked(user.getUserHandle());
}
}
すなわち、mEmulatedTemplateを初期化します.そうでない場合は、StorageVolumeを構築し、mVolumesに追加します.
else {
if (path == null || description == null) {
Slog.e(TAG, "Missing storage path or description in readStorageList");
} else {
final StorageVolume volume = new StorageVolume(new File(path),
descriptionId, primary, removable, emulated, mtpReserve,
allowMassStorage, maxFileSize, null, allowMtp);
addVolumeLocked(volume); // Until we hear otherwise, treat as unmounted mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
volume.setState(Environment.MEDIA_UNMOUNTED);
}
1.2、MountServiceHandlerサブスレッドの開拓
HandlerThread hthread = new HandlerThread(TAG);
hthread.start();
mHandler = new MountServiceHandler(hthread.getLooper());
1.3、登録ユーザー関連放送、マルチユーザー関連.
final IntentFilter userFilter = new IntentFilter();
userFilter.addAction(Intent.ACTION_USER_ADDED);
userFilter.addAction(Intent.ACTION_USER_REMOVED);
mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
1.4.マスターVolumeデバイスがmassStorageを許可する場合、usb状態を傍受する:
// Watch for USB changes on primary volume
final StorageVolume primary = getPrimaryPhysicalVolume();
if ((primary != null && primary.allowMassStorage()) ||
//ignore primary config, force to register if property is true
SystemProperties.getBoolean("persist.sys.ums", true)) {
mContext.registerReceiver(
mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
}
1.5 NativeDaemonConnectorを構築し、ユーザーとvoldはsocket通信を行う.スレッドを個別に開きます.
mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25,
null);
Thread thread = new Thread(mConnector, VOLD_TAG);
thread.start();
NativeDaemonConnectorは、voldプロセスのCommandListenerと通信し、2番目のパラメータはvold、標識、voldで通信します.1番目のパラメータはINativeDaemonConnectorCallbackで、3つのコールバックがあります.
void onDaemonConnected();
boolean onCheckHoldWakeLock(int code);
boolean onEvent(int code, String raw, String[] cooked);
voldとの通信中にonEventメソッドがコールバックされます.
2、システム起動時に、また実行器systemReady方法:
public void systemReady() {
mSystemReady = true;
mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget();
}
case H_SYSTEM_READY: {
try {
handleSystemReady();
} catch (Exception ex) {
Slog.e(TAG, "Boot-time mount exception", ex);
}
break;
}
handleSystemReadyでは、現在のストレージ・ブロック領域を巡回し、ステータスを更新します.
// Push mounted state for all emulated storage
synchronized (mVolumesLock) {
for (StorageVolume volume : mVolumes) { if (volume.isEmulated()) {
updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED); } } }
3.voldプロセスと通信し、MountServiceはそのonEventメソッドを実行する.
public boolean onEvent(int code, String raw, String[] cooked) { if (code == VoldResponseCode.VolumeStateChange) { } else if (code == VoldResponseCode.VolumeUuidChange) { } else if (code == VoldResponseCode.VolumeUserLabelChange) { } else if ((code == VoldResponseCode.VolumeDiskInserted) ||
(code == VoldResponseCode.VolumeDiskRemoved) ||
(code == VoldResponseCode.VolumeBadRemoval)) { } else if (code == VoldResponseCode.VolumeDiskRemoved) { } else if (code == VoldResponseCode.VolumeBadRemoval) { } else if (code == VoldResponseCode.FstrimCompleted) { }
。。。。
}
4、storate_を添付list.xmlファイルの内容:
<StorageList xmlns:android="http://schemas.android.com/apk/res/android">
<!-- internal emulated storage -->
<storage android:mountPoint="/storage/sdcard0" android:storageDescription="@string/storage_internal" android:primary="true" android:emulated="true" android:removable="false" android:mtpReserve="100" />
<storage android:mountPoint="/storage/sdcard1" android:storageDescription="@string/storage_sd_card" android:primary="false" android:emulated="false" android:removable="true" android:allowMassStorage="true" />
<storage android:mountPoint="/storage/uicc0" android:storageDescription="@string/storage_uicc" android:primary="false" android:emulated="false" android:removable="true" android:allowMassStorage="true" />
<storage android:mountPoint="/storage/uicc1" android:storageDescription="@string/storage_uicc" android:primary="false" android:emulated="false" android:removable="true" android:allowMassStorage="false" android:allowMtp="false" />
<storage android:mountPoint="/storage/usbotg" android:storageDescription="@string/storage_usb" android:primary="false" android:emulated="false" android:removable="true" android:allowMassStorage="false" />
</StorageList>
ロゴの説明:
04-21 21:50:36.230 D/MountService( 1269): got storage path: /storage/sdcard0 description: primary: true removable: false emulated: true mtpReserve: 100 allowMassStorage: false maxFileSize: 0 allowMtp: true
04-21 21:50:36.232 D/MountService( 1269): addVolumeLocked() StorageVolume:
04-21 21:50:36.232 D/MountService( 1269): mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040809
04-21 21:50:36.232 D/MountService( 1269): mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=100
04-21 21:50:36.232 D/MountService( 1269): mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null
04-21 21:50:36.232 D/MountService( 1269): mUserLabel=null mState=null mAllowMtp=true
04-21 21:50:36.232 D/MountService( 1269): got storage path: /storage/sdcard1 description: SD primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: true maxFileSize: 0 allowMtp: true
04-21 21:50:36.232 D/MountService( 1269): addVolumeLocked() StorageVolume:
04-21 21:50:36.232 D/MountService( 1269): mStorageId=0 mPath=/storage/sdcard1 mDescriptionId=17040810 mPrimary=false
04-21 21:50:36.232 D/MountService( 1269): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=true
04-21 21:50:36.232 D/MountService( 1269): mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null
04-21 21:50:36.232 D/MountService( 1269): mAllowMtp=true
04-21 21:50:36.232 D/MountService( 1269): got storage path: /storage/uicc0 description: primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: true maxFileSize: 0 allowMtp: true
04-21 21:50:36.232 D/MountService( 1269): addVolumeLocked() StorageVolume:
04-21 21:50:36.232 D/MountService( 1269): mStorageId=0 mPath=/storage/uicc0 mDescriptionId=17040812 mPrimary=false
04-21 21:50:36.232 D/MountService( 1269): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=true
04-21 21:50:36.232 D/MountService( 1269): mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null
04-21 21:50:36.232 D/MountService( 1269): mAllowMtp=true
04-21 21:50:36.232 D/MountService( 1269): got storage path: /storage/uicc1 description: primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0 allowMtp: false
04-21 21:50:36.233 D/MountService( 1269): addVolumeLocked() StorageVolume:
04-21 21:50:36.233 D/MountService( 1269): mStorageId=0 mPath=/storage/uicc1 mDescriptionId=17040812 mPrimary=false
04-21 21:50:36.233 D/MountService( 1269): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false
04-21 21:50:36.233 D/MountService( 1269): mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null
04-21 21:50:36.233 D/MountService( 1269): mAllowMtp=false
04-21 21:50:36.233 D/MountService( 1269): got storage path: /storage/usbotg description: USB primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0 allowMtp: true
04-21 21:50:36.233 D/MountService( 1269): addVolumeLocked() StorageVolume:
04-21 21:50:36.233 D/MountService( 1269): mStorageId=0 mPath=/storage/usbotg mDescriptionId=17040811 mPrimary=false
04-21 21:50:36.233 D/MountService( 1269): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false
04-21 21:50:36.233 D/MountService( 1269): mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null
04-21 21:50:36.233 D/MountService( 1269): mAllowMtp=true