Loading src/java/com/android/internal/telephony/Connection.java +11 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.util.concurrent.CopyOnWriteArraySet; * {@hide} */ public abstract class Connection { private static final String TAG = "Connection"; public interface PostDialListener { void onPostDialWait(); Loading Loading @@ -836,6 +837,16 @@ public abstract class Connection { public void setConnectionExtras(Bundle extras) { if (extras != null) { mExtras = new Bundle(extras); int previousCount = mExtras.size(); // Prevent vendors from passing in extras other than primitive types and android API // parcelables. mExtras = mExtras.filterValues(); int filteredCount = mExtras.size(); if (filteredCount != previousCount) { Rlog.i(TAG, "setConnectionExtras: filtering " + (previousCount - filteredCount) + " invalid extras."); } } else { mExtras = null; } Loading tests/telephonytests/src/android/telephony/ims/ImsCallProfileTest.java 0 → 100644 +112 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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. */ // Note: Package name is intentionally wrong for this test; the internal junk class is used to test // that parcelables of types other than android.* are stripped out. package com.android.telephony.ims; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import android.os.Parcel; import android.os.Parcelable; import android.support.test.runner.AndroidJUnit4; import android.telecom.DisconnectCause; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.ImsCallProfile; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests for the {@link com.android.ims.ImsCallProfile} class. */ @RunWith(AndroidJUnit4.class) public class ImsCallProfileTest { // A test-only parcelable class which is not in the android.* namespace. private static class JunkParcelable implements Parcelable { private int mTest; JunkParcelable() { } protected JunkParcelable(Parcel in) { mTest = in.readInt(); } public static final Creator<JunkParcelable> CREATOR = new Creator<JunkParcelable>() { @Override public JunkParcelable createFromParcel(Parcel in) { return new JunkParcelable(in); } @Override public JunkParcelable[] newArray(int size) { return new JunkParcelable[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mTest); } } /** * Ensures that the {@link ImsCallProfile} will discard invalid extras when it is parceled. */ @Test @SmallTest public void testExtrasCleanup() { ImsCallProfile srcParcel = new ImsCallProfile(); // Put in a private parcelable type. srcParcel.mCallExtras.putParcelable("JUNK", new JunkParcelable()); // Put in an api defined parcelable type. srcParcel.mCallExtras.putParcelable("NOTJUNK", new DisconnectCause(DisconnectCause.BUSY)); // Put in some valid things. srcParcel.mCallExtras.putInt("INT", 1); srcParcel.mCallExtras.putString("STRING", "hello"); // Parcel it. Parcel parcel = Parcel.obtain(); srcParcel.writeToParcel(parcel, 0); byte[] parcelBytes = parcel.marshall(); parcel.recycle(); // Unparcel it. parcel = Parcel.obtain(); parcel.unmarshall(parcelBytes, 0, parcelBytes.length); parcel.setDataPosition(0); ImsCallProfile unparceledProfile = ImsCallProfile.CREATOR.createFromParcel(parcel); parcel.recycle(); assertNotNull(unparceledProfile.mCallExtras); assertEquals(3, unparceledProfile.mCallExtras.size()); assertEquals(1, unparceledProfile.getCallExtraInt("INT")); assertEquals("hello", unparceledProfile.getCallExtra("STRING")); assertFalse(unparceledProfile.mCallExtras.containsKey("JUNK")); DisconnectCause parceledCause = unparceledProfile.mCallExtras.getParcelable("NOTJUNK"); assertEquals(DisconnectCause.BUSY, parceledCause.getCode()); } } Loading
src/java/com/android/internal/telephony/Connection.java +11 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import java.util.concurrent.CopyOnWriteArraySet; * {@hide} */ public abstract class Connection { private static final String TAG = "Connection"; public interface PostDialListener { void onPostDialWait(); Loading Loading @@ -836,6 +837,16 @@ public abstract class Connection { public void setConnectionExtras(Bundle extras) { if (extras != null) { mExtras = new Bundle(extras); int previousCount = mExtras.size(); // Prevent vendors from passing in extras other than primitive types and android API // parcelables. mExtras = mExtras.filterValues(); int filteredCount = mExtras.size(); if (filteredCount != previousCount) { Rlog.i(TAG, "setConnectionExtras: filtering " + (previousCount - filteredCount) + " invalid extras."); } } else { mExtras = null; } Loading
tests/telephonytests/src/android/telephony/ims/ImsCallProfileTest.java 0 → 100644 +112 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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. */ // Note: Package name is intentionally wrong for this test; the internal junk class is used to test // that parcelables of types other than android.* are stripped out. package com.android.telephony.ims; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import android.os.Parcel; import android.os.Parcelable; import android.support.test.runner.AndroidJUnit4; import android.telecom.DisconnectCause; import android.test.suitebuilder.annotation.SmallTest; import com.android.ims.ImsCallProfile; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests for the {@link com.android.ims.ImsCallProfile} class. */ @RunWith(AndroidJUnit4.class) public class ImsCallProfileTest { // A test-only parcelable class which is not in the android.* namespace. private static class JunkParcelable implements Parcelable { private int mTest; JunkParcelable() { } protected JunkParcelable(Parcel in) { mTest = in.readInt(); } public static final Creator<JunkParcelable> CREATOR = new Creator<JunkParcelable>() { @Override public JunkParcelable createFromParcel(Parcel in) { return new JunkParcelable(in); } @Override public JunkParcelable[] newArray(int size) { return new JunkParcelable[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mTest); } } /** * Ensures that the {@link ImsCallProfile} will discard invalid extras when it is parceled. */ @Test @SmallTest public void testExtrasCleanup() { ImsCallProfile srcParcel = new ImsCallProfile(); // Put in a private parcelable type. srcParcel.mCallExtras.putParcelable("JUNK", new JunkParcelable()); // Put in an api defined parcelable type. srcParcel.mCallExtras.putParcelable("NOTJUNK", new DisconnectCause(DisconnectCause.BUSY)); // Put in some valid things. srcParcel.mCallExtras.putInt("INT", 1); srcParcel.mCallExtras.putString("STRING", "hello"); // Parcel it. Parcel parcel = Parcel.obtain(); srcParcel.writeToParcel(parcel, 0); byte[] parcelBytes = parcel.marshall(); parcel.recycle(); // Unparcel it. parcel = Parcel.obtain(); parcel.unmarshall(parcelBytes, 0, parcelBytes.length); parcel.setDataPosition(0); ImsCallProfile unparceledProfile = ImsCallProfile.CREATOR.createFromParcel(parcel); parcel.recycle(); assertNotNull(unparceledProfile.mCallExtras); assertEquals(3, unparceledProfile.mCallExtras.size()); assertEquals(1, unparceledProfile.getCallExtraInt("INT")); assertEquals("hello", unparceledProfile.getCallExtra("STRING")); assertFalse(unparceledProfile.mCallExtras.containsKey("JUNK")); DisconnectCause parceledCause = unparceledProfile.mCallExtras.getParcelable("NOTJUNK"); assertEquals(DisconnectCause.BUSY, parceledCause.getCode()); } }