Skip to content

Commit 98034f5

Browse files
authored
Add AIDL interface for device registration service., Fixes AB#3127905 (#2926)
This pull request introduces a new IPC client for device registration and refines access control for service client methods. The most significant changes are the addition of the `DeviceRegistrationServiceClient`, the definition of its AIDL interface, and the adjustment of method visibility in service client classes for better encapsulation. ### Device Registration IPC Integration * Added a new AIDL interface `IDeviceRegistrationService.aidl` to define the contract for device registration operations between the broker and client. * Introduced `DeviceRegistrationServiceClient.kt`, a Kotlin class that binds to the device registration service and executes device registration protocol operations via IPC. ### Service Client API Refinement * Changed the visibility of `performOperationInternal` and `getInterfaceFromIBinder` methods in `BoundServiceClient.java` and `MicrosoftAuthClient.java` from `abstract`/`public` to `protected abstract`/`protected`, restricting their accessibility to subclasses only. [[1]](diffhunk://#diff-1369a21afc307a63e7cdfceb1e73ec2edeb70ac7405b434e4dca3a8c9aecff0fL70-R77) [[2]](diffhunk://#diff-b576e2272c121a318985101b4f74d1b6fedc6697d52202b7fd5a73525a4b42fcL78-R79) [[3]](diffhunk://#diff-b576e2272c121a318985101b4f74d1b6fedc6697d52202b7fd5a73525a4b42fcL132-R133) [AB#3127905](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3127905) Related PR: https://github.com/identity-authnz-teams/ad-accounts-for-android/pull/81
1 parent 5d30739 commit 98034f5

6 files changed

