diff options
7 files changed, 364 insertions, 129 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 7765cd96aa15..4a8f0481cef2 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -7890,6 +7890,7 @@ package android.app.admin { method public int getNetworkId(); method public boolean isEnabled(); method public boolean isFallbackToDefaultConnectionAllowed(); + method public boolean shouldBlockNonMatchingNetworks(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.PreferentialNetworkServiceConfig> CREATOR; field public static final int PREFERENTIAL_NETWORK_ID_1 = 1; // 0x1 @@ -7907,6 +7908,7 @@ package android.app.admin { method @NonNull public android.app.admin.PreferentialNetworkServiceConfig.Builder setFallbackToDefaultConnectionAllowed(boolean); method @NonNull public android.app.admin.PreferentialNetworkServiceConfig.Builder setIncludedUids(@NonNull int[]); method @NonNull public android.app.admin.PreferentialNetworkServiceConfig.Builder setNetworkId(int); + method @NonNull public android.app.admin.PreferentialNetworkServiceConfig.Builder setShouldBlockNonMatchingNetworks(boolean); } public class SecurityLog { @@ -30768,7 +30770,8 @@ package android.opengl { method public static void scaleM(float[], int, float, float, float); method public static void setIdentityM(float[], int); method public static void setLookAtM(float[], int, float, float, float, float, float, float, float, float, float); - method public static void setRotateEulerM(float[], int, float, float, float); + method @Deprecated public static void setRotateEulerM(float[], int, float, float, float); + method public static void setRotateEulerM2(@NonNull float[], int, float, float, float); method public static void setRotateM(float[], int, float, float, float, float); method public static void translateM(float[], int, float[], int, float, float, float); method public static void translateM(float[], int, float, float, float); diff --git a/core/java/android/app/admin/PreferentialNetworkServiceConfig.java b/core/java/android/app/admin/PreferentialNetworkServiceConfig.java index 63c9839a87e3..1e0d0628c310 100644 --- a/core/java/android/app/admin/PreferentialNetworkServiceConfig.java +++ b/core/java/android/app/admin/PreferentialNetworkServiceConfig.java @@ -50,6 +50,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { final boolean mIsEnabled; final int mNetworkId; final boolean mAllowFallbackToDefaultConnection; + final boolean mShouldBlockNonMatchingNetworks; final int[] mIncludedUids; final int[] mExcludedUids; @@ -63,6 +64,8 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { "preferential_network_service_network_id"; private static final String TAG_ALLOW_FALLBACK_TO_DEFAULT_CONNECTION = "allow_fallback_to_default_connection"; + private static final String TAG_BLOCK_NON_MATCHING_NETWORKS = + "block_non_matching_networks"; private static final String TAG_INCLUDED_UIDS = "included_uids"; private static final String TAG_EXCLUDED_UIDS = "excluded_uids"; private static final String ATTR_VALUE = "value"; @@ -110,10 +113,12 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } private PreferentialNetworkServiceConfig(boolean isEnabled, - boolean allowFallbackToDefaultConnection, int[] includedUids, + boolean allowFallbackToDefaultConnection, boolean shouldBlockNonMatchingNetworks, + int[] includedUids, int[] excludedUids, @PreferentialNetworkPreferenceId int networkId) { mIsEnabled = isEnabled; mAllowFallbackToDefaultConnection = allowFallbackToDefaultConnection; + mShouldBlockNonMatchingNetworks = shouldBlockNonMatchingNetworks; mIncludedUids = includedUids; mExcludedUids = excludedUids; mNetworkId = networkId; @@ -122,6 +127,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { private PreferentialNetworkServiceConfig(Parcel in) { mIsEnabled = in.readBoolean(); mAllowFallbackToDefaultConnection = in.readBoolean(); + mShouldBlockNonMatchingNetworks = in.readBoolean(); mNetworkId = in.readInt(); mIncludedUids = in.createIntArray(); mExcludedUids = in.createIntArray(); @@ -136,9 +142,18 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } /** - * is fallback to default network allowed. This boolean configures whether default connection - * (default internet or wifi) should be used or not if a preferential network service - * connection is not available. + * Whether fallback to the device-wide default network is allowed. + * + * This boolean configures whether the default connection (e.g. general cell network or wifi) + * should be used if no preferential network service connection is available. If true, the + * default connection will be used when no preferential service is available. If false, the + * UIDs subject to this configuration will have no default network. + * Note that while this boolean determines whether the UIDs subject to this configuration have + * a default network in the absence of a preferential service, apps can still explicitly decide + * to use another network than their default network by requesting them from the system. This + * boolean does not determine whether the UIDs are blocked from using such other networks. + * See {@link #shouldBlockNonMatchingNetworks()} for that configuration. + * * @return true if fallback is allowed, else false. */ public boolean isFallbackToDefaultConnectionAllowed() { @@ -146,6 +161,21 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } /** + * Whether to block UIDs from using other networks than the preferential service. + * + * Apps can inspect the list of available networks on the device and choose to use multiple + * of them concurrently for performance, privacy or other reasons. + * This boolean configures whether the concerned UIDs should be blocked from using + * networks that do not match the configured preferential network service even if these + * networks are otherwise open to all apps. + * + * @return true if UIDs should be blocked from using the other networks, else false. + */ + public boolean shouldBlockNonMatchingNetworks() { + return mShouldBlockNonMatchingNetworks; + } + + /** * Get the array of uids that are applicable for the profile preference. * * {@see #getExcludedUids()} @@ -189,6 +219,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { return "PreferentialNetworkServiceConfig{" + "mIsEnabled=" + isEnabled() + "mAllowFallbackToDefaultConnection=" + isFallbackToDefaultConnectionAllowed() + + "mBlockNonMatchingNetworks=" + shouldBlockNonMatchingNetworks() + "mIncludedUids=" + Arrays.toString(mIncludedUids) + "mExcludedUids=" + Arrays.toString(mExcludedUids) + "mNetworkId=" + mNetworkId @@ -202,6 +233,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { final PreferentialNetworkServiceConfig that = (PreferentialNetworkServiceConfig) o; return mIsEnabled == that.mIsEnabled && mAllowFallbackToDefaultConnection == that.mAllowFallbackToDefaultConnection + && mShouldBlockNonMatchingNetworks == that.mShouldBlockNonMatchingNetworks && mNetworkId == that.mNetworkId && Arrays.equals(mIncludedUids, that.mIncludedUids) && Arrays.equals(mExcludedUids, that.mExcludedUids); @@ -210,7 +242,8 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { @Override public int hashCode() { return Objects.hash(mIsEnabled, mAllowFallbackToDefaultConnection, - Arrays.hashCode(mIncludedUids), Arrays.hashCode(mExcludedUids), mNetworkId); + mShouldBlockNonMatchingNetworks, Arrays.hashCode(mIncludedUids), + Arrays.hashCode(mExcludedUids), mNetworkId); } /** @@ -221,6 +254,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { boolean mIsEnabled = false; int mNetworkId = 0; boolean mAllowFallbackToDefaultConnection = true; + boolean mShouldBlockNonMatchingNetworks = false; int[] mIncludedUids = new int[0]; int[] mExcludedUids = new int[0]; @@ -242,10 +276,21 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } /** - * Set whether the default connection should be used as fallback. - * This boolean configures whether the default connection (default internet or wifi) - * should be used if a preferential network service connection is not available. - * Default value is true + * Set whether fallback to the device-wide default network is allowed. + * + * This boolean configures whether the default connection (e.g. general cell network or + * wifi) should be used if no preferential network service connection is available. If true, + * the default connection will be used when no preferential service is available. If false, + * the UIDs subject to this configuration will have no default network. + * Note that while this boolean determines whether the UIDs subject to this configuration + * have a default network in the absence of a preferential service, apps can still + * explicitly decide to use another network than their default network by requesting them + * from the system. This boolean does not determine whether the UIDs are blocked from using + * such other networks. + * Use {@link #setShouldBlockNonMatchingNetworks(boolean)} to specify this. + * + * The default value is true. + * * @param allowFallbackToDefaultConnection true if fallback is allowed else false * @return The builder to facilitate chaining. */ @@ -258,6 +303,31 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } /** + * Set whether to block UIDs from using other networks than the preferential service. + * + * Apps can inspect the list of available networks on the device and choose to use multiple + * of them concurrently for performance, privacy or other reasons. + * This boolean configures whether the concerned UIDs should be blocked from using + * networks that do not match the configured preferential network service even if these + * networks are otherwise open to all apps. + * + * The default value is false. This value can only be set to {@code true} if + * {@link #setFallbackToDefaultConnectionAllowed(boolean)} is set to {@code false}, because + * allowing fallback but blocking it does not make sense. Failure to comply with this + * constraint will throw when building the object. + * + * @param blockNonMatchingNetworks true if UIDs should be blocked from using non-matching + * networks. + * @return The builder to facilitate chaining. + */ + @NonNull + public PreferentialNetworkServiceConfig.Builder setShouldBlockNonMatchingNetworks( + boolean blockNonMatchingNetworks) { + mShouldBlockNonMatchingNetworks = blockNonMatchingNetworks; + return this; + } + + /** * Set the array of uids whose network access will go through this preferential * network service. * {@see #setExcludedUids(int[])} @@ -305,8 +375,13 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { throw new IllegalStateException("Both includedUids and excludedUids " + "cannot be nonempty"); } + if (mShouldBlockNonMatchingNetworks && mAllowFallbackToDefaultConnection) { + throw new IllegalStateException("A config cannot both allow fallback and " + + "block non-matching networks"); + } return new PreferentialNetworkServiceConfig(mIsEnabled, - mAllowFallbackToDefaultConnection, mIncludedUids, mExcludedUids, mNetworkId); + mAllowFallbackToDefaultConnection, mShouldBlockNonMatchingNetworks, + mIncludedUids, mExcludedUids, mNetworkId); } /** @@ -331,6 +406,7 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { dest.writeBoolean(mIsEnabled); dest.writeBoolean(mAllowFallbackToDefaultConnection); + dest.writeBoolean(mShouldBlockNonMatchingNetworks); dest.writeInt(mNetworkId); dest.writeIntArray(mIncludedUids); dest.writeIntArray(mExcludedUids); @@ -422,6 +498,9 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { } else if (TAG_ALLOW_FALLBACK_TO_DEFAULT_CONNECTION.equals(tagDAM)) { resultBuilder.setFallbackToDefaultConnectionAllowed(parser.getAttributeBoolean( null, ATTR_VALUE, true)); + } else if (TAG_BLOCK_NON_MATCHING_NETWORKS.equals(tagDAM)) { + resultBuilder.setShouldBlockNonMatchingNetworks(parser.getAttributeBoolean( + null, ATTR_VALUE, false)); } else if (TAG_INCLUDED_UIDS.equals(tagDAM)) { resultBuilder.setIncludedUids(readStringListToIntArray(parser, TAG_UID)); } else if (TAG_EXCLUDED_UIDS.equals(tagDAM)) { @@ -442,6 +521,8 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { writeAttributeValueToXml(out, TAG_NETWORK_ID, getNetworkId()); writeAttributeValueToXml(out, TAG_ALLOW_FALLBACK_TO_DEFAULT_CONNECTION, isFallbackToDefaultConnectionAllowed()); + writeAttributeValueToXml(out, TAG_BLOCK_NON_MATCHING_NETWORKS, + shouldBlockNonMatchingNetworks()); writeAttributeValuesToXml(out, TAG_INCLUDED_UIDS, TAG_UID, intArrayToStringList(getIncludedUids())); writeAttributeValuesToXml(out, TAG_EXCLUDED_UIDS, TAG_UID, @@ -459,6 +540,8 @@ public final class PreferentialNetworkServiceConfig implements Parcelable { pw.println(mIsEnabled); pw.print("allowFallbackToDefaultConnection="); pw.println(mAllowFallbackToDefaultConnection); + pw.print("blockNonMatchingNetworks="); + pw.println(mShouldBlockNonMatchingNetworks); pw.print("includedUids="); pw.println(mIncludedUids); pw.print("excludedUids="); diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index d8522658d747..1c6c95f389aa 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -541,87 +541,6 @@ jint util_visibilityTest(JNIEnv *env, jclass clazz, indices.mData, indexCount); } -#define I(_i, _j) ((_j)+ 4*(_i)) - -static -void multiplyMM(float* r, const float* lhs, const float* rhs) -{ - for (int i=0 ; i<4 ; i++) { - const float rhs_i0 = rhs[ I(i,0) ]; - float ri0 = lhs[ I(0,0) ] * rhs_i0; - float ri1 = lhs[ I(0,1) ] * rhs_i0; - float ri2 = lhs[ I(0,2) ] * rhs_i0; - float ri3 = lhs[ I(0,3) ] * rhs_i0; - for (int j=1 ; j<4 ; j++) { - const float rhs_ij = rhs[ I(i,j) ]; - ri0 += lhs[ I(j,0) ] * rhs_ij; - ri1 += lhs[ I(j,1) ] * rhs_ij; - ri2 += lhs[ I(j,2) ] * rhs_ij; - ri3 += lhs[ I(j,3) ] * rhs_ij; - } - r[ I(i,0) ] = ri0; - r[ I(i,1) ] = ri1; - r[ I(i,2) ] = ri2; - r[ I(i,3) ] = ri3; - } -} - -static -void util_multiplyMM(JNIEnv *env, jclass clazz, - jfloatArray result_ref, jint resultOffset, - jfloatArray lhs_ref, jint lhsOffset, - jfloatArray rhs_ref, jint rhsOffset) { - - FloatArrayHelper resultMat(env, result_ref, resultOffset, 16); - FloatArrayHelper lhs(env, lhs_ref, lhsOffset, 16); - FloatArrayHelper rhs(env, rhs_ref, rhsOffset, 16); - - bool checkOK = resultMat.check() && lhs.check() && rhs.check(); - - if ( !checkOK ) { - return; - } - - resultMat.bind(); - lhs.bind(); - rhs.bind(); - - multiplyMM(resultMat.mData, lhs.mData, rhs.mData); - - resultMat.commitChanges(); -} - -static -void multiplyMV(float* r, const float* lhs, const float* rhs) -{ - mx4transform(rhs[0], rhs[1], rhs[2], rhs[3], lhs, r); -} - -static -void util_multiplyMV(JNIEnv *env, jclass clazz, - jfloatArray result_ref, jint resultOffset, - jfloatArray lhs_ref, jint lhsOffset, - jfloatArray rhs_ref, jint rhsOffset) { - - FloatArrayHelper resultV(env, result_ref, resultOffset, 4); - FloatArrayHelper lhs(env, lhs_ref, lhsOffset, 16); - FloatArrayHelper rhs(env, rhs_ref, rhsOffset, 4); - - bool checkOK = resultV.check() && lhs.check() && rhs.check(); - - if ( !checkOK ) { - return; - } - - resultV.bind(); - lhs.bind(); - rhs.bind(); - - multiplyMV(resultV.mData, lhs.mData, rhs.mData); - - resultV.commitChanges(); -} - // --------------------------------------------------------------------------- // The internal format is no longer the same as pixel format, per Table 2 in @@ -1009,11 +928,6 @@ static jint etc1_getHeight(JNIEnv *env, jclass clazz, * JNI registration */ -static const JNINativeMethod gMatrixMethods[] = { - { "multiplyMM", "([FI[FI[FI)V", (void*)util_multiplyMM }, - { "multiplyMV", "([FI[FI[FI)V", (void*)util_multiplyMV }, -}; - static const JNINativeMethod gVisibilityMethods[] = { { "computeBoundingSphere", "([FII[FI)V", (void*)util_computeBoundingSphere }, { "frustumCullSpheres", "([FI[FII[III)I", (void*)util_frustumCullSpheres }, @@ -1046,7 +960,6 @@ typedef struct _ClassRegistrationInfo { } ClassRegistrationInfo; static const ClassRegistrationInfo gClasses[] = { - {"android/opengl/Matrix", gMatrixMethods, NELEM(gMatrixMethods)}, {"android/opengl/Visibility", gVisibilityMethods, NELEM(gVisibilityMethods)}, {"android/opengl/GLUtils", gUtilsMethods, NELEM(gUtilsMethods)}, {"android/opengl/ETC1", gEtc1Methods, NELEM(gEtc1Methods)}, diff --git a/opengl/java/android/opengl/Matrix.java b/opengl/java/android/opengl/Matrix.java index ce3f57ebfea1..5ae341b7abce 100644 --- a/opengl/java/android/opengl/Matrix.java +++ b/opengl/java/android/opengl/Matrix.java @@ -16,6 +16,8 @@ package android.opengl; +import androidx.annotation.NonNull; + /** * Matrix math utilities. These methods operate on OpenGL ES format * matrices and vectors stored in float arrays. @@ -38,7 +40,11 @@ package android.opengl; public class Matrix { /** Temporary memory for operations that need temporary matrix data. */ - private final static float[] sTemp = new float[32]; + private static final ThreadLocal<float[]> ThreadTmp = new ThreadLocal() { + @Override protected float[] initialValue() { + return new float[32]; + } + }; /** * @deprecated All methods are static, do not instantiate this class. @@ -46,6 +52,40 @@ public class Matrix { @Deprecated public Matrix() {} + private static boolean overlap( + float[] a, int aStart, int aLength, float[] b, int bStart, int bLength) { + if (a != b) { + return false; + } + + if (aStart == bStart) { + return true; + } + + int aEnd = aStart + aLength; + int bEnd = bStart + bLength; + + if (aEnd == bEnd) { + return true; + } + + if (aStart < bStart && bStart < aEnd) { + return true; + } + if (aStart < bEnd && bEnd < aEnd) { + return true; + } + + if (bStart < aStart && aStart < bEnd) { + return true; + } + if (bStart < aEnd && aEnd < bEnd) { + return true; + } + + return false; + } + /** * Multiplies two 4x4 matrices together and stores the result in a third 4x4 * matrix. In matrix notation: result = lhs x rhs. Due to the way @@ -53,9 +93,9 @@ public class Matrix { * effect as first multiplying by the rhs matrix, then multiplying by * the lhs matrix. This is the opposite of what you might expect. * <p> - * The same float array may be passed for result, lhs, and/or rhs. However, - * the result element values are undefined if the result elements overlap - * either the lhs or rhs elements. + * The same float array may be passed for result, lhs, and/or rhs. This + * operation is expected to do the correct thing if the result elements + * overlap with either of the lhs or rhs elements. * * @param result The float array that holds the result. * @param resultOffset The offset into the result array where the result is @@ -65,20 +105,101 @@ public class Matrix { * @param rhs The float array that holds the right-hand-side matrix. * @param rhsOffset The offset into the rhs array where the rhs is stored. * - * @throws IllegalArgumentException if result, lhs, or rhs are null, or if - * resultOffset + 16 > result.length or lhsOffset + 16 > lhs.length or - * rhsOffset + 16 > rhs.length. + * @throws IllegalArgumentException under any of the following conditions: + * result, lhs, or rhs are null; + * resultOffset + 16 > result.length + * or lhsOffset + 16 > lhs.length + * or rhsOffset + 16 > rhs.length; + * resultOffset < 0 or lhsOffset < 0 or rhsOffset < 0 */ - public static native void multiplyMM(float[] result, int resultOffset, - float[] lhs, int lhsOffset, float[] rhs, int rhsOffset); + public static void multiplyMM(float[] result, int resultOffset, + float[] lhs, int lhsOffset, float[] rhs, int rhsOffset) { + // error checking + if (result == null) { + throw new IllegalArgumentException("result == null"); + } + if (lhs == null) { + throw new IllegalArgumentException("lhs == null"); + } + if (rhs == null) { + throw new IllegalArgumentException("rhs == null"); + } + if (resultOffset < 0) { + throw new IllegalArgumentException("resultOffset < 0"); + } + if (lhsOffset < 0) { + throw new IllegalArgumentException("lhsOffset < 0"); + } + if (rhsOffset < 0) { + throw new IllegalArgumentException("rhsOffset < 0"); + } + if (result.length < resultOffset + 16) { + throw new IllegalArgumentException("result.length < resultOffset + 16"); + } + if (lhs.length < lhsOffset + 16) { + throw new IllegalArgumentException("lhs.length < lhsOffset + 16"); + } + if (rhs.length < rhsOffset + 16) { + throw new IllegalArgumentException("rhs.length < rhsOffset + 16"); + } + + // Check for overlap between rhs and result or lhs and result + if ( overlap(result, resultOffset, 16, lhs, lhsOffset, 16) + || overlap(result, resultOffset, 16, rhs, rhsOffset, 16) ) { + float[] tmp = ThreadTmp.get(); + for (int i=0; i<4; i++) { + final float rhs_i0 = rhs[ 4*i + 0 + rhsOffset ]; + float ri0 = lhs[ 0 + lhsOffset ] * rhs_i0; + float ri1 = lhs[ 1 + lhsOffset ] * rhs_i0; + float ri2 = lhs[ 2 + lhsOffset ] * rhs_i0; + float ri3 = lhs[ 3 + lhsOffset ] * rhs_i0; + for (int j=1; j<4; j++) { + final float rhs_ij = rhs[ 4*i + j + rhsOffset]; + ri0 += lhs[ 4*j + 0 + lhsOffset ] * rhs_ij; + ri1 += lhs[ 4*j + 1 + lhsOffset ] * rhs_ij; + ri2 += lhs[ 4*j + 2 + lhsOffset ] * rhs_ij; + ri3 += lhs[ 4*j + 3 + lhsOffset ] * rhs_ij; + } + tmp[ 4*i + 0 ] = ri0; + tmp[ 4*i + 1 ] = ri1; + tmp[ 4*i + 2 ] = ri2; + tmp[ 4*i + 3 ] = ri3; + } + + // copy from tmp to result + for (int i=0; i < 16; i++) { + result[ i + resultOffset ] = tmp[ i ]; + } + + } else { + for (int i=0; i<4; i++) { + final float rhs_i0 = rhs[ 4*i + 0 + rhsOffset ]; + float ri0 = lhs[ 0 + lhsOffset ] * rhs_i0; + float ri1 = lhs[ 1 + lhsOffset ] * rhs_i0; + float ri2 = lhs[ 2 + lhsOffset ] * rhs_i0; + float ri3 = lhs[ 3 + lhsOffset ] * rhs_i0; + for (int j=1; j<4; j++) { + final float rhs_ij = rhs[ 4*i + j + rhsOffset]; + ri0 += lhs[ 4*j + 0 + lhsOffset ] * rhs_ij; + ri1 += lhs[ 4*j + 1 + lhsOffset ] * rhs_ij; + ri2 += lhs[ 4*j + 2 + lhsOffset ] * rhs_ij; + ri3 += lhs[ 4*j + 3 + lhsOffset ] * rhs_ij; + } + result[ 4*i + 0 + resultOffset ] = ri0; + result[ 4*i + 1 + resultOffset ] = ri1; + result[ 4*i + 2 + resultOffset ] = ri2; + result[ 4*i + 3 + resultOffset ] = ri3; + } + } + } /** * Multiplies a 4 element vector by a 4x4 matrix and stores the result in a * 4-element column vector. In matrix notation: result = lhs x rhs * <p> * The same float array may be passed for resultVec, lhsMat, and/or rhsVec. - * However, the resultVec element values are undefined if the resultVec - * elements overlap either the lhsMat or rhsVec elements. + * This operation is expected to do the correct thing if the result elements + * overlap with either of the lhs or rhs elements. * * @param resultVec The float array that holds the result vector. * @param resultVecOffset The offset into the result array where the result @@ -89,14 +210,67 @@ public class Matrix { * @param rhsVecOffset The offset into the rhs vector where the rhs vector * is stored. * - * @throws IllegalArgumentException if resultVec, lhsMat, - * or rhsVec are null, or if resultVecOffset + 4 > resultVec.length - * or lhsMatOffset + 16 > lhsMat.length or - * rhsVecOffset + 4 > rhsVec.length. + * @throws IllegalArgumentException under any of the following conditions: + * resultVec, lhsMat, or rhsVec are null; + * resultVecOffset + 4 > resultVec.length + * or lhsMatOffset + 16 > lhsMat.length + * or rhsVecOffset + 4 > rhsVec.length; + * resultVecOffset < 0 or lhsMatOffset < 0 or rhsVecOffset < 0 */ - public static native void multiplyMV(float[] resultVec, + public static void multiplyMV(float[] resultVec, int resultVecOffset, float[] lhsMat, int lhsMatOffset, - float[] rhsVec, int rhsVecOffset); + float[] rhsVec, int rhsVecOffset) { + // error checking + if (resultVec == null) { + throw new IllegalArgumentException("resultVec == null"); + } + if (lhsMat == null) { + throw new IllegalArgumentException("lhsMat == null"); + } + if (rhsVec == null) { + throw new IllegalArgumentException("rhsVec == null"); + } + if (resultVecOffset < 0) { + throw new IllegalArgumentException("resultVecOffset < 0"); + } + if (lhsMatOffset < 0) { + throw new IllegalArgumentException("lhsMatOffset < 0"); + } + if (rhsVecOffset < 0) { + throw new IllegalArgumentException("rhsVecOffset < 0"); + } + if (resultVec.length < resultVecOffset + 4) { + throw new IllegalArgumentException("resultVec.length < resultVecOffset + 4"); + } + if (lhsMat.length < lhsMatOffset + 16) { + throw new IllegalArgumentException("lhsMat.length < lhsMatOffset + 16"); + } + if (rhsVec.length < rhsVecOffset + 4) { + throw new IllegalArgumentException("rhsVec.length < rhsVecOffset + 4"); + } + + float tmp0 = lhsMat[0 + 4 * 0 + lhsMatOffset] * rhsVec[0 + rhsVecOffset] + + lhsMat[0 + 4 * 1 + lhsMatOffset] * rhsVec[1 + rhsVecOffset] + + lhsMat[0 + 4 * 2 + lhsMatOffset] * rhsVec[2 + rhsVecOffset] + + lhsMat[0 + 4 * 3 + lhsMatOffset] * rhsVec[3 + rhsVecOffset]; + float tmp1 = lhsMat[1 + 4 * 0 + lhsMatOffset] * rhsVec[0 + rhsVecOffset] + + lhsMat[1 + 4 * 1 + lhsMatOffset] * rhsVec[1 + rhsVecOffset] + + lhsMat[1 + 4 * 2 + lhsMatOffset] * rhsVec[2 + rhsVecOffset] + + lhsMat[1 + 4 * 3 + lhsMatOffset] * rhsVec[3 + rhsVecOffset]; + float tmp2 = lhsMat[2 + 4 * 0 + lhsMatOffset] * rhsVec[0 + rhsVecOffset] + + lhsMat[2 + 4 * 1 + lhsMatOffset] * rhsVec[1 + rhsVecOffset] + + lhsMat[2 + 4 * 2 + lhsMatOffset] * rhsVec[2 + rhsVecOffset] + + lhsMat[2 + 4 * 3 + lhsMatOffset] * rhsVec[3 + rhsVecOffset]; + float tmp3 = lhsMat[3 + 4 * 0 + lhsMatOffset] * rhsVec[0 + rhsVecOffset] + + lhsMat[3 + 4 * 1 + lhsMatOffset] * rhsVec[1 + rhsVecOffset] + + lhsMat[3 + 4 * 2 + lhsMatOffset] * rhsVec[2 + rhsVecOffset] + + lhsMat[3 + 4 * 3 + lhsMatOffset] * rhsVec[3 + rhsVecOffset]; + + resultVec[ 0 + resultVecOffset ] = tmp0; + resultVec[ 1 + resultVecOffset ] = tmp1; + resultVec[ 2 + resultVecOffset ] = tmp2; + resultVec[ 3 + resultVecOffset ] = tmp3; + } /** * Transposes a 4 x 4 matrix. @@ -537,10 +711,9 @@ public class Matrix { public static void rotateM(float[] rm, int rmOffset, float[] m, int mOffset, float a, float x, float y, float z) { - synchronized(sTemp) { - setRotateM(sTemp, 0, a, x, y, z); - multiplyMM(rm, rmOffset, m, mOffset, sTemp, 0); - } + float[] tmp = ThreadTmp.get(); + setRotateM(tmp, 16, a, x, y, z); + multiplyMM(rm, rmOffset, m, mOffset, tmp, 16); } /** @@ -556,11 +729,7 @@ public class Matrix { */ public static void rotateM(float[] m, int mOffset, float a, float x, float y, float z) { - synchronized(sTemp) { - setRotateM(sTemp, 0, a, x, y, z); - multiplyMM(sTemp, 16, m, mOffset, sTemp, 0); - System.arraycopy(sTemp, 16, m, mOffset, 16); - } + rotateM(m, mOffset, m, mOffset, a, x, y, z); } /** @@ -640,9 +809,14 @@ public class Matrix { * @param rm returns the result * @param rmOffset index into rm where the result matrix starts * @param x angle of rotation, in degrees - * @param y angle of rotation, in degrees + * @param y is broken, do not use * @param z angle of rotation, in degrees + * + * @deprecated This method is incorrect around the y axis. This method is + * deprecated and replaced (below) by setRotateEulerM2 which + * behaves correctly */ + @Deprecated public static void setRotateEulerM(float[] rm, int rmOffset, float x, float y, float z) { x *= (float) (Math.PI / 180.0f); @@ -679,6 +853,64 @@ public class Matrix { } /** + * Converts Euler angles to a rotation matrix. + * + * @param rm returns the result + * @param rmOffset index into rm where the result matrix starts + * @param x angle of rotation, in degrees + * @param y angle of rotation, in degrees + * @param z angle of rotation, in degrees + * + * @throws IllegalArgumentException if rm is null; + * or if rmOffset + 16 > rm.length; + * rmOffset < 0 + */ + public static void setRotateEulerM2(@NonNull float[] rm, int rmOffset, + float x, float y, float z) { + if (rm == null) { + throw new IllegalArgumentException("rm == null"); + } + if (rmOffset < 0) { + throw new IllegalArgumentException("rmOffset < 0"); + } + if (rm.length < rmOffset + 16) { + throw new IllegalArgumentException("rm.length < rmOffset + 16"); + } + + x *= (float) (Math.PI / 180.0f); + y *= (float) (Math.PI / 180.0f); + z *= (float) (Math.PI / 180.0f); + float cx = (float) Math.cos(x); + float sx = (float) Math.sin(x); + float cy = (float) Math.cos(y); + float sy = (float) Math.sin(y); + float cz = (float) Math.cos(z); + float sz = (float) Math.sin(z); + float cxsy = cx * sy; + float sxsy = sx * sy; + + rm[rmOffset + 0] = cy * cz; + rm[rmOffset + 1] = -cy * sz; + rm[rmOffset + 2] = sy; + rm[rmOffset + 3] = 0.0f; + + rm[rmOffset + 4] = sxsy * cz + cx * sz; + rm[rmOffset + 5] = -sxsy * sz + cx * cz; + rm[rmOffset + 6] = -sx * cy; + rm[rmOffset + 7] = 0.0f; + + rm[rmOffset + 8] = -cxsy * cz + sx * sz; + rm[rmOffset + 9] = cxsy * sz + sx * cz; + rm[rmOffset + 10] = cx * cy; + rm[rmOffset + 11] = 0.0f; + + rm[rmOffset + 12] = 0.0f; + rm[rmOffset + 13] = 0.0f; + rm[rmOffset + 14] = 0.0f; + rm[rmOffset + 15] = 1.0f; + } + + /** * Defines a viewing transformation in terms of an eye point, a center of * view, and an up vector. * diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags index 68fd0c12bea8..9743ba42e136 100644 --- a/services/core/java/com/android/server/EventLogTags.logtags +++ b/services/core/java/com/android/server/EventLogTags.logtags @@ -223,8 +223,8 @@ option java_package com.android.server # --------------------------- # NetworkStatsService.java # --------------------------- -51100 netstats_mobile_sample (dev_rx_bytes|2|2),(dev_tx_bytes|2|2),(dev_rx_pkts|2|1),(dev_tx_pkts|2|1),(xt_rx_bytes|2|2),(xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(uid_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3) -51101 netstats_wifi_sample (dev_rx_bytes|2|2),(dev_tx_bytes|2|2),(dev_rx_pkts|2|1),(dev_tx_pkts|2|1),(xt_rx_bytes|2|2),(xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(uid_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3) +51100 netstats_mobile_sample (xt_rx_bytes|2|2),(xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(uid_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3) +51101 netstats_wifi_sample (xt_rx_bytes|2|2),(xt_tx_bytes|2|2),(xt_rx_pkts|2|1),(xt_tx_pkts|2|1),(uid_rx_bytes|2|2),(uid_tx_bytes|2|2),(uid_rx_pkts|2|1),(uid_tx_pkts|2|1),(trusted_time|2|3) # --------------------------- diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java index bc939d6279cd..4afaca2f554f 100644 --- a/services/core/java/com/android/server/am/OomAdjuster.java +++ b/services/core/java/com/android/server/am/OomAdjuster.java @@ -2428,7 +2428,7 @@ public class OomAdjuster { } state.setCurRawAdj(adj); - + adj = psr.modifyRawOomAdj(adj); if (adj > state.getMaxAdj()) { adj = state.getMaxAdj(); if (adj <= ProcessList.PERCEPTIBLE_LOW_APP_ADJ) { @@ -2458,7 +2458,7 @@ public class OomAdjuster { // it when computing the final cached adj later. Note that we don't need to // worry about this for max adj above, since max adj will always be used to // keep it out of the cached vaues. - state.setCurAdj(psr.modifyRawOomAdj(adj)); + state.setCurAdj(adj); state.setCurCapability(capability); state.setCurrentSchedulingGroup(schedGroup); state.setCurProcState(procState); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 20d9cce9a622..55fb5990b9b3 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -136,6 +136,7 @@ import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES; import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_DEFAULT; import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE; +import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_BLOCKING; import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK; import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK; import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER; @@ -18330,6 +18331,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (preferentialNetworkServiceConfig.isEnabled()) { if (preferentialNetworkServiceConfig.isFallbackToDefaultConnectionAllowed()) { preferenceBuilder.setPreference(PROFILE_NETWORK_PREFERENCE_ENTERPRISE); + } else if (preferentialNetworkServiceConfig.shouldBlockNonMatchingNetworks()) { + preferenceBuilder.setPreference( + PROFILE_NETWORK_PREFERENCE_ENTERPRISE_BLOCKING); } else { preferenceBuilder.setPreference( PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK); |