这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit f2c1342

Browse files
Added: Add launcher icon/activity
This must not be allowed to be disabled since there is no other way to start Termux:API app again if it crashes multiple times and gets marked as bad process by android. This is also required to bypass OEM battery restrictions like DuraSpeed. This also easily allows users to know if the app is installed or not. Related issue termux/termux-widget#56 Related issue #447
1 parent c3befab commit f2c1342

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@
6565
android:theme="@android:style/Theme.Material.Light"
6666
tools:ignore="GoogleAppIndexingWarning">
6767

68+
<activity
69+
android:name=".activities.TermuxAPIActivity"
70+
android:theme="@style/Theme.BaseActivity.DayNight.NoActionBar"
71+
android:exported="true">
72+
<intent-filter>
73+
<action android:name="android.intent.action.MAIN"/>
74+
<category android:name="android.intent.category.LAUNCHER"/>
75+
</intent-filter>
76+
</activity>
77+
6878
<activity android:name=".activities.TermuxApiPermissionActivity"
6979
android:theme="@android:style/Theme.NoDisplay"
7080
android:noHistory="true"
@@ -108,6 +118,14 @@
108118
android:excludeFromRecents="true"
109119
android:exported="false" />
110120

121+
<!-- If you see "Unresolved package" errors for ReportActivity with manifest placeholder,
122+
ignore it. Android Studio linter is broken and correct package name will be used at build time." -->
123+
<activity
124+
android:name="${TERMUX_PACKAGE_NAME}.shared.activities.ReportActivity"
125+
android:theme="@style/Theme.MarkdownViewActivity.DayNight"
126+
android:documentLaunchMode="intoExisting"
127+
tools:ignore="MissingClass" />
128+
111129

112130

113131
<provider
@@ -122,6 +140,12 @@
122140
<receiver android:name=".TermuxApiReceiver"
123141
android:exported="false" />
124142

143+
<receiver
144+
android:name=".shared.activities.ReportActivity$ReportActivityBroadcastReceiver"
145+
android:exported="false"
146+
tools:ignore="MissingClass" />
147+
148+
125149

126150

127151
<service
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.termux.api.activities;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.os.Environment;
6+
import android.view.Menu;
7+
import android.view.MenuItem;
8+
import android.widget.TextView;
9+
10+
import androidx.appcompat.app.AppCompatActivity;
11+
12+
import com.termux.shared.activities.ReportActivity;
13+
import com.termux.shared.activity.ActivityUtils;
14+
import com.termux.shared.activity.media.AppCompatActivityUtils;
15+
import com.termux.shared.android.AndroidUtils;
16+
import com.termux.shared.file.FileUtils;
17+
import com.termux.shared.logger.Logger;
18+
import com.termux.shared.models.ReportInfo;
19+
import com.termux.shared.termux.TermuxConstants;
20+
import com.termux.shared.termux.TermuxUtils;
21+
import com.termux.shared.termux.theme.TermuxThemeUtils;
22+
import com.termux.shared.theme.NightMode;
23+
import com.termux.api.R;
24+
25+
public class TermuxAPIActivity extends AppCompatActivity {
26+
27+
private static final String LOG_TAG = "TermuxAPIActivity";
28+
29+
@Override
30+
protected void onCreate(Bundle savedInstanceState) {
31+
Logger.logDebug(LOG_TAG, "onCreate");
32+
33+
super.onCreate(savedInstanceState);
34+
setContentView(R.layout.activity_termux_api);
35+
36+
// Set NightMode.APP_NIGHT_MODE
37+
TermuxThemeUtils.setAppNightMode(this);
38+
AppCompatActivityUtils.setNightMode(this, NightMode.getAppNightMode().getName(), true);
39+
40+
AppCompatActivityUtils.setToolbar(this, R.id.toolbar);
41+
AppCompatActivityUtils.setToolbarTitle(this, R.id.toolbar, TermuxConstants.TERMUX_API_APP_NAME, 0);
42+
43+
TextView pluginInfo = findViewById(R.id.textview_plugin_info);
44+
pluginInfo.setText(getString(R.string.plugin_info, TermuxConstants.TERMUX_GITHUB_REPO_URL,
45+
TermuxConstants.TERMUX_API_GITHUB_REPO_URL, TermuxConstants.TERMUX_API_APT_PACKAGE_NAME,
46+
TermuxConstants.TERMUX_API_APT_GITHUB_REPO_URL));
47+
}
48+
49+
50+
@Override
51+
public boolean onCreateOptionsMenu(Menu menu) {
52+
super.onCreateOptionsMenu(menu);
53+
getMenuInflater().inflate(R.menu.activity_termux_api, menu);
54+
return true;
55+
}
56+
57+
@Override
58+
public boolean onOptionsItemSelected(MenuItem item) {
59+
int id = item.getItemId();
60+
61+
if (id == R.id.menu_info) {
62+
showInfo();
63+
return true;
64+
} else if (id == R.id.menu_settings) {
65+
openSettings();
66+
return true;
67+
}
68+
69+
return super.onOptionsItemSelected(item);
70+
}
71+
72+
private void showInfo() {
73+
new Thread() {
74+
@Override
75+
public void run() {
76+
String title = "About";
77+
78+
StringBuilder aboutString = new StringBuilder();
79+
aboutString.append(TermuxUtils.getAppInfoMarkdownString(TermuxAPIActivity.this, TermuxUtils.AppInfoMode.TERMUX_AND_PLUGIN_PACKAGE));
80+
aboutString.append("\n\n").append(AndroidUtils.getDeviceInfoMarkdownString(TermuxAPIActivity.this));
81+
aboutString.append("\n\n").append(TermuxUtils.getImportantLinksMarkdownString(TermuxAPIActivity.this));
82+
83+
ReportInfo reportInfo = new ReportInfo(title,
84+
TermuxConstants.TERMUX_APP.TERMUX_SETTINGS_ACTIVITY_NAME, title);
85+
reportInfo.setReportString(aboutString.toString());
86+
reportInfo.setReportSaveFileLabelAndPath(title,
87+
Environment.getExternalStorageDirectory() + "/" +
88+
FileUtils.sanitizeFileName(TermuxConstants.TERMUX_APP_NAME + "-" + title + ".log", true, true));
89+
90+
ReportActivity.startReportActivity(TermuxAPIActivity.this, reportInfo);
91+
}
92+
}.start();
93+
}
94+
95+
private void openSettings() {
96+
ActivityUtils.startActivity(this, new Intent().setClassName(TermuxConstants.TERMUX_PACKAGE_NAME, TermuxConstants.TERMUX_APP.TERMUX_SETTINGS_ACTIVITY_NAME));
97+
}
98+
99+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<include
8+
layout="@layout/partial_primary_toolbar"
9+
android:id="@+id/partial_primary_toolbar"/>
10+
11+
<ScrollView
12+
xmlns:tools="http://schemas.android.com/tools"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent" >
15+
<LinearLayout
16+
android:orientation="vertical"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:paddingTop="@dimen/activity_vertical_margin"
20+
android:paddingBottom="@dimen/activity_vertical_margin"
21+
android:paddingLeft="@dimen/activity_horizontal_margin"
22+
android:paddingRight="@dimen/activity_horizontal_margin"
23+
tools:context=".activities.TermuxAPIActivity">
24+
25+
<com.google.android.material.textview.MaterialTextView
26+
android:id="@+id/textview_plugin_info"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:paddingTop="@dimen/activity_vertical_margin"
30+
android:paddingBottom="@dimen/activity_vertical_margin"
31+
android:gravity="start|center_vertical"
32+
android:textSize="14sp"
33+
android:textStyle="normal"
34+
android:textColor="?android:textColorPrimary"
35+
android:textColorLink="?android:textColorLink"
36+
android:autoLink="web"/>
37+
</LinearLayout>
38+
39+
</ScrollView>
40+
</LinearLayout>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
tools:ignore="UnusedResources" >
7+
8+
<item
9+
android:id="@+id/menu_info"
10+
android:icon="@drawable/ic_info"
11+
android:title="@string/action_info"
12+
app:showAsAction="ifRoom" />
13+
14+
<item
15+
android:id="@+id/menu_settings"
16+
android:icon="@drawable/ic_settings"
17+
android:title="@string/action_settings"
18+
app:showAsAction="ifRoom" />
19+
20+
</menu>

app/src/main/res/values/strings.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,23 @@
1313
<string name="grant_permission">Grant permission</string>
1414
<string name="keep_alive_service">This service keeps Termux:API running in the background for faster startup of termux-* commands.</string>
1515
<string name="permission_description">This app needs the following permission(s):\n</string>
16+
17+
<string name="plugin_info">&TERMUX_API_APP_NAME; is a plugin app for the &TERMUX_APP_NAME; app
18+
that executes termux-api package commands.
19+
Check &TERMUX_APP_NAME; app github %1$s, &TERMUX_API_APP_NAME; app github %2$s and
20+
%3$s package github %4$s for more info.
21+
22+
\n\nThe &TERMUX_API_APP_NAME; app requires `%3$s` apt package to function.
23+
Run `pkg install %3$s` to install it.
24+
25+
\n\nNote that if &TERMUX_API_APP_NAME; app crashes too many times, then android will mark the
26+
app as a bad process and you will need to manually start this activity again once for the
27+
api commands to start working again, otherwise the commands will hang.
28+
29+
\n\nReports for some crashes may be shown when you restart &TERMUX_APP_NAME; app.</string>
30+
31+
32+
<string name="action_info">Info</string>
33+
<string name="action_settings">Settings</string>
34+
1635
</resources>

0 commit comments

Comments
 (0)