66import android .content .IntentFilter ;
77import android .content .pm .ApplicationInfo ;
88import android .content .pm .PackageInfo ;
9+ import android .content .pm .PackageManager ;
910import android .content .res .AssetManager ;
1011import android .net .ConnectivityManager ;
1112import android .net .NetworkInfo ;
@@ -168,7 +169,7 @@ protected static String[] getProGuardUuids(Context ctx) {
168169 }
169170 } catch (FileNotFoundException e ) {
170171 Log .d (TAG , "Proguard UUIDs file not found." );
171- } catch (Exception e ) {
172+ } catch (IOException | RuntimeException e ) {
172173 Log .e (TAG , "Error getting Proguard UUIDs." , e );
173174 }
174175
@@ -185,7 +186,7 @@ protected static String[] getProGuardUuids(Context ctx) {
185186 protected static PackageInfo getPackageInfo (Context ctx ) {
186187 try {
187188 return ctx .getPackageManager ().getPackageInfo (ctx .getPackageName (), 0 );
188- } catch (Exception e ) {
189+ } catch (PackageManager . NameNotFoundException | RuntimeException e ) {
189190 Log .e (TAG , "Error getting package info." , e );
190191 return null ;
191192 }
@@ -200,7 +201,7 @@ protected static PackageInfo getPackageInfo(Context ctx) {
200201 protected static String getFamily () {
201202 try {
202203 return Build .MODEL .split (" " )[0 ];
203- } catch (Exception e ) {
204+ } catch (RuntimeException e ) {
204205 Log .e (TAG , "Error getting device family." , e );
205206 return null ;
206207 }
@@ -221,7 +222,7 @@ protected static Boolean isEmulator() {
221222 || Build .MANUFACTURER .contains ("Genymotion" )
222223 || (Build .BRAND .startsWith ("generic" ) && Build .DEVICE .startsWith ("generic" ))
223224 || "google_sdk" .equals (Build .PRODUCT );
224- } catch (Exception e ) {
225+ } catch (RuntimeException e ) {
225226 Log .e (TAG , "Error checking whether application is running in an emulator." , e );
226227 return null ;
227228 }
@@ -239,7 +240,7 @@ protected static ActivityManager.MemoryInfo getMemInfo(Context ctx) {
239240 ActivityManager .MemoryInfo memInfo = new ActivityManager .MemoryInfo ();
240241 actManager .getMemoryInfo (memInfo );
241242 return memInfo ;
242- } catch (Exception e ) {
243+ } catch (RuntimeException e ) {
243244 Log .e (TAG , "Error getting MemoryInfo." , e );
244245 return null ;
245246 }
@@ -266,7 +267,7 @@ protected static String getOrientation(Context ctx) {
266267 break ;
267268 }
268269 return o ;
269- } catch (Exception e ) {
270+ } catch (RuntimeException e ) {
270271 Log .e (TAG , "Error getting device orientation." , e );
271272 return null ;
272273 }
@@ -297,7 +298,7 @@ protected static Float getBatteryLevel(Context ctx) {
297298 // CHECKSTYLE.ON: MagicNumber
298299
299300 return ((float ) level / (float ) scale ) * percentMultiplier ;
300- } catch (Exception e ) {
301+ } catch (RuntimeException e ) {
301302 Log .e (TAG , "Error getting device battery level." , e );
302303 return null ;
303304 }
@@ -318,7 +319,7 @@ protected static Boolean isCharging(Context ctx) {
318319
319320 int plugged = intent .getIntExtra (BatteryManager .EXTRA_PLUGGED , -1 );
320321 return plugged == BatteryManager .BATTERY_PLUGGED_AC || plugged == BatteryManager .BATTERY_PLUGGED_USB ;
321- } catch (Exception e ) {
322+ } catch (RuntimeException e ) {
322323 Log .e (TAG , "Error getting device charging state." , e );
323324 return null ;
324325 }
@@ -343,7 +344,7 @@ protected static String getKernelVersion() {
343344
344345 br = new BufferedReader (new FileReader (file ));
345346 return br .readLine ();
346- } catch (Exception e ) {
347+ } catch (IOException | RuntimeException e ) {
347348 Log .e (TAG , errorMsg , e );
348349 } finally {
349350 if (br != null ) {
@@ -392,7 +393,7 @@ protected static Boolean isRooted() {
392393 if (new File (probableRootPath ).exists ()) {
393394 return true ;
394395 }
395- } catch (Exception e ) {
396+ } catch (RuntimeException e ) {
396397 Log .e (TAG , "Exception while attempting to detect whether the device is rooted" , e );
397398 }
398399 }
@@ -417,7 +418,7 @@ protected static Long getUnusedInternalStorage() {
417418 long blockSize = stat .getBlockSize ();
418419 long availableBlocks = stat .getAvailableBlocks ();
419420 return availableBlocks * blockSize ;
420- } catch (Exception e ) {
421+ } catch (RuntimeException e ) {
421422 Log .e (TAG , "Error getting unused internal storage amount." , e );
422423 return null ;
423424 }
@@ -435,7 +436,7 @@ protected static Long getTotalInternalStorage() {
435436 long blockSize = stat .getBlockSize ();
436437 long totalBlocks = stat .getBlockCount ();
437438 return totalBlocks * blockSize ;
438- } catch (Exception e ) {
439+ } catch (RuntimeException e ) {
439440 Log .e (TAG , "Error getting total internal storage amount." , e );
440441 return null ;
441442 }
@@ -457,7 +458,7 @@ protected static Long getUnusedExternalStorage() {
457458 long availableBlocks = stat .getAvailableBlocks ();
458459 return availableBlocks * blockSize ;
459460 }
460- } catch (Exception e ) {
461+ } catch (RuntimeException e ) {
461462 Log .e (TAG , "Error getting unused external storage amount." , e );
462463 }
463464
@@ -480,7 +481,7 @@ protected static Long getTotalExternalStorage() {
480481 long totalBlocks = stat .getBlockCount ();
481482 return totalBlocks * blockSize ;
482483 }
483- } catch (Exception e ) {
484+ } catch (RuntimeException e ) {
484485 Log .e (TAG , "Error getting total external storage amount." , e );
485486 }
486487
@@ -496,7 +497,7 @@ protected static Long getTotalExternalStorage() {
496497 protected static DisplayMetrics getDisplayMetrics (Context ctx ) {
497498 try {
498499 return ctx .getResources ().getDisplayMetrics ();
499- } catch (Exception e ) {
500+ } catch (RuntimeException e ) {
500501 Log .e (TAG , "Error getting DisplayMetrics." , e );
501502 return null ;
502503 }
@@ -530,7 +531,7 @@ protected static String getApplicationName(Context ctx) {
530531 } else {
531532 return ctx .getString (stringId );
532533 }
533- } catch (Exception e ) {
534+ } catch (RuntimeException e ) {
534535 Log .e (TAG , "Error getting application name." , e );
535536 }
536537
0 commit comments