Commits

Anonymous committed 2f1134b Draft

change install method

Comments (0)

Files changed (8)

res/values/strings.xml

     <string name="removed_busybox">Removed busybox</string>
     <string name="dm_welcome">Welcome to Busybox Installer!\n\nBusybox Installer is the fastest and easiest way to install the latest version of busybox.\n\nPlease consider helping development by getting the pro version today.</string>
     <string name="dt_welcome">Welcome!</string>
+    <string name="prg_symlinking">Symlinking ...</string>
+    <string name="prg_remove_old">Removing old %s ...</string>
+    <string name="prg_installing">Installing %s ...</string>
 
     <!-- TOAST MESSAGES -->
     <string name="invalid_directory">\'%s\' is not a valid directory</string>
     <string name="pt_advanced">Advanced</string>
     <string name="pt_delete_busybox">Delete busybox</string>
     <string name="ps_delete_busybox">Remove busybox from your system</string>
+    <string name="ps_debug_mode">Debug Mode</string>
 
     <!-- CHECKBOX -->
     <string name="cb_symlink">Symlink applets</string>

res/xml/busybox_prefs.xml

             android:key="delete_busybox"
             android:summary="@string/ps_delete_busybox"
             android:title="@string/pt_delete_busybox" />
+        <CheckBoxPreference
+            android:defaultValue="false"
+            android:key="degub_mode"
+            android:title="@string/ps_debug_mode" />
     </PreferenceCategory>
     <PreferenceCategory
         android:key="general_scripter_settings"

src/com/jrummy/busybox/installer/AdvancedInstaller.java

 
 import com.jrummy.busybox.installer.util.BinaryInstaller;
 import com.jrummy.busybox.installer.util.CMDProcessor;
+import com.jrummy.busybox.installer.util.Constants;
 import com.jrummy.busybox.installer.util.Helpers;
 
 public class AdvancedInstaller extends FragmentActivity {
 				String tmp = busybox.getAbsolutePath();
 				CMDProcessor.SH su = new CMDProcessor().su;
 				BinaryInstaller.copyOver(mPath, tmp);
-				su.runWaitFor(BusyboxActivity.CHMOD + " 4755 " + tmp);
+				su.runWaitFor(Constants.CHMOD + " 4755 " + tmp);
 
 				List<String> applets = Helpers.getBusyboxApplets(tmp);
 				HashMap<String, Object> item;

src/com/jrummy/busybox/installer/BusyboxActivity.java

 import com.jrummy.busybox.installer.swipeytabs.SwipeyTabs;
 import com.jrummy.busybox.installer.swipeytabs.SwipeyTabsAdapter;
 import com.jrummy.busybox.installer.util.CMDProcessor;
+import com.jrummy.busybox.installer.util.Constants;
 import com.jrummy.busybox.installer.util.Helpers;
 
 public class BusyboxActivity extends FragmentActivity {
 
 	private static final String TAG = "BusyboxActivity";
-	public static final String CHMOD = "/data/data/com.jrummy.busybox.installer/files/chmod";
 
 	static final int DIALOG_WELCOME = 0;
 	static final int DIALOG_SHARE = 1;
 		mTitleFont = Typeface.createFromAsset(getAssets(), "fonts/sonysketch.ttf");
 		mMainFont = Typeface.createFromAsset(getAssets(), "fonts/default.ttf");
 		mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+		Constants.IS_DEBUG = mPrefs.getBoolean("degub_mode", false);
 		mViewPager = (ViewPager) findViewById(R.id.viewpager);
 		mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);
 		mTitleBar = new TitleBar(this);
 				editor.commit();
 				mHandler.sendEmptyMessage(MSG_SHOW_WELCOME_MSG);
 			}
-			if (!new File(CHMOD).exists()) {
+			if (!new File(Constants.CHMOD).exists()) {
 				transferAsset("chmod", "chmod");
 			}
-			new CMDProcessor().su.runWaitFor("chmod 755 " + CHMOD);
+			new CMDProcessor().su.runWaitFor("chmod 755 " + Constants.CHMOD);
 		}
 	};
 

src/com/jrummy/busybox/installer/BusyboxInstaller.java

 import java.util.List;
 
 import android.app.Activity;
+import android.app.ProgressDialog;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.graphics.Color;
 
 import com.jrummy.busybox.installer.BusyboxActivity.OnEditTextSavedListener;
 import com.jrummy.busybox.installer.util.BinaryInstaller;
-import com.jrummy.busybox.installer.util.Helpers;
 import com.jrummy.busybox.installer.util.CMDProcessor;
 import com.jrummy.busybox.installer.util.Downloader;
