Loading apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java +4 −2 Original line number Diff line number Diff line Loading @@ -291,11 +291,13 @@ public final class JobServiceContext implements ServiceConnection { bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_ALMOST_PERCEPTIBLE | Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS | Context.BIND_NOT_APP_COMPONENT_USAGE; | Context.BIND_NOT_APP_COMPONENT_USAGE | Context.BIND_DENY_ACTIVITY_STARTS; } else { bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_APP_COMPONENT_USAGE; | Context.BIND_NOT_APP_COMPONENT_USAGE | Context.BIND_DENY_ACTIVITY_STARTS; } binding = mContext.bindServiceAsUser(intent, this, bindFlags, UserHandle.of(job.getUserId())); Loading core/java/android/speech/tts/TextToSpeech.java +2 −1 Original line number Diff line number Diff line Loading @@ -2379,7 +2379,8 @@ public class TextToSpeech { boolean connect(String engine) { Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE); intent.setPackage(engine); return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_DENY_ACTIVITY_STARTS); } @Override Loading core/java/com/android/internal/util/BinaryXmlSerializer.java +10 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,8 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { */ private static final int BUFFER_SIZE = 32_768; private static final int MAX_UNSIGNED_SHORT = 65_535; private FastDataOutput mOut; /** Loading Loading @@ -221,6 +223,10 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { if (namespace != null && !namespace.isEmpty()) throw illegalNamespace(); mOut.writeByte(ATTRIBUTE | TYPE_BYTES_HEX); mOut.writeInternedUTF(name); if (value.length > MAX_UNSIGNED_SHORT) { throw new IOException("attributeBytesHex: input size (" + value.length + ") exceeds maximum allowed size (" + MAX_UNSIGNED_SHORT + ")"); } mOut.writeShort(value.length); mOut.write(value); return this; Loading @@ -232,6 +238,10 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { if (namespace != null && !namespace.isEmpty()) throw illegalNamespace(); mOut.writeByte(ATTRIBUTE | TYPE_BYTES_BASE64); mOut.writeInternedUTF(name); if (value.length > MAX_UNSIGNED_SHORT) { throw new IOException("attributeBytesBase64: input size (" + value.length + ") exceeds maximum allowed size (" + MAX_UNSIGNED_SHORT + ")"); } mOut.writeShort(value.length); mOut.write(value); return this; Loading core/tests/coretests/src/android/util/BinaryXmlTest.java +50 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import static android.util.XmlTest.doVerifyRead; import static android.util.XmlTest.doVerifyWrite; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import static org.xmlpull.v1.XmlPullParser.START_TAG; import android.os.PersistableBundle; Loading @@ -38,12 +40,15 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; @RunWith(AndroidJUnit4.class) public class BinaryXmlTest { private static final int MAX_UNSIGNED_SHORT = 65_535; /** * Verify that we can write and read large numbers of interned * {@link String} values. Loading Loading @@ -167,4 +172,49 @@ public class BinaryXmlTest { } } } @Test public void testAttributeBytes_BinaryDataOverflow() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT + 1]; assertThrows(IOException.class, () -> out.attributeBytesHex(/* namespace */ null, /* name */ "attributeBytesHex", testBytes)); assertThrows(IOException.class, () -> out.attributeBytesBase64(/* namespace */ null, /* name */ "attributeBytesBase64", testBytes)); } @Test public void testAttributeBytesHex_MaximumBinaryData() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT]; try { out.attributeBytesHex(/* namespace */ null, /* name */ "attributeBytesHex", testBytes); } catch (Exception e) { fail("testAttributeBytesHex fails with exception: " + e.toString()); } } @Test public void testAttributeBytesBase64_MaximumBinaryData() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT]; try { out.attributeBytesBase64(/* namespace */ null, /* name */ "attributeBytesBase64", testBytes); } catch (Exception e) { fail("testAttributeBytesBase64 fails with exception: " + e.toString()); } } } services/core/java/com/android/server/content/SyncManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -221,7 +221,8 @@ public class SyncManager { /** Flags used when connecting to a sync adapter service */ private static final int SYNC_ADAPTER_CONNECTION_FLAGS = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_ALLOW_OOM_MANAGEMENT; | Context.BIND_NOT_FOREGROUND | Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_DENY_ACTIVITY_STARTS; /** Singleton instance. */ @GuardedBy("SyncManager.class") Loading Loading
apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java +4 −2 Original line number Diff line number Diff line Loading @@ -291,11 +291,13 @@ public final class JobServiceContext implements ServiceConnection { bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_ALMOST_PERCEPTIBLE | Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS | Context.BIND_NOT_APP_COMPONENT_USAGE; | Context.BIND_NOT_APP_COMPONENT_USAGE | Context.BIND_DENY_ACTIVITY_STARTS; } else { bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_APP_COMPONENT_USAGE; | Context.BIND_NOT_APP_COMPONENT_USAGE | Context.BIND_DENY_ACTIVITY_STARTS; } binding = mContext.bindServiceAsUser(intent, this, bindFlags, UserHandle.of(job.getUserId())); Loading
core/java/android/speech/tts/TextToSpeech.java +2 −1 Original line number Diff line number Diff line Loading @@ -2379,7 +2379,8 @@ public class TextToSpeech { boolean connect(String engine) { Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE); intent.setPackage(engine); return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); return mContext.bindService(intent, this, Context.BIND_AUTO_CREATE | Context.BIND_DENY_ACTIVITY_STARTS); } @Override Loading
core/java/com/android/internal/util/BinaryXmlSerializer.java +10 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,8 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { */ private static final int BUFFER_SIZE = 32_768; private static final int MAX_UNSIGNED_SHORT = 65_535; private FastDataOutput mOut; /** Loading Loading @@ -221,6 +223,10 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { if (namespace != null && !namespace.isEmpty()) throw illegalNamespace(); mOut.writeByte(ATTRIBUTE | TYPE_BYTES_HEX); mOut.writeInternedUTF(name); if (value.length > MAX_UNSIGNED_SHORT) { throw new IOException("attributeBytesHex: input size (" + value.length + ") exceeds maximum allowed size (" + MAX_UNSIGNED_SHORT + ")"); } mOut.writeShort(value.length); mOut.write(value); return this; Loading @@ -232,6 +238,10 @@ public final class BinaryXmlSerializer implements TypedXmlSerializer { if (namespace != null && !namespace.isEmpty()) throw illegalNamespace(); mOut.writeByte(ATTRIBUTE | TYPE_BYTES_BASE64); mOut.writeInternedUTF(name); if (value.length > MAX_UNSIGNED_SHORT) { throw new IOException("attributeBytesBase64: input size (" + value.length + ") exceeds maximum allowed size (" + MAX_UNSIGNED_SHORT + ")"); } mOut.writeShort(value.length); mOut.write(value); return this; Loading
core/tests/coretests/src/android/util/BinaryXmlTest.java +50 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import static android.util.XmlTest.doVerifyRead; import static android.util.XmlTest.doVerifyWrite; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import static org.xmlpull.v1.XmlPullParser.START_TAG; import android.os.PersistableBundle; Loading @@ -38,12 +40,15 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; @RunWith(AndroidJUnit4.class) public class BinaryXmlTest { private static final int MAX_UNSIGNED_SHORT = 65_535; /** * Verify that we can write and read large numbers of interned * {@link String} values. Loading Loading @@ -167,4 +172,49 @@ public class BinaryXmlTest { } } } @Test public void testAttributeBytes_BinaryDataOverflow() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT + 1]; assertThrows(IOException.class, () -> out.attributeBytesHex(/* namespace */ null, /* name */ "attributeBytesHex", testBytes)); assertThrows(IOException.class, () -> out.attributeBytesBase64(/* namespace */ null, /* name */ "attributeBytesBase64", testBytes)); } @Test public void testAttributeBytesHex_MaximumBinaryData() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT]; try { out.attributeBytesHex(/* namespace */ null, /* name */ "attributeBytesHex", testBytes); } catch (Exception e) { fail("testAttributeBytesHex fails with exception: " + e.toString()); } } @Test public void testAttributeBytesBase64_MaximumBinaryData() throws Exception { final TypedXmlSerializer out = Xml.newBinarySerializer(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); out.setOutput(os, StandardCharsets.UTF_8.name()); final byte[] testBytes = new byte[MAX_UNSIGNED_SHORT]; try { out.attributeBytesBase64(/* namespace */ null, /* name */ "attributeBytesBase64", testBytes); } catch (Exception e) { fail("testAttributeBytesBase64 fails with exception: " + e.toString()); } } }
services/core/java/com/android/server/content/SyncManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -221,7 +221,8 @@ public class SyncManager { /** Flags used when connecting to a sync adapter service */ private static final int SYNC_ADAPTER_CONNECTION_FLAGS = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_ALLOW_OOM_MANAGEMENT; | Context.BIND_NOT_FOREGROUND | Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_DENY_ACTIVITY_STARTS; /** Singleton instance. */ @GuardedBy("SyncManager.class") Loading