Skip to content

Commit ddd25d1

Browse files
authored
Update min SDK to 21 (#2607)
- Update minSdk to 21 - Remove conditions for 16 Build.VERSION_CODES.JELLY_BEAN 17 Build.VERSION_CODES.JELLY_BEAN_MR1 18 Build.VERSION_CODES.JELLY_BEAN_MR2 19 KIKAT 20 KITKAT_WATCH 21 LOLLIPOP
1 parent 3c192cb commit ddd25d1

30 files changed

Lines changed: 52 additions & 212 deletions

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vNext
22
----------
3+
- [PATCH] Update minSdk to 21(#2607)
34
- [MINOR] Add handler for resume switch_browser flow on WebViewAuthorizationFragment (#2557)
45
- [PATCH] Track MAM flow in telemetry (#2608)
56
- [PATCH] Fix multiple prompts issue in cross cloud request (#2599)

common/src/androidTest/java/com/microsoft/identity/common/internal/platform/AndroidDevicePoPManagerEncryptionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
// https://github.com/robolectric/robolectric/issues/1518
5353
//todo: Investigate if these tests can be migrated to common4j
5454
@RunWith(Parameterized.class)
55+
@Config(sdk =21)
5556
public class AndroidDevicePoPManagerEncryptionTests {
5657

5758
private static final String DATA_TO_ENCRYPT = "The quick brown fox jumped over the lazy dog.";
@@ -63,10 +64,9 @@ public class AndroidDevicePoPManagerEncryptionTests {
6364
public static Iterable<IDevicePopManager.Cipher> testParams() {
6465
final List<IDevicePopManager.Cipher> ciphers = new ArrayList<>();
6566

66-
// Only execute these tests at appropriate API levels...
67-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
68-
ciphers.add(RSA_ECB_PKCS1_PADDING);
69-
}
67+
68+
ciphers.add(RSA_ECB_PKCS1_PADDING);
69+
7070

7171
//https://stackoverflow.com/questions/36015194/android-keystoreexception-unknown-error -
7272
//https://issuetracker.google.com/issues/37075898

common/src/main/java/com/microsoft/identity/common/adal/internal/AuthenticationSettings.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,10 @@ public void setSecretKey(byte[] rawKey) {
134134
if (rawKey == null || rawKey.length != SECRET_RAW_KEY_LENGTH) {
135135
throw new IllegalArgumentException("rawKey");
136136
}
137-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
138-
Logger.warn(methodTag, "You're using setSecretKey in a version of android " +
139-
"that supports keyStore functionality. Consider not doing this, as it only exists " +
140-
"for devices with an SDK lower than " + Build.VERSION_CODES.JELLY_BEAN_MR2);
141-
}
137+
Logger.warn(methodTag, "You're using setSecretKey in a version of android " +
138+
"that supports keyStore functionality. Consider not doing this, as it only exists " +
139+
"for devices with an SDK lower than " + Build.VERSION_CODES.JELLY_BEAN_MR2);
140+
142141
mSecretKeyData.set(rawKey);
143142
}
144143

common/src/main/java/com/microsoft/identity/common/adal/internal/cache/ADALOAuth2TokenCache.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ private void setItem(final String key, final ADALTokenCacheItem cacheItem) {
391391

392392
private void validateSecretKeySetting() {
393393
Logger.verbose(TAG, "Validating secret key settings.");
394-
final byte[] secretKeyData = AuthenticationSettings.INSTANCE.getSecretKeyData();
395-
396-
if (secretKeyData == null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
397-
throw new IllegalArgumentException("Secret key must be provided for API < 18. "
398-
+ "Use AuthenticationSettings.INSTANCE.setSecretKey()");
399-
}
400394
}
401395

402396
@Override

common/src/main/java/com/microsoft/identity/common/crypto/AndroidWrappedKeyLoader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
* Instead, the actual key that we use to encrypt/decrypt data is 'wrapped/encrypted' with the keystore key
7272
* before it get saved to the file.
7373
*/
74-
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
7574
public class AndroidWrappedKeyLoader extends AES256KeyLoader {
7675
private static final String TAG = AndroidWrappedKeyLoader.class.getSimpleName() + "#";
7776

@@ -359,7 +358,6 @@ public void deleteSecretKeyFromStorage() throws ClientException {
359358
* @param context an Android {@link Context} object.
360359
* @return a {@link AlgorithmParameterSpec} for the keystore key (that we'll use to wrap the secret key).
361360
*/
362-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
363361
private static AlgorithmParameterSpec getLegacySpecForKeyStoreKey(@NonNull final Context context,
364362
@NonNull final String alias) {
365363
// Generate a self-signed cert.

common/src/main/java/com/microsoft/identity/common/internal/fido/LegacyFidoActivityResultContract.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ package com.microsoft.identity.common.internal.fido
2525
import android.app.Activity
2626
import android.content.Context
2727
import android.content.Intent
28-
import android.os.Build
2928
import android.util.Base64
3029
import androidx.activity.result.IntentSenderRequest
3130
import androidx.activity.result.contract.ActivityResultContract
3231
import androidx.activity.result.contract.ActivityResultContracts
33-
import androidx.annotation.RequiresApi
3432
import com.google.android.gms.fido.Fido
3533
import com.google.android.gms.fido.fido2.api.common.AuthenticatorAssertionResponse
3634
import com.google.android.gms.fido.fido2.api.common.AuthenticatorErrorResponse
@@ -58,7 +56,6 @@ class LegacyFidoActivityResultContract : ActivityResultContract<LegacyFido2ApiOb
5856
)
5957
}
6058

61-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
6259
override fun parseResult(resultCode: Int, intent: Intent?): Void? {
6360
if (intent == null) {
6461
errorCallback.invoke(

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidDevicePopManager.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ private static IKeyStoreKeyManager<KeyStore.PrivateKeyEntry> createKeyStoreKeyMa
118118
.build();
119119
}
120120

121-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
122121
@Override
123122
public KeyPair generateNewRsaKeyPair(int keySize) throws UnsupportedOperationException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
124123
return generateNewRsaKeyPair(mContext, keySize);
@@ -169,7 +168,6 @@ protected void performCleanupIfMintShrFails(@NonNull final Exception e) {
169168
* @return The newly generated RSA KeyPair.
170169
* @throws UnsupportedOperationException
171170
*/
172-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
173171
@SuppressLint(NewApi)
174172
private KeyPair generateNewRsaKeyPair(@androidx.annotation.NonNull final Context context,
175173
final int minKeySize)
@@ -293,7 +291,6 @@ private static boolean isNegativeInternalError(@androidx.annotation.NonNull fina
293291
* @throws NoSuchProviderException If the designated crypto provider cannot be found.
294292
* @throws StrongBoxUnavailableException If StrongBox is unavailable.
295293
*/
296-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
297294
private KeyPair generateNewKeyPair(@androidx.annotation.NonNull final Context context, final boolean useStrongbox,
298295
final boolean enableImport, final boolean trySetAttestationChallenge)
299296
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException,
@@ -321,7 +318,6 @@ private KeyPair generateNewKeyPair(@androidx.annotation.NonNull final Context co
321318
}
322319
}
323320

324-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
325321
private KeyPairGenerator getInitializedRsaKeyPairGenerator(@androidx.annotation.NonNull final Context context,
326322
final int keySize,
327323
final boolean useStrongbox,
@@ -352,7 +348,6 @@ private KeyPairGenerator getInitializedRsaKeyPairGenerator(@androidx.annotation.
352348
* @param trySetAttestationChallenge True if we should attempt to generate an attestation challenge cert.
353349
* @throws InvalidAlgorithmParameterException
354350
*/
355-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
356351
private void initialize(@androidx.annotation.NonNull final Context context,
357352
@androidx.annotation.NonNull final KeyPairGenerator keyPairGenerator,
358353
final int keySize,
@@ -491,7 +486,6 @@ private void initialize28(@androidx.annotation.NonNull final KeyPairGenerator ke
491486

492487

493488
@SuppressLint(NewApi)
494-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
495489
@SuppressWarnings("deprecation")
496490
private void initializePre23(@androidx.annotation.NonNull final Context context,
497491
@androidx.annotation.NonNull final KeyPairGenerator keyPairGenerator,
@@ -508,11 +502,9 @@ private void initializePre23(@androidx.annotation.NonNull final Context context,
508502
.setSerialNumber(AndroidDevicePopManager.CertificateProperties.SERIAL_NUMBER)
509503
.setSubject(new X500Principal(AndroidDevicePopManager.CertificateProperties.COMMON_NAME));
510504

511-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
512-
specBuilder.setAlgorithmParameterSpec(
513-
new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4)
514-
);
515-
}
505+
specBuilder.setAlgorithmParameterSpec(
506+
new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4)
507+
);
516508

517509
final android.security.KeyPairGeneratorSpec spec = specBuilder.build();
518510
keyPairGenerator.initialize(spec);

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidKeystoreAsymmetricRsaKey.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.platform;
2424

25-
import android.content.Context;
26-
import android.os.Build;
2725

2826
import androidx.annotation.NonNull;
29-
import androidx.annotation.RequiresApi;
3027

3128
import com.microsoft.identity.common.java.crypto.SecureHardwareState;
3229
import com.microsoft.identity.common.java.crypto.SigningAlgorithm;
@@ -41,10 +38,8 @@
4138
*/
4239
public class AndroidKeystoreAsymmetricRsaKey implements AsymmetricRsaKey {
4340

44-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
4541
public static final IDevicePopManager.Cipher RSA_ECB_PKCS_1_PADDING = IDevicePopManager.Cipher.RSA_ECB_PKCS1_PADDING;
4642

47-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
4843
public static final SigningAlgorithm SHA_256_WITH_RSA = SigningAlgorithm.SHA_256_WITH_RSA;
4944

5045
/**
@@ -94,25 +89,21 @@ public String getPublicKey() throws ClientException {
9489
return mDevicePopManager.getPublicKey(IDevicePopManager.PublicKeyFormat.JWK);
9590
}
9691

97-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
9892
@Override
9993
public String sign(@NonNull final String data) throws ClientException {
10094
return mDevicePopManager.sign(SHA_256_WITH_RSA, data);
10195
}
10296

103-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
10497
@Override
10598
public boolean verify(@NonNull final String plainText, @NonNull final String signatureStr) {
10699
return mDevicePopManager.verify(SHA_256_WITH_RSA, plainText, signatureStr);
107100
}
108101

109-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
110102
@Override
111103
public String encrypt(@NonNull final String plaintext) throws ClientException {
112104
return mDevicePopManager.encrypt(RSA_ECB_PKCS_1_PADDING, plaintext);
113105
}
114106

115-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
116107
@Override
117108
public String decrypt(@NonNull final String ciphertext) throws ClientException {
118109
return mDevicePopManager.decrypt(RSA_ECB_PKCS_1_PADDING, ciphertext);
@@ -123,25 +114,21 @@ public SecureHardwareState getSecureHardwareState() throws ClientException {
123114
return mDevicePopManager.getSecureHardwareState();
124115
}
125116

126-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
127117
@Override
128118
public byte[] encrypt(byte[] plaintext) throws ClientException {
129119
return mDevicePopManager.encrypt(RSA_ECB_PKCS_1_PADDING, plaintext);
130120
}
131121

132-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
133122
@Override
134123
public byte[] decrypt(byte[] ciphertext) throws ClientException {
135124
return mDevicePopManager.encrypt(RSA_ECB_PKCS_1_PADDING, ciphertext);
136125
}
137126

138-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
139127
@Override
140128
public byte[] sign(byte[] text) throws ClientException {
141129
return mDevicePopManager.sign(SHA_256_WITH_RSA, text);
142130
}
143131

144-
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
145132
@Override
146133
public boolean verify(byte[] text, byte[] signature) throws ClientException {
147134
return mDevicePopManager.verify(SHA_256_WITH_RSA, text, signature);

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidPlatformUtil.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ public void onReturnCommandResult(@NonNull ICommand<?> command) {
179179

180180
@Override
181181
public long getNanosecondTime() {
182-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
183-
return SystemClock.elapsedRealtimeNanos();
184-
} else {
185-
return System.nanoTime();
186-
}
182+
return SystemClock.elapsedRealtimeNanos();
187183
}
188184

189185
@Override
@@ -250,7 +246,7 @@ public static boolean isInManagedProfile(@NonNull final Context appContext) {
250246
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
251247
final UserManager um = (UserManager) appContext.getSystemService(Context.USER_SERVICE);
252248
return um.isManagedProfile();
253-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
249+
} else {
254250
final DevicePolicyManager dpm = (DevicePolicyManager) appContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
255251
final List<ComponentName> activeAdmins = dpm.getActiveAdmins();
256252
if (activeAdmins != null) {

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidSecretKeyAccessor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.platform;
2424

25-
import android.os.Build;
26-
27-
import androidx.annotation.RequiresApi;
2825

2926
import com.microsoft.identity.common.java.crypto.CryptoSuite;
3027
import com.microsoft.identity.common.java.crypto.IKeyStoreKeyManager;
@@ -69,7 +66,6 @@ public class AndroidSecretKeyAccessor implements IManagedKeyAccessor<KeyStore.Se
6966
private static final Charset UTF8 = Charset.forName("UTF-8");
7067
private final AndroidDeviceKeyManager<KeyStore.SecretKeyEntry> mKeyManager;
7168
private final CryptoSuite suite;
72-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
7369
@Override
7470
public byte[] encrypt(@NonNull final byte[] plaintext) throws ClientException {
7571
final String errCode;
@@ -110,7 +106,6 @@ public byte[] encrypt(@NonNull final byte[] plaintext) throws ClientException {
110106
throw new ClientException(errCode, exception.getMessage(), exception);
111107
}
112108

113-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
114109
@Override
115110
public byte[] decrypt(@NonNull final byte[] ciphertext) throws ClientException {
116111
final String errCode;

0 commit comments

Comments
 (0)