+import com.jrummy.busybox.installer.util.Helpers;
 import com.jrummy.busybox.installer.util.VersionParser;
 
 public class BusyboxInstaller {
 
 	private static final int MSG_INIT_INSTALLER = 0;
 	private static final int MSG_INSTALL_COMPLETE = 1;
+	private static final int MSG_UPDATE_PBAR = 2;
 
 	private SharedPreferences mPrefs;
 	private SharedPreferences.Editor mPrefsEditor;
 	private String mDownloadPath;
 	private String mInstallLocation;
 	private String mBinaryName;
+	private ProgressDialog mPbarDialog;
 
 	protected LinearLayout mLoadingProgress;
 	protected LinearLayout mSymlinkCheckBoxLayout;
 				initInstaller();
 				break;
 			case MSG_INSTALL_COMPLETE:
+				if (mPbarDialog != null) {
+					mPbarDialog.dismiss();
+				}
 				BusyboxActivity act = BusyboxActivity.getActivity();
 				boolean success = msg.getData().getBoolean("success");
 				if (mBinaryName.equals("busybox")) {
 					act.showDialog(id);
 				}
 				break;
+			case MSG_UPDATE_PBAR:
+				mPbarDialog.setMessage(msg.getData().getString("msg"));
+				break;
 			case Downloader.STATUS_UPDATE:
 				BusyboxActivity activity = BusyboxActivity.getActivity();
 				TitleBar titleBar = activity.mTitleBar;
 	};
 
 	private void installBinary() {
+		mPbarDialog = new ProgressDialog(mActivity);
+		mPbarDialog.setTitle(mActivity.getString(R.string.please_wait));
+		mPbarDialog.setMessage(mActivity.getString(R.string.prg_installing, mBinaryName));
+		mPbarDialog.show();
+
 		new Thread() {
 			@Override
 			public void run() {
 				BinaryInstaller installer = new BinaryInstaller(
 						mDownloadPath, mInstallLocation, mBinaryName);
 				boolean installSuccess = false;
+				Message msg = mHandler.obtainMessage(MSG_UPDATE_PBAR);
+				Bundle data = new Bundle();
 
-				// remove old busybox
+				// remove old binary
 				if (Helpers.isBinaryInstalled(mBinaryName)) {
+					data.putString("msg", mActivity.getString(
+							R.string.prg_remove_old, mBinaryName));
+					msg.setData(data);
+					mHandler.sendMessage(msg);
+
 					String path = Helpers.getBinaryPath("busybox", mBinaryName);
 					Helpers.setMount(path, "rw");
-					new CMDProcessor().su.runWaitFor("busybox rm -f \"" + path + "\"");
+					new CMDProcessor().su.runWaitFor("busybox rm \"" + path + "\"");
 					Helpers.setMount(path, "ro");
+
+					msg = mHandler.obtainMessage(MSG_UPDATE_PBAR);
+					data.putString("msg", mActivity.getString(
+							R.string.prg_installing, mBinaryName));
+					msg.setData(data);
+					mHandler.sendMessage(msg);
 				}
 
 				// install binary
 						installSuccess = true;
 					}
 					if (mSymlinkAppletsCheckBox.isChecked() && mBinaryName.equals("busybox")) {
+						msg = mHandler.obtainMessage(MSG_UPDATE_PBAR);
+						data.putString("msg", mActivity.getString(
+								R.string.prg_symlinking));
+						msg.setData(data);
+						mHandler.sendMessage(msg);
 						installer.symlinkBusybox(mInstallLocation);
 					}
 				}
 				}
 
 				// dismiss progress
-				Message msg = mHandler.obtainMessage(MSG_INSTALL_COMPLETE);
-				Bundle data = new Bundle();
+				msg = mHandler.obtainMessage(MSG_INSTALL_COMPLETE);
+				data = new Bundle();
 				data.putBoolean("success", installSuccess);
 				msg.setData(data);
 				mHandler.sendMessage(msg);
 			mInstallButton.setEnabled(false);
 			TitleBar titleBar = BusyboxActivity.getActivity().mTitleBar;
 			titleBar.showProgressSpinner(true);
-			
+
 			mVersion = mBusyboxVersions.get(mSpinBusyboxVersions.getSelectedItemPosition());
 			mBinaryName = mVersion.get("binary");
 			String url = mVersion.get("url");

src/com/jrummy/busybox/installer/BusyboxPreferences.java

 import android.widget.TimePicker;
 import android.widget.Toast;
 
+import com.jrummy.busybox.installer.util.Constants;
 import com.jrummy.busybox.installer.util.Helpers;
 import com.jrummy.busybox.installer.util.UpdateHelper;
 
 	public static final String KEY_RUN_SCRIPT_AS_ROOT = "scripter_run_as_root";
 	public static final String KEY_USE_BASH_SHELL = "scripter_use_bash_shell";
 	public static final String KEY_DELETE_BUSYBOX = "delete_busybox";
+	public static final String KEY_DEBUG_MODE = "debug_mode";
 
 	public static final int LAST_VERSION_NUMBER = 1200;
 
 				UpdateHelper.cancelAlarm(getApplicationContext(), 
 						UpdateHelper.getPendingIntent(getApplicationContext()));
 			}
+		} else if (key.equals(KEY_DEBUG_MODE)) {
+			Constants.IS_DEBUG = sharedPreferences.getBoolean(key, false);
 		}
 	}
 

src/com/jrummy/busybox/installer/util/BinaryInstaller.java

 
 import java.io.File;
 
