Loading core/java/android/content/pm/IPackageInstallerSession.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -69,4 +69,5 @@ interface IPackageInstallerSession { ParcelFileDescriptor getAppMetadataFd(); ParcelFileDescriptor getAppMetadataFd(); ParcelFileDescriptor openWriteAppMetadata(); ParcelFileDescriptor openWriteAppMetadata(); void removeAppMetadata(); } } core/java/android/content/pm/PackageInstaller.java +10 −4 Original line number Original line Diff line number Diff line Loading @@ -1956,16 +1956,22 @@ public class PackageInstaller { /** /** * Optionally set the app metadata. The size of this data cannot exceed the maximum allowed. * Optionally set the app metadata. The size of this data cannot exceed the maximum allowed. * Any existing data from the previous install will not be retained even if no data is set * Any existing data from the previous install will not be retained even if no data is set * for the current install session. * for the current install session. Setting data to null or an empty PersistableBundle will * remove any metadata that has previously been set in the same session. * * * @param data a PersistableBundle containing the app metadata. If this is set to null then * @param data a PersistableBundle containing the app metadata. * any existing app metadata will be removed. * @throws IOException if writing the data fails. * @throws IOException if writing the data fails. */ */ public void setAppMetadata(@Nullable PersistableBundle data) throws IOException { public void setAppMetadata(@Nullable PersistableBundle data) throws IOException { if (data == null) { if (data == null || data.isEmpty()) { try { mSession.removeAppMetadata(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } return; return; } } Objects.requireNonNull(data); try (OutputStream outputStream = openWriteAppMetadata()) { try (OutputStream outputStream = openWriteAppMetadata()) { data.writeToStream(outputStream); data.writeToStream(outputStream); } } Loading services/core/java/com/android/server/pm/PackageInstallerSession.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -1521,7 +1521,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { public ParcelFileDescriptor getAppMetadataFd() { public ParcelFileDescriptor getAppMetadataFd() { assertCallerIsOwnerOrRoot(); assertCallerIsOwnerOrRoot(); synchronized (mLock) { synchronized (mLock) { assertPreparedAndNotCommittedOrDestroyedLocked("openRead"); assertPreparedAndNotCommittedOrDestroyedLocked("getAppMetadataFd"); if (getStagedAppMetadataFile() == null) { return null; } try { try { return openReadInternalLocked(APP_METADATA_FILE_NAME); return openReadInternalLocked(APP_METADATA_FILE_NAME); } catch (IOException e) { } catch (IOException e) { Loading @@ -1530,6 +1533,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } } } @Override public void removeAppMetadata() { File file = getStagedAppMetadataFile(); if (file != null) { file.delete(); } } private static long getAppMetadataSizeLimit() { private static long getAppMetadataSizeLimit() { final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity(); try { try { Loading Loading
core/java/android/content/pm/IPackageInstallerSession.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -69,4 +69,5 @@ interface IPackageInstallerSession { ParcelFileDescriptor getAppMetadataFd(); ParcelFileDescriptor getAppMetadataFd(); ParcelFileDescriptor openWriteAppMetadata(); ParcelFileDescriptor openWriteAppMetadata(); void removeAppMetadata(); } }
core/java/android/content/pm/PackageInstaller.java +10 −4 Original line number Original line Diff line number Diff line Loading @@ -1956,16 +1956,22 @@ public class PackageInstaller { /** /** * Optionally set the app metadata. The size of this data cannot exceed the maximum allowed. * Optionally set the app metadata. The size of this data cannot exceed the maximum allowed. * Any existing data from the previous install will not be retained even if no data is set * Any existing data from the previous install will not be retained even if no data is set * for the current install session. * for the current install session. Setting data to null or an empty PersistableBundle will * remove any metadata that has previously been set in the same session. * * * @param data a PersistableBundle containing the app metadata. If this is set to null then * @param data a PersistableBundle containing the app metadata. * any existing app metadata will be removed. * @throws IOException if writing the data fails. * @throws IOException if writing the data fails. */ */ public void setAppMetadata(@Nullable PersistableBundle data) throws IOException { public void setAppMetadata(@Nullable PersistableBundle data) throws IOException { if (data == null) { if (data == null || data.isEmpty()) { try { mSession.removeAppMetadata(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } return; return; } } Objects.requireNonNull(data); try (OutputStream outputStream = openWriteAppMetadata()) { try (OutputStream outputStream = openWriteAppMetadata()) { data.writeToStream(outputStream); data.writeToStream(outputStream); } } Loading
services/core/java/com/android/server/pm/PackageInstallerSession.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -1521,7 +1521,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { public ParcelFileDescriptor getAppMetadataFd() { public ParcelFileDescriptor getAppMetadataFd() { assertCallerIsOwnerOrRoot(); assertCallerIsOwnerOrRoot(); synchronized (mLock) { synchronized (mLock) { assertPreparedAndNotCommittedOrDestroyedLocked("openRead"); assertPreparedAndNotCommittedOrDestroyedLocked("getAppMetadataFd"); if (getStagedAppMetadataFile() == null) { return null; } try { try { return openReadInternalLocked(APP_METADATA_FILE_NAME); return openReadInternalLocked(APP_METADATA_FILE_NAME); } catch (IOException e) { } catch (IOException e) { Loading @@ -1530,6 +1533,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } } } @Override public void removeAppMetadata() { File file = getStagedAppMetadataFile(); if (file != null) { file.delete(); } } private static long getAppMetadataSizeLimit() { private static long getAppMetadataSizeLimit() { final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity(); try { try { Loading