
package com.tcl.factory.view;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import android.util.Log;

import com.tcl.factory.thirdparty.ThirdParty;

public class DModeEmmcInfo extends SubMenu
{
	private  String EmmcRivison = "";
	private  String EXT_CSD_163 = "";
	private  String EXT_CSD_268 = "";
	private boolean EmmcInfoReaded = false;
	
	public static  String MenuInfos_DModeEmmcInfo[][]={
		{"Revision",""},
		{"REG[163]",""},
		{"REG[268]",""},

	};	
	public DModeEmmcInfo()
	{	
		super.menuInfos=MenuInfos_DModeEmmcInfo;
		super.menuLabel = "Main menu\\Server\\RegInfo";
		super.setTAG();
		getEmmcInfomations();
		updateMenuInfos();
	}
	
	/* (non-Javadoc)
	 * Factory
	 */
	@Override
	public void updateMenuInfos() {
		// TODO Auto-generated method stub
		if(EmmcInfoReaded == true){
			menuInfos[0][1] = EmmcRivison;			
		}
		if(Integer.parseInt(EmmcRivison) >= 7)
		{
			menuInfos[1][1] = EXT_CSD_163;
			menuInfos[2][1] = EXT_CSD_268;
		}
		else 
		{
			menuInfos[1][1] = "";
			menuInfos[2][1] = "";
		}
	}

	@Override
	public void KeyEvent(int keyCode, int pos) {
		// TODO Auto-generated method stub
		
	}
	
	public void getEmmcInfomations(){
		ThirdParty.setRootSeek("cat /sys/kernel/debug/mmc0/mmc0:0001/ext_csd > /tmp/fac-EMMC.txt");
		ThirdParty.setRootSeek("chmod 777 /tmp/fac-EMMC.txt");
		File emmc_info_file = new File("/tmp/","fac-EMMC.txt");
		try{
			FileReader fr = new FileReader(emmc_info_file);
			BufferedReader br = new BufferedReader(fr);
			int value[] = new int[3];
			if(br.skip(326)>0){
				value[0] = br.read();
				value[1] = br.read();
				value[2] = '\0';
				Log.d(TAG,"-"+value[0]+value[1]+value[2]);
				EXT_CSD_163 = "" + (char)value[0] + (char)value[1] + (char)value[2];
			}
			else{
				br.close();
				fr.close();				
				return;
			}// 328/2 = 164
			if(br.skip(56)>0){
				value[0] = br.read();
				value[1] = br.read();
				value[2] = '\0';
				Log.d(TAG,"--"+value[0]+value[1]);
				EmmcRivison = "" + (char)value[0] + (char)value[1];					
			}
			else{
				br.close();
				fr.close();
				return;				
			}// 386/2 = 193
			if(br.skip(150)>0){
				value[0] = br.read();
				value[1] = br.read();
				value[2] = '\0';
				Log.d(TAG,"---"+value[0]+value[1]+value[2]);
				EXT_CSD_268 = "" + (char)value[0] + (char)value[1] + (char)value[2];	
			}
			else{
				br.close();
				fr.close();
				return;
			}
			br.close();
			fr.close();
			EmmcInfoReaded = true;			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}

}

