RK Android 7.1 emmc 存储总大小

一.adb 命令

cat /proc/partitions
mmcblk1 mmcblk2

 二.Andoird 7.1.1  以上查询

7.1.1 版本之后才有  getPrimaryStorageSize()

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

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

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

cat /sys/block/mmcblk2/size
14942208

b.   cat /proc/partitions  

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

    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

    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  添加元素

    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 @ 2021-04-30 11:28  CrushGirl  阅读(1346)  评论(0编辑  收藏  举报