summaryrefslogtreecommitdiff
authorTing Li <ting.li@amlogic.com>2015-11-10 08:55:52 (GMT)
committer Ting Li <ting.li@amlogic.com>2015-11-10 09:00:03 (GMT)
commit0b5a387a4ee6adcf25ca283f30053cb45065bf65 (patch)
tree494b3aded87ce732e4168fd8c6988c174b6ccb54
parente5e00250a6a3c82f3955e3412a794cc2cd66b97a (diff)
downloadOTAUpgrade2-0b5a387a4ee6adcf25ca283f30053cb45065bf65.zip
OTAUpgrade2-0b5a387a4ee6adcf25ca283f30053cb45065bf65.tar.gz
OTAUpgrade2-0b5a387a4ee6adcf25ca283f30053cb45065bf65.tar.bz2
merge for m-amlogic
Change-Id: Id04ca22586c7716f39cc71f4faeea85d9346fcda
Diffstat
-rw-r--r--Android.mk26
-rw-r--r--[-rwxr-xr-x]src/com/droidlogic/otaupgrade/FileSelector.java43
-rw-r--r--[-rwxr-xr-x]src/com/droidlogic/otaupgrade/LoaderReceiver.java30
-rw-r--r--[-rwxr-xr-x]src/com/droidlogic/otaupgrade/MainActivity.java37
-rw-r--r--[-rwxr-xr-x]src/com/droidlogic/otaupgrade/PrefUtils.java67
5 files changed, 143 insertions, 60 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..cb588c2
--- a/dev/null
+++ b/Android.mk
@@ -0,0 +1,26 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_STATIC_JAVA_LIBRARIES := libota
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := OTAUpgrade
+LOCAL_CERTIFICATE := platform
+LOCAL_DEX_PREOPT := false
+LOCAL_PROGUARD_ENABLED := full
+LOCAL_PROGUARD_FLAGS := -include $(LOCAL_PATH)/proguard.flags
+
+include $(BUILD_PACKAGE)
+##############################################
+
+include $(CLEAR_VARS)
+LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libota:libs/libotaupdate.jar
+
+include $(BUILD_MULTI_PREBUILT)
+
+
+
+# Use the folloing include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/src/com/droidlogic/otaupgrade/FileSelector.java b/src/com/droidlogic/otaupgrade/FileSelector.java
index 48a8ff9..013caaf 100755..100644
--- a/src/com/droidlogic/otaupgrade/FileSelector.java
+++ b/src/com/droidlogic/otaupgrade/FileSelector.java
@@ -54,13 +54,11 @@ import java.util.ArrayList;
public class FileSelector extends Activity implements OnItemClickListener {
private static final String TAG = "FileSelector";
public static final String FILE = "file";
- private static final String LOCAL = "/sdcard";
- private static final String UDISK = "/storage/udisk";
- private static final String SDCARD = "/storage/sdcard";
private static final int MSG_HIDE_SHOW_DIALOG = 1;
private static final int MSG_SHOW_WAIT_DIALOG = 2;
private static final int MSG_NOTIFY_DATACHANGE = 3;
private static final int WAITDIALOG_DISPALY_TIME = 500;
+ private PrefUtils mPrefUtil;
private File mCurrentDirectory;
private LayoutInflater mInflater;
private FileAdapter mAdapter = new FileAdapter();
@@ -97,9 +95,7 @@ public class FileSelector extends Activity implements OnItemClickListener {
mHandler.sendMessageDelayed ( nmsg, WAITDIALOG_DISPALY_TIME );
new Thread() {
public void run() {
- File[] files = new File[2];
- files[0] = new File ( "/sdcard" );
- files[1] = new File ( "/storage" );
+ ArrayList<File> files = mPrefUtil.getExternalStorageList();
mAdapter.getList ( files );
mHandler.sendEmptyMessage ( MSG_HIDE_SHOW_DIALOG );
}
@@ -115,6 +111,7 @@ public class FileSelector extends Activity implements OnItemClickListener {
mListView.setAdapter ( mAdapter );
startScanThread();
mListView.setOnItemClickListener ( this );
+ mPrefUtil = new PrefUtils(this);
}
@Override
@@ -129,19 +126,6 @@ public class FileSelector extends Activity implements OnItemClickListener {
}
}
- public static boolean isUdisk ( String dir ) {
- if ( dir.startsWith ( UDISK ) && !dir.contains ( "sdcard" ) ) {
- return true;
- }
- return false;
- }
-
- public static boolean isSdcard ( String dir ) {
- if ( dir.startsWith ( SDCARD ) ) {
- return true;
- }
- return false;
- }
private class FileAdapter extends BaseAdapter {
private File[] mFiles;
@@ -159,6 +143,21 @@ public class FileSelector extends Activity implements OnItemClickListener {
}
}
+ public void getList ( ArrayList<File> dir ) {
+ if ( dir == null) {
+ return;
+ }
+ for (int i = 0; i < dir.size(); i++ ) {
+ File directory = dir.get(i);
+ setCurrentList ( directory );
+ }
+ mFiles = new File[files.size()];
+ for ( int i = 0; i < files.size(); i++ ) {
+ mFiles[i] = ( File ) files.get ( i );
+ }
+ mHandler.sendEmptyMessage ( MSG_NOTIFY_DATACHANGE );
+ }
+
public void getList ( File[] dir ) {
for ( int j = 0; j < dir.length; j++ ) {
setCurrentList ( dir[j] );
@@ -204,11 +203,7 @@ public class FileSelector extends Activity implements OnItemClickListener {
String dir = directory.getPath();
if ( new File ( directory, file ).isDirectory() ) {
return true;
- } else if ( file.toLowerCase().endsWith ( ".zip" ) && isSdcard ( dir ) &&
- !isUdisk ( dir ) ) {
- return true;
- } else if ( file.toLowerCase().endsWith ( ".zip" ) && isUdisk ( dir ) &&
- !isSdcard ( dir ) ) {
+ } else if ( file.toLowerCase().endsWith ( ".zip" )) {
return true;
} else {
return false;
diff --git a/src/com/droidlogic/otaupgrade/LoaderReceiver.java b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
index a8e9622..4c164aa 100755..100644
--- a/src/com/droidlogic/otaupgrade/LoaderReceiver.java
+++ b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
@@ -32,6 +32,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.util.ArrayList;
public class LoaderReceiver extends BroadcastReceiver {
private static final String TAG = PrefUtils.TAG;
@@ -44,11 +45,12 @@ public class LoaderReceiver extends BroadcastReceiver {
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() ) {
+ private void getBackUpFileName() {
+
+ ArrayList<File> devs = mPref.getExternalStorageList();
+ for ( int i = 0; (devs != null) && i < devs.size(); i++) {
+ File dev = devs.get(i);
+ if ( dev != null && dev.isDirectory() && dev.canWrite() ) {
BACKUP_OLDFILE = dev.getAbsolutePath();
BACKUP_OLDFILE += "/BACKUP";
break;
@@ -58,9 +60,10 @@ public class LoaderReceiver extends BroadcastReceiver {
@Override
public void onReceive ( Context context, Intent intent ) {
- getBackUpFileName();
+
mContext = context;
mPref = new PrefUtils ( mContext );
+ getBackUpFileName();
Log.d ( TAG, "action:" + intent.getAction() );
if ( intent.getAction().equals ( Intent.ACTION_BOOT_COMPLETED ) ||
intent.getAction().equals ( RESTOREDATA ) ) {
@@ -106,8 +109,9 @@ public class LoaderReceiver extends BroadcastReceiver {
final String[] args = { BACKUP_FILE, "restore", "-apk", "-system", "-all" };
new Thread() {
public void run() {
+ File outFile = new File(BACKUP_OLDFILE);
File backupFile = new File ( BACKUP_FILE );
- if ( !backupFile.exists() ) {
+ if ( outFile.exists() && !backupFile.exists() ) {
try {
PrefUtils.copyFile ( BACKUP_OLDFILE, BACKUP_FILE );
} catch ( Exception ex ) {
@@ -119,7 +123,7 @@ public class LoaderReceiver extends BroadcastReceiver {
File flagFile = new File ( new File ( BACKUP_FILE ).getParentFile(),
PrefUtils.FlagFile );
//if (ismounted) {
- File bkfile = new File ( BACKUP_FILE );
+ //File bkfile = new File ( BACKUP_FILE );
if ( flagFile.exists() ) {
try {
String files = null;
@@ -135,21 +139,21 @@ public class LoaderReceiver extends BroadcastReceiver {
} catch ( IOException ex ) {
}
}
- if ( bkfile.exists() && !mPref.getBooleanVal ( PrefUtils.PREF_START_RESTORE, false ) ) {
+ if ( backupFile.exists() && !mPref.getBooleanVal ( PrefUtils.PREF_START_RESTORE, false ) ) {
mPref.setBoolean ( PrefUtils.PREF_START_RESTORE, true );
try {
- FileInputStream fis = new FileInputStream ( bkfile );
+ FileInputStream fis = new FileInputStream ( backupFile );
if ( fis.available() <= 0 ) {
- bkfile.delete();
+ backupFile.delete();
} else {
Backup mBackup = new Backup ( mContext );
mBackup.main ( args );
}
} catch ( Exception ex ) {
}
- } else if ( bkfile.exists() ) {
+ } else if ( backupFile.exists() ) {
mPref.setBoolean ( PrefUtils.PREF_START_RESTORE, false );
- bkfile.delete();
+ backupFile.delete();
}
}
} .start();
diff --git a/src/com/droidlogic/otaupgrade/MainActivity.java b/src/com/droidlogic/otaupgrade/MainActivity.java
index bd43777..d15e452 100755..100644
--- a/src/com/droidlogic/otaupgrade/MainActivity.java
+++ b/src/com/droidlogic/otaupgrade/MainActivity.java
@@ -31,7 +31,7 @@ import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemProperties;
-
+import android.os.storage.DiskInfo;
import android.util.Log;
import android.view.LayoutInflater;
@@ -50,13 +50,11 @@ import android.widget.Toast;
import com.amlogic.update.OtaUpgradeUtils;
-import org.apache.http.util.EncodingUtils;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-
+import java.io.UnsupportedEncodingException;
import java.util.Locale;
@@ -360,13 +358,18 @@ public class MainActivity extends Activity implements OnClickListener {
res += "--update_package=";
- if (Environment.MEDIA_MOUNTED.equals(
- Environment.getExternalStorageState()) &&
- FileSelector.isSdcard(fullpath)) {
- res += "/sdcard/";
- } else if (FileSelector.isUdisk(fullpath)) {
- res += "/udisk/";
- } else {
+ DiskInfo info = mPreference.getDiskInfo(fullpath);
+ if ( info != null) {
+ if ( info.isSd() ) {
+ res += "/sdcard/";
+ }else if ( info.isUsb() ) {
+ res += "/udisk/";
+ }else {
+ res += "/cache/";
+ UpdateMode = OtaUpgradeUtils.UPDATE_UPDATE;
+ }
+ }else {
+ res += "/cache/";
UpdateMode = OtaUpgradeUtils.UPDATE_UPDATE;
}
@@ -389,6 +392,16 @@ public class MainActivity extends Activity implements OnClickListener {
return true;
}
+ public static String getString(final byte[] data, final String charset) {
+ if (data == null) {
+ throw new IllegalArgumentException("Parameter may not be null");
+ }
+ try {
+ return new String(data, 0, data.length, charset);
+ } catch (UnsupportedEncodingException e) {
+ return new String(data, 0, data.length);
+ }
+ }
public String getFromAssets(String fileName) {
String result = "";
@@ -397,7 +410,7 @@ public class MainActivity extends Activity implements OnClickListener {
int lenght = in.available();
byte[] buffer = new byte[lenght];
in.read(buffer);
- result = EncodingUtils.getString(buffer, ENCODING);
+ result = getString(buffer,"US-ASCII");
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/com/droidlogic/otaupgrade/PrefUtils.java b/src/com/droidlogic/otaupgrade/PrefUtils.java
index aea7be2..3de8df5 100755..100644
--- a/src/com/droidlogic/otaupgrade/PrefUtils.java
+++ b/src/com/droidlogic/otaupgrade/PrefUtils.java
@@ -23,9 +23,14 @@ import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import android.os.storage.VolumeInfo;
+import android.os.storage.DiskInfo;
+import android.os.storage.StorageManager;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.ArrayList;
+import java.util.Collections;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedInputStream;
@@ -153,17 +158,53 @@ public class PrefUtils {
"ro.product.update.autocheck" ) );
}
+ public ArrayList<File> getExternalStorageList(){
+ ArrayList<File> devList = new ArrayList<File>();
+ StorageManager mStorageManager = (StorageManager)mContext.getSystemService(Context.STORAGE_SERVICE);
+
+ List<VolumeInfo> mVolumes = mStorageManager.getVolumes();
+ Collections.sort(mVolumes, VolumeInfo.getDescriptionComparator());
+ for (VolumeInfo vol : mVolumes) {
+ if (vol != null && vol.isMountedReadable() && vol.getType() == VolumeInfo.TYPE_PUBLIC) {
+ devList.add(vol.getPath());
+ Log.d(TAG, "path.getName():" + vol.getPath().getAbsolutePath());
+ }
+ }
+ return devList;
+ }
+
+ public DiskInfo getDiskInfo(String filePath){
+ StorageManager mStorageManager = (StorageManager)mContext.getSystemService(Context.STORAGE_SERVICE);
+
+ List<VolumeInfo> mVolumes = mStorageManager.getVolumes();
+ Collections.sort(mVolumes, VolumeInfo.getDescriptionComparator());
+ for ( VolumeInfo vol : mVolumes ) {
+ if ( vol != null && vol.isMountedReadable() ) {
+ DiskInfo info = vol.getDisk();
+ if ( info != null && filePath.contains(vol.getPath().getAbsolutePath()) ) {
+ return info;
+ }
+ Log.d(TAG, "path.getName():" + vol.getPath().getAbsolutePath());
+ }
+ }
+ return null;
+ }
+
+
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();
+ ArrayList<File> externalDevs = getExternalStorageList();
+ String flagParentPath = null;
+ for ( int j = 0; (externalDevs != null) && j < externalDevs.size(); j++ ) {
+ File dir = externalDevs.get(j);
+ if ( dir.isDirectory() && dir.canWrite() ) {
+ flagParentPath = dir.getAbsolutePath();
flagParentPath += "/";
break;
}
}
+ if ( flagParentPath == null ) {
+ return;
+ }
File flagFile = new File ( flagParentPath, FlagFile );
if ( !flagFile.exists() ) {
try {
@@ -174,6 +215,7 @@ public class PrefUtils {
if ( !flagFile.canWrite() ) {
return;
}
+
FileWriter fw = null;
try {
fw = new FileWriter ( flagFile );
@@ -226,7 +268,7 @@ public class PrefUtils {
FileOutputStream fo = null;
FileChannel in = null;
FileChannel out = null;
-
+ Log.d(TAG,"copyFile from "+fileFromPath+" to "+fileToPath);
try {
fi = new FileInputStream ( new File ( fileFromPath ) );
in = fi.getChannel();
@@ -234,10 +276,13 @@ public class PrefUtils {
out = fo.getChannel();
in.transferTo ( 0, in.size(), out );
} finally {
- fi.close();
- fo.close();
- in.close();
- out.close();
+ try{
+ fi.close();
+ fo.close();
+ in.close();
+ out.close();
+ }catch(Exception ex){
+ }
}
}