android开发笔记之mtk平台 手机恢复出厂设置数据不删除的方法

      手机开发时,有时候,需要一个数据,在手机恢复出厂设置时,不删除,保持原来的值,这个如何处理呢?

       如果你是在mtk平台下(mtk6572),这有一个解决方案:


(1)mediatek/config/hongyu72_wet_jb3/init.project.rc

on fs
# for multi-logo (emmc)
chown system system /dev/logo
chown system system /dev/block/mmcblk0
chown system system /sys/class/BOOT/BOOT/boot/logo_mode
chmod 0644 /dev/logo
chmod 0664 /dev/block/mmcblk0
chmod 7777 /sys/class/BOOT/BOOT/boot/logo_mode


on post-fs-data


(2)数据读写api:

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

static String SALE_SAT_FILE = "/sys/class/BOOT/BOOT/boot/logo_mode";


	public boolean setSaleStatCompletedFlag() {
        try {
            BufferedReader in = new BufferedReader(new FileReader(SALE_SAT_FILE));
            String line = null;
            FileWriter fw = new FileWriter(SALE_SAT_FILE);
            fw.write("yes", 0, "yes".length());
            fw.flush();
            // rewrite check
            line = in.readLine();
            if (line == null || (line != null && !line.equals("yes"))) {
                fw.write("yes", 0, "yes".length());
                fw.flush();
            }
            fw.close();
            in.close();
        } catch (Exception e) {
			e.printStackTrace();        	
        }		

		return true;
	}

	private static int getsalesat() {
		// TODO Auto-generated method stub
		try {
			FileReader fr = new FileReader(SALE_SAT_FILE);
			BufferedReader br = new BufferedReader(fr);
			try {
				String line = br.readLine();
				if(line.equals("yes")){
					br.close();
					fr.close();
					return 1;
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				try {
					br.close();
					fr.close();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					return 0;
				}
				return 0;
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

		return 0;
	}
    
	public static boolean isSaleStatCompletedFlag() {
		if(getsalesat() == 1){
			Log.v("LIUJIANFANG", "isSaleStatCompletedFlag  yes");
			return true;
		}
		return false;		
	}



(3)其实,这个方法主要是参考settings模块,


packages/apps/settings/src/com/android/settings/testingSettingsBroadcastReceiver.java

   void writeBootLogo(final Context context, String mode) {
        try {
            BufferedReader in = new BufferedReader(new FileReader(
                    "sys/class/BOOT/BOOT/boot/logo_mode"));
            String line = null;
            FileWriter fw = new FileWriter("sys/class/BOOT/BOOT/boot/logo_mode");
            fw.write(mode, 0, mode.length());
            fw.flush();
            // rewrite check
            line = in.readLine();
            if (line == null || (line != null && !line.equals(mode))) {
                fw.write(mode, 0, mode.length());
                fw.flush();
            }
            fw.close();
            in.close();

            (new Handler()).postDelayed(new Runnable() {
                public void run() {
                    PowerManager pm = (PowerManager) context
                            .getSystemService("power");
                    pm.reboot(null);
                }
            }, 1000);
        } catch (Exception e) {
            Log.e("FactoryMode", "e---------->>" + e.getMessage());
        }
    }



你可能感兴趣的:(android,MTK,手机恢复出厂设置,数据不删除)