-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.termux.app; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
|
||
import com.termux.terminal.EmulatorDebug; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
public class ApkInstaller { | ||
static void installPackageApk(String packageName, Context context) { | ||
// FIXME: Different file names in case of multiple packages being installed at same time. | ||
new Thread() { | ||
@Override | ||
public void run() { | ||
try { | ||
String urlString = "https://termux.net/apks/" + packageName + ".apk"; | ||
Log.e(EmulatorDebug.LOG_TAG, "Installing " + packageName + ", url is " + urlString); | ||
File downloadFile = new File(Environment.getExternalStorageDirectory(), "tmp.apk"); | ||
URL url = new URL(urlString); | ||
try (FileOutputStream out = new FileOutputStream(downloadFile)) { | ||
try (InputStream in = url.openStream()) { | ||
byte[] buffer = new byte[8196]; | ||
int read; | ||
while ((read = in.read(buffer)) >= 0) { | ||
out.write(buffer, 0, read); | ||
} | ||
} | ||
} | ||
|
||
Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); | ||
installIntent.setData(Uri.parse("content://com.termux.files" + downloadFile.getAbsolutePath())); | ||
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
context.startActivity(installIntent); | ||
} catch (Exception e) { | ||
Log.e("termux", "Error installing " + packageName, e); | ||
} | ||
} | ||
}.start(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/data/data/com.termux/files/usr/bin/bash | ||
set -e -u | ||
|
||
show_help() { | ||
echo 'Usage: pkg command [arguments]' | ||
echo '' | ||
echo 'A tool for managing packages. Commands:' | ||
echo '' | ||
echo ' install <packages>' | ||
exit 1 | ||
} | ||
|
||
if [ $# = 0 ]; then | ||
show_help | ||
fi | ||
|
||
CMD="$1" | ||
shift 1 | ||
|
||
install_packages() { | ||
ALL_PACKAGES="$@" | ||
am startservice \ | ||
--user 0 \ | ||
--esa packages "${ALL_PACKAGES// /,}" \ | ||
-a com.termux.install_packages \ | ||
com.termux/com.termux.app.TermuxService \ | ||
> /dev/null | ||
} | ||
|
||
case "$CMD" in | ||
h*) show_help;; | ||
add|i*) install_packages "$@";; | ||
*) echo "Unknown command: '$CMD' (run 'pkg help' for usage information)"; exit 1;; | ||
esac |