summaryrefslogtreecommitdiff
authorTing Li <ting.li@amlogic.com>2016-05-09 05:30:32 (GMT)
committer Ting Li <ting.li@amlogic.com>2016-05-09 05:30:32 (GMT)
commit99b5b999ccb41c0ca70391f053ca73d4dc721ab6 (patch)
treef67694dbe87ce9ebfcd282b5f0349d148b64c2cb
parent5d2b27c2e1fdc35225a476dae07317ed0e644c28 (diff)
downloadOTAUpgrade2-99b5b999ccb41c0ca70391f053ca73d4dc721ab6.zip
OTAUpgrade2-99b5b999ccb41c0ca70391f053ca73d4dc721ab6.tar.gz
OTAUpgrade2-99b5b999ccb41c0ca70391f053ca73d4dc721ab6.tar.bz2
update hide api use reflect
Change-Id: I1981dd49ddbce33d1fe2eaa448126832e8d42ab0
Diffstat
-rw-r--r--Android.mk2
-rw-r--r--res/values-zh-rCN/strings.xml2
-rw-r--r--res/values/strings.xml1
-rw-r--r--src/com/droidlogic/otaupgrade/LoaderReceiver.java12
-rw-r--r--src/com/droidlogic/otaupgrade/MainActivity.java2
-rw-r--r--src/com/droidlogic/otaupgrade/PrefUtils.java172
-rw-r--r--src/com/droidlogic/otaupgrade/UpdateService.java17
7 files changed, 141 insertions, 67 deletions
diff --git a/Android.mk b/Android.mk
index cb588c2..17a96d5 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,7 +3,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := libota
-
+LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := OTAUpgrade
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index b51e131..9c569df 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -100,6 +100,8 @@
<string name="scan_tip">扫描中,请等待...</string>
<string name="backup_result">备份完成</string>
<string name="restore_result">备份已经恢复</string>
+ <string name="noti_msg">"下载成功"</string>
+
<string name="remove_hit">"保证外设连接正常,否则备份转存失败"</string>
<string name="prepare_waitting">"数据准备中,确认您的外设中有备份文件"</string>
</resources> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0e6927c..9d19a01 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -100,5 +100,6 @@
<string name="backup_result">backup finish</string>
<string name="restore_result">restore finish</string>
<string name="remove_hit">backup will save to external storage if exists or backup save fail</string>
+ <string name="noti_msg">Download success</string>
<string name="prepare_waitting">"prepare,make sure BACKUP file in your external storage"</string>
</resources> \ No newline at end of file
diff --git a/src/com/droidlogic/otaupgrade/LoaderReceiver.java b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
index 835b789..a1f5459 100644
--- a/src/com/droidlogic/otaupgrade/LoaderReceiver.java
+++ b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
@@ -14,10 +14,8 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
-
+import android.os.Bundle;
import android.os.Environment;
-import android.os.SystemProperties;
-
import android.util.Log;
import com.amlogic.update.Backup;
@@ -77,8 +75,8 @@ public class LoaderReceiver extends BroadcastReceiver {
}
//Log.d(TAG,"getAction:"+intent.getAction());
if ( ( ConnectivityManager.CONNECTIVITY_ACTION ).equals ( intent.getAction() ) ) {
- NetworkInfo netInfo = ( NetworkInfo ) intent.getExtra ( WifiManager.EXTRA_NETWORK_INFO,
- null );
+ Bundle bundle = intent.getExtras();
+ NetworkInfo netInfo = ( NetworkInfo )bundle.getParcelable( WifiManager.EXTRA_NETWORK_INFO);
if ( PrefUtils.DEBUG ) {
Log.d ( TAG,
"BootCompleteFlag" +
@@ -95,8 +93,8 @@ public class LoaderReceiver extends BroadcastReceiver {
mContext.startService ( new Intent (
UpdateService.ACTION_AUTOCHECK ) );
return;
- } else if ( ( "true" ).equals ( SystemProperties.getBoolean (
- "ro.product.update.autocheck", false ) ) ) {
+ } else if ( ( "true" ).equals ( PrefUtils.getProperties (
+ "ro.product.update.autocheck", "false" ) ) ) {
mPref.setBoolean ( PrefUtils.PREF_AUTO_CHECK, true );
mContext.startService ( new Intent (
UpdateService.ACTION_AUTOCHECK ) );
diff --git a/src/com/droidlogic/otaupgrade/MainActivity.java b/src/com/droidlogic/otaupgrade/MainActivity.java
index a6d404b..7851e4e 100644
--- a/src/com/droidlogic/otaupgrade/MainActivity.java
+++ b/src/com/droidlogic/otaupgrade/MainActivity.java
@@ -30,8 +30,6 @@ 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;
diff --git a/src/com/droidlogic/otaupgrade/PrefUtils.java b/src/com/droidlogic/otaupgrade/PrefUtils.java
index 2de946f..3be4035 100644
--- a/src/com/droidlogic/otaupgrade/PrefUtils.java
+++ b/src/com/droidlogic/otaupgrade/PrefUtils.java
@@ -14,7 +14,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
-import android.os.SystemProperties;
import android.util.Log;
import java.io.BufferedWriter;
import java.io.File;
@@ -24,8 +23,6 @@ import java.io.FileWriter;
import java.io.IOException;
import com.amlogic.update.DownloadUpdateTask;
-import android.os.storage.VolumeInfo;
-import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import java.util.HashSet;
import java.util.Locale;
@@ -41,6 +38,8 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.nio.channels.FileChannel;
import com.amlogic.update.OtaUpgradeUtils;
+import java.lang.reflect.Method;
+import java.lang.reflect.Field;
/**
* @ClassName PrefUtils
* @Description TODO
@@ -148,10 +147,24 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{
setLong ( PREFS_UPDATE_FILESIZE, fileSize );
}
+ public static Object getProperties(String key, String def) {
+ String defVal = def;
+ try {
+ Class properClass = Class.forName("android.os.SystemProperties");
+ Method getMethod = properClass.getMethod("get",String.class,String.class);
+ defVal = (String)getMethod.invoke(null,key,def);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ Log.d(TAG,"getProperty:"+key+" defVal:"+defVal);
+ return defVal;
+ }
+
+ }
static boolean isUserVer() {
- String userVer = SystemProperties.get ( "ro.secure", "" );
- String userDebug = SystemProperties.get ( "ro.debuggable", "" );
- String hideLocalUp = SystemProperties.get ( "ro.otaupdate.local", "" );
+ String userVer = (String)getProperties("ro.secure",null);//SystemProperties.get ( "ro.secure", "" );
+ String userDebug = (String)getProperties("ro.debuggable","0");//SystemProperties.get ( "ro.debuggable", "" );
+ String hideLocalUp = (String)getProperties("ro.otaupdate.local",null);//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" ) );
@@ -161,40 +174,75 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{
}
public static boolean getAutoCheck() {
- return ( "true" ).equals ( SystemProperties.get (
- "ro.product.update.autocheck" ) );
+ String auto = (String)getProperties("ro.product.update.autocheck","false");
+ return ( "true" ).equals ( auto );
}
public ArrayList<File> getExternalStorageList(){
- ArrayList<File> devList = new ArrayList<File>();
+ Class<?> volumeInfoC = null;
+ Method getcomparator = null;
+ Method getvolume = null;
+ Method isMount = null;
+ Method getType = null;
+ Method getPath = null;
+ List<?> mVolumes = null;
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());
+ ArrayList<File> devList = new ArrayList<File>();
+ try {
+ volumeInfoC = Class.forName("android.os.storage.VolumeInfo");
+ getcomparator = volumeInfoC.getMethod("getDescriptionComparator");
+ getvolume = StorageManager.class.getMethod("getVolumes");
+ isMount = volumeInfoC.getMethod("isMountedReadable");
+ getType = volumeInfoC.getMethod("getType");
+ getPath = volumeInfoC.getMethod("getPath");
+ mVolumes = (List<?>)getvolume.invoke(mStorageManager);
+
+ for (Object vol : mVolumes) {
+ if (vol != null && (boolean)isMount.invoke(vol) && (int)getType.invoke(vol) == 0) {
+ devList.add((File)getPath.invoke(vol));
+ Log.d(TAG, "path.getName():" + getPath.invoke(vol));
+ }
}
+ }catch (Exception ex) {
+ ex.printStackTrace();
+ }finally {
+ return devList;
}
- return devList;
}
- public DiskInfo getDiskInfo(String filePath){
+ public Object 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;
+ Class<?> volumeInfoC = null;
+ Class<?> deskInfoC = null;
+ Method getcomparator = null;
+ Method getvolume = null;
+ Method getDisk = null;
+ Method isMount = null;
+ Method getPath = null;
+ List<?> mVolumes = null;
+ try {
+ volumeInfoC = Class.forName("android.os.storage.VolumeInfo");
+ deskInfoC = Class.forName("android.os.storage.DiskInfo");
+ getcomparator = volumeInfoC.getMethod("getDescriptionComparator");
+ getvolume = StorageManager.class.getMethod("getVolumes");
+ mVolumes = (List<?>)getvolume.invoke(mStorageManager);//mStorageManager.getVolumes();
+ isMount = volumeInfoC.getMethod("isMountedReadable");
+ getDisk = volumeInfoC.getMethod("getDisk");
+ getPath = volumeInfoC.getMethod("getPath");
+ for (Object vol : mVolumes) {
+ if (vol != null && (boolean)isMount.invoke(vol)) {
+ Object info = getDisk.invoke(vol);
+ if ( info != null && filePath.contains(((File)getPath.invoke(vol)).getAbsolutePath()) ) {
+ return info;
+ }
+ Log.d(TAG, "path.getName():" +((File)getPath.invoke(vol)).getAbsolutePath());
}
- Log.d(TAG, "path.getName():" + vol.getPath().getAbsolutePath());
}
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ return null;
}
- return null;
}
public String getTransPath(String inPath) {
@@ -203,23 +251,39 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{
String pathVol;
int idx = -1;
int len;
-
+ Class<?> volumeInfoC = null;
+ Method getBestVolumeDescription = null;
+ Method getVolumes = null;
+ Method getType = null;
+ Method isMount = null;
+ Method getPath = null;
+ List<?> volumes = null;
StorageManager storageManager = (StorageManager)mContext.getSystemService(Context.STORAGE_SERVICE);
- List<VolumeInfo> volumes = storageManager.getVolumes();
- Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
- for (VolumeInfo vol : volumes) {
- if (vol != null && vol.isMountedReadable() && vol.getType() == VolumeInfo.TYPE_PUBLIC) {
- pathVol = vol.getPath().getAbsolutePath();
- idx = inPath.indexOf(pathVol);
- if (idx != -1) {
- len = pathVol.length();
- pathLast = inPath.substring(idx + len);
- outPath = storageManager.getBestVolumeDescription(vol) + pathLast;
+ try {
+ volumeInfoC = Class.forName("android.os.storage.VolumeInfo");
+ getVolumes = StorageManager.class.getMethod("getVolumes",StorageManager.class);
+ volumes = (List)getVolumes.invoke(storageManager);
+ isMount = volumeInfoC.getMethod("isMountedReadable");
+ getType = volumeInfoC.getMethod("getType");
+ getPath = volumeInfoC.getMethod("getPath");
+ for (Object vol : volumes) {
+ if (vol != null && (boolean)isMount.invoke(vol) && (int)getType.invoke(vol,"") == 0) {
+ pathVol = ((File)getPath.invoke(vol)).getAbsolutePath();
+ idx = inPath.indexOf(pathVol);
+ if (idx != -1) {
+ len = pathVol.length();
+ pathLast = inPath.substring(idx + len);
+ getBestVolumeDescription = StorageManager.class.getMethod("getBestVolumeDescription",volumeInfoC);
+
+ outPath = ((String)getBestVolumeDescription.invoke(storageManager,vol)) + pathLast;
+ }
}
}
+ } catch (Exception ex) {
+ } finally {
+ return outPath;
}
- return outPath;
}
private String getCanWritePath(){
ArrayList<File> externalDevs = getExternalStorageList();
@@ -256,18 +320,28 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{
}
res += "--update_package=";
-
- DiskInfo info = getDiskInfo(fullpath);
- if ( info != null) {
- if ( info.isSd() ) {
- res += "/sdcard/";
- }else if ( info.isUsb() ) {
- res += "/udisk/";
- }else {
+ Class<?> deskInfoClass = null;
+ Method isSd = null;
+ Method isUsb = null;
+ Object info = getDiskInfo(fullpath);
+ try {
+ deskInfoClass = Class.forName("android.os.storage.DeskInfo");
+ isSd = deskInfoClass.getMethod("isSd()");
+ if ( info != null ) {
+ if ( (boolean)isSd.invoke(info) ) {
+ res += "/sdcard/";
+ }else if ( (boolean)isUsb.invoke(info) ) {
+ res += "/udisk/";
+ }else {
+ res += "/cache/";
+ UpdateMode = OtaUpgradeUtils.UPDATE_OTA;
+ }
+ } else {
res += "/cache/";
UpdateMode = OtaUpgradeUtils.UPDATE_OTA;
}
- }else {
+
+ } catch (Exception ex) {
res += "/cache/";
UpdateMode = OtaUpgradeUtils.UPDATE_OTA;
}
diff --git a/src/com/droidlogic/otaupgrade/UpdateService.java b/src/com/droidlogic/otaupgrade/UpdateService.java
index 4ee83d9..07ce20b 100644
--- a/src/com/droidlogic/otaupgrade/UpdateService.java
+++ b/src/com/droidlogic/otaupgrade/UpdateService.java
@@ -296,16 +296,17 @@ public class UpdateService extends Service {
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(mContext, UpdateActivity.class);
intent.setAction(ACTION_DOWNLOAD_SUCCESS);
-
PendingIntent contentItent = PendingIntent.getActivity(mContext, 0,
intent, 0);
- Notification notification = new Notification();
- notification.icon = R.drawable.ic_icon;
- notification.tickerText = "Downlaod Success";
- notification.defaults = Notification.DEFAULT_SOUND;
- notification.setLatestEventInfo(mContext, "Upgrade",
- "downlaod notify", contentItent);
- notificationManager.notify(0, notification);
+ Notification.Builder notification = new Notification.Builder(mContext)
+ .setTicker(mContext.getString(R.string.noti_msg))
+ .setWhen(System.currentTimeMillis())
+ .setContentTitle(mContext.getString(R.string.app_name))
+ .setContentText(mContext.getString(R.string.noti_msg))
+ .setSmallIcon(R.drawable.ic_icon)
+ .setContentIntent(contentItent);
+
+ notificationManager.notify(0, notification.getNotification());
}
}
}