Android Open Source - misound Firmware Zip File






From Project

Back to project page misound.

License

The source code is released under:

Apache License

If you think the Android project misound listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.xiaomi.mitv.soundbarapp.upgrade;
/*from   ww  w  . j  a va  2 s  .  c  om*/
import android.content.Context;
import android.util.Base64;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Created by chenxuetong on 6/25/14.
 */
public class FirmwareZipFile {
    private static final String ZIP_DUF_NAME = "firmware.dfu";
    private static final String ZIP_MANIFEST = "Manifest";
    private static final int BUFFER_SIZE = 1024;

    private final File mZipFile;
    private String mDufFile;

    public FirmwareZipFile(File file){
        mZipFile = file;
    }

    public boolean unzip(Context context) {
        try {
            ZipFile zipFile = new ZipFile(mZipFile);
            ZipEntry dfu = zipFile.getEntry(ZIP_DUF_NAME);
            if(dfu != null){
                String dfuFile =  dfu.getName()+dfu.getTime();
                context.deleteFile(dfuFile);

                MessageDigest digester = null;
                try {
                    MessageDigest.getInstance("MD5");
                } catch (NoSuchAlgorithmException e) {e.printStackTrace();}

                byte[] buffer = new byte[BUFFER_SIZE];
                FileOutputStream out = context.openFileOutput(dfuFile, Context.MODE_PRIVATE);
                BufferedOutputStream bos = new BufferedOutputStream(out, BUFFER_SIZE);
                BufferedInputStream bio = new BufferedInputStream(zipFile.getInputStream(dfu));
                int read = 0;
                while((read=bio.read(buffer, 0, BUFFER_SIZE))!=-1) {
                    bos.write(buffer, 0, read);
                    //md5
                    if(digester!=null){
                        digester.update(buffer, 0, read);
                    }
                }
                bos.flush();
                bos.close();

                //check md5
                if(digester != null) {
//                    byte[] md5 = digester.digest();
//                    Properties manifest = unzipManifest(zipFile, ZIP_MANIFEST);
//                    if(!Base64.encode(md5, Base64.DEFAULT).equalsIgnoreCase(manifest.getProperty("md5"))){
//                        return false;
//                    }
                }
                mDufFile = dfuFile;
            }
        } catch (IOException e) {
            //ignore, it is not a zip file
        }
        return  true;
    }

    public String getDfuFile() {
        return mDufFile;
    }

    Properties unzipManifest(ZipFile zipFile, String name){
        Properties manifest =  new Properties() ;
        ZipEntry entry = zipFile.getEntry(ZIP_MANIFEST);
        if(entry != null) {
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                BufferedInputStream bio = new BufferedInputStream(zipFile.getInputStream(entry));
                byte[] buffer = new byte[BUFFER_SIZE];
                int read = 0;
                while((read=bio.read(buffer)) != -1){
                    out.write(buffer, 0 ,read);
                }
                out.flush();
                JSONObject json = new JSONObject(out.toString("utf-8"));
                manifest.setProperty("build", json.getString("build"));
                manifest.setProperty("hardware", json.getString("hardware"));
                manifest.setProperty("md5", json.getString("md5"));
                manifest.setProperty("version_code", json.getString("version_code"));
                manifest.setProperty("version_name", json.getString("version_name"));
            }catch (IOException e){
                e.printStackTrace();
            }catch (JSONException e) { e.printStackTrace(); }
        }

        return manifest;
    }
}




Java Source Code List

com.xiaomi.mitv.soundbar.DefaultMisoundDevice.java
com.xiaomi.mitv.soundbarapp.BarInfoUtils.java
com.xiaomi.mitv.soundbarapp.ConnectingActivity.java
com.xiaomi.mitv.soundbarapp.MainActivity2.java
com.xiaomi.mitv.soundbarapp.SoundBarApplication.java
com.xiaomi.mitv.soundbarapp.TestActivity.java
com.xiaomi.mitv.soundbarapp.TypefaceManager.java
com.xiaomi.mitv.soundbarapp.WrapperActivity.java
com.xiaomi.mitv.soundbarapp.diagnosis.DiagnosisFragment.java
com.xiaomi.mitv.soundbarapp.diagnosis.Engine.java
com.xiaomi.mitv.soundbarapp.diagnosis.ViewWrapper.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Entry.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Node.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.OrderedList.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.QAElement.java
com.xiaomi.mitv.soundbarapp.eq.EQManager.java
com.xiaomi.mitv.soundbarapp.eq.EQSettingsFragment.java
com.xiaomi.mitv.soundbarapp.eq.EQStyleResource.java
com.xiaomi.mitv.soundbarapp.eq.EQStyle.java
com.xiaomi.mitv.soundbarapp.eq.UserEQControlFragment.java
com.xiaomi.mitv.soundbarapp.faq.FaqDataStore.java
com.xiaomi.mitv.soundbarapp.faq.FaqFragment.java
com.xiaomi.mitv.soundbarapp.fragment.A2dpDlg.java
com.xiaomi.mitv.soundbarapp.fragment.BaseFragment.java
com.xiaomi.mitv.soundbarapp.fragment.FeedbackFragment.java
com.xiaomi.mitv.soundbarapp.fragment.MainEntryFragment.java
com.xiaomi.mitv.soundbarapp.fragment.PanelFragment.java
com.xiaomi.mitv.soundbarapp.fragment.SettingsFragment.java
com.xiaomi.mitv.soundbarapp.player.MediaButtonIntentReceiver.java
com.xiaomi.mitv.soundbarapp.player.MusicUtils.java
com.xiaomi.mitv.soundbarapp.player.PlayListFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerService.java
com.xiaomi.mitv.soundbarapp.player.Player.java
com.xiaomi.mitv.soundbarapp.provider.DataProvider.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareManager.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareZipFile.java
com.xiaomi.mitv.soundbarapp.upgrade.UpdateActivity.java
com.xiaomi.mitv.soundbarapp.upgrade.UpgradeFragment.java
com.xiaomi.mitv.soundbarapp.upgrade.VersionSelectFragment.java
com.xiaomi.mitv.soundbarapp.util.ConfirmActivityDlg.java
com.xiaomi.mitv.soundbarapp.util.Worker.java
com.xiaomi.mitv.widget.GainView.java
com.xiaomi.mitv.widget.GifView.java
com.xiaomi.mitv.widget.LetterIndexSilderBar.java
com.xiaomi.mitv.widget.MiSwitch.java
com.xiaomi.mitv.widget.RoundAnimationView.java
com.xiaomi.mitv.widget.RoundProgressBar.java
com.xiaomi.mitv.widget.RoundSeekBar.java