Lines changed: 121 additions & 5 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vNext
22
----------
3+
- [MINOR] Add AIDL interface for device registration service.(#2926)
34
- [MINOR] Move debugIntuneCE and prodIntuneCE from BrokerData to AppRegistry as App instances (#3012)
45
- [MINOR] Remove LruCache from SharedPreferencesFileManager (#2910)
56
- [MINOR] Edge TB: Claims (#2925)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.client;
24+
25+
/**
26+
* AIDL interface for the device registration bound service exposed by the broker.
27+
* Client applications (such as Authenticator or CP) call into this service to execute device registration operations
28+
* when the content provider strategy is not available. The implementation of this service resides in the broker app.
29+
*/
30+
interface IDeviceRegistrationService {
31+
/**
32+
* Executes a device registration protocol with the broker.
33+
*
34+
* @param protocolParams Bundle containing device registration protocol parameters
35+
* @return Bundle containing the protocol response from the broker
36+
*/
37+
Bundle executeDeviceRegistrationProtocol(in Bundle protocolParams);
38+
}

common/src/main/java/com/microsoft/identity/common/internal/broker/BoundServiceClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public abstract class BoundServiceClient<T extends IInterface> {
6767
/**
6868
* Perform the given operation with the given .aidl {@link IInterface}
6969
*/
70-
abstract @Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle inputBundle,
71-
@NonNull final T aidlInterface) throws RemoteException, BrokerCommunicationException;
70+
protected abstract @Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle inputBundle,
71+
@NonNull final T aidlInterface) throws RemoteException, BrokerCommunicationException;
7272

7373
/**
7474
* Extracts {@link IInterface} from a given {@link IBinder}
7575
* i.e. T.Stub.asInterface(binder), where T is an .aidl {@link IInterface}.
7676
*/
77-
abstract @NonNull T getInterfaceFromIBinder(@NonNull final IBinder binder);
77+
protected abstract @NonNull T getInterfaceFromIBinder(@NonNull final IBinder binder);
7878

7979
/**
8080
* BoundServiceClient's constructor.

common/src/main/java/com/microsoft/identity/common/internal/broker/MicrosoftAuthClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public MicrosoftAuthClient(@NonNull final Context context,
7575
}
7676

7777
@Override
78-
@Nullable Bundle performOperationInternal(@NonNull final BrokerOperationBundle brokerOperationBundle,
78+
@Nullable
79+
protected Bundle performOperationInternal(@NonNull final BrokerOperationBundle brokerOperationBundle,
7980
@NonNull final IMicrosoftAuthService microsoftAuthService)
8081
throws RemoteException, BrokerCommunicationException {
8182

@@ -129,7 +130,7 @@ public MicrosoftAuthClient(@NonNull final Context context,
129130
}
130131

131132
@Override
132-
@NonNull IMicrosoftAuthService getInterfaceFromIBinder(@NonNull IBinder binder) {
133+
@NonNull protected IMicrosoftAuthService getInterfaceFromIBinder(@NonNull IBinder binder) {
133134
final IMicrosoftAuthService service = IMicrosoftAuthService.Stub.asInterface(binder);
134135
if (service == null) {
135136
throw new IllegalStateException("Failed to extract IMicrosoftAuthService from IBinder.", null);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.common.internal.broker.ipc
24+
25+
import android.content.Context
26+
import android.os.Bundle
27+
import android.os.IBinder
28+
import com.microsoft.identity.client.IDeviceRegistrationService
29+
import com.microsoft.identity.common.internal.broker.BoundServiceClient
30+
31+
/**
32+
* A client for communicating with the DeviceRegistrationService via IPC.
33+
* This client binds to the service and allows executing device registration protocol operations with the broker.
34+
*
35+
* @param context the application context used to bind to the service.
36+
*/
37+
class DeviceRegistrationServiceClient(context: Context) :
38+
BoundServiceClient<IDeviceRegistrationService>(
39+
context,
40+
SERVICE_CLASS_NAME,
41+
SERVICE_INTENT_FILTER
42+
) {
43+
companion object {
44+
/** The fully qualified class name of the DeviceRegistrationService to bind to. */
45+
private const val SERVICE_CLASS_NAME = "com.microsoft.identity.client.DeviceRegistrationService"
46+
47+
/** The intent filter used to identify the DeviceRegistrationService. */
48+
private const val SERVICE_INTENT_FILTER = "com.microsoft.identity.client.DeviceRegistration"
49+
}
50+
51+
/**
52+
* Extracts the [IDeviceRegistrationService] AIDL interface from the given [IBinder].
53+
*
54+
* @param binder the [IBinder] returned by the service connection.
55+
* @return the [IDeviceRegistrationService] interface for communicating with the service.
56+
*/
57+
protected override fun getInterfaceFromIBinder(binder: IBinder): IDeviceRegistrationService =
58+
IDeviceRegistrationService.Stub.asInterface(binder)
59+
60+
/**
61+
* Executes the device registration protocol operation by delegating to the AIDL interface.
62+
*
63+
* @param inputBundle the [BrokerOperationBundle] containing the operation parameters.
64+
* @param aidlInterface the [IDeviceRegistrationService] AIDL interface bound to the service.
65+
* @return a [Bundle] containing the result of the device registration protocol, or null if no result.
66+
*/
67+
protected override fun performOperationInternal(
68+
inputBundle: BrokerOperationBundle,
69+
aidlInterface: IDeviceRegistrationService
70+
): Bundle? = aidlInterface.executeDeviceRegistrationProtocol(inputBundle.bundle)
71+
}

common4j/src/main/com/microsoft/identity/common/java/exception/ClientException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ public class ClientException extends BaseException {
537537
*/
538538
public static final String DEVICE_NOT_SUPPORT_HARDWARE_WRAPPED_KEY_IMPORT = "device_not_supported_hardware_wrapped_key_import";
539539

540+
/**
541+
* Emitted when a function that must not run on the main (UI) thread is called from the main thread.
542+
*/
543+
public static final String CALLED_ON_MAIN_THREAD = "called_on_main_thread";
544+
540545
/**
541546
* Constructor of ClientException.
542547
*

0 commit comments

Comments
 (0)