summaryrefslogtreecommitdiff
authorTing Li <ting.li@amlogic.com>2014-11-27 06:19:11 (GMT)
committer Ting Li <ting.li@amlogic.com>2014-11-27 06:46:08 (GMT)
commit4e23191172395ec022cbc3cff29fe6b6cee28659 (patch)
treefb78b63dddb70a35929ccaa574ea9886fa3f2143
parentaffb4c2445aeda98a638fc246c8be5de8673fd9a (diff)
downloadOTAUpgrade2-4e23191172395ec022cbc3cff29fe6b6cee28659.zip
OTAUpgrade2-4e23191172395ec022cbc3cff29fe6b6cee28659.tar.gz
OTAUpgrade2-4e23191172395ec022cbc3cff29fe6b6cee28659.tar.bz2
update backup&restore to data Partition because of selinux
Change-Id: Ia7f38ef32d6cea9a65d67db072788cdd4679a865
Diffstat
-rwxr-xr-xAndroidManifest.xml4
-rwxr-xr-xres/layout/install_ota.xml10
-rwxr-xr-xres/values-zh-rCN/strings.xml1
-rwxr-xr-xres/values/strings.xml1
-rwxr-xr-xsrc/com/droidlogic/otaupgrade/BackupActivity.java8
-rwxr-xr-xsrc/com/droidlogic/otaupgrade/InstallPackage.java12
-rwxr-xr-xsrc/com/droidlogic/otaupgrade/LoaderReceiver.java239
-rwxr-xr-xsrc/com/droidlogic/otaupgrade/PrefUtils.java329
8 files changed, 325 insertions, 279 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b21895e..c612f8d 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.droidlogic.otaupgrade"
android:versionCode="2"
- android:versionName="2.0201411131439" >
+ android:versionName="2.0201411271418" >
<uses-permission android:name="android.permission.BACKUP" />
<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />
@@ -78,4 +78,4 @@
</service>
</application>
-</manifest> \ No newline at end of file
+</manifest>
diff --git a/res/layout/install_ota.xml b/res/layout/install_ota.xml
index 421005e..9fa3625 100755
--- a/res/layout/install_ota.xml
+++ b/res/layout/install_ota.xml
@@ -22,6 +22,16 @@
android:layout_height="match_parent" >
<ProgressBar
+ android:id="@+id/prepare_progress"
+ style="?android:attr/progressBarStyleSmall"
+ android:layout_width="400dp"
+ android:visibility="gone"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="15dp" />
+
+ <ProgressBar
android:id="@+id/verify_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="400dp"
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index dd468f9..404de88 100755
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -33,6 +33,7 @@
<string name="install_ota_output_confirm">"升级过程请勿中断"</string>
<string name="install_ota_output_start">"开始更新您的系统,请确保升级过程中电量充足"</string>
<string name="install_ota_output_checking">"正在验证您的升级包"</string>
+ <string name="install_prepare">"正在准备升级环境,请耐心等待..."</string>
<string name="install_ota_output_check_ok">"升级包验证成功..."</string>
<string name="install_ota_output_check_error">"升级包验证失败,请检查您的升级包是否正确"</string>
<string name="install_ota_output_copying">"正在复制文件..."</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5f94e9a..ccfc786 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -33,6 +33,7 @@
<string name="install_ota_output_confirm">This Action Can Not Be Interrupted When You Are Updating, please backup you data.</string>
<string name="install_ota_output_start">"Start Update...Please Ensure that Equipment Power"</string>
<string name="install_ota_output_checking">Checking The Package...</string>
+ <string name="install_prepare">Preparing...waitting</string>
<string name="install_ota_output_check_ok">Package Verify Successfully...</string>
<string name="install_ota_output_check_error">Verifying Failed Lease Check Your Package.</string>
<string name="install_ota_output_copying">Copying...</string>
diff --git a/src/com/droidlogic/otaupgrade/BackupActivity.java b/src/com/droidlogic/otaupgrade/BackupActivity.java
index 90b6b01..d65b453 100755
--- a/src/com/droidlogic/otaupgrade/BackupActivity.java
+++ b/src/com/droidlogic/otaupgrade/BackupActivity.java
@@ -36,13 +36,13 @@ import java.io.File;
* @Version V1.0
*/
public class BackupActivity extends Activity {
- public static String BACKUP_FILE = "/storage/external_storage/sdcard1/BACKUP";
+ public static String BACKUP_FILE = "/data/data/com.droidlogic.otaupgrade/BACKUP";
public static final String SdcardDir = "/storage/external_storage/sdcard1/";
public static final int FUNCBACKUP = 1;
public static final int FUNCRESTORE = 2;
public static int func = 0;
- private static void getBackUpFileName() {
+ /*private static void getBackUpFileName() {
File devDir = new File(PrefUtils.DEV_PATH);
File[] devs = devDir.listFiles();
@@ -54,11 +54,11 @@ public class BackupActivity extends Activity {
break;
}
}
- }
+ }*/
@Override
protected void onCreate(Bundle icicle) {
- getBackUpFileName();
+ //getBackUpFileName();
super.onCreate(icicle);
boolean flag = false;
diff --git a/src/com/droidlogic/otaupgrade/InstallPackage.java b/src/com/droidlogic/otaupgrade/InstallPackage.java
index 9cd664f..225aa91 100755
--- a/src/com/droidlogic/otaupgrade/InstallPackage.java
+++ b/src/com/droidlogic/otaupgrade/InstallPackage.java
@@ -34,6 +34,7 @@ import java.io.File;
public class InstallPackage extends LinearLayout implements OtaUpgradeUtils.ProgressListener {
private ProgressBar mProgressBar;
+ private ProgressBar mPrepareBar;
private LinearLayout mOutputField;
private LayoutInflater mInflater;
private String mPackagePath;
@@ -61,6 +62,7 @@ public class InstallPackage extends LinearLayout implements OtaUpgradeUtils.Prog
super.onFinishInflate();
mProgressBar = (ProgressBar) findViewById(R.id.verify_progress);
mOutputField = (LinearLayout) findViewById(R.id.output_field);
+ mPrepareBar = (ProgressBar) findViewById(R.id.prepare_progress);
final TextView tv = (TextView) mInflater.inflate(R.layout.medium_text,
null);
@@ -82,15 +84,21 @@ public class InstallPackage extends LinearLayout implements OtaUpgradeUtils.Prog
if (mPref != null) {
mPref.write2File();
}
-
+ mDismiss.setEnabled(false);
+ TextView tv = (TextView) mInflater.inflate(R.layout.medium_text,
+ null);
+ tv.setText(R.string.install_prepare);
+ mOutputField.addView(tv);
+ mPrepareBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
+ PrefUtils.copyBKFile();
+ mPrepareBar.setVisibility(View.GONE);
mUpdateUtils.upgrade(new File(mPackagePath),
InstallPackage.this, mUpdateMode);
}
}).start();
- mDismiss.setEnabled(false);
}
});
}
diff --git a/src/com/droidlogic/otaupgrade/LoaderReceiver.java b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
index f19340b..a8e9622 100755
--- a/src/com/droidlogic/otaupgrade/LoaderReceiver.java
+++ b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
@@ -25,150 +25,139 @@ import com.amlogic.update.Backup;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
public class LoaderReceiver extends BroadcastReceiver {
- private static final String TAG = PrefUtils.TAG;
- public static final String UPDATE_GET_NEW_VERSION = "com.android.update.UPDATE_GET_NEW_VERSION";
- public static final String CHECKING_TASK_COMPLETED = "com.android.update.CHECKING_TASK_COMPLETED";
- public static final String RESTOREDATA = "com.android.amlogic.restoredata";
- public static final String BACKUPDATA = "com.android.amlogic.backupdata";
- public static String BACKUP_FILE = "/storage/external_storage/sdcard1/BACKUP";
- private PrefUtils mPref;
- private Context mContext;
-
- private static void getBackUpFileName() {
- File devDir = new File(PrefUtils.DEV_PATH);
- File[] devs = devDir.listFiles();
-
- for (File dev : devs) {
- if (dev.isDirectory() && dev.canWrite()) {
- BACKUP_FILE = dev.getAbsolutePath();
- BACKUP_FILE += "/BACKUP";
-
- break;
- }
- }
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- getBackUpFileName();
- mContext = context;
- mPref = new PrefUtils(mContext);
-
- if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) ||
- intent.getAction().equals(RESTOREDATA)) {
- mPref.setBoolean("Boot_Checked", true);
- afterReboot();
- } else if (intent.getAction().equals(BACKUPDATA)) {
- if (PrefUtils.DEBUG) {
- Log.d(TAG, "backup");
+ private static final String TAG = PrefUtils.TAG;
+ public static final String UPDATE_GET_NEW_VERSION = "com.android.update.UPDATE_GET_NEW_VERSION";
+ public static final String CHECKING_TASK_COMPLETED = "com.android.update.CHECKING_TASK_COMPLETED";
+ public static final String RESTOREDATA = "com.android.amlogic.restoredata";
+ public static final String BACKUPDATA = "com.android.amlogic.backupdata";
+ public static String BACKUP_FILE = "/data/data/com.droidlogic.otaupgrade/BACKUP";
+ public static String BACKUP_OLDFILE = "/storage/external_storage/sdcard1/BACKUP";
+ private PrefUtils mPref;
+ private Context mContext;
+
+ private static void getBackUpFileName() {
+ File devDir = new File ( PrefUtils.DEV_PATH );
+ File[] devs = devDir.listFiles();
+ for ( File dev : devs ) {
+ if ( dev.isDirectory() && dev.canWrite() ) {
+ BACKUP_OLDFILE = dev.getAbsolutePath();
+ BACKUP_OLDFILE += "/BACKUP";
+ break;
+ }
}
-
- backup();
}
- //Log.d(TAG,"getAction:"+intent.getAction());
- if ((ConnectivityManager.CONNECTIVITY_ACTION).equals(intent.getAction())) {
- NetworkInfo netInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO,
- null);
-
- if (PrefUtils.DEBUG) {
- Log.d(TAG,
- "BootCompleteFlag" +
- (mPref.getBooleanVal("Boot_Checked", false)) + "" +
- (netInfo != null) + "" +
- mPref.getBooleanVal(PrefUtils.PREF_AUTO_CHECK, false) +
- (netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED));
+ @Override
+ public void onReceive ( Context context, Intent intent ) {
+ getBackUpFileName();
+ mContext = context;
+ mPref = new PrefUtils ( mContext );
+ Log.d ( TAG, "action:" + intent.getAction() );
+ if ( intent.getAction().equals ( Intent.ACTION_BOOT_COMPLETED ) ||
+ intent.getAction().equals ( RESTOREDATA ) ) {
+ mPref.setBoolean ( "Boot_Checked", true );
+ afterReboot();
+ } else if ( intent.getAction().equals ( BACKUPDATA ) ) {
+ if ( PrefUtils.DEBUG ) {
+ Log.d ( TAG, "backup" );
+ }
+ backup();
}
-
- if (mPref.getBooleanVal("Boot_Checked", false) &&
- (netInfo != null) &&
- (netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED)) {
- mPref.setBoolean("Boot_Checked", false);
-
- if (mPref.getBooleanVal(PrefUtils.PREF_AUTO_CHECK, false)) {
- mContext.startService(new Intent(
- UpdateService.ACTION_AUTOCHECK));
-
- return;
- } else if (("true").equals(SystemProperties.getBoolean(
- "ro.product.update.autocheck", false))) {
- mPref.setBoolean(PrefUtils.PREF_AUTO_CHECK, true);
- mContext.startService(new Intent(
- UpdateService.ACTION_AUTOCHECK));
+ //Log.d(TAG,"getAction:"+intent.getAction());
+ if ( ( ConnectivityManager.CONNECTIVITY_ACTION ).equals ( intent.getAction() ) ) {
+ NetworkInfo netInfo = ( NetworkInfo ) intent.getExtra ( WifiManager.EXTRA_NETWORK_INFO,
+ null );
+ if ( PrefUtils.DEBUG ) {
+ Log.d ( TAG,
+ "BootCompleteFlag" +
+ ( mPref.getBooleanVal ( "Boot_Checked", false ) ) + "" +
+ ( netInfo != null ) + "" +
+ mPref.getBooleanVal ( PrefUtils.PREF_AUTO_CHECK, false ) +
+ ( netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED ) );
+ }
+ if ( mPref.getBooleanVal ( "Boot_Checked", false ) &&
+ ( netInfo != null ) &&
+ ( netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED ) ) {
+ mPref.setBoolean ( "Boot_Checked", false );
+ if ( mPref.getBooleanVal ( PrefUtils.PREF_AUTO_CHECK, false ) ) {
+ mContext.startService ( new Intent (
+ UpdateService.ACTION_AUTOCHECK ) );
+ return;
+ } else if ( ( "true" ).equals ( SystemProperties.getBoolean (
+ "ro.product.update.autocheck", false ) ) ) {
+ mPref.setBoolean ( PrefUtils.PREF_AUTO_CHECK, true );
+ mContext.startService ( new Intent (
+ UpdateService.ACTION_AUTOCHECK ) );
+ }
}
}
}
- }
- private void afterReboot() {
- final String[] args = { BACKUP_FILE, "restore", "-apk", "-system", "-all" };
- new Thread() {
+ private void afterReboot() {
+ final String[] args = { BACKUP_FILE, "restore", "-apk", "-system", "-all" };
+ new Thread() {
public void run() {
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- } finally {
- //boolean ismounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorage2State());
- File flagFile = new File(new File(BACKUP_FILE).getParentFile(),
- PrefUtils.FlagFile);
-
- //if (ismounted) {
- File bkfile = new File(BACKUP_FILE);
-
- if (flagFile.exists()) {
- try {
- String files = null;
- BufferedReader input = new BufferedReader(new FileReader(
- flagFile));
-
- while ((files = input.readLine()) != null) {
- File temp = new File(files);
-
- if (temp.exists()) {
- temp.delete();
- }
+ File backupFile = new File ( BACKUP_FILE );
+ if ( !backupFile.exists() ) {
+ try {
+ PrefUtils.copyFile ( BACKUP_OLDFILE, BACKUP_FILE );
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ new File ( BACKUP_OLDFILE ).delete();
+ }
+ //boolean ismounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorage2State());
+ File flagFile = new File ( new File ( BACKUP_FILE ).getParentFile(),
+ PrefUtils.FlagFile );
+ //if (ismounted) {
+ File bkfile = new File ( BACKUP_FILE );
+ if ( flagFile.exists() ) {
+ try {
+ String files = null;
+ BufferedReader input = new BufferedReader ( new FileReader (
+ flagFile ) );
+ while ( ( files = input.readLine() ) != null ) {
+ File temp = new File ( files );
+ if ( temp.exists() ) {
+ temp.delete();
}
-
- flagFile.delete();
- } catch (IOException ex) {
}
+ flagFile.delete();
+ } catch ( IOException ex ) {
}
-
- if (bkfile.exists() &&
- !mPref.getBooleanVal(
- PrefUtils.PREF_START_RESTORE, false)) {
- mPref.setBoolean(PrefUtils.PREF_START_RESTORE, true);
-
- try {
- FileInputStream fis = new FileInputStream(bkfile);
-
- if (fis.available() <= 0) {
- bkfile.delete();
- } else {
- Backup mBackup = new Backup(mContext);
- mBackup.main(args);
- }
- } catch (Exception ex) {
+ }
+ if ( bkfile.exists() && !mPref.getBooleanVal ( PrefUtils.PREF_START_RESTORE, false ) ) {
+ mPref.setBoolean ( PrefUtils.PREF_START_RESTORE, true );
+ try {
+ FileInputStream fis = new FileInputStream ( bkfile );
+ if ( fis.available() <= 0 ) {
+ bkfile.delete();
+ } else {
+ Backup mBackup = new Backup ( mContext );
+ mBackup.main ( args );
}
- } else if (bkfile.exists()) {
- mPref.setBoolean(PrefUtils.PREF_START_RESTORE, false);
- bkfile.delete();
+ } catch ( Exception ex ) {
}
-
- // }
+ } else if ( bkfile.exists() ) {
+ mPref.setBoolean ( PrefUtils.PREF_START_RESTORE, false );
+ bkfile.delete();
}
}
- }.start();
- }
+ } .start();
+ }
- private void backup() {
- final String[] args = { BACKUP_FILE, "backup", "-apk", "-system", "-all" };
- Backup mBackup = new Backup(mContext);
- mBackup.main(args);
- }
+ private void backup() {
+ final String[] args = { BACKUP_FILE, "backup", "-apk", "-system", "-all" };
+ Backup mBackup = new Backup ( mContext );
+ mBackup.main ( args );
+ }
}
diff --git a/src/com/droidlogic/otaupgrade/PrefUtils.java b/src/com/droidlogic/otaupgrade/PrefUtils.java
index e1c3e2c..aea7be2 100755
--- a/src/com/droidlogic/otaupgrade/PrefUtils.java
+++ b/src/com/droidlogic/otaupgrade/PrefUtils.java
@@ -15,16 +15,22 @@ import android.content.SharedPreferences;
import android.os.Environment;
import android.os.SystemProperties;
-
+import android.util.Log;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.nio.channels.FileChannel;
/**
* @ClassName PrefUtils
@@ -35,173 +41,204 @@ import java.util.Set;
* @Version V1.0
*/
public class PrefUtils {
- public static Boolean DEBUG = false;
- public static final String TAG = "OTA";
- private static final String PREFS_DOWNLOAD_FILELIST = "download_filelist";
- private static final String PREFS_UPDATE_FILEPATH = "update_file_path";
- private static final String PREFS_UPDATE_SCRIPT = "update_with_script";
- private static final String PREFS_UPDATE_FILESIZE = "update_file_size";
- private static final String PREFS_UPDATE_DESC = "update_desc";
- public static final String DEV_PATH = "/storage/external_storage";
- public static final String PREF_START_RESTORE = "retore_start";
- public static final String PREF_AUTO_CHECK = "auto_check";
- static final String FlagFile = ".wipe_record";
- private Context mContext;
- private SharedPreferences mPrefs;
-
- PrefUtils(Context context) {
- mPrefs = context.getSharedPreferences("update", Context.MODE_PRIVATE);
- mContext = context;
- }
-
- private void setString(String key, String Str) {
- SharedPreferences.Editor mEditor = mPrefs.edit();
- mEditor.putString(key, Str);
- mEditor.commit();
- }
-
- private void setStringSet(String key, Set<String> downSet) {
- SharedPreferences.Editor mEditor = mPrefs.edit();
- mEditor.putStringSet(key, downSet);
- mEditor.commit();
- }
-
- private void setInt(String key, int Int) {
- SharedPreferences.Editor mEditor = mPrefs.edit();
- mEditor.putInt(key, Int);
- mEditor.commit();
- }
-
- public void setDescrib(String desc) {
- setString(PREFS_UPDATE_DESC, desc);
- }
-
- public String getDescri() {
- return mPrefs.getString(PREFS_UPDATE_DESC, "");
- }
-
- private void setLong(String key, long Long) {
- SharedPreferences.Editor mEditor = mPrefs.edit();
- mEditor.putLong(key, Long);
- mEditor.commit();
- }
-
- void setBoolean(String key, Boolean bool) {
- SharedPreferences.Editor mEditor = mPrefs.edit();
- mEditor.putBoolean(key, bool);
- mEditor.commit();
- }
-
- public void setScriptAsk(boolean bool) {
- setBoolean(PREFS_UPDATE_SCRIPT, bool);
- }
-
- public boolean getScriptAsk() {
- return mPrefs.getBoolean(PREFS_UPDATE_SCRIPT, false);
- }
-
- void setDownFileList(Set<String> downlist) {
- if (downlist.size() > 0) {
- setStringSet(PREFS_DOWNLOAD_FILELIST, downlist);
- }
- }
-
- Set<String> getDownFileSet() {
- return mPrefs.getStringSet(PREFS_DOWNLOAD_FILELIST, null);
- }
-
- boolean getBooleanVal(String key, boolean def) {
- return mPrefs.getBoolean(key, def);
- }
-
- public void setUpdatePath(String path) {
- setString(PREFS_UPDATE_FILEPATH, path);
- }
-
- public String getUpdatePath() {
- return mPrefs.getString(PREFS_UPDATE_FILEPATH, null);
- }
-
- public long getFileSize() {
- return mPrefs.getLong(PREFS_UPDATE_FILESIZE, 0);
- }
-
- public void saveFileSize(long fileSize) {
- setLong(PREFS_UPDATE_FILESIZE, fileSize);
- }
-
- static boolean isUserVer() {
- String userVer = SystemProperties.get("ro.secure", "");
- String userDebug = SystemProperties.get("ro.debuggable", "");
- String hideLocalUp = SystemProperties.get("ro.otaupdate.local", "");
-
- if ((hideLocalUp != null) && hideLocalUp.equals("1")) {
- if ((userVer != null) && (userVer.length() > 0)) {
- return (userVer.trim().equals("1")) && (userDebug.equals("0"));
- }
+ public static Boolean DEBUG = true;
+ public static final String TAG = "OTA";
+ private static final String PREFS_DOWNLOAD_FILELIST = "download_filelist";
+ private static final String PREFS_UPDATE_FILEPATH = "update_file_path";
+ private static final String PREFS_UPDATE_SCRIPT = "update_with_script";
+ private static final String PREFS_UPDATE_FILESIZE = "update_file_size";
+ private static final String PREFS_UPDATE_DESC = "update_desc";
+ public static final String DEV_PATH = "/storage/external_storage";
+ public static final String PREF_START_RESTORE = "retore_start";
+ public static final String PREF_AUTO_CHECK = "auto_check";
+ static final String FlagFile = ".wipe_record";
+ private Context mContext;
+ private SharedPreferences mPrefs;
+
+ PrefUtils ( Context context ) {
+ mPrefs = context.getSharedPreferences ( "update", Context.MODE_PRIVATE );
+ mContext = context;
}
- return false;
- }
+ private void setString ( String key, String Str ) {
+ SharedPreferences.Editor mEditor = mPrefs.edit();
+ mEditor.putString ( key, Str );
+ mEditor.commit();
+ }
+
+ private void setStringSet ( String key, Set<String> downSet ) {
+ SharedPreferences.Editor mEditor = mPrefs.edit();
+ mEditor.putStringSet ( key, downSet );
+ mEditor.commit();
+ }
- public static boolean getAutoCheck() {
- return ("true").equals(SystemProperties.get(
- "ro.product.update.autocheck"));
- }
+ private void setInt ( String key, int Int ) {
+ SharedPreferences.Editor mEditor = mPrefs.edit();
+ mEditor.putInt ( key, Int );
+ mEditor.commit();
+ }
- void write2File() {
- String flagParentPath = "/storage/external_storage/sdcard1/";
- File devDir = new File(DEV_PATH);
- File[] devs = devDir.listFiles();
+ public void setDescrib ( String desc ) {
+ setString ( PREFS_UPDATE_DESC, desc );
+ }
- for (File dev : devs) {
- if (dev.isDirectory() && dev.canWrite()) {
- flagParentPath = dev.getAbsolutePath();
- flagParentPath += "/";
+ public String getDescri() {
+ return mPrefs.getString ( PREFS_UPDATE_DESC, "" );
+ }
- break;
- }
+ private void setLong ( String key, long Long ) {
+ SharedPreferences.Editor mEditor = mPrefs.edit();
+ mEditor.putLong ( key, Long );
+ mEditor.commit();
}
- File flagFile = new File(flagParentPath, FlagFile);
+ void setBoolean ( String key, Boolean bool ) {
+ SharedPreferences.Editor mEditor = mPrefs.edit();
+ mEditor.putBoolean ( key, bool );
+ mEditor.commit();
+ }
- if (!flagFile.exists()) {
- try {
- flagFile.createNewFile();
- } catch (IOException excep) {
+ public void setScriptAsk ( boolean bool ) {
+ setBoolean ( PREFS_UPDATE_SCRIPT, bool );
+ }
+
+ public boolean getScriptAsk() {
+ return mPrefs.getBoolean ( PREFS_UPDATE_SCRIPT, false );
+ }
+
+ void setDownFileList ( Set<String> downlist ) {
+ if ( downlist.size() > 0 ) {
+ setStringSet ( PREFS_DOWNLOAD_FILELIST, downlist );
}
}
- if (!flagFile.canWrite()) {
- return;
+ Set<String> getDownFileSet() {
+ return mPrefs.getStringSet ( PREFS_DOWNLOAD_FILELIST, null );
}
- FileWriter fw = null;
+ boolean getBooleanVal ( String key, boolean def ) {
+ return mPrefs.getBoolean ( key, def );
+ }
- try {
- fw = new FileWriter(flagFile);
- } catch (IOException excep) {
+ public void setUpdatePath ( String path ) {
+ setString ( PREFS_UPDATE_FILEPATH, path );
}
- BufferedWriter output = new BufferedWriter(fw);
- Set<String> downfiles = mPrefs.getStringSet(PREFS_DOWNLOAD_FILELIST,
- null);
+ public String getUpdatePath() {
+ return mPrefs.getString ( PREFS_UPDATE_FILEPATH, null );
+ }
- if ((downfiles != null) && (downfiles.size() > 0)) {
- String[] downlist = downfiles.toArray(new String[0]);
+ public long getFileSize() {
+ return mPrefs.getLong ( PREFS_UPDATE_FILESIZE, 0 );
+ }
+
+ public void saveFileSize ( long fileSize ) {
+ setLong ( PREFS_UPDATE_FILESIZE, fileSize );
+ }
- for (int i = 0; i < downlist.length; i++) {
+ static boolean isUserVer() {
+ String userVer = SystemProperties.get ( "ro.secure", "" );
+ String userDebug = SystemProperties.get ( "ro.debuggable", "" );
+ String hideLocalUp = SystemProperties.get ( "ro.otaupdate.local", "" );
+ if ( ( hideLocalUp != null ) && hideLocalUp.equals ( "1" ) ) {
+ if ( ( userVer != null ) && ( userVer.length() > 0 ) ) {
+ return ( userVer.trim().equals ( "1" ) ) && ( userDebug.equals ( "0" ) );
+ }
+ }
+ return false;
+ }
+
+ public static boolean getAutoCheck() {
+ return ( "true" ).equals ( SystemProperties.get (
+ "ro.product.update.autocheck" ) );
+ }
+
+ void write2File() {
+ String flagParentPath = "/storage/external_storage/sdcard1/";
+ File devDir = new File ( DEV_PATH );
+ File[] devs = devDir.listFiles();
+ for ( File dev : devs ) {
+ if ( dev.isDirectory() && dev.canWrite() ) {
+ flagParentPath = dev.getAbsolutePath();
+ flagParentPath += "/";
+ break;
+ }
+ }
+ File flagFile = new File ( flagParentPath, FlagFile );
+ if ( !flagFile.exists() ) {
try {
- output.write(downlist[i]);
- output.newLine();
- } catch (IOException ex) {
+ flagFile.createNewFile();
+ } catch ( IOException excep ) {
+ }
+ }
+ if ( !flagFile.canWrite() ) {
+ return;
+ }
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter ( flagFile );
+ } catch ( IOException excep ) {
+ }
+ BufferedWriter output = new BufferedWriter ( fw );
+ Set<String> downfiles = mPrefs.getStringSet ( PREFS_DOWNLOAD_FILELIST,
+ null );
+ if ( ( downfiles != null ) && ( downfiles.size() > 0 ) ) {
+ String[] downlist = downfiles.toArray ( new String[0] );
+ for ( int i = 0; i < downlist.length; i++ ) {
+ try {
+ output.write ( downlist[i] );
+ output.newLine();
+ } catch ( IOException ex ) {
+ }
}
}
+ try {
+ output.close();
+ } catch ( IOException e ) {
+ }
}
- try {
- output.close();
- } catch (IOException e) {
+ public static void copyBKFile() {
+ String backupInrFile = "/data/data/com.droidlogic.otaupgrade/BACKUP";
+ String backupOutFile = "";
+ if ( new File ( backupInrFile ).exists() ) {
+ File devDir = new File ( PrefUtils.DEV_PATH );
+ File[] devs = devDir.listFiles();
+ for ( File dev : devs ) {
+ if ( dev.isDirectory() && dev.canWrite() ) {
+ backupOutFile = dev.getAbsolutePath();
+ backupOutFile += "/BACKUP";
+ break;
+ }
+ }
+ if ( !backupOutFile.equals ( "" ) ) {
+ try {
+ copyFile ( backupInrFile, backupOutFile );
+ } catch ( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
}
- }
+ public static void copyFile ( String fileFromPath, String fileToPath ) throws Exception {
+
+ FileInputStream fi = null;
+ FileOutputStream fo = null;
+ FileChannel in = null;
+ FileChannel out = null;
+
+ try {
+ fi = new FileInputStream ( new File ( fileFromPath ) );
+ in = fi.getChannel();
+ fo = new FileOutputStream ( new File ( fileToPath ) );
+ out = fo.getChannel();
+ in.transferTo ( 0, in.size(), out );
+ } finally {
+ fi.close();
+ fo.close();
+ in.close();
+ out.close();
+ }
+ }
+
}