Loading api/system-current.txt +19 −0 Original line number Diff line number Diff line Loading @@ -9690,6 +9690,25 @@ package android.content.pm { field public int reqTouchScreen; } public deprecated class ContainerEncryptionParams implements android.os.Parcelable { ctor public ContainerEncryptionParams(java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey) throws java.security.InvalidAlgorithmParameterException; ctor public ContainerEncryptionParams(java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey, java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey, byte[], long, long, long) throws java.security.InvalidAlgorithmParameterException; method public int describeContents(); method public long getAuthenticatedDataStart(); method public long getDataEnd(); method public long getEncryptedDataStart(); method public java.lang.String getEncryptionAlgorithm(); method public javax.crypto.SecretKey getEncryptionKey(); method public java.security.spec.AlgorithmParameterSpec getEncryptionSpec(); method public java.lang.String getMacAlgorithm(); method public javax.crypto.SecretKey getMacKey(); method public java.security.spec.AlgorithmParameterSpec getMacSpec(); method public byte[] getMacTag(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator<android.content.pm.ContainerEncryptionParams> CREATOR; field protected static final java.lang.String TAG = "ContainerEncryptionParams"; } public final class EphemeralResolveInfo implements android.os.Parcelable { ctor public EphemeralResolveInfo(android.net.Uri, java.lang.String, java.util.List<android.content.IntentFilter>); method public int describeContents(); core/java/android/app/ApplicationPackageManager.java +58 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.IntentSender; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ComponentInfo; import android.content.pm.ContainerEncryptionParams; import android.content.pm.EphemeralApplicationInfo; import android.content.pm.FeatureInfo; import android.content.pm.IOnPermissionsChangeListener; Loading @@ -52,6 +53,7 @@ import android.content.pm.ProviderInfo; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; import android.content.res.Resources; import android.content.res.XmlResourceParser; Loading Loading @@ -1452,27 +1454,80 @@ public class ApplicationPackageManager extends PackageManager { @Override public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName) { final VerificationParams verificationParams = new VerificationParams(null, null, null, VerificationParams.NO_UID); installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, mContext.getUserId()); installerPackageName, verificationParams, null, mContext.getUserId()); } @Override public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams) { final VerificationParams verificationParams = new VerificationParams(verificationURI, null, null, VerificationParams.NO_UID); installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackage(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName) { installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId()); installPackageAsUser(packageURI, observer, flags, installerPackageName, mContext.getUserId()); } @Override public void installPackageAsUser(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, int userId) { final VerificationParams verificationParams = new VerificationParams(null, null, null, VerificationParams.NO_UID); installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null, userId); } @Override public void installPackageWithVerification(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams) { final VerificationParams verificationParams = new VerificationParams(verificationURI, null, null, VerificationParams.NO_UID); installCommon(packageURI, observer, flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackageWithVerificationAndEncryption(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { installCommon(packageURI, observer, flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } private void installCommon(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams, int userId) { if (!"file".equals(packageURI.getScheme())) { throw new UnsupportedOperationException("Only file:// URIs are supported"); } if (encryptionParams != null) { throw new UnsupportedOperationException("ContainerEncryptionParams not supported"); } final String originPath = packageURI.getPath(); try { mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName, userId); verificationParams, null, userId); } catch (RemoteException ignored) { } } Loading core/java/android/content/pm/ContainerEncryptionParams.java 0 → 100644 +384 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.content.pm; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.util.Slog; import java.security.InvalidAlgorithmParameterException; import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; /** * Represents encryption parameters used to read a container. * * @deprecated encrypted containers are legacy. * @hide */ @SystemApi @Deprecated public class ContainerEncryptionParams implements Parcelable { protected static final String TAG = "ContainerEncryptionParams"; /** What we print out first when toString() is called. */ private static final String TO_STRING_PREFIX = "ContainerEncryptionParams{"; /** * Parameter type for parceling that indicates the next parameters are * IvParameters. */ private static final int ENC_PARAMS_IV_PARAMETERS = 1; /** Parameter type for paceling that indicates there are no MAC parameters. */ private static final int MAC_PARAMS_NONE = 1; /** The encryption algorithm used. */ private final String mEncryptionAlgorithm; /** The parameter spec to be used for encryption. */ private final IvParameterSpec mEncryptionSpec; /** Secret key to be used for decryption. */ private final SecretKey mEncryptionKey; /** Algorithm name for the MAC to be used. */ private final String mMacAlgorithm; /** The parameter spec to be used for the MAC tag authentication. */ private final AlgorithmParameterSpec mMacSpec; /** Secret key to be used for MAC tag authentication. */ private final SecretKey mMacKey; /** MAC tag authenticating the data in the container. */ private final byte[] mMacTag; /** Offset into file where authenticated (e.g., MAC protected) data begins. */ private final long mAuthenticatedDataStart; /** Offset into file where encrypted data begins. */ private final long mEncryptedDataStart; /** * Offset into file for the end of encrypted data (and, by extension, * authenticated data) in file. */ private final long mDataEnd; public ContainerEncryptionParams(String encryptionAlgorithm, AlgorithmParameterSpec encryptionSpec, SecretKey encryptionKey) throws InvalidAlgorithmParameterException { this(encryptionAlgorithm, encryptionSpec, encryptionKey, null, null, null, null, -1, -1, -1); } /** * Creates container encryption specifications for installing from encrypted * containers. * * @param encryptionAlgorithm encryption algorithm to use; format matches * JCE * @param encryptionSpec algorithm parameter specification * @param encryptionKey key used for decryption * @param macAlgorithm MAC algorithm to use; format matches JCE * @param macSpec algorithm parameters specification, may be {@code null} * @param macKey key used for authentication (i.e., for the MAC tag) * @param macTag message authentication code (MAC) tag for the authenticated * data * @param authenticatedDataStart offset of start of authenticated data in * stream * @param encryptedDataStart offset of start of encrypted data in stream * @param dataEnd offset of the end of both the authenticated and encrypted * data * @throws InvalidAlgorithmParameterException */ public ContainerEncryptionParams(String encryptionAlgorithm, AlgorithmParameterSpec encryptionSpec, SecretKey encryptionKey, String macAlgorithm, AlgorithmParameterSpec macSpec, SecretKey macKey, byte[] macTag, long authenticatedDataStart, long encryptedDataStart, long dataEnd) throws InvalidAlgorithmParameterException { if (TextUtils.isEmpty(encryptionAlgorithm)) { throw new NullPointerException("algorithm == null"); } else if (encryptionSpec == null) { throw new NullPointerException("encryptionSpec == null"); } else if (encryptionKey == null) { throw new NullPointerException("encryptionKey == null"); } if (!TextUtils.isEmpty(macAlgorithm)) { if (macKey == null) { throw new NullPointerException("macKey == null"); } } if (!(encryptionSpec instanceof IvParameterSpec)) { throw new InvalidAlgorithmParameterException( "Unknown parameter spec class; must be IvParameters"); } mEncryptionAlgorithm = encryptionAlgorithm; mEncryptionSpec = (IvParameterSpec) encryptionSpec; mEncryptionKey = encryptionKey; mMacAlgorithm = macAlgorithm; mMacSpec = macSpec; mMacKey = macKey; mMacTag = macTag; mAuthenticatedDataStart = authenticatedDataStart; mEncryptedDataStart = encryptedDataStart; mDataEnd = dataEnd; } public String getEncryptionAlgorithm() { return mEncryptionAlgorithm; } public AlgorithmParameterSpec getEncryptionSpec() { return mEncryptionSpec; } public SecretKey getEncryptionKey() { return mEncryptionKey; } public String getMacAlgorithm() { return mMacAlgorithm; } public AlgorithmParameterSpec getMacSpec() { return mMacSpec; } public SecretKey getMacKey() { return mMacKey; } public byte[] getMacTag() { return mMacTag; } public long getAuthenticatedDataStart() { return mAuthenticatedDataStart; } public long getEncryptedDataStart() { return mEncryptedDataStart; } public long getDataEnd() { return mDataEnd; } @Override public int describeContents() { return 0; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ContainerEncryptionParams)) { return false; } final ContainerEncryptionParams other = (ContainerEncryptionParams) o; // Primitive comparison if ((mAuthenticatedDataStart != other.mAuthenticatedDataStart) || (mEncryptedDataStart != other.mEncryptedDataStart) || (mDataEnd != other.mDataEnd)) { return false; } // String comparison if (!mEncryptionAlgorithm.equals(other.mEncryptionAlgorithm) || !mMacAlgorithm.equals(other.mMacAlgorithm)) { return false; } // Object comparison if (!isSecretKeyEqual(mEncryptionKey, other.mEncryptionKey) || !isSecretKeyEqual(mMacKey, other.mMacKey)) { return false; } if (!Arrays.equals(mEncryptionSpec.getIV(), other.mEncryptionSpec.getIV()) || !Arrays.equals(mMacTag, other.mMacTag) || (mMacSpec != other.mMacSpec)) { return false; } return true; } private static final boolean isSecretKeyEqual(SecretKey key1, SecretKey key2) { final String keyFormat = key1.getFormat(); final String otherKeyFormat = key2.getFormat(); if (keyFormat == null) { if (keyFormat != otherKeyFormat) { return false; } if (key1.getEncoded() != key2.getEncoded()) { return false; } } else { if (!keyFormat.equals(key2.getFormat())) { return false; } if (!Arrays.equals(key1.getEncoded(), key2.getEncoded())) { return false; } } return true; } @Override public int hashCode() { int hash = 3; hash += 5 * mEncryptionAlgorithm.hashCode(); hash += 7 * Arrays.hashCode(mEncryptionSpec.getIV()); hash += 11 * mEncryptionKey.hashCode(); hash += 13 * mMacAlgorithm.hashCode(); hash += 17 * mMacKey.hashCode(); hash += 19 * Arrays.hashCode(mMacTag); hash += 23 * mAuthenticatedDataStart; hash += 29 * mEncryptedDataStart; hash += 31 * mDataEnd; return hash; } @Override public String toString() { final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX); sb.append("mEncryptionAlgorithm=\""); sb.append(mEncryptionAlgorithm); sb.append("\","); sb.append("mEncryptionSpec="); sb.append(mEncryptionSpec.toString()); sb.append("mEncryptionKey="); sb.append(mEncryptionKey.toString()); sb.append("mMacAlgorithm=\""); sb.append(mMacAlgorithm); sb.append("\","); sb.append("mMacSpec="); sb.append(mMacSpec.toString()); sb.append("mMacKey="); sb.append(mMacKey.toString()); sb.append(",mAuthenticatedDataStart="); sb.append(mAuthenticatedDataStart); sb.append(",mEncryptedDataStart="); sb.append(mEncryptedDataStart); sb.append(",mDataEnd="); sb.append(mDataEnd); sb.append('}'); return sb.toString(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(mEncryptionAlgorithm); dest.writeInt(ENC_PARAMS_IV_PARAMETERS); dest.writeByteArray(mEncryptionSpec.getIV()); dest.writeSerializable(mEncryptionKey); dest.writeString(mMacAlgorithm); dest.writeInt(MAC_PARAMS_NONE); dest.writeByteArray(new byte[0]); dest.writeSerializable(mMacKey); dest.writeByteArray(mMacTag); dest.writeLong(mAuthenticatedDataStart); dest.writeLong(mEncryptedDataStart); dest.writeLong(mDataEnd); } private ContainerEncryptionParams(Parcel source) throws InvalidAlgorithmParameterException { mEncryptionAlgorithm = source.readString(); final int encParamType = source.readInt(); final byte[] encParamsEncoded = source.createByteArray(); mEncryptionKey = (SecretKey) source.readSerializable(); mMacAlgorithm = source.readString(); final int macParamType = source.readInt(); source.createByteArray(); // byte[] macParamsEncoded mMacKey = (SecretKey) source.readSerializable(); mMacTag = source.createByteArray(); mAuthenticatedDataStart = source.readLong(); mEncryptedDataStart = source.readLong(); mDataEnd = source.readLong(); switch (encParamType) { case ENC_PARAMS_IV_PARAMETERS: mEncryptionSpec = new IvParameterSpec(encParamsEncoded); break; default: throw new InvalidAlgorithmParameterException("Unknown parameter type " + encParamType); } switch (macParamType) { case MAC_PARAMS_NONE: mMacSpec = null; break; default: throw new InvalidAlgorithmParameterException("Unknown parameter type " + macParamType); } if (mEncryptionKey == null) { throw new NullPointerException("encryptionKey == null"); } } public static final Parcelable.Creator<ContainerEncryptionParams> CREATOR = new Parcelable.Creator<ContainerEncryptionParams>() { public ContainerEncryptionParams createFromParcel(Parcel source) { try { return new ContainerEncryptionParams(source); } catch (InvalidAlgorithmParameterException e) { Slog.e(TAG, "Invalid algorithm parameters specified", e); return null; } } public ContainerEncryptionParams[] newArray(int size) { return new ContainerEncryptionParams[size]; } }; } No newline at end of file core/java/android/content/pm/IPackageManager.aidl +10 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.content.pm.PermissionInfo; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; import android.graphics.Bitmap; import android.net.Uri; Loading Loading @@ -213,11 +214,19 @@ interface IPackageManager { List<InstrumentationInfo> queryInstrumentation( String targetPackage, int flags); /** @deprecated Use PackageInstaller instead */ void installPackage(in String originPath, in IPackageInstallObserver2 observer, int flags, in String installerPackageName, in VerificationParams verificationParams, in String packageAbiOverride); void installPackageAsUser(in String originPath, in IPackageInstallObserver2 observer, int flags, in String installerPackageName, in VerificationParams verificationParams, in String packageAbiOverride, int userId); void finishPackageInstall(int token); Loading core/java/android/content/pm/PackageManager.java +48 −8 Original line number Diff line number Diff line Loading @@ -4504,20 +4504,60 @@ public abstract class PackageManager { */ @Deprecated public abstract void installPackage( Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackage( Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); public abstract void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackage(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageAsUser(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, @UserIdInt int userId); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerification(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerificationAndEncryption(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams); /** * If there is already an application with the given package name installed Loading Loading
api/system-current.txt +19 −0 Original line number Diff line number Diff line Loading @@ -9690,6 +9690,25 @@ package android.content.pm { field public int reqTouchScreen; } public deprecated class ContainerEncryptionParams implements android.os.Parcelable { ctor public ContainerEncryptionParams(java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey) throws java.security.InvalidAlgorithmParameterException; ctor public ContainerEncryptionParams(java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey, java.lang.String, java.security.spec.AlgorithmParameterSpec, javax.crypto.SecretKey, byte[], long, long, long) throws java.security.InvalidAlgorithmParameterException; method public int describeContents(); method public long getAuthenticatedDataStart(); method public long getDataEnd(); method public long getEncryptedDataStart(); method public java.lang.String getEncryptionAlgorithm(); method public javax.crypto.SecretKey getEncryptionKey(); method public java.security.spec.AlgorithmParameterSpec getEncryptionSpec(); method public java.lang.String getMacAlgorithm(); method public javax.crypto.SecretKey getMacKey(); method public java.security.spec.AlgorithmParameterSpec getMacSpec(); method public byte[] getMacTag(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator<android.content.pm.ContainerEncryptionParams> CREATOR; field protected static final java.lang.String TAG = "ContainerEncryptionParams"; } public final class EphemeralResolveInfo implements android.os.Parcelable { ctor public EphemeralResolveInfo(android.net.Uri, java.lang.String, java.util.List<android.content.IntentFilter>); method public int describeContents();
core/java/android/app/ApplicationPackageManager.java +58 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.content.IntentSender; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ComponentInfo; import android.content.pm.ContainerEncryptionParams; import android.content.pm.EphemeralApplicationInfo; import android.content.pm.FeatureInfo; import android.content.pm.IOnPermissionsChangeListener; Loading @@ -52,6 +53,7 @@ import android.content.pm.ProviderInfo; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; import android.content.res.Resources; import android.content.res.XmlResourceParser; Loading Loading @@ -1452,27 +1454,80 @@ public class ApplicationPackageManager extends PackageManager { @Override public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName) { final VerificationParams verificationParams = new VerificationParams(null, null, null, VerificationParams.NO_UID); installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, mContext.getUserId()); installerPackageName, verificationParams, null, mContext.getUserId()); } @Override public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams) { final VerificationParams verificationParams = new VerificationParams(verificationURI, null, null, VerificationParams.NO_UID); installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackage(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName) { installCommon(packageURI, observer, flags, installerPackageName, mContext.getUserId()); installPackageAsUser(packageURI, observer, flags, installerPackageName, mContext.getUserId()); } @Override public void installPackageAsUser(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, int userId) { final VerificationParams verificationParams = new VerificationParams(null, null, null, VerificationParams.NO_UID); installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null, userId); } @Override public void installPackageWithVerification(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams) { final VerificationParams verificationParams = new VerificationParams(verificationURI, null, null, VerificationParams.NO_UID); installCommon(packageURI, observer, flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } @Override public void installPackageWithVerificationAndEncryption(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) { installCommon(packageURI, observer, flags, installerPackageName, verificationParams, encryptionParams, mContext.getUserId()); } private void installCommon(Uri packageURI, PackageInstallObserver observer, int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams, int userId) { if (!"file".equals(packageURI.getScheme())) { throw new UnsupportedOperationException("Only file:// URIs are supported"); } if (encryptionParams != null) { throw new UnsupportedOperationException("ContainerEncryptionParams not supported"); } final String originPath = packageURI.getPath(); try { mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName, userId); verificationParams, null, userId); } catch (RemoteException ignored) { } } Loading
core/java/android/content/pm/ContainerEncryptionParams.java 0 → 100644 +384 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.content.pm; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import android.util.Slog; import java.security.InvalidAlgorithmParameterException; import java.security.spec.AlgorithmParameterSpec; import java.util.Arrays; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; /** * Represents encryption parameters used to read a container. * * @deprecated encrypted containers are legacy. * @hide */ @SystemApi @Deprecated public class ContainerEncryptionParams implements Parcelable { protected static final String TAG = "ContainerEncryptionParams"; /** What we print out first when toString() is called. */ private static final String TO_STRING_PREFIX = "ContainerEncryptionParams{"; /** * Parameter type for parceling that indicates the next parameters are * IvParameters. */ private static final int ENC_PARAMS_IV_PARAMETERS = 1; /** Parameter type for paceling that indicates there are no MAC parameters. */ private static final int MAC_PARAMS_NONE = 1; /** The encryption algorithm used. */ private final String mEncryptionAlgorithm; /** The parameter spec to be used for encryption. */ private final IvParameterSpec mEncryptionSpec; /** Secret key to be used for decryption. */ private final SecretKey mEncryptionKey; /** Algorithm name for the MAC to be used. */ private final String mMacAlgorithm; /** The parameter spec to be used for the MAC tag authentication. */ private final AlgorithmParameterSpec mMacSpec; /** Secret key to be used for MAC tag authentication. */ private final SecretKey mMacKey; /** MAC tag authenticating the data in the container. */ private final byte[] mMacTag; /** Offset into file where authenticated (e.g., MAC protected) data begins. */ private final long mAuthenticatedDataStart; /** Offset into file where encrypted data begins. */ private final long mEncryptedDataStart; /** * Offset into file for the end of encrypted data (and, by extension, * authenticated data) in file. */ private final long mDataEnd; public ContainerEncryptionParams(String encryptionAlgorithm, AlgorithmParameterSpec encryptionSpec, SecretKey encryptionKey) throws InvalidAlgorithmParameterException { this(encryptionAlgorithm, encryptionSpec, encryptionKey, null, null, null, null, -1, -1, -1); } /** * Creates container encryption specifications for installing from encrypted * containers. * * @param encryptionAlgorithm encryption algorithm to use; format matches * JCE * @param encryptionSpec algorithm parameter specification * @param encryptionKey key used for decryption * @param macAlgorithm MAC algorithm to use; format matches JCE * @param macSpec algorithm parameters specification, may be {@code null} * @param macKey key used for authentication (i.e., for the MAC tag) * @param macTag message authentication code (MAC) tag for the authenticated * data * @param authenticatedDataStart offset of start of authenticated data in * stream * @param encryptedDataStart offset of start of encrypted data in stream * @param dataEnd offset of the end of both the authenticated and encrypted * data * @throws InvalidAlgorithmParameterException */ public ContainerEncryptionParams(String encryptionAlgorithm, AlgorithmParameterSpec encryptionSpec, SecretKey encryptionKey, String macAlgorithm, AlgorithmParameterSpec macSpec, SecretKey macKey, byte[] macTag, long authenticatedDataStart, long encryptedDataStart, long dataEnd) throws InvalidAlgorithmParameterException { if (TextUtils.isEmpty(encryptionAlgorithm)) { throw new NullPointerException("algorithm == null"); } else if (encryptionSpec == null) { throw new NullPointerException("encryptionSpec == null"); } else if (encryptionKey == null) { throw new NullPointerException("encryptionKey == null"); } if (!TextUtils.isEmpty(macAlgorithm)) { if (macKey == null) { throw new NullPointerException("macKey == null"); } } if (!(encryptionSpec instanceof IvParameterSpec)) { throw new InvalidAlgorithmParameterException( "Unknown parameter spec class; must be IvParameters"); } mEncryptionAlgorithm = encryptionAlgorithm; mEncryptionSpec = (IvParameterSpec) encryptionSpec; mEncryptionKey = encryptionKey; mMacAlgorithm = macAlgorithm; mMacSpec = macSpec; mMacKey = macKey; mMacTag = macTag; mAuthenticatedDataStart = authenticatedDataStart; mEncryptedDataStart = encryptedDataStart; mDataEnd = dataEnd; } public String getEncryptionAlgorithm() { return mEncryptionAlgorithm; } public AlgorithmParameterSpec getEncryptionSpec() { return mEncryptionSpec; } public SecretKey getEncryptionKey() { return mEncryptionKey; } public String getMacAlgorithm() { return mMacAlgorithm; } public AlgorithmParameterSpec getMacSpec() { return mMacSpec; } public SecretKey getMacKey() { return mMacKey; } public byte[] getMacTag() { return mMacTag; } public long getAuthenticatedDataStart() { return mAuthenticatedDataStart; } public long getEncryptedDataStart() { return mEncryptedDataStart; } public long getDataEnd() { return mDataEnd; } @Override public int describeContents() { return 0; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ContainerEncryptionParams)) { return false; } final ContainerEncryptionParams other = (ContainerEncryptionParams) o; // Primitive comparison if ((mAuthenticatedDataStart != other.mAuthenticatedDataStart) || (mEncryptedDataStart != other.mEncryptedDataStart) || (mDataEnd != other.mDataEnd)) { return false; } // String comparison if (!mEncryptionAlgorithm.equals(other.mEncryptionAlgorithm) || !mMacAlgorithm.equals(other.mMacAlgorithm)) { return false; } // Object comparison if (!isSecretKeyEqual(mEncryptionKey, other.mEncryptionKey) || !isSecretKeyEqual(mMacKey, other.mMacKey)) { return false; } if (!Arrays.equals(mEncryptionSpec.getIV(), other.mEncryptionSpec.getIV()) || !Arrays.equals(mMacTag, other.mMacTag) || (mMacSpec != other.mMacSpec)) { return false; } return true; } private static final boolean isSecretKeyEqual(SecretKey key1, SecretKey key2) { final String keyFormat = key1.getFormat(); final String otherKeyFormat = key2.getFormat(); if (keyFormat == null) { if (keyFormat != otherKeyFormat) { return false; } if (key1.getEncoded() != key2.getEncoded()) { return false; } } else { if (!keyFormat.equals(key2.getFormat())) { return false; } if (!Arrays.equals(key1.getEncoded(), key2.getEncoded())) { return false; } } return true; } @Override public int hashCode() { int hash = 3; hash += 5 * mEncryptionAlgorithm.hashCode(); hash += 7 * Arrays.hashCode(mEncryptionSpec.getIV()); hash += 11 * mEncryptionKey.hashCode(); hash += 13 * mMacAlgorithm.hashCode(); hash += 17 * mMacKey.hashCode(); hash += 19 * Arrays.hashCode(mMacTag); hash += 23 * mAuthenticatedDataStart; hash += 29 * mEncryptedDataStart; hash += 31 * mDataEnd; return hash; } @Override public String toString() { final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX); sb.append("mEncryptionAlgorithm=\""); sb.append(mEncryptionAlgorithm); sb.append("\","); sb.append("mEncryptionSpec="); sb.append(mEncryptionSpec.toString()); sb.append("mEncryptionKey="); sb.append(mEncryptionKey.toString()); sb.append("mMacAlgorithm=\""); sb.append(mMacAlgorithm); sb.append("\","); sb.append("mMacSpec="); sb.append(mMacSpec.toString()); sb.append("mMacKey="); sb.append(mMacKey.toString()); sb.append(",mAuthenticatedDataStart="); sb.append(mAuthenticatedDataStart); sb.append(",mEncryptedDataStart="); sb.append(mEncryptedDataStart); sb.append(",mDataEnd="); sb.append(mDataEnd); sb.append('}'); return sb.toString(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(mEncryptionAlgorithm); dest.writeInt(ENC_PARAMS_IV_PARAMETERS); dest.writeByteArray(mEncryptionSpec.getIV()); dest.writeSerializable(mEncryptionKey); dest.writeString(mMacAlgorithm); dest.writeInt(MAC_PARAMS_NONE); dest.writeByteArray(new byte[0]); dest.writeSerializable(mMacKey); dest.writeByteArray(mMacTag); dest.writeLong(mAuthenticatedDataStart); dest.writeLong(mEncryptedDataStart); dest.writeLong(mDataEnd); } private ContainerEncryptionParams(Parcel source) throws InvalidAlgorithmParameterException { mEncryptionAlgorithm = source.readString(); final int encParamType = source.readInt(); final byte[] encParamsEncoded = source.createByteArray(); mEncryptionKey = (SecretKey) source.readSerializable(); mMacAlgorithm = source.readString(); final int macParamType = source.readInt(); source.createByteArray(); // byte[] macParamsEncoded mMacKey = (SecretKey) source.readSerializable(); mMacTag = source.createByteArray(); mAuthenticatedDataStart = source.readLong(); mEncryptedDataStart = source.readLong(); mDataEnd = source.readLong(); switch (encParamType) { case ENC_PARAMS_IV_PARAMETERS: mEncryptionSpec = new IvParameterSpec(encParamsEncoded); break; default: throw new InvalidAlgorithmParameterException("Unknown parameter type " + encParamType); } switch (macParamType) { case MAC_PARAMS_NONE: mMacSpec = null; break; default: throw new InvalidAlgorithmParameterException("Unknown parameter type " + macParamType); } if (mEncryptionKey == null) { throw new NullPointerException("encryptionKey == null"); } } public static final Parcelable.Creator<ContainerEncryptionParams> CREATOR = new Parcelable.Creator<ContainerEncryptionParams>() { public ContainerEncryptionParams createFromParcel(Parcel source) { try { return new ContainerEncryptionParams(source); } catch (InvalidAlgorithmParameterException e) { Slog.e(TAG, "Invalid algorithm parameters specified", e); return null; } } public ContainerEncryptionParams[] newArray(int size) { return new ContainerEncryptionParams[size]; } }; } No newline at end of file
core/java/android/content/pm/IPackageManager.aidl +10 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.content.pm.PermissionInfo; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; import android.graphics.Bitmap; import android.net.Uri; Loading Loading @@ -213,11 +214,19 @@ interface IPackageManager { List<InstrumentationInfo> queryInstrumentation( String targetPackage, int flags); /** @deprecated Use PackageInstaller instead */ void installPackage(in String originPath, in IPackageInstallObserver2 observer, int flags, in String installerPackageName, in VerificationParams verificationParams, in String packageAbiOverride); void installPackageAsUser(in String originPath, in IPackageInstallObserver2 observer, int flags, in String installerPackageName, in VerificationParams verificationParams, in String packageAbiOverride, int userId); void finishPackageInstall(int token); Loading
core/java/android/content/pm/PackageManager.java +48 −8 Original line number Diff line number Diff line Loading @@ -4504,20 +4504,60 @@ public abstract class PackageManager { */ @Deprecated public abstract void installPackage( Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackage( Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); public abstract void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerificationAndEncryption(Uri packageURI, IPackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackage(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageAsUser(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, @UserIdInt int userId); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerification(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, Uri verificationURI, ContainerEncryptionParams encryptionParams); /** * @deprecated replaced by {@link PackageInstaller} * @hide */ @Deprecated public abstract void installPackageWithVerificationAndEncryption(Uri packageURI, PackageInstallObserver observer, @InstallFlags int flags, String installerPackageName, VerificationParams verificationParams, ContainerEncryptionParams encryptionParams); /** * If there is already an application with the given package name installed Loading