diff options
| author | Alex Buynytskyy <alexbuy@google.com> | 2019-12-16 06:44:49 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-16 06:44:49 +0000 |
| commit | 247901bb4f97b7ecbc6da4995a520b54cf392612 (patch) | |
| tree | 8eb72baa54f7ab360dbd52f2b8d6d49c53fc2b1d /core/java | |
| parent | dbd8737bcebed48660d81ee87e62159ebb042244 (diff) | |
| parent | f5c894f7ceea7993c23fe19bfe6b59de6836367e (diff) | |
Merge "[incremental] Java service and shell command handler"
Diffstat (limited to 'core/java')
6 files changed, 173 insertions, 166 deletions
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index fe774f8f639a..85027d9a1e18 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4991,7 +4991,7 @@ public abstract class Context { * {@link android.os.incremental.IncrementalManager}. * @hide */ - public static final String INCREMENTAL_SERVICE = "incremental"; + public static final String INCREMENTAL_SERVICE = "incremental_service"; /** * Determine whether the given permission is allowed for a particular diff --git a/core/java/android/os/incremental/IIncrementalManager.aidl b/core/java/android/os/incremental/IIncrementalManager.aidl index d6446d485af5..f84d7efe06b1 100644 --- a/core/java/android/os/incremental/IIncrementalManager.aidl +++ b/core/java/android/os/incremental/IIncrementalManager.aidl @@ -16,89 +16,22 @@ package android.os.incremental; +import android.os.incremental.IncrementalFileSystemControlParcel; import android.os.incremental.IncrementalDataLoaderParamsParcel; +import android.content.pm.IDataLoaderStatusListener; -/** @hide */ +/** + * Binder service to receive calls from native Incremental Service and handle Java tasks such as + * looking up data loader service package names, binding and talking to the data loader service. + * @hide + */ interface IIncrementalManager { - /** - * A set of flags for the |createMode| parameters when creating a new Incremental storage. - */ - const int CREATE_MODE_TEMPORARY_BIND = 1; - const int CREATE_MODE_PERMANENT_BIND = 2; - const int CREATE_MODE_CREATE = 4; - const int CREATE_MODE_OPEN_EXISTING = 8; - - /** - * Opens or creates a storage given a target path and data loader params. Returns the storage ID. - */ - int openStorage(in @utf8InCpp String path); - int createStorage(in @utf8InCpp String path, in IncrementalDataLoaderParamsParcel params, int createMode); - int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode); - - /** - * Bind-mounts a path under a storage to a full path. Can be permanent or temporary. - */ - const int BIND_TEMPORARY = 0; - const int BIND_PERMANENT = 1; - int makeBindMount(int storageId, in @utf8InCpp String pathUnderStorage, in @utf8InCpp String targetFullPath, int bindType); - - /** - * Deletes an existing bind mount on a path under a storage. Returns 0 on success, and -errno on failure. - */ - int deleteBindMount(int storageId, in @utf8InCpp String targetFullPath); - - /** - * Creates a directory under a storage. The target directory is specified by its relative path under the storage. - */ - int makeDirectory(int storageId, in @utf8InCpp String pathUnderStorage); - - /** - * Recursively creates a directory under a storage. The target directory is specified by its relative path under the storage. - * All the parent directories of the target directory will be created if they do not exist already. - */ - int makeDirectories(int storageId, in @utf8InCpp String pathUnderStorage); - - /** - * Creates a file under a storage, specifying its name, size and metadata. - */ - int makeFile(int storageId, in @utf8InCpp String pathUnderStorage, long size, in byte[] metadata); - - /** - * Creates a file under a storage. Content of the file is from a range inside another file. - * Both files are specified by relative paths under storage. - */ - int makeFileFromRange(int storageId, in @utf8InCpp String targetPathUnderStorage, in @utf8InCpp String sourcePathUnderStorage, long start, long end); - - /** - * Creates a hard link between two files in two storage instances. - * Source and dest specified by parent storage IDs and their relative paths under the storage. - * The source and dest storage instances should be in the same fs mount. - * Note: destStorageId can be the same as sourceStorageId. - */ - int makeLink(int sourceStorageId, in @utf8InCpp String sourcePathUnderStorage, int destStorageId, in @utf8InCpp String destPathUnderStorage); - - /** - * Deletes a hard link in a storage, specified by the relative path of the link target under storage. - */ - int unlink(int storageId, in @utf8InCpp String pathUnderStorage); - - /** - * Checks if a file's certain range is loaded. File is specified by relative file path under storage. - */ - boolean isFileRangeLoaded(int storageId, in @utf8InCpp String pathUnderStorage, long start, long end); - - /** - * Reads the metadata of a file. File is specified by relative path under storage. - */ - byte[] getFileMetadata(int storageId, in @utf8InCpp String pathUnderStorage); - - /** - * Starts loading data for a storage. - */ - boolean startLoading(int storageId); - - /** - * Deletes a storage given its ID. Deletes its bind mounts and unmount it. Stop its data loader. - */ - void deleteStorage(int storageId); + boolean prepareDataLoader(int mountId, + in IncrementalFileSystemControlParcel control, + in IncrementalDataLoaderParamsParcel params, + in IDataLoaderStatusListener listener); + boolean startDataLoader(int mountId); + void showHealthBlockedUI(int mountId); + void destroyDataLoader(int mountId); + void newFileForDataLoader(int mountId, long inode, in byte[] metadata); } diff --git a/core/java/android/os/incremental/IIncrementalManagerNative.aidl b/core/java/android/os/incremental/IIncrementalManagerNative.aidl new file mode 100644 index 000000000000..d9c7c6b5cc21 --- /dev/null +++ b/core/java/android/os/incremental/IIncrementalManagerNative.aidl @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os.incremental; + +import android.os.incremental.IncrementalDataLoaderParamsParcel; + +/** @hide */ +interface IIncrementalManagerNative { + /** + * A set of flags for the |createMode| parameters when creating a new Incremental storage. + */ + const int CREATE_MODE_TEMPORARY_BIND = 1; + const int CREATE_MODE_PERMANENT_BIND = 2; + const int CREATE_MODE_CREATE = 4; + const int CREATE_MODE_OPEN_EXISTING = 8; + + /** + * Opens or creates a storage given a target path and data loader params. Returns the storage ID. + */ + int openStorage(in @utf8InCpp String path); + int createStorage(in @utf8InCpp String path, in IncrementalDataLoaderParamsParcel params, int createMode); + int createLinkedStorage(in @utf8InCpp String path, int otherStorageId, int createMode); + + /** + * Bind-mounts a path under a storage to a full path. Can be permanent or temporary. + */ + const int BIND_TEMPORARY = 0; + const int BIND_PERMANENT = 1; + int makeBindMount(int storageId, in @utf8InCpp String pathUnderStorage, in @utf8InCpp String targetFullPath, int bindType); + + /** + * Deletes an existing bind mount on a path under a storage. Returns 0 on success, and -errno on failure. + */ + int deleteBindMount(int storageId, in @utf8InCpp String targetFullPath); + + /** + * Creates a directory under a storage. The target directory is specified by its relative path under the storage. + */ + int makeDirectory(int storageId, in @utf8InCpp String pathUnderStorage); + + /** + * Recursively creates a directory under a storage. The target directory is specified by its relative path under the storage. + * All the parent directories of the target directory will be created if they do not exist already. + */ + int makeDirectories(int storageId, in @utf8InCpp String pathUnderStorage); + + /** + * Creates a file under a storage, specifying its name, size and metadata. + */ + int makeFile(int storageId, in @utf8InCpp String pathUnderStorage, long size, in byte[] metadata); + + /** + * Creates a file under a storage. Content of the file is from a range inside another file. + * Both files are specified by relative paths under storage. + */ + int makeFileFromRange(int storageId, in @utf8InCpp String targetPathUnderStorage, in @utf8InCpp String sourcePathUnderStorage, long start, long end); + + /** + * Creates a hard link between two files in two storage instances. + * Source and dest specified by parent storage IDs and their relative paths under the storage. + * The source and dest storage instances should be in the same fs mount. + * Note: destStorageId can be the same as sourceStorageId. + */ + int makeLink(int sourceStorageId, in @utf8InCpp String sourcePathUnderStorage, int destStorageId, in @utf8InCpp String destPathUnderStorage); + + /** + * Deletes a hard link in a storage, specified by the relative path of the link target under storage. + */ + int unlink(int storageId, in @utf8InCpp String pathUnderStorage); + + /** + * Checks if a file's certain range is loaded. File is specified by relative file path under storage. + */ + boolean isFileRangeLoaded(int storageId, in @utf8InCpp String pathUnderStorage, long start, long end); + + /** + * Reads the metadata of a file. File is specified by relative path under storage. + */ + byte[] getFileMetadata(int storageId, in @utf8InCpp String pathUnderStorage); + + /** + * Starts loading data for a storage. + */ + boolean startLoading(int storageId); + + /** + * Deletes a storage given its ID. Deletes its bind mounts and unmount it. Stop its data loader. + */ + void deleteStorage(int storageId); +} diff --git a/core/java/android/os/incremental/IIncrementalServiceProxy.aidl b/core/java/android/os/incremental/IIncrementalServiceProxy.aidl deleted file mode 100644 index ffff52e5aac9..000000000000 --- a/core/java/android/os/incremental/IIncrementalServiceProxy.aidl +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.os.incremental; - -import android.os.incremental.IncrementalFileSystemControlParcel; -import android.os.incremental.IncrementalDataLoaderParamsParcel; -import android.content.pm.IDataLoaderStatusListener; - -/** - * Binder service to receive calls from native Incremental Service and handle Java tasks such as - * looking up data loader service package names, binding and talking to the data loader service. - * @hide - */ -interface IIncrementalServiceProxy { - boolean prepareDataLoader(int mountId, - in IncrementalFileSystemControlParcel control, - in IncrementalDataLoaderParamsParcel params, - in IDataLoaderStatusListener listener); - boolean startDataLoader(int mountId); - void showHealthBlockedUI(int mountId); - void destroyDataLoader(int mountId); - void newFileForDataLoader(int mountId, long inode, in byte[] metadata); -} diff --git a/core/java/android/os/incremental/IncrementalManager.java b/core/java/android/os/incremental/IncrementalManager.java index 5aabf86e17e6..c30f5589a835 100644 --- a/core/java/android/os/incremental/IncrementalManager.java +++ b/core/java/android/os/incremental/IncrementalManager.java @@ -36,31 +36,28 @@ import java.nio.file.Path; import java.nio.file.Paths; /** - * Provides operations to open or create an IncrementalStorage, using IIncrementalManager service. - * Example Usage: + * Provides operations to open or create an IncrementalStorage, using IIncrementalManagerNative + * service. Example Usage: * * <blockquote><pre> - * IncrementalManager manager = (IncrementalManager) getSystemService(Context.INCREMENTAL_MANAGER); + * IncrementalManager manager = (IncrementalManager) getSystemService(Context.INCREMENTAL_SERVICE); * IncrementalStorage storage = manager.openStorage("/path/to/incremental/dir"); * </pre></blockquote> * * @hide */ @SystemService(Context.INCREMENTAL_SERVICE) -public class IncrementalManager { +public final class IncrementalManager { private static final String TAG = "IncrementalManager"; - private final IIncrementalManager mService; - @GuardedBy("mStorages") - private final SparseArray<IncrementalStorage> mStorages = new SparseArray<>(); public static final int CREATE_MODE_TEMPORARY_BIND = - IIncrementalManager.CREATE_MODE_TEMPORARY_BIND; + IIncrementalManagerNative.CREATE_MODE_TEMPORARY_BIND; public static final int CREATE_MODE_PERMANENT_BIND = - IIncrementalManager.CREATE_MODE_PERMANENT_BIND; + IIncrementalManagerNative.CREATE_MODE_PERMANENT_BIND; public static final int CREATE_MODE_CREATE = - IIncrementalManager.CREATE_MODE_CREATE; + IIncrementalManagerNative.CREATE_MODE_CREATE; public static final int CREATE_MODE_OPEN_EXISTING = - IIncrementalManager.CREATE_MODE_OPEN_EXISTING; + IIncrementalManagerNative.CREATE_MODE_OPEN_EXISTING; @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"CREATE_MODE_"}, value = { @@ -72,8 +69,12 @@ public class IncrementalManager { public @interface CreateMode { } - public IncrementalManager(@NonNull IIncrementalManager is) { - mService = is; + private final @Nullable IIncrementalManagerNative mNativeService; + @GuardedBy("mStorages") + private final SparseArray<IncrementalStorage> mStorages = new SparseArray<>(); + + public IncrementalManager(IIncrementalManagerNative nativeService) { + mNativeService = nativeService; } /** @@ -82,6 +83,7 @@ public class IncrementalManager { * @param storageId The storage ID to identify the storage object. * @return IncrementalStorage object corresponding to storage ID. */ + // TODO(b/136132412): remove this @Nullable public IncrementalStorage getStorage(int storageId) { synchronized (mStorages) { @@ -95,8 +97,8 @@ public class IncrementalManager { * * @param path Absolute path to mount Incremental File System on. * @param params IncrementalDataLoaderParams object to configure data loading. - * @param createMode Mode for opening an old Incremental File System mount or - * creating a new mount. + * @param createMode Mode for opening an old Incremental File System mount or creating + * a new mount. * @param autoStartDataLoader Set true to immediately start data loader after creating storage. * @return IncrementalStorage object corresponding to the mounted directory. */ @@ -105,11 +107,11 @@ public class IncrementalManager { @NonNull IncrementalDataLoaderParams params, @CreateMode int createMode, boolean autoStartDataLoader) { try { - final int id = mService.createStorage(path, params.getData(), createMode); + final int id = mNativeService.createStorage(path, params.getData(), createMode); if (id < 0) { return null; } - final IncrementalStorage storage = new IncrementalStorage(mService, id); + final IncrementalStorage storage = new IncrementalStorage(mNativeService, id); synchronized (mStorages) { mStorages.put(id, storage); } @@ -123,8 +125,8 @@ public class IncrementalManager { } /** - * Opens an existing Incremental File System mounted directory and returns an - * IncrementalStorage object. + * Opens an existing Incremental File System mounted directory and returns an IncrementalStorage + * object. * * @param path Absolute target path that Incremental File System has been mounted on. * @return IncrementalStorage object corresponding to the mounted directory. @@ -132,11 +134,11 @@ public class IncrementalManager { @Nullable public IncrementalStorage openStorage(@NonNull String path) { try { - final int id = mService.openStorage(path); + final int id = mNativeService.openStorage(path); if (id < 0) { return null; } - final IncrementalStorage storage = new IncrementalStorage(mService, id); + final IncrementalStorage storage = new IncrementalStorage(mNativeService, id); synchronized (mStorages) { mStorages.put(id, storage); } @@ -155,11 +157,12 @@ public class IncrementalManager { public IncrementalStorage createStorage(@NonNull String path, @NonNull IncrementalStorage linkedStorage, @CreateMode int createMode) { try { - final int id = mService.createLinkedStorage(path, linkedStorage.getId(), createMode); + final int id = mNativeService.createLinkedStorage( + path, linkedStorage.getId(), createMode); if (id < 0) { return null; } - final IncrementalStorage storage = new IncrementalStorage(mService, id); + final IncrementalStorage storage = new IncrementalStorage(mNativeService, id); synchronized (mStorages) { mStorages.put(id, storage); } @@ -175,6 +178,7 @@ public class IncrementalManager { * @param file Target file to search storage for. * @return Absolute path which is a bind-mount point of Incremental File System. */ + @Nullable private Path getStoragePathForFile(File file) { File currentPath = new File(file.getParent()); while (currentPath.getParent() != null) { @@ -198,18 +202,19 @@ public class IncrementalManager { * </li> * </ol> * - * @param sourcePath Absolute path to the source. Should be the same type as the destPath - * (file or dir). Expected to already exist and is an Incremental path. - * @param destPath Absolute path to the destination. - * @throws IllegalArgumentException when 1) source does not exist, - * or 2) source and dest type mismatch (one is file and the other is dir), - * or 3) source path is not on Incremental File System, - * @throws IOException when 1) cannot find the root path of the Incremental storage of source, - * or 2) cannot retrieve the Incremental storage instance of the source, - * or 3) renaming a file, but dest is not on the same Incremental Storage, - * or 4) renaming a dir, dest dir does not exist but fails to be created. - * - * TODO(b/136132412): add unit tests + * @param sourcePath Absolute path to the source. Should be the same type as the destPath (file + * or dir). Expected to already exist and is an Incremental path. + * @param destPath Absolute path to the destination. + * @throws IllegalArgumentException when 1) source does not exist, or 2) source and dest type + * mismatch (one is file and the other is dir), or 3) source + * path is not on Incremental File System, + * @throws IOException when 1) cannot find the root path of the Incremental storage + * of source, or 2) cannot retrieve the Incremental storage + * instance of the source, or 3) renaming a file, but dest is + * not on the same Incremental Storage, or 4) renaming a dir, + * dest dir does not exist but fails to be created. + * <p> + * TODO(b/136132412): add unit tests */ public void rename(@NonNull String sourcePath, @NonNull String destPath) throws IOException { final File source = new File(sourcePath); @@ -243,6 +248,7 @@ public class IncrementalManager { if (storage == null) { throw new IOException("Failed to retrieve storage from Incremental Service."); } + if (source.isFile()) { renameFile(storage, storagePath, source, dest); } else { @@ -304,11 +310,11 @@ public class IncrementalManager { */ public void closeStorage(@NonNull String path) { try { - final int id = mService.openStorage(path); + final int id = mNativeService.openStorage(path); if (id < 0) { return; } - mService.deleteStorage(id); + mNativeService.deleteStorage(id); synchronized (mStorages) { mStorages.remove(id); } @@ -321,7 +327,7 @@ public class IncrementalManager { * Checks if path is mounted on Incremental File System. */ public static boolean isIncrementalPath(@NonNull String path) { - // TODO(b/136132412): implement native method + // TODO(b/136132412): add jni implementation return false; } } diff --git a/core/java/android/os/incremental/IncrementalStorage.java b/core/java/android/os/incremental/IncrementalStorage.java index 2bf89ed7f7e8..275086832c51 100644 --- a/core/java/android/os/incremental/IncrementalStorage.java +++ b/core/java/android/os/incremental/IncrementalStorage.java @@ -24,11 +24,11 @@ import java.io.File; import java.io.IOException; /** - * Provides operations on an Incremental File System directory, using IncrementalService. Example - * usage: + * Provides operations on an Incremental File System directory, using IncrementalServiceNative. + * Example usage: * * <blockquote><pre> - * IncrementalManager manager = (IncrementalManager) getSystemService(Context.INCREMENTAL_MANAGER); + * IncrementalManager manager = (IncrementalManager) getSystemService(Context.INCREMENTAL_SERVICE); * IncrementalStorage storage = manager.openStorage("/path/to/incremental/dir"); * storage.makeDirectory("subdir"); * </pre></blockquote> @@ -38,10 +38,10 @@ import java.io.IOException; public final class IncrementalStorage { private static final String TAG = "IncrementalStorage"; private final int mId; - private final IIncrementalManager mService; + private final IIncrementalManagerNative mService; - public IncrementalStorage(@NonNull IIncrementalManager is, int id) { + public IncrementalStorage(@NonNull IIncrementalManagerNative is, int id) { mService = is; mId = id; } @@ -72,7 +72,7 @@ public final class IncrementalStorage { throws IOException { try { int res = mService.makeBindMount(mId, sourcePathUnderStorage, targetPath, - IIncrementalManager.BIND_TEMPORARY); + IIncrementalManagerNative.BIND_TEMPORARY); if (res < 0) { throw new IOException("bind() failed with errno " + -res); } @@ -103,7 +103,7 @@ public final class IncrementalStorage { throws IOException { try { int res = mService.makeBindMount(mId, sourcePathUnderStorage, targetPath, - IIncrementalManager.BIND_PERMANENT); + IIncrementalManagerNative.BIND_PERMANENT); if (res < 0) { throw new IOException("bind() permanent failed with errno " + -res); } @@ -274,7 +274,8 @@ public final class IncrementalStorage { throw new IOException("moveDir() requires that destination dir already exists."); } try { - int res = mService.makeBindMount(mId, "", destPath, IIncrementalManager.BIND_PERMANENT); + int res = mService.makeBindMount(mId, "", destPath, + IIncrementalManagerNative.BIND_PERMANENT); if (res < 0) { throw new IOException("moveDir() failed at making bind mount, errno " + -res); } |
