Commit 9a6801c8 authored by feihuaduo's avatar feihuaduo

更改替换内核目录

parent 5458e02f
......@@ -5,6 +5,7 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
......@@ -32,6 +33,7 @@ import com.pgyersdk.update.UpdateManagerListener;
import com.pgyersdk.update.javabean.AppBean;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -82,8 +84,8 @@ import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
public class SettingFragment extends PreferenceFragmentPlus {
private static final int COPY_SO_OK=0;
private static final int COPY_SO_EXCEPTION=1;
private static final int COPY_SO_OK = 0;
private static final int COPY_SO_EXCEPTION = 1;
public SettingFragment() {
......@@ -120,7 +122,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind(PREF_GAME_FONT, mSettings.getFontPath());
bind(PREF_READ_EX, mSettings.isReadExpansions());
bind(PREF_DECK_MANAGER_V2, mSettings.isUseDeckManagerV2());
bind(PERF_TEST_REPLACE_KERNEL,"替换ygopro的内核");
bind(PERF_TEST_REPLACE_KERNEL, "需root权限,请在开发者的指导下食用");
Preference preference = findPreference(PREF_READ_EX);
if (preference != null) {
preference.setSummary(mSettings.getExpansionsPath().getAbsolutePath());
......@@ -316,8 +318,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
} else if (PREF_GAME_PATH.equals(key)) {
showFolderChooser(preference, mSettings.getResourcePath(), getString(R.string.choose_game_path));
}else if (PERF_TEST_REPLACE_KERNEL.equals(key)){
showFileChooser(preference,".so", mSettings.getResourcePath(),"内核文件选择");
} else if (PERF_TEST_REPLACE_KERNEL.equals(key)) {
showFileChooser(preference, ".so", mSettings.getResourcePath(), "内核文件选择");
}
return false;
}
......@@ -355,44 +357,67 @@ public class SettingFragment extends PreferenceFragmentPlus {
((CheckBoxPreference) preference).setChecked(true);
mSettings.setUseExtraCards(true);
copyDataBase(preference, file);
} else if(PERF_TEST_REPLACE_KERNEL.equals(key)){
File path=App.get().getDir("lib",Context.MODE_APPEND);
String name="libYGOMobile.so";
File soFile=new File(path.getAbsolutePath(),name);
} else if (PERF_TEST_REPLACE_KERNEL.equals(key)) {
File path = App.get().getFilesDir().getParentFile();
String name = "libYGOMobile.so";
File soFile = new File(path.getAbsolutePath() + "/lib", name);
new Thread(new Runnable() {
@Override
public void run() {
Message me=new Message();
Message me = new Message();
Process process = null;
DataOutputStream os = null;
try {
String cmd = "chmod -R 777 " + soFile.getAbsolutePath();
process = Runtime.getRuntime().exec("su"); //切换到root帐号
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
IOUtils.delete(soFile);
IOUtils.copyFile(file,soFile.getAbsolutePath(),true);
me.what=COPY_SO_OK;
} catch (FileNotFoundException e) {
Log.e("SettingFragment", "file: " + file);
Log.e("SettingFragment", "path: " + soFile.getAbsolutePath());
IOUtils.copyFile(file, soFile.getAbsolutePath(), true);
me.what = COPY_SO_OK;
} catch (Exception e) {
e.printStackTrace();
me.what=COPY_SO_EXCEPTION;
me.obj=e;
me.what = COPY_SO_EXCEPTION;
me.obj = e;
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
process.destroy();
}
handler.sendMessage(me);
}
}).start();
}else {
} else {
super.onChooseFileOk(preference, file);
}
}
@SuppressLint("HandlerLeak")
Handler handler=new Handler(){
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
switch (msg.what) {
case COPY_SO_OK:
Toast.makeText(getActivity(),"替换成功", Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "替换成功", Toast.LENGTH_SHORT).show();
break;
case COPY_SO_EXCEPTION:
Toast.makeText(getActivity(),"替换失败,原因为"+msg.obj, Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "替换失败,原因为" + msg.obj, Toast.LENGTH_SHORT).show();
break;
}
}
......
......@@ -229,7 +229,7 @@ public class IOUtils {
return false;
}
public static void copyFile(String oldPath, String newPath, boolean isname) throws FileNotFoundException {
public static void copyFile(String oldPath, String newPath, boolean isname) throws FileNotFoundException, IOException {
//判断复制后的路径是否含有文件名,如果没有则加上
if (!isname) {
......@@ -239,9 +239,15 @@ public class IOUtils {
}
FileInputStream fis=new FileInputStream(oldPath);
copyToFile(fis,newPath);
FileOutputStream fos=new FileOutputStream(newPath);
byte[] buf=new byte[1024];
int len=0;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
fis.close();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment