Skip to content

Commit deebe89

Browse files
fix: remove unnecessary contextcompat class lookup (#2091)
AWSMobileClient tried to check if the library has network access. As part of this, it checks whether or not there is permission to access the network. The existing mechanism to achieve this performed a reflective class lookup on an (old) Android support library. Instead, guard the checkSelfPermission(..) call in an API level guard. Resolves: #2063
1 parent 0c4f30f commit deebe89

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import android.net.ConnectivityManager;
2727
import android.net.NetworkInfo;
2828
import android.net.Uri;
29+
import android.os.Build;
30+
import android.util.Log;
2931
import androidx.annotation.AnyThread;
3032
import androidx.annotation.WorkerThread;
3133
import androidx.browser.customtabs.CustomTabsCallback;
@@ -34,7 +36,6 @@
3436
import androidx.browser.customtabs.CustomTabsServiceConnection;
3537
import androidx.browser.customtabs.CustomTabsSession;
3638
import androidx.core.content.ContextCompat;
37-
import android.util.Log;
3839

3940
import com.amazonaws.AmazonClientException;
4041
import com.amazonaws.ClientConfiguration;
@@ -767,15 +768,12 @@ public void run() {
767768
* @return true if permission to access network state is granted and network is connected.
768769
*/
769770
protected boolean isNetworkAvailable(final Context context) {
770-
try {
771-
Class.forName("android.support.v4.content.ContextCompat");
771+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
772772
int hasReadExternalStoragePermission = ContextCompat.checkSelfPermission(context,
773773
Manifest.permission.ACCESS_NETWORK_STATE);
774774
if (hasReadExternalStoragePermission != PackageManager.PERMISSION_GRANTED) {
775775
return false;
776776
}
777-
} catch (ClassNotFoundException e) {
778-
Log.w(TAG, "Could not check if ACCESS_NETWORK_STATE permission is available.", e);
779777
}
780778

781779
try {
@@ -3989,4 +3987,4 @@ Uri exchangeCode(String uri) {
39893987
return null;
39903988
}
39913989

3992-
}
3990+
}

0 commit comments

Comments
 (0)