yy1717
2021-02-07 cea2a94fc97e79897cdfd217be8250c075974a1a
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.anyun.exam.lib;
 
import android.content.Context;
import android.os.Build;
import android.os.RecoverySystem;
import android.util.Log;
 
import java.io.File;
import java.io.IOException;
 
public class Ota {
    private final static String TAG = "OTA";
 
    static String dest = "/data/media/0/update.zip";
 
    public boolean excuteUpdateZip(Context context, String path) {
        boolean verifyPass = false;
        // TODO Auto-generated method stub
        try {
            File ota = new File(dest);
 
 
            Log.d(TAG, "path = " + ota.getCanonicalPath() + "  " + ota.exists());
 
            Log.d(TAG, "Product Model: " + Build.DISPLAY);
 
            try {
                RecoverySystem.verifyPackage(ota, recoveryVerifyListener, null);
                verifyPass = true;
                Log.d(TAG, "Verify OK");
            } catch (Exception e) {
                verifyPass = false;
                Log.d(TAG, "Zip Verify Fail!");
            }
 
            if (verifyPass) {
                RecoverySystem.installPackage(context, ota);
            }
 
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, "OTA 错误 " + e.getMessage());
        } finally {
            return verifyPass;
        }
    }
 
    RecoverySystem.ProgressListener recoveryVerifyListener = new RecoverySystem.ProgressListener() {
        public void onProgress(int progress) {
            Log.d(TAG, "verify progress" + progress);
//            final int progress1=progress;
//            showinfo("verify progress " + progress1+" %");
        }
    };
}