author | Ting Li <ting.li@amlogic.com> | 2017-10-18 07:15:10 (GMT) |
---|---|---|
committer | Ting Li <ting.li@amlogic.com> | 2017-10-18 07:15:10 (GMT) |
commit | c75898a9b76be3590f0ff9189f9f02a135e02a3a (patch) | |
tree | 303b75b880908f37094bf9bdd42cff3ebe0f41aa | |
parent | 7f7fba084ed5c04ec4dff75365cef9bffa81ab1d (diff) | |
download | OTAUpgrade2-c75898a9b76be3590f0ff9189f9f02a135e02a3a.zip OTAUpgrade2-c75898a9b76be3590f0ff9189f9f02a135e02a3a.tar.gz OTAUpgrade2-c75898a9b76be3590f0ff9189f9f02a135e02a3a.tar.bz2 |
OTA: use droidlogic FileListManager to get Local or External Device[1/1]
PD# 152065
use droidlogic FileListManager to get Local or External Device on androidO
Change-Id: Ife5bc474395c7d548f58fa8a7680b8d38c2e0f38
-rw-r--r-- | AndroidManifest.xml | 1 | ||||
-rw-r--r-- | src/com/droidlogic/otaupgrade/FileSelector.java | 2 | ||||
-rw-r--r-- | src/com/droidlogic/otaupgrade/LoaderReceiver.java | 2 | ||||
-rw-r--r-- | src/com/droidlogic/otaupgrade/PrefUtils.java | 164 |
4 files changed, 134 insertions, 35 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 92bcbe7..e6349c2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -45,6 +45,7 @@ android:launchMode="singleTask" android:label="@string/app_name" android:theme="@style/AppTheme" > + <uses-library android:name="droidlogic.software.core" /> <activity android:name="com.droidlogic.otaupgrade.UpdateActivity" android:label="@string/app_name" diff --git a/src/com/droidlogic/otaupgrade/FileSelector.java b/src/com/droidlogic/otaupgrade/FileSelector.java index e8f72f3..b6a043d 100644 --- a/src/com/droidlogic/otaupgrade/FileSelector.java +++ b/src/com/droidlogic/otaupgrade/FileSelector.java @@ -101,7 +101,7 @@ public class FileSelector extends Activity implements OnItemClickListener { mHandler.sendMessageDelayed ( nmsg, WAITDIALOG_DISPALY_TIME ); new Thread() { public void run() { - ArrayList<File> files = mPrefUtil.getMainStorageList(); + ArrayList<File> files = mPrefUtil.getStorageList(false); mAdapter.getList ( files ); mHandler.sendEmptyMessage ( MSG_HIDE_SHOW_DIALOG ); } diff --git a/src/com/droidlogic/otaupgrade/LoaderReceiver.java b/src/com/droidlogic/otaupgrade/LoaderReceiver.java index 2402dbf..e599e18 100644 --- a/src/com/droidlogic/otaupgrade/LoaderReceiver.java +++ b/src/com/droidlogic/otaupgrade/LoaderReceiver.java @@ -55,7 +55,7 @@ public class LoaderReceiver extends BroadcastReceiver { private void getBackUpFileName() {
- ArrayList<File> devs = mPref.getExternalStorageList();
+ ArrayList<File> devs = mPref.getStorageList(true);
for ( int i = 0; (devs != null) && i < devs.size(); i++) {
File dev = devs.get(i);
if ( dev != null && dev.isDirectory() && dev.canWrite() ) {
diff --git a/src/com/droidlogic/otaupgrade/PrefUtils.java b/src/com/droidlogic/otaupgrade/PrefUtils.java index 4af3bed..0679a92 100644 --- a/src/com/droidlogic/otaupgrade/PrefUtils.java +++ b/src/com/droidlogic/otaupgrade/PrefUtils.java @@ -18,7 +18,7 @@ package com.droidlogic.otaupgrade; import android.content.Context; import android.content.SharedPreferences; - +import android.os.Build; import android.os.Environment; import android.util.Log; import java.io.BufferedWriter; @@ -31,6 +31,7 @@ import com.amlogic.update.DownloadUpdateTask; import android.os.storage.StorageManager; import java.util.HashSet; +import java.util.HashMap; import java.util.Locale; import java.util.List; import java.util.Set; @@ -46,6 +47,8 @@ import java.nio.channels.FileChannel; import com.amlogic.update.OtaUpgradeUtils; import java.lang.reflect.Method; import java.lang.reflect.Field; +import java.lang.reflect.Constructor; + /** * @ClassName PrefUtils * @Description TODO @@ -202,7 +205,7 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ return ( "true" ).equals ( auto ); } - public ArrayList<File> getExternalStorageList(){ + private ArrayList<File> getExternalStorageListOnN(){ Class<?> volumeInfoC = null; Method getvolume = null; Method isMount = null; @@ -231,7 +234,40 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ return devList; } } - public ArrayList<File> getMainStorageList(){ + public ArrayList<File> getStorageList(boolean extern) { + + if ( Build.VERSION.SDK_INT >= 26 ) { + Class<?> fileListClass = null; + Method getdev = null; + ArrayList<File> devList = new ArrayList<File>(); + try { + fileListClass = Class.forName("com.droidlogic.app.FileListManager"); + getdev = fileListClass.getMethod("getDevices"); + Constructor constructor =fileListClass.getConstructor(new Class[]{Context.class}); + Object fileListObj = constructor.newInstance(mContext); + ArrayList<HashMap<String, Object>> devices = new ArrayList<HashMap<String,Object>>(); + devices = (ArrayList<HashMap<String, Object>>)getdev.invoke(fileListObj); + + for (HashMap<String, Object> dev : devices) { + Log.d(TAG,"getDevice:"+dev.get("key_name")+"getType:"+dev.get("key_type")); + String name = (String)dev.get("key_name"); + if (name.equals("Local Disk") && extern) { + continue; + } + devList.add(new File((String)dev.get("key_path"))); + } + }catch (Exception ex) { + ex.printStackTrace(); + }finally { + return devList; + } + }else if(extern) { + return getExternalStorageListOnN(); + }else { + return getMainDeviceListonN(); + } + } + private ArrayList<File> getMainDeviceListonN(){ Class<?> volumeInfoC = null; Method getvolume = null; Method isMount = null; @@ -295,8 +331,36 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ return null; } - public String getTransPath(String inPath) { + if ( Build.VERSION.SDK_INT >= 26 ) { + Class<?> fileListClass = null; + Method getdev = null; + String outPath = inPath; + try { + fileListClass = Class.forName("com.droidlogic.app.FileListManager"); + getdev = fileListClass.getMethod("getDevices"); + Constructor constructor =fileListClass.getConstructor(new Class[]{Context.class}); + Object fileListObj = constructor.newInstance(mContext); + ArrayList<HashMap<String, Object>> devices = new ArrayList<HashMap<String,Object>>(); + devices = (ArrayList<HashMap<String, Object>>)getdev.invoke(fileListObj); + + for (HashMap<String, Object> dev : devices) { + String name = (String)dev.get("key_name"); + String volName = (String)dev.get("key_path"); + if (outPath.contains(volName)) { + outPath = outPath.replace(volName,name); + } + } + }catch (Exception ex) { + ex.printStackTrace(); + }finally { + return outPath; + } + } else { + return getNickName(inPath); + } + } + private String getNickName(String inPath) { String outPath = inPath; String pathLast; String pathVol; @@ -312,7 +376,7 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ StorageManager storageManager = (StorageManager)mContext.getSystemService(Context.STORAGE_SERVICE); try { volumeInfoC = Class.forName("android.os.storage.VolumeInfo"); - getVolumes = StorageManager.class.getMethod("getVolumes",StorageManager.class); + getVolumes = StorageManager.class.getMethod("getVolumes"); volumes = (List)getVolumes.invoke(storageManager); isMount = volumeInfoC.getMethod("isMountedReadable"); getType = volumeInfoC.getMethod("getType"); @@ -331,13 +395,14 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ } } } catch (Exception ex) { + ex.printStackTrace(); } finally { return outPath; } } private String getCanWritePath(){ - ArrayList<File> externalDevs = getExternalStorageList(); + ArrayList<File> externalDevs = getStorageList(true); String filePath = ""; for ( int j = 0; (externalDevs != null) && j < externalDevs.size(); j++ ) { File dir = externalDevs.get(j); @@ -349,37 +414,43 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ } return filePath; } - - public int createAmlScript(String fullpath, boolean wipe_data, boolean wipe_cache) { - - File file; - String res = ""; - int UpdateMode = OtaUpgradeUtils.UPDATE_UPDATE; - file = new File("/cache/recovery/command"); - - try { - File parent = file.getParentFile(); - if (file.exists()) { - file.delete(); - } - if (!parent.exists()) { - parent.mkdirs(); - } - - if (!file.exists()) { - file.createNewFile(); + private String getAttribute(String inPath) { + if ( Build.VERSION.SDK_INT >= 26 ) { + Class<?> fileListClass = null; + Method getdev = null; + try { + fileListClass = Class.forName("com.droidlogic.app.FileListManager"); + getdev = fileListClass.getMethod("getDevices"); + Constructor constructor =fileListClass.getConstructor(new Class[]{Context.class}); + Object fileListObj = constructor.newInstance(mContext); + ArrayList<HashMap<String, Object>> devices = new ArrayList<HashMap<String,Object>>(); + devices = (ArrayList<HashMap<String, Object>>)getdev.invoke(fileListObj); + + for (HashMap<String, Object> dev : devices) { + String name = (String)dev.get("key_name"); + String volName = (String)dev.get("key_path"); + if (inPath.contains(volName)) { + String type = (String)dev.get("key_type"); + if (type == "type_udisk") return "/udisk/"; + else if(type == "type_sdcard") return "/sdcard/"; + } + } + }catch (Exception ex) { + ex.printStackTrace(); } - } catch (IOException e) { - e.printStackTrace(); + return "/cache/"; + } else { + return getAttributeonN(inPath); } - res += "--update_package="; + } + private String getAttributeonN(String inPath) { + String res =""; Class<?> deskInfoClass = null; Method isSd = null; Method isUsb = null; - Object info = getDiskInfo(fullpath); + Object info = getDiskInfo(inPath); if (info == null) { res += "/cache/"; - UpdateMode = OtaUpgradeUtils.UPDATE_OTA; } else { try { deskInfoClass = Class.forName("android.os.storage.DiskInfo"); @@ -392,19 +463,46 @@ public class PrefUtils implements DownloadUpdateTask.CheckPathCallBack{ res += "/udisk/"; }else { res += "/cache/"; - UpdateMode = OtaUpgradeUtils.UPDATE_OTA; } } else { res += "/cache/"; - UpdateMode = OtaUpgradeUtils.UPDATE_OTA; } } catch (Exception ex) { ex.printStackTrace(); res += "/cache/"; - UpdateMode = OtaUpgradeUtils.UPDATE_OTA; } } + return res; + } + + public int createAmlScript(String fullpath, boolean wipe_data, boolean wipe_cache) { + + File file; + String res = ""; + int UpdateMode = OtaUpgradeUtils.UPDATE_UPDATE; + file = new File("/cache/recovery/command"); + + try { + File parent = file.getParentFile(); + if (file.exists()) { + file.delete(); + } + if (!parent.exists()) { + parent.mkdirs(); + } + + if (!file.exists()) { + file.createNewFile(); + } + } catch (IOException e) { + e.printStackTrace(); + } + res += "--update_package="; + String updateFilePath = getAttribute(fullpath); + res += updateFilePath; + if (updateFilePath.startsWith("/cache/")) + UpdateMode = OtaUpgradeUtils.UPDATE_OTA; res += new File(fullpath).getName(); res += ("\n--locale=" + Locale.getDefault().toString()); res += (wipe_data? "\n--wipe_data" : ""); |