Commit 9a6801c8 authored by feihuaduo's avatar feihuaduo

更改替换内核目录

parent 5458e02f
...@@ -5,6 +5,7 @@ import android.app.Dialog; ...@@ -5,6 +5,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
...@@ -32,6 +33,7 @@ import com.pgyersdk.update.UpdateManagerListener; ...@@ -32,6 +33,7 @@ import com.pgyersdk.update.UpdateManagerListener;
import com.pgyersdk.update.javabean.AppBean; import com.pgyersdk.update.javabean.AppBean;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
...@@ -82,8 +84,8 @@ import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath; ...@@ -82,8 +84,8 @@ import static cn.garymb.ygomobile.ui.home.ResCheckTask.getDatapath;
public class SettingFragment extends PreferenceFragmentPlus { public class SettingFragment extends PreferenceFragmentPlus {
private static final int COPY_SO_OK=0; private static final int COPY_SO_OK = 0;
private static final int COPY_SO_EXCEPTION=1; private static final int COPY_SO_EXCEPTION = 1;
public SettingFragment() { public SettingFragment() {
...@@ -120,7 +122,7 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -120,7 +122,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind(PREF_GAME_FONT, mSettings.getFontPath()); bind(PREF_GAME_FONT, mSettings.getFontPath());
bind(PREF_READ_EX, mSettings.isReadExpansions()); bind(PREF_READ_EX, mSettings.isReadExpansions());
bind(PREF_DECK_MANAGER_V2, mSettings.isUseDeckManagerV2()); 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); Preference preference = findPreference(PREF_READ_EX);
if (preference != null) { if (preference != null) {
preference.setSummary(mSettings.getExpansionsPath().getAbsolutePath()); preference.setSummary(mSettings.getExpansionsPath().getAbsolutePath());
...@@ -316,8 +318,8 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -316,8 +318,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
} }
} else if (PREF_GAME_PATH.equals(key)) { } else if (PREF_GAME_PATH.equals(key)) {
showFolderChooser(preference, mSettings.getResourcePath(), getString(R.string.choose_game_path)); showFolderChooser(preference, mSettings.getResourcePath(), getString(R.string.choose_game_path));
}else if (PERF_TEST_REPLACE_KERNEL.equals(key)){ } else if (PERF_TEST_REPLACE_KERNEL.equals(key)) {
showFileChooser(preference,".so", mSettings.getResourcePath(),"内核文件选择"); showFileChooser(preference, ".so", mSettings.getResourcePath(), "内核文件选择");
} }
return false; return false;
} }
...@@ -355,44 +357,67 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -355,44 +357,67 @@ public class SettingFragment extends PreferenceFragmentPlus {
((CheckBoxPreference) preference).setChecked(true); ((CheckBoxPreference) preference).setChecked(true);
mSettings.setUseExtraCards(true); mSettings.setUseExtraCards(true);
copyDataBase(preference, file); copyDataBase(preference, file);
} else if(PERF_TEST_REPLACE_KERNEL.equals(key)){ } else if (PERF_TEST_REPLACE_KERNEL.equals(key)) {
File path=App.get().getDir("lib",Context.MODE_APPEND); File path = App.get().getFilesDir().getParentFile();
String name="libYGOMobile.so"; String name = "libYGOMobile.so";
File soFile=new File(path.getAbsolutePath(),name); File soFile = new File(path.getAbsolutePath() + "/lib", name);
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
Message me=new Message(); Message me = new Message();
Process process = null;
DataOutputStream os = null;
try { 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.delete(soFile);
IOUtils.copyFile(file,soFile.getAbsolutePath(),true); Log.e("SettingFragment", "file: " + file);
me.what=COPY_SO_OK; Log.e("SettingFragment", "path: " + soFile.getAbsolutePath());
} catch (FileNotFoundException e) { IOUtils.copyFile(file, soFile.getAbsolutePath(), true);
me.what = COPY_SO_OK;
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
me.what=COPY_SO_EXCEPTION; me.what = COPY_SO_EXCEPTION;
me.obj=e; me.obj = e;
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
process.destroy();
} }
handler.sendMessage(me); handler.sendMessage(me);
} }
}).start(); }).start();
}else { } else {
super.onChooseFileOk(preference, file); super.onChooseFileOk(preference, file);
} }
} }
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
Handler handler=new Handler(){ Handler handler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
switch (msg.what){ switch (msg.what) {
case COPY_SO_OK: case COPY_SO_OK:
Toast.makeText(getActivity(),"替换成功", Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "替换成功", Toast.LENGTH_SHORT).show();
break; break;
case COPY_SO_EXCEPTION: case COPY_SO_EXCEPTION:
Toast.makeText(getActivity(),"替换失败,原因为"+msg.obj, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), "替换失败,原因为" + msg.obj, Toast.LENGTH_SHORT).show();
break; break;
} }
} }
......
...@@ -229,7 +229,7 @@ public class IOUtils { ...@@ -229,7 +229,7 @@ public class IOUtils {
return false; 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) { if (!isname) {
...@@ -239,9 +239,15 @@ public class IOUtils { ...@@ -239,9 +239,15 @@ public class IOUtils {
} }
FileInputStream fis=new FileInputStream(oldPath); 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