Add test to verify CtsIsolatedInferenceService can only be bound by system-uid. Bug: 369871251 Flag: EXEMPT bugfix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b712e2ca770ec14eccb6e34fa79eae43de286c18) Merged-In: Iafe243b4858332a320bf9c6bce88b784b4c5e1ba Change-Id: Iafe243b4858332a320bf9c6bce88b784b4c5e1ba
diff --git a/tests/ondeviceintelligence/src/android/ondeviceintelligence/cts/OnDeviceIntelligenceManagerTest.java b/tests/ondeviceintelligence/src/android/ondeviceintelligence/cts/OnDeviceIntelligenceManagerTest.java index f499b3a..751cefc 100644 --- a/tests/ondeviceintelligence/src/android/ondeviceintelligence/cts/OnDeviceIntelligenceManagerTest.java +++ b/tests/ondeviceintelligence/src/android/ondeviceintelligence/cts/OnDeviceIntelligenceManagerTest.java
@@ -45,12 +45,15 @@ import android.app.ondeviceintelligence.StreamingProcessingCallback; import android.app.ondeviceintelligence.TokenInfo; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.os.Bundle; import android.os.CancellationSignal; +import android.os.IBinder; import android.os.PersistableBundle; import android.os.Process; import android.os.UserHandle; @@ -165,6 +168,30 @@ getInstrumentation().getUiAutomation().dropShellPermissionIdentity(); } + @Test + @SkipSetupAndTeardown + @RequiresFlagsEnabled(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) + public void cannotBindToIsolatedComputeAppEvenFromSamePackage() { + assertThrows( + "Cannot bind to isolated_compute_app process from same package", + SecurityException.class, + () -> getInstrumentation().getContext().bindService( + new Intent().setComponent(new ComponentName(CTS_PACKAGE_NAME, + CtsIsolatedInferenceService.class.getCanonicalName())), + new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, + IBinder service) { + Log.i(TAG, "Service connected"); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + Log.i(TAG, "Service disconnected"); + } + }, + Context.BIND_AUTO_CREATE)); + } //=====================Tests for Access Denied without Permission on all Manager Methods========= @@ -873,7 +900,8 @@ public void canAccessFilesInIsolated() throws Exception { int[] requestTypes = new int[]{REQUEST_TYPE_GET_FILE_FROM_MAP, REQUEST_TYPE_GET_FILE_FROM_STREAM, - REQUEST_TYPE_GET_FILE_FROM_PFD, REQUEST_TYPE_GET_FILE_FROM_NON_FILES_DIRECTORY}; + REQUEST_TYPE_GET_FILE_FROM_PFD, + REQUEST_TYPE_GET_FILE_FROM_NON_FILES_DIRECTORY}; for (int requestType : requestTypes) { sendRequestToReadTestFile(requestType); }