3636public class DeviceUtil {
3737
3838 private static String uniqueId ;
39+
3940 public static String getUUID () {
4041 if (!TextUtils .isEmpty (uniqueId )) {
4142 return uniqueId ;
@@ -289,8 +290,6 @@ public static String getMobileNum(Context context) {
289290
290291 /**
291292 * 返回内置sd卡路径,带后置分隔符 要获取下载目录, 请使用DownloadConfig.getDownloadPath
292- *
293- * @return
294293 */
295294 public static String getSDCardDir () {
296295 String sdcardPath = Environment .getExternalStorageDirectory ().getPath ();
@@ -308,8 +307,6 @@ public static String getSDCardDir() {
308307
309308 /**
310309 * 返回内置sd卡路径,带后置分隔符 要获取下载目录, 请使用DownloadConfig.getDownloadPath
311- *
312- * @return
313310 */
314311 public static String getPrimarySDCard () {
315312 // return Environment.getExternalStorageDirectory().getPath();
@@ -322,8 +319,6 @@ public static String getPrimarySDCard() {
322319
323320 /**
324321 * 返回外置sd卡路径,带后置分隔符 返回除内置存储器外, 可用空间最大的存储器
325- *
326- * @return
327322 */
328323 private static String sSlaveSDCard = null ;
329324
@@ -338,13 +333,13 @@ public static String getSlaveSDCard() {
338333
339334 ArrayList <String > storageArrayList = getMountedDevicesList ();
340335
341- /*
336+ /*
342337 * ----------------------------------------------------------------------
343- * ------- 特殊情况: 有些手机加载SD卡比较特殊,在设备列表中找不到该路径,这里山寨一点,加入一些
344- * 常用的外置SD路径,如果设别列表路径没有,则从里面猜一个
345- * ------------------------------------------
346- * -----------------------------------
347- */
338+ * ------- 特殊情况: 有些手机加载SD卡比较特殊,在设备列表中找不到该路径,这里山寨一点,加入一些
339+ * 常用的外置SD路径,如果设别列表路径没有,则从里面猜一个
340+ * ------------------------------------------
341+ * -----------------------------------
342+ */
348343 storageArrayList .add ("/mnt/external1" );
349344 //
350345 // ... 如有需要后续这里可以再加其他路径
@@ -363,7 +358,7 @@ public static String getSlaveSDCard() {
363358 }
364359
365360 // 过来不存在的路径
366- if (FileUtil .isDirExist (storagePath ) == false ) {
361+ if (! FileUtil .isDirExist (storagePath )) {
367362 continue ;
368363 }
369364
@@ -414,7 +409,7 @@ public static ArrayList<String> getMountedDevicesList() {
414409 // final int INDEX_PARTITION = 3;
415410 final int INDEX_SYSFS_PATH = 4 ;
416411
417- ArrayList <String > volumnPathList = new ArrayList <String >();
412+ ArrayList <String > volumnPathList = new ArrayList <>();
418413 if (VOLD_FSTAB .exists () == false ) {
419414 return volumnPathList ;
420415 }
@@ -433,6 +428,7 @@ public static ArrayList<String> getMountedDevicesList() {
433428 reader .close ();
434429 mountCmdLines .trimToSize ();
435430 } catch (IOException e ) {
431+ LogUtil .printError (e );
436432 }
437433
438434 for (final String mountCmdLine : mountCmdLines ) {
@@ -441,7 +437,7 @@ public static ArrayList<String> getMountedDevicesList() {
441437 }
442438
443439 String [] infos = mountCmdLine .split (" " );
444- if (infos == null || infos .length < INDEX_SYSFS_PATH ) {
440+ if (infos .length < INDEX_SYSFS_PATH ) {
445441 continue ;
446442 }
447443
@@ -453,7 +449,6 @@ public static ArrayList<String> getMountedDevicesList() {
453449 if (!new File (path ).exists ()) {
454450 continue ;
455451 }
456-
457452 volumnPathList .add (path );
458453 }
459454
@@ -462,9 +457,6 @@ public static ArrayList<String> getMountedDevicesList() {
462457
463458 /**
464459 * 获取指定磁盘的可用空间
465- *
466- * @param storagePath
467- * @return
468460 */
469461 public static long getAvailableSizeOf (final String storagePath ) {
470462 StatFs stat = new StatFs (storagePath );
@@ -475,8 +467,6 @@ public static long getAvailableSizeOf(final String storagePath) {
475467
476468 /**
477469 * 获取扩展SD卡的总大小
478- *
479- * @return
480470 */
481471 public static long getTotalExtSdCardMemorySize () {
482472 String path = getSlaveSDCard ();
@@ -490,11 +480,8 @@ public static long getTotalExtSdCardMemorySize() {
490480
491481 /**
492482 * 获取扩展SD卡的空余大小
493- *
494- * @return
495483 */
496484 public static long getFreeExtSdCardMemorySize () {
497- // String path = getSlaveSDCard();
498485 String path = getSDCardDir ();
499486 if (path == null )
500487 return 0 ;
@@ -509,8 +496,6 @@ public static long getFreeExtSdCardMemorySize() {
509496
510497 /**
511498 * 获取SD卡的总大小
512- *
513- * @return
514499 */
515500 public static long getTotalExternalMemorySize () {
516501 String path = Environment .getExternalStorageDirectory ().getPath ();
@@ -522,8 +507,6 @@ public static long getTotalExternalMemorySize() {
522507
523508 /**
524509 * 获取SD卡的剩余大小(包括不可用部分)
525- *
526- * @return
527510 */
528511 public static long getAvailableExternalMemorySize () {
529512 String path = Environment .getExternalStorageDirectory ().getPath ();
@@ -535,8 +518,6 @@ public static long getAvailableExternalMemorySize() {
535518
536519 /**
537520 * 获取SD卡的剩余大小
538- *
539- * @return
540521 */
541522 public static long getFreeExternalMemorySize () {
542523 String path = Environment .getExternalStorageDirectory ().getPath ();
@@ -573,49 +554,29 @@ static public long getTotalInternalMemorySize() {
573554 */
574555 @ SuppressLint ("NewApi" )
575556 static public boolean isExternalStorageEmulated () {
576-
577- if (Build .VERSION .SDK_INT >= 11 ) {
578- boolean b = Environment .isExternalStorageEmulated (); // SDK版本号要高于11才能用
579- return b ;
580-
581- } else {
582- return false ;
583-
584- }
585-
557+ return Build .VERSION .SDK_INT >= 11 && Environment .isExternalStorageEmulated ();
586558 }
587559
588560 /**
589561 * 判断系统的内置SD卡是否可插拔
590562 */
591563 @ SuppressLint ("NewApi" )
592564 static public boolean isExternalStorageRemovable () {
593-
594- if (Build .VERSION .SDK_INT >= 11 ) {
595- boolean b = Environment .isExternalStorageRemovable (); // SDK版本号要高于11才能用
596- return b ;
597-
598- } else {
599- return false ;
600-
601- }
565+ return Build .VERSION .SDK_INT >= 11 && Environment .isExternalStorageRemovable (); // SDK版本号要高于11才能用
602566 }
603567
604568 /**
605569 * 获取序列号
606- *
607- * @return
608570 */
609571 public static String getSerialId (Context context ) {
610-
611572 String seria_num = null ;
612573 try {
613-
614574 Class <?> c = Class .forName ("android.os.SystemProperties" );
615575 Method m = c .getMethod ("get" , String .class );
616576 seria_num = (String ) m .invoke (c , "ro.serialno" );
617577
618578 } catch (Exception e ) {
579+ LogUtil .printError (e );
619580 }
620581 if (seria_num == null || seria_num .equals ("" )) {
621582 TelephonyManager tManager = (TelephonyManager ) context
@@ -670,8 +631,6 @@ public static String getCpuType() {
670631 * 通过读取"/proc/meminfo"系统内存信息文件获取,因为
671632 * 从API16开始才添加了从ActivityManager读取MemoryInfo.TotalMem 的方法,因此需要从文件读取 MemTotal:
672633 * 94096 kB MemFree: 1684 kB
673- *
674- * @return
675634 */
676635 public static long getTotalMemory () {
677636 String str1 = "/proc/meminfo" ;
@@ -714,8 +673,7 @@ public static long getTotalMemory() {
714673 * @return 总的内存大小
715674 */
716675 public static long getTotalMemorySize () {
717- long totalMemory = getTotalMemory ();
718- return totalMemory ;
676+ return getTotalMemory ();
719677 }
720678
721679 /**
@@ -728,15 +686,12 @@ public static long getHasMemorySize(Context context) {
728686 ActivityManager mActivityManager = (ActivityManager ) context
729687 .getSystemService (Context .ACTIVITY_SERVICE );
730688 mActivityManager .getMemoryInfo (memoryInfo );
731- long hasMemory = memoryInfo .availMem ;
732- return hasMemory ;
689+ return memoryInfo .availMem ;
733690 }
734691
735692
736693 /**
737694 * 获得CPU频率
738- *
739- * @return
740695 */
741696 public static String getCurCpuFreq () {
742697 String result = "N/A" ;
@@ -768,8 +723,6 @@ public static String getCurCpuFreq() {
768723 * 获取CPU最大频率(单位KHZ)
769724 * "/system/bin/cat" 命令行
770725 * "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的路径
771- *
772- * @return
773726 */
774727 public static long getMaxCpuFreq () {
775728 String result = null ;
@@ -798,8 +751,6 @@ public static long getMaxCpuFreq() {
798751
799752 /**
800753 * 获取cpu 内核数
801- *
802- * @return
803754 */
804755 public static int getCpuNum () {
805756 int cpuNum = 1 ;
@@ -827,14 +778,9 @@ public static boolean supportsOpenGLES2(final Context context) {
827778
828779 /**
829780 * 判断当前设备是否为魅族手机
830- *
831- * @return
832781 */
833782 public static boolean isMeizu () {
834783 Build build = new Build ();
835- if (build .BRAND .indexOf ("Meizu" ) != -1 ) {
836- return true ;
837- }
838- return false ;
784+ return build .BRAND .indexOf ("Meizu" ) != -1 ;
839785 }
840786}
0 commit comments