diff --git a/changelog.txt b/changelog.txt index 9d08425952..44f98d7cc6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ vNext ---------- +- [MINOR] Add AIDL interface for device registration service.(#2926) - [MINOR] Move debugIntuneCE and prodIntuneCE from BrokerData to AppRegistry as App instances (#3012) - [MINOR] Remove LruCache from SharedPreferencesFileManager (#2910) - [MINOR] Edge TB: Claims (#2925) diff --git a/common/src/main/aidl/com/microsoft/identity/client/IDeviceRegistrationService.aidl b/common/src/main/aidl/com/microsoft/identity/client/IDeviceRegistrationService.aidl new file mode 100644 index 0000000000..903e89e328 --- /dev/null +++ b/common/src/main/aidl/com/microsoft/identity/client/IDeviceRegistrationService.aidl @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.client; + +/** +* AIDL interface for the device registration bound service exposed by the broker. +* Client applications (such as Authenticator or CP) call into this service to execute device registration operations +* when the content provider strategy is not available. The implementation of this service resides in the broker app. +*/ +interface IDeviceRegistrationService { + /** + * Executes a device registration protocol with the broker. + * + * @param protocolParams Bundle containing device registration protocol parameters + * @return Bundle containing the protocol response from the broker + */ + Bundle executeDeviceRegistrationProtocol(in Bundle protocolParams); +} diff --git a/common/src/main/java/com/microsoft/identity/common/internal/broker/BoundServiceClient.java b/common/src/main/java/com/microsoft/identity/common/internal/broker/BoundServiceClient.java index d0e1ecf206..b932d12e49 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/broker/BoundServiceClient.java +++ b/common/src/main/java/com/microsoft/identity/common/internal/broker/BoundServiceClient.java @@ -67,14 +67,14 @@ public abstract class BoundServiceClient { /** * Perform the given operation with the given .aidl {@link IInterface} */ - abstract @Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle inputBundle, - @NonNull final T aidlInterface) throws RemoteException, BrokerCommunicationException; + protected abstract @Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle inputBundle, + @NonNull final T aidlInterface) throws RemoteException, BrokerCommunicationException; /** * Extracts {@link IInterface} from a given {@link IBinder} * i.e. T.Stub.asInterface(binder), where T is an .aidl {@link IInterface}. */ - abstract @NonNull T getInterfaceFromIBinder(@NonNull final IBinder binder); + protected abstract @NonNull T getInterfaceFromIBinder(@NonNull final IBinder binder); /** * BoundServiceClient's constructor. diff --git a/common/src/main/java/com/microsoft/identity/common/internal/broker/MicrosoftAuthClient.java b/common/src/main/java/com/microsoft/identity/common/internal/broker/MicrosoftAuthClient.java index 820171c03d..adeb1e5325 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/broker/MicrosoftAuthClient.java +++ b/common/src/main/java/com/microsoft/identity/common/internal/broker/MicrosoftAuthClient.java @@ -75,7 +75,8 @@ public MicrosoftAuthClient(@NonNull final Context context, } @Override - @Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle brokerOperationBundle, + @Nullable + protected Bundle performOperationInternal(@NonNull final BrokerOperationBundle brokerOperationBundle, @NonNull final IMicrosoftAuthService microsoftAuthService) throws RemoteException, BrokerCommunicationException { @@ -129,7 +130,7 @@ public MicrosoftAuthClient(@NonNull final Context context, } @Override - @NonNull IMicrosoftAuthService getInterfaceFromIBinder(@NonNull IBinder binder) { + @NonNull protected IMicrosoftAuthService getInterfaceFromIBinder(@NonNull IBinder binder) { final IMicrosoftAuthService service = IMicrosoftAuthService.Stub.asInterface(binder); if (service == null) { throw new IllegalStateException("Failed to extract IMicrosoftAuthService from IBinder.", null); diff --git a/common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/DeviceRegistrationServiceClient.kt b/common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/DeviceRegistrationServiceClient.kt new file mode 100644 index 0000000000..969af6665f --- /dev/null +++ b/common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/DeviceRegistrationServiceClient.kt @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.common.internal.broker.ipc + +import android.content.Context +import android.os.Bundle +import android.os.IBinder +import com.microsoft.identity.client.IDeviceRegistrationService +import com.microsoft.identity.common.internal.broker.BoundServiceClient + +/** + * A client for communicating with the DeviceRegistrationService via IPC. + * This client binds to the service and allows executing device registration protocol operations with the broker. + * + * @param context the application context used to bind to the service. + */ +class DeviceRegistrationServiceClient(context: Context) : + BoundServiceClient( + context, + SERVICE_CLASS_NAME, + SERVICE_INTENT_FILTER + ) { + companion object { + /** The fully qualified class name of the DeviceRegistrationService to bind to. */ + private const val SERVICE_CLASS_NAME = "com.microsoft.identity.client.DeviceRegistrationService" + + /** The intent filter used to identify the DeviceRegistrationService. */ + private const val SERVICE_INTENT_FILTER = "com.microsoft.identity.client.DeviceRegistration" + } + + /** + * Extracts the [IDeviceRegistrationService] AIDL interface from the given [IBinder]. + * + * @param binder the [IBinder] returned by the service connection. + * @return the [IDeviceRegistrationService] interface for communicating with the service. + */ + protected override fun getInterfaceFromIBinder(binder: IBinder): IDeviceRegistrationService = + IDeviceRegistrationService.Stub.asInterface(binder) + + /** + * Executes the device registration protocol operation by delegating to the AIDL interface. + * + * @param inputBundle the [BrokerOperationBundle] containing the operation parameters. + * @param aidlInterface the [IDeviceRegistrationService] AIDL interface bound to the service. + * @return a [Bundle] containing the result of the device registration protocol, or null if no result. + */ + protected override fun performOperationInternal( + inputBundle: BrokerOperationBundle, + aidlInterface: IDeviceRegistrationService + ): Bundle? = aidlInterface.executeDeviceRegistrationProtocol(inputBundle.bundle) +} diff --git a/common4j/src/main/com/microsoft/identity/common/java/exception/ClientException.java b/common4j/src/main/com/microsoft/identity/common/java/exception/ClientException.java index c38df98e61..b3a5a67363 100644 --- a/common4j/src/main/com/microsoft/identity/common/java/exception/ClientException.java +++ b/common4j/src/main/com/microsoft/identity/common/java/exception/ClientException.java @@ -537,6 +537,11 @@ public class ClientException extends BaseException { */ public static final String DEVICE_NOT_SUPPORT_HARDWARE_WRAPPED_KEY_IMPORT = "device_not_supported_hardware_wrapped_key_import"; + /** + * Emitted when a function that must not run on the main (UI) thread is called from the main thread. + */ + public static final String CALLED_ON_MAIN_THREAD = "called_on_main_thread"; + /** * Constructor of ClientException. *