Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vNext
----------
- [MINOR] Move camera logic to CameraPermissionRequestHandler and add SdmQrPinManager (#2630)
- [MINOR] Pass Work Profile existence, OS Version, and Manufacturer to ESTS (#2627)
- [MINOR] Add telemetry for the switch browser protocol (#2612)

Expand Down
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
}
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
}
}
}
Loading
Loading