Loading core/java/android/os/storage/StorageManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.os.Binder; import android.os.Environment; import android.os.FileUtils; import android.os.Handler; import android.os.IVold; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; Loading Loading @@ -219,9 +220,9 @@ public class StorageManager { public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10; /** {@hide} */ public static final int FSTRIM_FLAG_DEEP = 1 << 0; public static final int FSTRIM_FLAG_DEEP = IVold.FSTRIM_FLAG_DEEP_TRIM; /** {@hide} */ public static final int FSTRIM_FLAG_BENCHMARK = 1 << 1; public static final int FSTRIM_FLAG_BENCHMARK = IVold.FSTRIM_FLAG_BENCHMARK_AFTER; /** @hide The volume is not encrypted. */ public static final int ENCRYPTION_STATE_NONE = 1; Loading services/core/java/com/android/server/StorageManagerService.java +69 −22 Original line number Diff line number Diff line Loading @@ -530,13 +530,13 @@ class StorageManagerService extends IStorageManager.Stub class ObbState implements IBinder.DeathRecipient { public ObbState(String rawPath, String canonicalPath, int callingUid, IObbActionListener token, int nonce) { IObbActionListener token, int nonce, String volId) { this.rawPath = rawPath; this.canonicalPath = canonicalPath; this.ownerGid = UserHandle.getSharedAppGid(callingUid); this.token = token; this.nonce = nonce; this.volId = volId; } final String rawPath; Loading @@ -550,6 +550,8 @@ class StorageManagerService extends IStorageManager.Stub // Identifier to pass back to the token final int nonce; String volId; public IBinder getBinder() { return token.asBinder(); } Loading @@ -576,6 +578,7 @@ class StorageManagerService extends IStorageManager.Stub sb.append(",ownerGid=").append(ownerGid); sb.append(",token=").append(token); sb.append(",binder=").append(getBinder()); sb.append(",volId=").append(volId); sb.append('}'); return sb.toString(); } Loading Loading @@ -686,6 +689,7 @@ class StorageManagerService extends IStorageManager.Stub try { if (ENABLE_BINDER) { mVold.shutdown(); success = true; } else { success = mConnector.execute("volume", "shutdown").isClassOk(); } Loading Loading @@ -2087,9 +2091,13 @@ class StorageManagerService extends IStorageManager.Stub } try { if (ENABLE_BINDER) { mVold.fstrim(flags); } else { mConnector.execute("fstrim", cmd); } catch (NativeDaemonConnectorException e) { Slog.e(TAG, "Failed to run fstrim: " + e); } } catch (Exception e) { Slog.wtf(TAG, e); } } Loading Loading @@ -2651,6 +2659,10 @@ class StorageManagerService extends IStorageManager.Stub return null; } if (ENABLE_BINDER) { return findVolumeByIdOrThrow(state.volId).getPath().getAbsolutePath(); } final NativeDaemonEvent event; try { event = mConnector.execute("obb", "path", state.canonicalPath); Loading Loading @@ -2682,7 +2694,8 @@ class StorageManagerService extends IStorageManager.Stub Preconditions.checkNotNull(token, "token cannot be null"); final int callingUid = Binder.getCallingUid(); final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce); final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce, null); final ObbAction action = new MountObbAction(obbState, key, callingUid); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); Loading @@ -2702,8 +2715,8 @@ class StorageManagerService extends IStorageManager.Stub if (existingState != null) { // TODO: separate state object from request data final int callingUid = Binder.getCallingUid(); final ObbState newState = new ObbState( rawPath, existingState.canonicalPath, callingUid, token, nonce); final ObbState newState = new ObbState(rawPath, existingState.canonicalPath, callingUid, token, nonce, existingState.volId); final ObbAction action = new UnmountObbAction(newState, force); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); Loading Loading @@ -3167,7 +3180,15 @@ class StorageManagerService extends IStorageManager.Stub @Override public ParcelFileDescriptor open() throws NativeDaemonConnectorException { final NativeDaemonEvent event = StorageManagerService.this.mConnector.execute( if (ENABLE_BINDER) { try { return new ParcelFileDescriptor( mVold.mountAppFuse(uid, Process.myPid(), mountId)); } catch (Exception e) { throw new NativeDaemonConnectorException("Failed to mount", e); } } else { final NativeDaemonEvent event = mConnector.execute( "appfuse", "mount", uid, Process.myPid(), mountId); opened = true; if (event.getFileDescriptors() == null || Loading @@ -3176,11 +3197,16 @@ class StorageManagerService extends IStorageManager.Stub } return new ParcelFileDescriptor(event.getFileDescriptors()[0]); } } @Override public void close() throws Exception { if (opened) { if (ENABLE_BINDER) { mVold.unmountAppFuse(uid, Process.myPid(), mountId); } else { mConnector.execute("appfuse", "unmount", uid, Process.myPid(), mountId); } opened = false; } } Loading Loading @@ -3848,8 +3874,10 @@ class StorageManagerService extends IStorageManager.Stub } final String hashedKey; final String binderKey; if (mKey == null) { hashedKey = "none"; binderKey = ""; } else { try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); Loading @@ -3859,6 +3887,7 @@ class StorageManagerService extends IStorageManager.Stub SecretKey key = factory.generateSecret(ks); BigInteger bi = new BigInteger(key.getEncoded()); hashedKey = bi.toString(16); binderKey = hashedKey; } catch (NoSuchAlgorithmException e) { Slog.e(TAG, "Could not load PBKDF2 algorithm", e); sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); Loading @@ -3872,13 +3901,22 @@ class StorageManagerService extends IStorageManager.Stub int rc = StorageResultCode.OperationSucceeded; try { mConnector.execute("obb", "mount", mObbState.canonicalPath, new SensitiveArg(hashedKey), if (ENABLE_BINDER) { mObbState.volId = mVold.createObb(mObbState.canonicalPath, binderKey, mObbState.ownerGid); mVold.mount(mObbState.volId, 0, -1); } else { mConnector.execute("obb", "mount", mObbState.canonicalPath, new SensitiveArg(hashedKey), mObbState.ownerGid); } } catch (NativeDaemonConnectorException e) { int code = e.getCode(); if (code != VoldResponseCode.OpFailedStorageBusy) { rc = StorageResultCode.OperationFailedInternalError; } } catch (Exception e) { Slog.w(TAG, e); rc = StorageResultCode.OperationFailedInternalError; } if (rc == StorageResultCode.OperationSucceeded) { Loading Loading @@ -3944,11 +3982,17 @@ class StorageManagerService extends IStorageManager.Stub int rc = StorageResultCode.OperationSucceeded; try { if (ENABLE_BINDER) { mVold.unmount(mObbState.volId); mVold.destroyObb(mObbState.volId); mObbState.volId = null; } else { final Command cmd = new Command("obb", "unmount", mObbState.canonicalPath); if (mForceUnmount) { cmd.appendArg("force"); } mConnector.execute(cmd); } } catch (NativeDaemonConnectorException e) { int code = e.getCode(); if (code == VoldResponseCode.OpFailedStorageBusy) { Loading @@ -3959,6 +4003,9 @@ class StorageManagerService extends IStorageManager.Stub } else { rc = StorageResultCode.OperationFailedInternalError; } } catch (Exception e) { Slog.w(TAG, e); rc = StorageResultCode.OperationFailedInternalError; } if (rc == StorageResultCode.OperationSucceeded) { Loading Loading
core/java/android/os/storage/StorageManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.os.Binder; import android.os.Environment; import android.os.FileUtils; import android.os.Handler; import android.os.IVold; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; Loading Loading @@ -219,9 +220,9 @@ public class StorageManager { public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10; /** {@hide} */ public static final int FSTRIM_FLAG_DEEP = 1 << 0; public static final int FSTRIM_FLAG_DEEP = IVold.FSTRIM_FLAG_DEEP_TRIM; /** {@hide} */ public static final int FSTRIM_FLAG_BENCHMARK = 1 << 1; public static final int FSTRIM_FLAG_BENCHMARK = IVold.FSTRIM_FLAG_BENCHMARK_AFTER; /** @hide The volume is not encrypted. */ public static final int ENCRYPTION_STATE_NONE = 1; Loading
services/core/java/com/android/server/StorageManagerService.java +69 −22 Original line number Diff line number Diff line Loading @@ -530,13 +530,13 @@ class StorageManagerService extends IStorageManager.Stub class ObbState implements IBinder.DeathRecipient { public ObbState(String rawPath, String canonicalPath, int callingUid, IObbActionListener token, int nonce) { IObbActionListener token, int nonce, String volId) { this.rawPath = rawPath; this.canonicalPath = canonicalPath; this.ownerGid = UserHandle.getSharedAppGid(callingUid); this.token = token; this.nonce = nonce; this.volId = volId; } final String rawPath; Loading @@ -550,6 +550,8 @@ class StorageManagerService extends IStorageManager.Stub // Identifier to pass back to the token final int nonce; String volId; public IBinder getBinder() { return token.asBinder(); } Loading @@ -576,6 +578,7 @@ class StorageManagerService extends IStorageManager.Stub sb.append(",ownerGid=").append(ownerGid); sb.append(",token=").append(token); sb.append(",binder=").append(getBinder()); sb.append(",volId=").append(volId); sb.append('}'); return sb.toString(); } Loading Loading @@ -686,6 +689,7 @@ class StorageManagerService extends IStorageManager.Stub try { if (ENABLE_BINDER) { mVold.shutdown(); success = true; } else { success = mConnector.execute("volume", "shutdown").isClassOk(); } Loading Loading @@ -2087,9 +2091,13 @@ class StorageManagerService extends IStorageManager.Stub } try { if (ENABLE_BINDER) { mVold.fstrim(flags); } else { mConnector.execute("fstrim", cmd); } catch (NativeDaemonConnectorException e) { Slog.e(TAG, "Failed to run fstrim: " + e); } } catch (Exception e) { Slog.wtf(TAG, e); } } Loading Loading @@ -2651,6 +2659,10 @@ class StorageManagerService extends IStorageManager.Stub return null; } if (ENABLE_BINDER) { return findVolumeByIdOrThrow(state.volId).getPath().getAbsolutePath(); } final NativeDaemonEvent event; try { event = mConnector.execute("obb", "path", state.canonicalPath); Loading Loading @@ -2682,7 +2694,8 @@ class StorageManagerService extends IStorageManager.Stub Preconditions.checkNotNull(token, "token cannot be null"); final int callingUid = Binder.getCallingUid(); final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce); final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce, null); final ObbAction action = new MountObbAction(obbState, key, callingUid); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); Loading @@ -2702,8 +2715,8 @@ class StorageManagerService extends IStorageManager.Stub if (existingState != null) { // TODO: separate state object from request data final int callingUid = Binder.getCallingUid(); final ObbState newState = new ObbState( rawPath, existingState.canonicalPath, callingUid, token, nonce); final ObbState newState = new ObbState(rawPath, existingState.canonicalPath, callingUid, token, nonce, existingState.volId); final ObbAction action = new UnmountObbAction(newState, force); mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action)); Loading Loading @@ -3167,7 +3180,15 @@ class StorageManagerService extends IStorageManager.Stub @Override public ParcelFileDescriptor open() throws NativeDaemonConnectorException { final NativeDaemonEvent event = StorageManagerService.this.mConnector.execute( if (ENABLE_BINDER) { try { return new ParcelFileDescriptor( mVold.mountAppFuse(uid, Process.myPid(), mountId)); } catch (Exception e) { throw new NativeDaemonConnectorException("Failed to mount", e); } } else { final NativeDaemonEvent event = mConnector.execute( "appfuse", "mount", uid, Process.myPid(), mountId); opened = true; if (event.getFileDescriptors() == null || Loading @@ -3176,11 +3197,16 @@ class StorageManagerService extends IStorageManager.Stub } return new ParcelFileDescriptor(event.getFileDescriptors()[0]); } } @Override public void close() throws Exception { if (opened) { if (ENABLE_BINDER) { mVold.unmountAppFuse(uid, Process.myPid(), mountId); } else { mConnector.execute("appfuse", "unmount", uid, Process.myPid(), mountId); } opened = false; } } Loading Loading @@ -3848,8 +3874,10 @@ class StorageManagerService extends IStorageManager.Stub } final String hashedKey; final String binderKey; if (mKey == null) { hashedKey = "none"; binderKey = ""; } else { try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); Loading @@ -3859,6 +3887,7 @@ class StorageManagerService extends IStorageManager.Stub SecretKey key = factory.generateSecret(ks); BigInteger bi = new BigInteger(key.getEncoded()); hashedKey = bi.toString(16); binderKey = hashedKey; } catch (NoSuchAlgorithmException e) { Slog.e(TAG, "Could not load PBKDF2 algorithm", e); sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL); Loading @@ -3872,13 +3901,22 @@ class StorageManagerService extends IStorageManager.Stub int rc = StorageResultCode.OperationSucceeded; try { mConnector.execute("obb", "mount", mObbState.canonicalPath, new SensitiveArg(hashedKey), if (ENABLE_BINDER) { mObbState.volId = mVold.createObb(mObbState.canonicalPath, binderKey, mObbState.ownerGid); mVold.mount(mObbState.volId, 0, -1); } else { mConnector.execute("obb", "mount", mObbState.canonicalPath, new SensitiveArg(hashedKey), mObbState.ownerGid); } } catch (NativeDaemonConnectorException e) { int code = e.getCode(); if (code != VoldResponseCode.OpFailedStorageBusy) { rc = StorageResultCode.OperationFailedInternalError; } } catch (Exception e) { Slog.w(TAG, e); rc = StorageResultCode.OperationFailedInternalError; } if (rc == StorageResultCode.OperationSucceeded) { Loading Loading @@ -3944,11 +3982,17 @@ class StorageManagerService extends IStorageManager.Stub int rc = StorageResultCode.OperationSucceeded; try { if (ENABLE_BINDER) { mVold.unmount(mObbState.volId); mVold.destroyObb(mObbState.volId); mObbState.volId = null; } else { final Command cmd = new Command("obb", "unmount", mObbState.canonicalPath); if (mForceUnmount) { cmd.appendArg("force"); } mConnector.execute(cmd); } } catch (NativeDaemonConnectorException e) { int code = e.getCode(); if (code == VoldResponseCode.OpFailedStorageBusy) { Loading @@ -3959,6 +4003,9 @@ class StorageManagerService extends IStorageManager.Stub } else { rc = StorageResultCode.OperationFailedInternalError; } } catch (Exception e) { Slog.w(TAG, e); rc = StorageResultCode.OperationFailedInternalError; } if (rc == StorageResultCode.OperationSucceeded) { Loading