RK Android 7.1 emmc 存储总大小

一.adb 命令

1
2
cat /proc/partitions
mmcblk1 mmcblk2

 二.Andoird 7.1.1  以上查询

7.1.1 版本之后才有  getPrimaryStorageSize()

2.1. packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import android.os.storage.StorageManager;
import android.text.format.Formatter;
public class DeviceInfoSettings extends SettingsPreferenceFragment implements Indexable {
    private static final String LOG_TAG = "DeviceInfoSettings";
@@ -96,6 +99,9 @@
     
    private static DecimalFormat fileIntegerFormat = new DecimalFormat("#0");
    private static DecimalFormat fileDecimalFormat = new DecimalFormat("#0.#");
     
    private static StorageManager mStorageManager = null;
    private static long sTotalInternalStorage;
    public static String formatFileSize(long size, boolean isInteger) {
        DecimalFormat df = isInteger ? fileIntegerFormat : fileDecimalFormat;
@@ -203,6 +209,8 @@
        mUm = UserManager.get(getActivity());
        addPreferencesFromResource(R.xml.device_info_settings);
         
        mStorageManager = (StorageManager) getActivity().getSystemService(StorageManager.class);
        setStringSummary(KEY_FIRMWARE_VERSION, Build.VERSION.RELEASE);
        findPreference(KEY_FIRMWARE_VERSION).setEnabled(true);
@@ -224,7 +232,11 @@
        findPreference(KEY_SCREEN_FPS).setSummary(GetScreenFps());
         
            String emmcString=formatFileSize(getEmmc_total(), true);
        if (sTotalInternalStorage <= 0) {
            sTotalInternalStorage = mStorageManager.getPrimaryStorageSize() / 1024 / 1024 /1024;         
        }
         
            String emmcString=String.valueOf(sTotalInternalStorage);//formatFileSize(getEmmc_total(), true);
             
            int size=Integer.valueOf(emmcString);
            if(size<8)

2.2.eclipse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.lang.reflect.Method;
import android.content.Context;
import android.os.storage.StorageManager;
 
    // rk3399
    private static StorageManager mStorageManager = null;
    private static long sTotalInternalStorage;
    private Context mContext;
    private static long totalSize = 0L;
     
     
 
    // android7.1 RK391
    public DeviceInfo(Context mContext) {
        super();
        this.mContext = mContext;
        mStorageManager = (StorageManager) mContext.getSystemService(StorageManager.class);
        if (sTotalInternalStorage <= 0) {
            Log.d("gatsby", "sTotalInternalStorage<=0");
            try {
                Method getPrimaryStorageSize = StorageManager.class.getMethod("getPrimaryStorageSize");
                totalSize = (long) getPrimaryStorageSize.invoke(mStorageManager) / 1024 / 1024 / 1024;
                Log.d("gatsby", "totalSize->" + totalSize);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
 
        }
    }
 
        String emmcString;
        if (product.contains(R391)) {
            emmcString = String.valueOf(totalSize);
            Log.d("gatsby", "emmcString->" + emmcString);
        }

2.3.adb

 a.  cat /sys/block/mmcblk2/size

1
2
cat /sys/block/mmcblk2/size
14942208

b.   cat /proc/partitions  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cat /proc/partitions
major minor  #blocks  name
 
   1        0       8192 ram0
   1        1       8192 ram1
   1        2       8192 ram2
   1        3       8192 ram3
   1        4       8192 ram4
   1        5       8192 ram5
   1        6       8192 ram6
   1        7       8192 ram7
   1        8       8192 ram8
   1        9       8192 ram9
   1       10       8192 ram10
   1       11       8192 ram11
   1       12       8192 ram12
   1       13       8192 ram13
   1       14       8192 ram14
   1       15       8192 ram15
 254        0     520912 zram0
 179        0    7471104 mmcblk2
 179        1       4096 mmcblk2p1
 179        2       4096 mmcblk2p2
 179        3       4096 mmcblk2p3
 179        4      16384 mmcblk2p4
 179        5      24576 mmcblk2p5
 179        6      32768 mmcblk2p6
 179        7      32768 mmcblk2p7
 179        8     114688 mmcblk2p8
 179        9     131072 mmcblk2p9
 179       10    2097152 mmcblk2p10
 179       11      16384 mmcblk2p11
 179       12      51200 mmcblk2p12
 179       13      51200 mmcblk2p13
 179       14       8192 mmcblk2p14
 179       15    4872192 mmcblk2p15
 179       96       4096 mmcblk2rpmb
 179       64       4096 mmcblk2boot1
 179       32       4096 mmcblk2boot0

仨.RK3288 Android7.1 StorageManager 获取EMMC 显示不对

frameworks\base\core\java\android\os\storage\StorageManager.java 

3.1.计算emmc  

a.eMMC_ID

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private int  probeEmmc()
{
    for(int i=0;i<2;i++)
    {
            String path=String.format("/sys/block/mmcblk%drpmb", i);
            if(new File(path).exists())
            {
                    Slog.d(TAG,"probeEmmc find "+path);
                    return i;
            }
    }
    return -1;
}
 
public StorageManager(Context context, Looper looper) {
    mContext = context;
    mResolver = context.getContentResolver();
    mLooper = looper;
    mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
    if (mMountService == null) {
        throw new IllegalStateException("Failed to find running mount service");
    }
    eMMC_ID=probeEmmc();
}  

b.当eMMC_ID 获取为-1  INTERNAL_STORAGE_SIZE_PATHS 数组元素都被注释掉了   只能返回 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
private static final String[] INTERNAL_STORAGE_SIZE_PATHS = {
        //"/sys/block/mmcblk0/size",
        //"/sys/block/sda/size"
}
 
private static final int INTERNAL_STORAGE_SECTOR_SIZE = 512;
 
/** {@hide} */
public long getPrimaryStorageSize() {
    if(-1 != eMMC_ID ){
        String path=String.format("/sys/block/mmcblk%d/size",eMMC_ID);
        final long numberBlocks = readLong(path);
        if (numberBlocks > 0) {
            return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
        }
    }
    else{
        for (String path : INTERNAL_STORAGE_SIZE_PATHS) {
            final long numberBlocks = readLong(path);
            if (numberBlocks > 0) {
                return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
            }
        }
    }
    return 0;
}
 
private long readLong(String path) {
    try (final FileInputStream fis = new FileInputStream(path);
            final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
        return Long.parseLong(reader.readLine());
    } catch (Exception e) {
        Slog.w(TAG, "Could not read " + path, e);
        return 0;
    }
}

 c.主存储块的位置因设备而异 为INTERNAL_STORAGE_SIZE_PATHS  添加元素

1
2
3
4
5
6
private static final String[] INTERNAL_STORAGE_SIZE_PATHS = {
        "/sys/block/mmcblk0/size",
        "/sys/block/mmcblk1/size",
        "/sys/block/mmcblk2/size"
        //"/sys/block/sda/size"
};

  

 

posted @   CrushGirl  阅读(1383)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示