Skip to content

Commit

Permalink
Settings: Add Superuser entry
Browse files Browse the repository at this point in the history
Amended for r-x86 porting by electrikjesus.

Squashed commit of the following:

Author: Koushik Dutta <[email protected]>
Switch to new Superuser
Change-Id: I9d91392ad6fbc9953d19059ab59b91d214c00e0c

Author: Danny Baumann <[email protected]>
Hide Superuser entry if root access for apps is disabled.
Change-Id: Ibb77ba5a0fccf22564a26b8b1e13f7762c65718e

Author: Ricardo Cerqueira <[email protected]>
Development: Root for apps is unavailable if the su daemon isn't running

The superuser options are tied to the Superuser app variant we use,
which in turn is tied to the su daemon. No daemon, no menu options.
Change-Id: I41d58e62986759336ab38e67f26a558c2eed5aa3

Change-Id: I9d91392ad6fbc9953d19059ab59b91d214c00e0c
Conflicts:
	Android.bp
	AndroidManifest.xml
	res/xml/development_settings.xml
	src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
  • Loading branch information
koush authored and hmtheboy154 committed Aug 18, 2021
1 parent 36278d1 commit 4a4de01
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ android_library {

srcs: ["src/**/*.java",
"SakuraSettings/src/**/*.java",
"koush/Widgets/Widgets/src/**/*.java",
"koush/Superuser/Superuser/src/**/*.java",
"src/com/android/settings/cyanogenmod/superuser/*.java",
],

aaptflags: ["--extra-packages com.sakura.settings"],
aaptflags: ["--extra-packages com.sakura.settings",
"--extra-packages com.koushikdutta.superuser",
"--extra-packages com.koushikdutta.widgets",
],

resource_dirs: ["res",
"SakuraSettings/res"
"SakuraSettings/res",
"koush/Widgets/WidgetsSample/res",
"koush/Widgets/Widgets/res",
"koush/Superuser/Superuser/res",
],

static_libs: [
Expand Down
89 changes: 89 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@
<uses-permission android:name="android.permission.READ_DREAM_STATE" />
<uses-permission android:name="android.permission.READ_DREAM_SUPPRESSION" />


<permission
android:name="android.permission.REQUEST_SUPERUSER"
android:protectionLevel="signature" />

<permission
android:name="android.permission.REPORT_SUPERUSER"
android:protectionLevel="signature" />

<permission-group
android:name="android.permission-group.SUPERUSER"
android:description="@string/superuser_description_more"
android:icon="@drawable/ic_action_permission"
android:label="@string/superuser"
android:priority="10000" />

<permission
android:name="android.permission.ACCESS_SUPERUSER"
android:description="@string/superuser_description_more"
android:icon="@drawable/ic_action_permission"
android:label="@string/superuser_description"
android:logo="@drawable/ic_action_permission"
android:permissionGroup="android.permission-group.SUPERUSER"
android:protectionLevel="dangerous" />

<application android:label="@string/settings_label"
android:icon="@mipmap/ic_launcher"
android:theme="@style/Theme.Settings"
Expand All @@ -122,6 +147,48 @@
android:appComponentFactory="androidx.core.app.CoreComponentFactory">

<uses-library android:name="org.apache.http.legacy" />

<!-- Only system/su can open this activity -->
<!-- This activity will then call the MultitaskSuRequestActivity to create a new task stack -->
<activity
android:name=".cyanogenmod.superuser.RequestActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/superuser"
android:launchMode="singleTask"
android:excludeFromRecents="true"
android:permission="android.permission.REQUEST_SUPERUSER"
android:process=":superuser"
android:taskAffinity="com.android.settings.superuser"
android:theme="@style/RequestThemeDark" />
<!-- Only system/su can open this activity -->
<!-- This is activity is started in multiuser mode when the user invoking su -->
<!-- is not the device owner (user id 0). -->
<activity
android:name=".cyanogenmod.superuser.NotifyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/superuser"
android:launchMode="singleTask"
android:excludeFromRecents="true"
android:permission="android.permission.REQUEST_SUPERUSER"
android:process=":superuser"
android:taskAffinity="com.android.settings.superuser"
android:theme="@style/RequestThemeDark" />

<!-- Multiple instances of this activity can be running for multiple su requests -->
<activity
android:name=".cyanogenmod.superuser.MultitaskSuRequestActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:excludeFromRecents="true"
android:exported="false"
android:label="@string/request"
android:process=":superuser"
android:taskAffinity="com.android.settings.superuser"
android:theme="@style/RequestThemeDark" />

<receiver
android:name=".cyanogenmod.superuser.SuReceiver"
android:permission="android.permission.REPORT_SUPERUSER" />

<!-- Settings -->

<activity android:name=".homepage.SettingsHomepageActivity"
Expand Down Expand Up @@ -2003,6 +2070,28 @@
android:value="com.android.settings.print.PrintJobSettingsFragment" />
</activity>

<activity android:name="Settings$SuperuserActivity"
android:label="@string/superuser"
android:icon="@drawable/ic_action_permission"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings$AccountDashboardActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="3">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.summary"
android:resource="@string/superuser_description"/>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.accounts" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.cyanogenmod.superuser.PolicyNativeFragment" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>

<activity android:name=".development.AppPicker"
android:label="@string/select_application" />

Expand Down
1 change: 1 addition & 0 deletions koush
2 changes: 2 additions & 0 deletions proguard.flags
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

# Keep all Fragments in this package, which are used by reflection.
-keep public class com.android.settings.** extends androidx.fragment.app.Fragment
-keep public class com.android.settings.cyanogenmod.superuser.**
-keep public class com.koushikdutta.**

# Keep all preference controllers needed by slice and DashboardFragment.
-keep class * extends com.android.settings.core.BasePreferenceController {
Expand Down
1 change: 1 addition & 0 deletions src/com/android/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static class TrustedCredentialsSettingsActivity extends SettingsActivity
public static class PaymentSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrintSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
public static class SuperuserActivity extends SettingsActivity { /* empty */ }
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeBehaviorSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeBlockedEffectsSettingsActivity extends SettingsActivity { /* empty */ }
Expand Down
6 changes: 6 additions & 0 deletions src/com/android/settings/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.gateway.SettingsGateway;
import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.development.RootAccessPreferenceController;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wfd.WifiDisplaySettings;
Expand Down Expand Up @@ -639,6 +640,11 @@ private void doUpdateTilesList() {
&& !Utils.isMonkeyRunning(), isAdmin)
|| somethingChanged;

somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Settings.SuperuserActivity.class.getName()),
RootAccessPreferenceController.isRootForAppsEnabled(), isAdmin)
|| somethingChanged;

final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
&& !Utils.isMonkeyRunning();
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Expand Down
2 changes: 2 additions & 0 deletions src/com/android/settings/core/gateway/SettingsGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
import com.android.settings.cyanogenmod.superuser.PolicyNativeFragment;
import com.android.settings.datausage.DataSaverSummary;
import com.android.settings.datausage.DataUsageList;
import com.android.settings.datausage.DataUsageSummary;
Expand Down Expand Up @@ -244,6 +245,7 @@ public class SettingsGateway {
ZenAccessSettings.class.getName(),
ZenAccessDetails.class.getName(),
ZenModeAutomationSettings.class.getName(),
PolicyNativeFragment.class.getName(),
PrintSettingsFragment.class.getName(),
PrintJobSettingsFragment.class.getName(),
TrustedCredentialsSettings.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.android.settings.cyanogenmod.superuser;

public class MultitaskSuRequestActivity extends com.koushikdutta.superuser.MultitaskSuRequestActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.android.settings.cyanogenmod.superuser;

public class NotifyActivity extends com.koushikdutta.superuser.NotifyActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.android.settings.cyanogenmod.superuser;

public class PolicyNativeFragment extends com.koushikdutta.superuser.PolicyNativeFragment {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.android.settings.cyanogenmod.superuser;

public class RequestActivity extends com.koushikdutta.superuser.RequestActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.android.settings.cyanogenmod.superuser;

public class SuReceiver extends com.koushikdutta.superuser.SuReceiver {
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public void onRootAccessDialogDismissed() {
updatePreference();
}

public static boolean isRootForAppsEnabled() {
int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 0);
boolean daemonState =
SystemProperties.get("init.svc.su_daemon", "absent").equals("running");
return daemonState && (value == 1 || value == 3);
}

private void writeRootAccessOptions(Object newValue) {
String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
Expand Down

0 comments on commit 4a4de01

Please sign in to comment.