-
Notifications
You must be signed in to change notification settings - Fork 46
Move camera logic to CameraPermissionRequestHandler and add SdmQrPinManager , Fixes AB#3121976 #2630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Move camera logic to CameraPermissionRequestHandler and add SdmQrPinManager , Fixes AB#3121976 #2630
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
240a04b
Add SDM QR PIN Manager
p3dr0rv 7277161
add JvmStatic to buildMultiValueRequest
p3dr0rv 5bd1668
only update every 6 hours
p3dr0rv 9f83bf0
update doc
p3dr0rv 42ad9c4
update docs
p3dr0rv 344dea0
update SdmQrPinManager
p3dr0rv 514f98c
Merge branch 'dev' into pedroro/qr-pin-rework
p3dr0rv 394cc89
fix tags and rework methods in SdmQrPinManager for null cases
p3dr0rv 67de430
update chnagelog
p3dr0rv 66d351a
improve doc on SdmQrPinManager and override restrictionsManager on init
p3dr0rv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
common/src/main/java/com/microsoft/identity/common/internal/broker/IRestrictionsManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // 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 | ||
|
|
||
| import android.os.Bundle | ||
|
|
||
| /** | ||
| * Helper class to read the app restrictions manager. | ||
| */ | ||
| interface IRestrictionsManager { | ||
| companion object BrokerRestrictionsManagerKeys { | ||
| /** Keys to group the values in the bundle. */ | ||
| const val BOOLEAN_VALUES_KEY = "booleanValuesKey" | ||
| const val STRING_VALUES_KEY = "stringValuesKey" | ||
|
|
||
| /** Keys to be used in the app restrictions manager to read the values. */ | ||
| // String keys | ||
| const val PREFERRED_AUTH_CONFIG = "preferred_auth_config" | ||
| // Boolean keys | ||
| const val SUPPRESS_CAMERA_CONSENT = "sdm_suppress_camera_consent" | ||
|
|
||
| /** | ||
| * Creates a request bundle with the keys to be requested from the app restrictions manager. | ||
| * The keys are filtered based on the type of the keys. | ||
| * | ||
| * @param stringKeys Keys to be requested from the app restrictions manager. | ||
| * @param booleanKeys Keys to be requested from the app restrictions manager. | ||
| * @return Bundle with the keys to be requested from the app restrictions manager. | ||
| */ | ||
| @JvmStatic | ||
| @JvmOverloads | ||
| fun buildMultiValueRequest(stringKeys: Set<String>? = null, booleanKeys: Set<String>? = null): Bundle { | ||
| val stringList = stringKeys?.let { ArrayList(it) } | ||
| val booleanList = booleanKeys?.let { ArrayList(it) } | ||
| return Bundle().apply { | ||
| this.putStringArrayList(STRING_VALUES_KEY, stringList) | ||
| this.putStringArrayList(BOOLEAN_VALUES_KEY, booleanList) | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * Gets the [key] value from the [brokerAppPackageName] restrictions manager. | ||
| * Returns null if the key is not found or failed to read the value. | ||
| */ | ||
| fun getString(key: String, brokerAppPackageName: String, defaultValue: String? = null): String? | ||
|
|
||
| /** | ||
| * Gets the [key] value from the [brokerAppPackageName] restrictions manager. | ||
| * Returns null if the key is not found or failed to read the value. | ||
| */ | ||
| fun getBoolean(key: String, brokerAppPackageName: String, defaultValue: Boolean = false): Boolean | ||
|
|
||
| /** | ||
| * Reads the keys from the [bundleOfKeys] provided | ||
| * and returns a bundle with the values from the [brokerAppPackageName] restrictions manager. | ||
| * <p> | ||
| * The provided bundle should contain a key determining the type of the keys to be requested | ||
| * and the value should be an array list of keys. | ||
| * Example: if the bundle contains a key "stringValues" with an array list of keys ["key1s", "key2s"] | ||
| * and a key "booleanValues" with an array list of keys ["key0b"]. | ||
| * Then the returned bundle will contain the values for the keys "key1s", "key2s" and "key0b". | ||
| * | ||
| * | ||
| * @param bundleOfKeys Bundle of keys to be requested from the app restrictions manager. | ||
| * @return Bundle with the values from the app restrictions manager. | ||
| */ | ||
| fun getMultiValues(brokerAppPackageName: String, bundleOfKeys: Bundle) : Bundle | ||
| } |
93 changes: 93 additions & 0 deletions
93
common/src/main/java/com/microsoft/identity/common/internal/broker/SdmQrPinManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // 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 | ||
|
|
||
| import com.microsoft.identity.common.internal.broker.IRestrictionsManager.BrokerRestrictionsManagerKeys.PREFERRED_AUTH_CONFIG | ||
| import com.microsoft.identity.common.internal.broker.IRestrictionsManager.BrokerRestrictionsManagerKeys.SUPPRESS_CAMERA_CONSENT | ||
| import com.microsoft.identity.common.logging.Logger | ||
|
|
||
| /** | ||
| * Manages the SDM QR PIN mode settings for the device. | ||
| * by reading the restrictions manager of the Authenticator app. | ||
| * | ||
| * This object contains functions to check" | ||
| * - Whether camera consent should be suppressed. | ||
| * - The preferred authentication method for the device. | ||
| * | ||
| * It is initialized each time `brokerAndroidBrokerPlatformComponentsFactory.create` is called. | ||
| * | ||
| * Note: If this object is not initialized, values default to `false` and `null`, | ||
| * meaning the device is not in SDM QR PIN mode. | ||
| */ | ||
| object SdmQrPinManager { | ||
|
|
||
| private const val TAG = "SdmQrPinManager" | ||
|
|
||
| private val authenticatorPackageName = BrokerData.prodMicrosoftAuthenticator.packageName | ||
| private var restrictionsManager: IRestrictionsManager? = null | ||
|
|
||
| /** | ||
| * This method is used to initialize the SDM QR PIN manager with the broker restrictions manager. | ||
| * This is called when brokerAndroidBrokerPlatformComponentsFactory.create is called | ||
| * to ensure the manager is initialized with the correct broker restrictions manager. | ||
| */ | ||
| fun initializeSdmQrPinManager(restrictionsManager: IRestrictionsManager) { | ||
| this.restrictionsManager = restrictionsManager | ||
| } | ||
|
|
||
| /** | ||
| * This method checks if the device preferred authentication config is set. | ||
| */ | ||
| fun getPreferredAuthConfig(): String? { | ||
| val methodTag = "$TAG:getPreferredAuthConfig" | ||
| val defaultValue = null | ||
| restrictionsManager?.let { manager -> | ||
| return manager.getString( | ||
| key = PREFERRED_AUTH_CONFIG, | ||
| brokerAppPackageName = authenticatorPackageName, | ||
| defaultValue = defaultValue | ||
| ) | ||
| } ?: run { | ||
| Logger.warn(methodTag, "Broker restrictions manager is not initialized.") | ||
| return defaultValue | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This method checks if the camera consent is suppressed. | ||
| */ | ||
| fun isCameraConsentSuppressed(): Boolean { | ||
| val methodTag = "$TAG:isCameraConsentSuppressed" | ||
| val defaultValue = false | ||
| restrictionsManager?.let { manager -> | ||
| return manager.getBoolean( | ||
| key = SUPPRESS_CAMERA_CONSENT, | ||
| brokerAppPackageName = authenticatorPackageName, | ||
| defaultValue = defaultValue | ||
| ) | ||
| } ?: run { | ||
| Logger.warn(methodTag, "Broker restrictions manager is not initialized.") | ||
| return defaultValue | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.