@@ -36,19 +36,27 @@ import com.microsoft.identity.common.logging.Logger
3636 */
3737object SdmQrPinManager {
3838
39- const val TAG = " SdmQrPinManager"
39+ private const val TAG = " SdmQrPinManager"
40+ private const val SIX_HOURS_IN_SECONDS = 21600L
4041
4142 /* *
4243 * This is a flag to indicate if the device is on SDM QR PIN mode.
4344 * If this is true, the device should prompt the user for camera consent.
4445 */
4546 var isDeviceOnSdmQrPinAuth = false
47+ private set
4648
4749 /* *
4850 * This is a flag to indicate if the camera consent should be suppressed.
4951 * If this is true, the device should not prompt the user for camera consent.
5052 */
5153 var isCameraConsentSuppressed = false
54+ private set
55+
56+ /* *
57+ * This variable is used to store the last update time of the SDM QR PIN manager.
58+ */
59+ private var lastUpdateTime: Long = 0L
5260
5361 /* *
5462 * This method initializes the SDM QR PIN manager by checking the broker restrictions manager.
@@ -60,19 +68,45 @@ object SdmQrPinManager {
6068 */
6169 fun initializeSdmQrPinManager (brokerRestrictionsManager : IBrokerRestrictionsManager ) {
6270 Logger .info(TAG , " Initializing SDM QR PIN manager." )
63- val multiValueRequest = buildMultiValueRequest(
71+ if (! needsUpdate()) {
72+ Logger .info(TAG , " SDM QR PIN manager is already initialized." )
73+ return
74+ }
75+ val multiValueRequest = buildMultiValueRequest(
6476 booleanKeys = setOf (SUPPRESS_CAMERA_CONSENT ),
6577 stringKeys = setOf (PREFERRED_AUTH_CONFIG )
6678 )
6779 val multiValues = brokerRestrictionsManager.getMultiValues(
68- brokerAppPackageName = BrokerData .prodMicrosoftAuthenticator.packageName,
80+ brokerAppPackageName = BrokerData .prodMicrosoftAuthenticator.packageName,
6981 bundleOfKeys = multiValueRequest
7082 )
71- val preferredAuthConfig = multiValues.getString(PREFERRED_AUTH_CONFIG )
72- if (preferredAuthConfig != null && preferredAuthConfig == PreferredAuthMethod .QR .value) {
83+ val preferredAuthConfig = multiValues.getString(PREFERRED_AUTH_CONFIG )
84+ if (preferredAuthConfig != null && preferredAuthConfig == PreferredAuthMethod .QR .value) {
7385 isDeviceOnSdmQrPinAuth = true
7486 }
7587 isCameraConsentSuppressed = multiValues.getBoolean(SUPPRESS_CAMERA_CONSENT )
76- Logger .info(TAG , " isDeviceOnSdmQrPinAuth: $isDeviceOnSdmQrPinAuth , isCameraConsentSuppressed: $isCameraConsentSuppressed " )
88+ Logger .info(
89+ TAG ,
90+ " isDeviceOnSdmQrPinAuth: $isDeviceOnSdmQrPinAuth , isCameraConsentSuppressed: $isCameraConsentSuppressed "
91+ )
92+ }
93+
94+ /* *
95+ * This method checks if the SDM QR PIN manager needs to be updated.
96+ * It checks if the last update time is more than 6 hours ago.
97+ *
98+ * @return true if the SDM QR PIN manager needs to be updated, false otherwise.
99+ */
100+ private fun needsUpdate (): Boolean {
101+ val methodTag = " $TAG :needsUpdate"
102+ val currentTime = System .currentTimeMillis() / 1000 // current time in seconds
103+ return if (currentTime - lastUpdateTime >= SIX_HOURS_IN_SECONDS ) {
104+ Logger .info(methodTag, " SDM QR PIN manager needs update." )
105+ lastUpdateTime = currentTime
106+ true
107+ } else {
108+ Logger .info(methodTag, " Update skipped: less than 6 hours since last update." )
109+ false
110+ }
77111 }
78112}
0 commit comments