Loading core/java/android/service/ondeviceintelligence/IOnDeviceSandboxedInferenceService.aidl +7 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.IProcessingSignal; import android.app.ondeviceintelligence.Feature; import android.os.IRemoteCallback; import android.os.ICancellationSignal; import android.os.PersistableBundle; import android.os.Bundle; Loading @@ -34,18 +35,19 @@ import android.service.ondeviceintelligence.IProcessingUpdateStatusCallback; * @hide */ oneway interface IOnDeviceSandboxedInferenceService { void registerRemoteStorageService(in IRemoteStorageService storageService); void registerRemoteStorageService(in IRemoteStorageService storageService, in IRemoteCallback remoteCallback) = 0; void requestTokenInfo(int callerUid, in Feature feature, in Bundle request, in AndroidFuture cancellationSignal, in ITokenInfoCallback tokenInfoCallback); in ITokenInfoCallback tokenInfoCallback) = 1; void processRequest(int callerUid, in Feature feature, in Bundle request, in int requestType, in AndroidFuture cancellationSignal, in AndroidFuture processingSignal, in IResponseCallback callback); in IResponseCallback callback) = 2; void processRequestStreaming(int callerUid, in Feature feature, in Bundle request, in int requestType, in AndroidFuture cancellationSignal, in AndroidFuture processingSignal, in IStreamingResponseCallback callback); in IStreamingResponseCallback callback) = 3; void updateProcessingState(in Bundle processingState, in IProcessingUpdateStatusCallback callback); in IProcessingUpdateStatusCallback callback) = 4; } No newline at end of file core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java +5 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.os.Handler; import android.os.HandlerExecutor; import android.os.IBinder; import android.os.ICancellationSignal; import android.os.IRemoteCallback; import android.os.Looper; import android.os.OutcomeReceiver; import android.os.ParcelFileDescriptor; Loading Loading @@ -148,9 +149,12 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { if (SERVICE_INTERFACE.equals(intent.getAction())) { return new IOnDeviceSandboxedInferenceService.Stub() { @Override public void registerRemoteStorageService(IRemoteStorageService storageService) { public void registerRemoteStorageService(IRemoteStorageService storageService, IRemoteCallback remoteCallback) throws RemoteException { Objects.requireNonNull(storageService); mRemoteStorageService = storageService; remoteCallback.sendResult( Bundle.EMPTY); //to notify caller uid to system-server. } @Override Loading services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerInternal.java +1 −1 Original line number Diff line number Diff line Loading @@ -17,5 +17,5 @@ package com.android.server.ondeviceintelligence; public interface OnDeviceIntelligenceManagerInternal { String getRemoteServicePackageName(); int getInferenceServiceUid(); } No newline at end of file services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java +24 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.ICancellationSignal; import android.os.IRemoteCallback; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; Loading Loading @@ -142,6 +143,9 @@ public class OnDeviceIntelligenceManagerService extends SystemService { private RemoteOnDeviceIntelligenceService mRemoteOnDeviceIntelligenceService; volatile boolean mIsServiceEnabled; @GuardedBy("mLock") private int remoteInferenceServiceUid = -1; @GuardedBy("mLock") private String[] mTemporaryServiceNames; @GuardedBy("mLock") Loading Loading @@ -174,7 +178,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Context.ON_DEVICE_INTELLIGENCE_SERVICE, getOnDeviceIntelligenceManagerService(), /* allowIsolated = */true); LocalServices.addService(OnDeviceIntelligenceManagerInternal.class, OnDeviceIntelligenceManagerService.this::getRemoteConfiguredPackageName); this::getRemoteInferenceServiceUid); } @Override Loading Loading @@ -603,7 +607,13 @@ public class OnDeviceIntelligenceManagerService extends SystemService { try { ensureRemoteIntelligenceServiceInitialized(); service.registerRemoteStorageService( getIRemoteStorageService()); getIRemoteStorageService(), new IRemoteCallback.Stub() { @Override public void sendResult(Bundle bundle) { final int uid = Binder.getCallingUid(); setRemoteInferenceServiceUid(uid); } }); mRemoteOnDeviceIntelligenceService.run( IOnDeviceIntelligenceService::notifyInferenceServiceConnected); broadcastExecutor.execute( Loading Loading @@ -1038,4 +1048,16 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Settings.Secure.ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS, TimeUnit.HOURS.toMillis(1), mContext.getUserId()); } private int getRemoteInferenceServiceUid() { synchronized (mLock) { return remoteInferenceServiceUid; } } private void setRemoteInferenceServiceUid(int remoteInferenceServiceUid) { synchronized (mLock){ this.remoteInferenceServiceUid = remoteInferenceServiceUid; } } } services/core/java/com/android/server/pm/ComputerEngine.java +5 −24 Original line number Diff line number Diff line Loading @@ -4364,7 +4364,7 @@ public class ComputerEngine implements Computer { uid = getBaseSdkSandboxUid(); } final int callingUserId = UserHandle.getUserId(callingUid); if (isKnownIsolatedComputeApp(uid, callingUserId)) { if (isKnownIsolatedComputeApp(uid)) { try { uid = getIsolatedOwner(uid); } catch (IllegalStateException e) { Loading Loading @@ -4407,7 +4407,7 @@ public class ComputerEngine implements Computer { if (Process.isSdkSandboxUid(uid)) { uid = getBaseSdkSandboxUid(); } if (isKnownIsolatedComputeApp(uid, callingUserId)) { if (isKnownIsolatedComputeApp(uid)) { try { uid = getIsolatedOwner(uid); } catch (IllegalStateException e) { Loading Loading @@ -5809,7 +5809,7 @@ public class ComputerEngine implements Computer { } private boolean isKnownIsolatedComputeApp(int uid, int callingUserId) { private boolean isKnownIsolatedComputeApp(int uid) { if (!Process.isIsolatedUid(uid)) { return false; } Loading @@ -5822,27 +5822,8 @@ public class ComputerEngine implements Computer { } OnDeviceIntelligenceManagerInternal onDeviceIntelligenceManagerInternal = mInjector.getLocalService(OnDeviceIntelligenceManagerInternal.class); if (onDeviceIntelligenceManagerInternal == null) { return false; } String onDeviceIntelligencePackage = onDeviceIntelligenceManagerInternal.getRemoteServicePackageName(); if (onDeviceIntelligencePackage == null) { return false; } try { if (getIsolatedOwner(uid) == getPackageUid(onDeviceIntelligencePackage, 0, callingUserId)) { return true; } } catch (IllegalStateException e) { // If the owner uid doesn't exist, just use the current uid Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e); } return false; return onDeviceIntelligenceManagerInternal != null && uid == onDeviceIntelligenceManagerInternal.getInferenceServiceUid(); } @Nullable Loading Loading
core/java/android/service/ondeviceintelligence/IOnDeviceSandboxedInferenceService.aidl +7 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.app.ondeviceintelligence.IResponseCallback; import android.app.ondeviceintelligence.ITokenInfoCallback; import android.app.ondeviceintelligence.IProcessingSignal; import android.app.ondeviceintelligence.Feature; import android.os.IRemoteCallback; import android.os.ICancellationSignal; import android.os.PersistableBundle; import android.os.Bundle; Loading @@ -34,18 +35,19 @@ import android.service.ondeviceintelligence.IProcessingUpdateStatusCallback; * @hide */ oneway interface IOnDeviceSandboxedInferenceService { void registerRemoteStorageService(in IRemoteStorageService storageService); void registerRemoteStorageService(in IRemoteStorageService storageService, in IRemoteCallback remoteCallback) = 0; void requestTokenInfo(int callerUid, in Feature feature, in Bundle request, in AndroidFuture cancellationSignal, in ITokenInfoCallback tokenInfoCallback); in ITokenInfoCallback tokenInfoCallback) = 1; void processRequest(int callerUid, in Feature feature, in Bundle request, in int requestType, in AndroidFuture cancellationSignal, in AndroidFuture processingSignal, in IResponseCallback callback); in IResponseCallback callback) = 2; void processRequestStreaming(int callerUid, in Feature feature, in Bundle request, in int requestType, in AndroidFuture cancellationSignal, in AndroidFuture processingSignal, in IStreamingResponseCallback callback); in IStreamingResponseCallback callback) = 3; void updateProcessingState(in Bundle processingState, in IProcessingUpdateStatusCallback callback); in IProcessingUpdateStatusCallback callback) = 4; } No newline at end of file
core/java/android/service/ondeviceintelligence/OnDeviceSandboxedInferenceService.java +5 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import android.os.Handler; import android.os.HandlerExecutor; import android.os.IBinder; import android.os.ICancellationSignal; import android.os.IRemoteCallback; import android.os.Looper; import android.os.OutcomeReceiver; import android.os.ParcelFileDescriptor; Loading Loading @@ -148,9 +149,12 @@ public abstract class OnDeviceSandboxedInferenceService extends Service { if (SERVICE_INTERFACE.equals(intent.getAction())) { return new IOnDeviceSandboxedInferenceService.Stub() { @Override public void registerRemoteStorageService(IRemoteStorageService storageService) { public void registerRemoteStorageService(IRemoteStorageService storageService, IRemoteCallback remoteCallback) throws RemoteException { Objects.requireNonNull(storageService); mRemoteStorageService = storageService; remoteCallback.sendResult( Bundle.EMPTY); //to notify caller uid to system-server. } @Override Loading
services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerInternal.java +1 −1 Original line number Diff line number Diff line Loading @@ -17,5 +17,5 @@ package com.android.server.ondeviceintelligence; public interface OnDeviceIntelligenceManagerInternal { String getRemoteServicePackageName(); int getInferenceServiceUid(); } No newline at end of file
services/core/java/com/android/server/ondeviceintelligence/OnDeviceIntelligenceManagerService.java +24 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.ICancellationSignal; import android.os.IRemoteCallback; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; Loading Loading @@ -142,6 +143,9 @@ public class OnDeviceIntelligenceManagerService extends SystemService { private RemoteOnDeviceIntelligenceService mRemoteOnDeviceIntelligenceService; volatile boolean mIsServiceEnabled; @GuardedBy("mLock") private int remoteInferenceServiceUid = -1; @GuardedBy("mLock") private String[] mTemporaryServiceNames; @GuardedBy("mLock") Loading Loading @@ -174,7 +178,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Context.ON_DEVICE_INTELLIGENCE_SERVICE, getOnDeviceIntelligenceManagerService(), /* allowIsolated = */true); LocalServices.addService(OnDeviceIntelligenceManagerInternal.class, OnDeviceIntelligenceManagerService.this::getRemoteConfiguredPackageName); this::getRemoteInferenceServiceUid); } @Override Loading Loading @@ -603,7 +607,13 @@ public class OnDeviceIntelligenceManagerService extends SystemService { try { ensureRemoteIntelligenceServiceInitialized(); service.registerRemoteStorageService( getIRemoteStorageService()); getIRemoteStorageService(), new IRemoteCallback.Stub() { @Override public void sendResult(Bundle bundle) { final int uid = Binder.getCallingUid(); setRemoteInferenceServiceUid(uid); } }); mRemoteOnDeviceIntelligenceService.run( IOnDeviceIntelligenceService::notifyInferenceServiceConnected); broadcastExecutor.execute( Loading Loading @@ -1038,4 +1048,16 @@ public class OnDeviceIntelligenceManagerService extends SystemService { Settings.Secure.ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS, TimeUnit.HOURS.toMillis(1), mContext.getUserId()); } private int getRemoteInferenceServiceUid() { synchronized (mLock) { return remoteInferenceServiceUid; } } private void setRemoteInferenceServiceUid(int remoteInferenceServiceUid) { synchronized (mLock){ this.remoteInferenceServiceUid = remoteInferenceServiceUid; } } }
services/core/java/com/android/server/pm/ComputerEngine.java +5 −24 Original line number Diff line number Diff line Loading @@ -4364,7 +4364,7 @@ public class ComputerEngine implements Computer { uid = getBaseSdkSandboxUid(); } final int callingUserId = UserHandle.getUserId(callingUid); if (isKnownIsolatedComputeApp(uid, callingUserId)) { if (isKnownIsolatedComputeApp(uid)) { try { uid = getIsolatedOwner(uid); } catch (IllegalStateException e) { Loading Loading @@ -4407,7 +4407,7 @@ public class ComputerEngine implements Computer { if (Process.isSdkSandboxUid(uid)) { uid = getBaseSdkSandboxUid(); } if (isKnownIsolatedComputeApp(uid, callingUserId)) { if (isKnownIsolatedComputeApp(uid)) { try { uid = getIsolatedOwner(uid); } catch (IllegalStateException e) { Loading Loading @@ -5809,7 +5809,7 @@ public class ComputerEngine implements Computer { } private boolean isKnownIsolatedComputeApp(int uid, int callingUserId) { private boolean isKnownIsolatedComputeApp(int uid) { if (!Process.isIsolatedUid(uid)) { return false; } Loading @@ -5822,27 +5822,8 @@ public class ComputerEngine implements Computer { } OnDeviceIntelligenceManagerInternal onDeviceIntelligenceManagerInternal = mInjector.getLocalService(OnDeviceIntelligenceManagerInternal.class); if (onDeviceIntelligenceManagerInternal == null) { return false; } String onDeviceIntelligencePackage = onDeviceIntelligenceManagerInternal.getRemoteServicePackageName(); if (onDeviceIntelligencePackage == null) { return false; } try { if (getIsolatedOwner(uid) == getPackageUid(onDeviceIntelligencePackage, 0, callingUserId)) { return true; } } catch (IllegalStateException e) { // If the owner uid doesn't exist, just use the current uid Slog.wtf(TAG, "Expected isolated uid " + uid + " to have an owner", e); } return false; return onDeviceIntelligenceManagerInternal != null && uid == onDeviceIntelligenceManagerInternal.getInferenceServiceUid(); } @Nullable Loading