summaryrefslogtreecommitdiffstats
path: root/Settings
diff options
context:
space:
mode:
authordhacker29 <dhackerdvm@gmail.com>2015-04-30 02:56:19 -0400
committerdhacker29 <dhackerdvm@gmail.com>2015-11-07 23:06:38 -0500
commit02c31385c0e89d77250be17cd2b9f925cd455aa7 (patch)
treed8808344d9c99011a03c753be76b691028f7b8e8 /Settings
parentdeae7e4cc590da4714896808fbbc6b1798f4724f (diff)
downloadandroid_packages_apps_TvSettings-02c31385c0e89d77250be17cd2b9f925cd455aa7.tar.gz
android_packages_apps_TvSettings-02c31385c0e89d77250be17cd2b9f925cd455aa7.tar.bz2
android_packages_apps_TvSettings-02c31385c0e89d77250be17cd2b9f925cd455aa7.zip
Developer Settings: Enable Local Terminal
Change-Id: I7926e14617eb7dcf8bc02a91a2244db040420052
Diffstat (limited to 'Settings')
-rw-r--r--Settings/res/values/cm_strings.xml4
-rw-r--r--Settings/src/com/android/tv/settings/system/DeveloperOptionsActivity.java63
2 files changed, 67 insertions, 0 deletions
diff --git a/Settings/res/values/cm_strings.xml b/Settings/res/values/cm_strings.xml
index ef6da330..2e8f624b 100644
--- a/Settings/res/values/cm_strings.xml
+++ b/Settings/res/values/cm_strings.xml
@@ -59,4 +59,8 @@
<string name="root_access_apps">Apps only</string>
<string name="root_access_adb">ADB only</string>
<string name="root_access_all">Apps and ADB</string>
+
+ <!-- Setting that enables the terminal app. [CHAR LIMIT=32] -->
+ <string name="enable_terminal_title">Local terminal</string>
+ <string name="enable_terminal_summary">Enable terminal app that offers local shell access</string>
</resources>
diff --git a/Settings/src/com/android/tv/settings/system/DeveloperOptionsActivity.java b/Settings/src/com/android/tv/settings/system/DeveloperOptionsActivity.java
index 3c29c15b..75e51d27 100644
--- a/Settings/src/com/android/tv/settings/system/DeveloperOptionsActivity.java
+++ b/Settings/src/com/android/tv/settings/system/DeveloperOptionsActivity.java
@@ -24,6 +24,10 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PackageInfo;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.net.wifi.WifiManager;
import android.os.Build;
@@ -70,6 +74,7 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
private static final String ADB_ROOT_PROPERTY = "service.adb.root";
private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
private static String setting = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
+ private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
private static final int ACTION_BASE_MASK = -1 << 20;
@@ -160,6 +165,8 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
private static final int ACTION_ROOT_ACCESS_APPS = ACTION_CM_BASE + 1;
private static final int ACTION_ROOT_ACCESS_ADB = ACTION_CM_BASE + 2;
private static final int ACTION_ROOT_ACCESS_ALL = ACTION_CM_BASE + 3;
+ private static final int ACTION_ENABLE_TERMINAL_ON = ACTION_CM_BASE + 4;
+ private static final int ACTION_ENABLE_TERMINAL_OFF = ACTION_CM_BASE + 5;
private IWindowManager mWindowManager;
private WifiManager mWifiManager;
@@ -590,6 +597,9 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
private Layout.Header getCmHeader() {
final Resources res = getResources();
+ final String onTitle = getString(R.string.action_on_description);
+ final String offTitle = getString(R.string.action_off_description);
+
final Layout.Header header = new Layout.Header.Builder(res)
.title(R.string.system_cm)
.build();
@@ -611,6 +621,17 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
.select(getRootAccessId())
.build()));
}
+ if (isPackageInstalled(this, TERMINAL_APP_PACKAGE)) {
+ header.add(new Layout.Header.Builder(res)
+ .title(R.string.enable_terminal_title)
+ .detailedDescription(R.string.enable_terminal_summary)
+ .build()
+ .setSelectionGroup(new Layout.SelectionGroup.Builder(2)
+ .add(onTitle, null, ACTION_ENABLE_TERMINAL_ON)
+ .add(offTitle, null, ACTION_ENABLE_TERMINAL_OFF)
+ .select(getEnableTerminalId())
+ .build()));
+ }
return header;
}
@@ -859,6 +880,12 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
case ACTION_ROOT_ACCESS_ALL:
setRootAccessByAction(id);
break;
+ case ACTION_ENABLE_TERMINAL_ON:
+ setEnableTerminal(true);
+ break;
+ case ACTION_ENABLE_TERMINAL_OFF:
+ setEnableTerminal(false);
+ break;
}
}
@@ -1414,6 +1441,42 @@ public class DeveloperOptionsActivity extends SettingsLayoutActivity {
.show();
}
+ /**
+ * Enable Terminal app.
+ */
+ private int getEnableTerminalId() {
+ final PackageManager pm = this.getPackageManager();
+ return pm.getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
+ == PackageManager.COMPONENT_ENABLED_STATE_ENABLED ?
+ ACTION_ENABLE_TERMINAL_ON : ACTION_ENABLE_TERMINAL_OFF;
+ }
+
+ private void setEnableTerminal(boolean value) {
+ final PackageManager pm = this.getPackageManager();
+ pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
+ value ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
+ }
+
+ public static boolean isPackageInstalled(Context context, String pkg, boolean ignoreState) {
+ if (pkg != null) {
+ try {
+ PackageInfo pi = context.getPackageManager().getPackageInfo(pkg, 0);
+ if (!pi.applicationInfo.enabled && !ignoreState) {
+ return false;
+ }
+ } catch (NameNotFoundException e) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean isPackageInstalled(Context context, String pkg) {
+ return isPackageInstalled(context, pkg, true);
+ }
+
private void tryReboot() {
new AlertDialog.Builder(this)
.setTitle(R.string.system_reboot_confirm)