1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.pm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 23 /** 24 * Definition of a file in a streaming installation session. 25 * You can use this class to retrieve the information of such a file, such as its name, size and 26 * metadata. These file attributes will be consistent with those used in: 27 * {@code PackageInstaller.Session#addFile}, when the file was first added into the session. 28 * 29 * @see android.content.pm.PackageInstaller.Session#addFile 30 * @hide 31 */ 32 @SystemApi 33 public final class InstallationFile { 34 private final @NonNull InstallationFileParcel mParcel; 35 36 /** 37 * Constructor, internal use only 38 * @hide 39 */ InstallationFile(@ackageInstaller.FileLocation int location, @NonNull String name, long lengthBytes, @Nullable byte[] metadata, @Nullable byte[] signature)40 public InstallationFile(@PackageInstaller.FileLocation int location, @NonNull String name, 41 long lengthBytes, @Nullable byte[] metadata, @Nullable byte[] signature) { 42 mParcel = new InstallationFileParcel(); 43 mParcel.location = location; 44 mParcel.name = name; 45 mParcel.size = lengthBytes; 46 mParcel.metadata = metadata; 47 mParcel.signature = signature; 48 } 49 50 /** 51 * Installation Location of this file. Can be one of the following three locations: 52 * <ul> 53 * <li>(1) {@code PackageInstaller.LOCATION_DATA_APP}</li> 54 * <li>(2) {@code PackageInstaller.LOCATION_MEDIA_OBB}</li> 55 * <li>(3) {@code PackageInstaller.LOCATION_MEDIA_DATA}</li> 56 * </ul> 57 * @see android.content.pm.PackageInstaller 58 * @return Integer that denotes the installation location of the file. 59 */ getLocation()60 public @PackageInstaller.FileLocation int getLocation() { 61 return mParcel.location; 62 } 63 64 /** 65 * @return Name of the file. 66 */ getName()67 public @NonNull String getName() { 68 return mParcel.name; 69 } 70 71 /** 72 * @return File size in bytes. 73 */ getLengthBytes()74 public long getLengthBytes() { 75 return mParcel.size; 76 } 77 78 /** 79 * @return File metadata as a byte array 80 */ getMetadata()81 public @Nullable byte[] getMetadata() { 82 return mParcel.metadata; 83 } 84 85 /** 86 * @return File signature info as a byte array 87 */ getSignature()88 public @Nullable byte[] getSignature() { 89 return mParcel.signature; 90 } 91 92 /** @hide */ getData()93 public @NonNull InstallationFileParcel getData() { 94 return mParcel; 95 } 96 } 97