-import com.jrummy.busybox.installer.BusyboxActivity;
+import android.util.Log;
 
 
 public class BinaryInstaller {
 
+	private static final String TAG = "BinaryInstaller";
 	private String mBinaryPath;
 	private String mInstallLocation;
 	private String mBinaryName;
 	}
 
 	public boolean installBinary() {
+		String dest = new File(mInstallLocation, mBinaryName).getAbsolutePath();
 		CMDProcessor.SH su = new CMDProcessor().su;
-		Helpers.setMount(mInstallLocation, "rw");
-		String dest = new File(mInstallLocation, mBinaryName).getAbsolutePath();
 		boolean installSuccess = false;
+		if (!Helpers.mountSystemRW()) {
+			Log.d(TAG, "Failed to mount system read/write;");
+		}
 
 		if (!new File(mInstallLocation).isDirectory()) {
 			su.runWaitFor("mkdir -p " + mInstallLocation);
 
 		if (copyOver(mBinaryPath, dest)) {
 			installSuccess = true;
-			CMDProcessor.CommandResult result = su.runWaitFor("chmod 4755 " + dest);
-			if (!result.success()) {
-				result = su.runWaitFor(BusyboxActivity.CHMOD + " 4755 " + dest);
-				if (!result.success() && mBinaryName.equals("busybox")) {
-					installSuccess = su.runWaitFor(
-							mBinaryPath + " chmod 4755 " + dest).success();
-				}
+			if (!Helpers.setPermissions("4755", dest)) {
+				Log.d(TAG, "Failed to give permissions to " + dest);
 			}
-
 		}
 
-		Helpers.setMount(mInstallLocation, "ro");
+		Helpers.mountSystemRO();
 
 		return installSuccess;
 	}
 		Helpers.setMount(path, "rw");
 		CMDProcessor.CommandResult result = new CMDProcessor().su.runWaitFor(
 				"busybox --install -s " + path);
+		if (!result.success()) {
+			Log.i(TAG, "Failed to symlink busybox. --install applet most likely not found.");
+		}
 		Helpers.setMount(path, "rw");
 		return result.success();
 	}
 
 	public static boolean copyOver(String path, String dest) {
-
 		CMDProcessor.SH su = new CMDProcessor().su;
 		CMDProcessor.CommandResult result;
 
-		result = su.runWaitFor("toolbox dd if=\"" + path + "\" of=\"" + dest + "\"");
-		if (result.success()) {
-			return true;
-		}
+		String[] commands = {
+				"dd if=\"" + path + "\" of=\"" + dest + "\"",
+				"cat \"" + path + "\" > \"" + dest + "\"",
+				"cp \"" + path + "\" \"" + dest + "\"",
+				"toolbox dd if=\"" + path + "\" of=\"" + dest + "\"",
+				"toolbox cat \"" + path + "\" > \"" + dest + "\"",
+				"toolbox cp \"" + path + "\" \"" + dest + "\"",
+				"/system/bin/toolbox dd if=\"" + path + "\" of=\"" + dest + "\"",
+				"/system/bin/toolbox cat \"" + path + "\" > \"" + dest + "\"",
+				"/system/bin/toolbox cp \"" + path + "\" \"" + dest + "\"",
+				path + " dd if=\"" + path + "\" of=\"" + dest + "\"",
+				path + " cat \"" + path + "\" > \"" + dest + "\"",
+				path + " cp \"" + path + "\" \"" + dest + "\"",
+		};
 
-		result = su.runWaitFor("toolbox cat \"" + path + "\" > \"" + dest + "\"");
-		if (result.success()) {
-			return true;
-		}
-
-		result = su.runWaitFor("toolbox cp \"" + path + "\" \"" + dest + "\"");
-		if (result.success()) {
-			return true;
+		for (String cmd : commands) {
+			result = su.runWaitFor(cmd);
+			if (result.success()) {
+				return true;
+			} else if (Constants.IS_DEBUG) {
+				Log.d(TAG, "Copying over '" + path + "' failed.");
+				Log.d(TAG, "cmd: " + cmd);
+				Log.d(TAG, "stdout: " + result.stdout);
+				Log.d(TAG, "stderr: " + result.stderr);
+				Log.d(TAG, "exit_code: " + result.exit_value);
+			}
 		}
 
 		return false;

src/com/jrummy/busybox/installer/util/Helpers.java

 		return removed;
 	}
 
+	public static boolean setPermissions(String mode, String file) {
+		String[] tools = {
+				"chmod", "toolbox chmod", Constants.CHMOD, 
+				"busybox chmod", "/system/bin/toolbox chmod"	
+		};
+
+		CMDProcessor.SH shell = new CMDProcessor().su;
+		CMDProcessor.CommandResult result;
+		boolean success = false;
+
+		setMount(file, "rw");
+		for (String tool : tools) {
+			result = shell.runWaitFor(tool + " " + mode + " " + file);
+			if (result.success()) {
+				success = true;
+				break;
+			}
+		}
+		setMount(file, "ro");
+
+		return success;
+	}
+
 	public static String getRomVersion() {
 		CMDProcessor.CommandResult result = new CMDProcessor().sh.runWaitFor(
 				"getprop ro.modversion");