RootInstaller: multiple apks
This commit is contained in:
parent
588e22462b
commit
b3ca915459
@ -20,6 +20,7 @@
|
|||||||
package org.fdroid.fdroid.installer;
|
package org.fdroid.fdroid.installer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
|
||||||
@ -74,12 +75,11 @@ abstract public class Installer {
|
|||||||
*/
|
*/
|
||||||
public interface InstallerCallback {
|
public interface InstallerCallback {
|
||||||
|
|
||||||
public static final int OPERATION_GENERIC_ERROR = 0;
|
|
||||||
public static final int OPERATION_INSTALL = 1;
|
public static final int OPERATION_INSTALL = 1;
|
||||||
public static final int OPERATION_DELETE = 2;
|
public static final int OPERATION_DELETE = 2;
|
||||||
|
|
||||||
public void onSuccess(int operation, boolean unattended);
|
public void onSuccess(int operation, boolean unattended);
|
||||||
|
|
||||||
public void onError(int operation, boolean unattended, String reason);
|
public void onError(int operation, boolean unattended, String reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +186,18 @@ abstract public class Installer {
|
|||||||
// extended class now actually installs the package
|
// extended class now actually installs the package
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void installPackage(List<File> apkFiles) throws AndroidNotCompatibleException {
|
||||||
|
// check if files exist...
|
||||||
|
for (File apkFile : apkFiles) {
|
||||||
|
if (!apkFile.exists()) {
|
||||||
|
Log.d(TAG, "Couldn't find file " + apkFile + " to install.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// extended class now actually installs the package
|
||||||
|
}
|
||||||
|
|
||||||
public void deletePackage(String packageName) throws AndroidNotCompatibleException {
|
public void deletePackage(String packageName) throws AndroidNotCompatibleException {
|
||||||
// check if package exists before proceeding...
|
// check if package exists before proceeding...
|
||||||
try {
|
try {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package org.fdroid.fdroid.installer;
|
package org.fdroid.fdroid.installer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.chainfire.libsuperuser.Shell;
|
import eu.chainfire.libsuperuser.Shell;
|
||||||
@ -39,17 +40,21 @@ public class RootInstaller extends Installer {
|
|||||||
super(context, pm, callback);
|
super(context, pm, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Shell.Builder createShellBuilder() {
|
||||||
public void installPackage(final File apkFile) throws AndroidNotCompatibleException {
|
|
||||||
super.installPackage(apkFile);
|
|
||||||
|
|
||||||
Shell.Builder shellBuilder = new Shell.Builder()
|
Shell.Builder shellBuilder = new Shell.Builder()
|
||||||
.useSU()
|
.useSU()
|
||||||
.setWantSTDERR(true)
|
.setWantSTDERR(true)
|
||||||
.setWatchdogTimeout(5)
|
.setWatchdogTimeout(5)
|
||||||
.setMinimalLogging(true);
|
.setMinimalLogging(true);
|
||||||
|
|
||||||
rootSession = shellBuilder.open(new Shell.OnCommandResultListener() {
|
return shellBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installPackage(final File apkFile) throws AndroidNotCompatibleException {
|
||||||
|
super.installPackage(apkFile);
|
||||||
|
|
||||||
|
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
|
||||||
|
|
||||||
// Callback to report whether the shell was successfully
|
// Callback to report whether the shell was successfully
|
||||||
// started up
|
// started up
|
||||||
@ -63,11 +68,37 @@ public class RootInstaller extends Installer {
|
|||||||
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
|
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
mCallback.onError(InstallerCallback.OPERATION_GENERIC_ERROR, true,
|
mCallback.onError(InstallerCallback.OPERATION_INSTALL, true,
|
||||||
"Error opening root shell with exitCode " + exitCode);
|
"Error opening root shell with exitCode " + exitCode);
|
||||||
} else {
|
} else {
|
||||||
// Shell is up: send our first request
|
addInstallCommand(apkFile);
|
||||||
sendInstallCommand(apkFile);
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installPackage(final List<File> apkFiles) throws AndroidNotCompatibleException {
|
||||||
|
super.installPackage(apkFiles);
|
||||||
|
|
||||||
|
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
|
||||||
|
|
||||||
|
// Callback to report whether the shell was successfully
|
||||||
|
// started up
|
||||||
|
@Override
|
||||||
|
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
||||||
|
if (exitCode != Shell.OnCommandResultListener.SHELL_RUNNING) {
|
||||||
|
// TODO
|
||||||
|
// wrong uid
|
||||||
|
// Shell.OnCommandResultListener.SHELL_WRONG_UID
|
||||||
|
// exec failed
|
||||||
|
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
mCallback.onError(InstallerCallback.OPERATION_INSTALL, true,
|
||||||
|
"Error opening root shell with exitCode " + exitCode);
|
||||||
|
} else {
|
||||||
|
addInstallCommand(apkFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -77,13 +108,7 @@ public class RootInstaller extends Installer {
|
|||||||
public void deletePackage(final String packageName) throws AndroidNotCompatibleException {
|
public void deletePackage(final String packageName) throws AndroidNotCompatibleException {
|
||||||
super.deletePackage(packageName);
|
super.deletePackage(packageName);
|
||||||
|
|
||||||
Shell.Builder shellBuilder = new Shell.Builder()
|
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
|
||||||
.useSU()
|
|
||||||
.setWantSTDERR(true)
|
|
||||||
.setWatchdogTimeout(5)
|
|
||||||
.setMinimalLogging(true);
|
|
||||||
|
|
||||||
rootSession = shellBuilder.open(new Shell.OnCommandResultListener() {
|
|
||||||
|
|
||||||
// Callback to report whether the shell was successfully
|
// Callback to report whether the shell was successfully
|
||||||
// started up
|
// started up
|
||||||
@ -97,11 +122,10 @@ public class RootInstaller extends Installer {
|
|||||||
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
|
// Shell.OnCommandResultListener.SHELL_EXEC_FAILED
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
mCallback.onError(InstallerCallback.OPERATION_GENERIC_ERROR, true,
|
mCallback.onError(InstallerCallback.OPERATION_DELETE, true,
|
||||||
"Error opening root shell with exitCode " + exitCode);
|
"Error opening root shell with exitCode " + exitCode);
|
||||||
} else {
|
} else {
|
||||||
// Shell is up: send our first request
|
addDeleteCommand(packageName);
|
||||||
sendDeleteCommand(packageName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -114,7 +138,48 @@ public class RootInstaller extends Installer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendInstallCommand(File apkFile) {
|
private void addInstallCommand(List<File> apkFiles) {
|
||||||
|
ArrayList<String> commands = new ArrayList<String>();
|
||||||
|
String pm = "pm install -r ";
|
||||||
|
for (File apkFile : apkFiles) {
|
||||||
|
commands.add(pm + apkFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
rootSession.addCommand(commands, 0,
|
||||||
|
new Shell.OnCommandResultListener() {
|
||||||
|
public void onCommandResult(int commandCode, int exitCode,
|
||||||
|
List<String> output) {
|
||||||
|
// close su shell
|
||||||
|
rootSession.close();
|
||||||
|
|
||||||
|
if (exitCode < 0) {
|
||||||
|
// TODO
|
||||||
|
mCallback.onError(InstallerCallback.OPERATION_INSTALL, true,
|
||||||
|
"Install failed with exit code " + exitCode);
|
||||||
|
} else {
|
||||||
|
// wait until Android's internal PackageManger
|
||||||
|
// has received the new package state
|
||||||
|
Thread wait = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
mCallback.onSuccess(
|
||||||
|
InstallerCallback.OPERATION_INSTALL,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
wait.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addInstallCommand(File apkFile) {
|
||||||
rootSession.addCommand("pm install -r " + apkFile.getAbsolutePath(), 0,
|
rootSession.addCommand("pm install -r " + apkFile.getAbsolutePath(), 0,
|
||||||
new Shell.OnCommandResultListener() {
|
new Shell.OnCommandResultListener() {
|
||||||
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
||||||
@ -145,7 +210,7 @@ public class RootInstaller extends Installer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendDeleteCommand(String packageName) {
|
private void addDeleteCommand(String packageName) {
|
||||||
rootSession.addCommand("pm uninstall " + packageName, 0,
|
rootSession.addCommand("pm uninstall " + packageName, 0,
|
||||||
new Shell.OnCommandResultListener() {
|
new Shell.OnCommandResultListener() {
|
||||||
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
public void onCommandResult(int commandCode, int exitCode, List<String> output) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user