Skip to content

Commit 8f09d27

Browse files
committed
Prompt user to enable root access
1 parent b52275c commit 8f09d27

File tree

2 files changed

+158
-2
lines changed

2 files changed

+158
-2
lines changed

src/android/os/SystemProperties.java

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (C) 2006 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.os;
18+
19+
20+
/**
21+
* Gives access to the system properties store. The system properties
22+
* store contains a list of string key-value pairs.
23+
*
24+
* {@hide}
25+
*/
26+
public class SystemProperties
27+
{
28+
public static final int PROP_NAME_MAX = 31;
29+
public static final int PROP_VALUE_MAX = 91;
30+
31+
private static native String native_get(String key);
32+
private static native String native_get(String key, String def);
33+
private static native int native_get_int(String key, int def);
34+
private static native long native_get_long(String key, long def);
35+
private static native boolean native_get_boolean(String key, boolean def);
36+
private static native void native_set(String key, String def);
37+
38+
/**
39+
* Get the value for the given key.
40+
* @return an empty string if the key isn't found
41+
* @throws IllegalArgumentException if the key exceeds 32 characters
42+
*/
43+
public static String get(String key) {
44+
if (key.length() > PROP_NAME_MAX) {
45+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
46+
}
47+
return native_get(key);
48+
}
49+
50+
/**
51+
* Get the value for the given key.
52+
* @return if the key isn't found, return def if it isn't null, or an empty string otherwise
53+
* @throws IllegalArgumentException if the key exceeds 32 characters
54+
*/
55+
public static String get(String key, String def) {
56+
if (key.length() > PROP_NAME_MAX) {
57+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
58+
}
59+
return native_get(key, def);
60+
}
61+
62+
/**
63+
* Get the value for the given key, and return as an integer.
64+
* @param key the key to lookup
65+
* @param def a default value to return
66+
* @return the key parsed as an integer, or def if the key isn't found or
67+
* cannot be parsed
68+
* @throws IllegalArgumentException if the key exceeds 32 characters
69+
*/
70+
public static int getInt(String key, int def) {
71+
if (key.length() > PROP_NAME_MAX) {
72+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
73+
}
74+
return native_get_int(key, def);
75+
}
76+
77+
/**
78+
* Get the value for the given key, and return as a long.
79+
* @param key the key to lookup
80+
* @param def a default value to return
81+
* @return the key parsed as a long, or def if the key isn't found or
82+
* cannot be parsed
83+
* @throws IllegalArgumentException if the key exceeds 32 characters
84+
*/
85+
public static long getLong(String key, long def) {
86+
if (key.length() > PROP_NAME_MAX) {
87+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
88+
}
89+
return native_get_long(key, def);
90+
}
91+
92+
/**
93+
* Get the value for the given key, returned as a boolean.
94+
* Values 'n', 'no', '0', 'false' or 'off' are considered false.
95+
* Values 'y', 'yes', '1', 'true' or 'on' are considered true.
96+
* (case sensitive).
97+
* If the key does not exist, or has any other value, then the default
98+
* result is returned.
99+
* @param key the key to lookup
100+
* @param def a default value to return
101+
* @return the key parsed as a boolean, or def if the key isn't found or is
102+
* not able to be parsed as a boolean.
103+
* @throws IllegalArgumentException if the key exceeds 32 characters
104+
*/
105+
public static boolean getBoolean(String key, boolean def) {
106+
if (key.length() > PROP_NAME_MAX) {
107+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
108+
}
109+
return native_get_boolean(key, def);
110+
}
111+
112+
/**
113+
* Set the value for the given key.
114+
* @throws IllegalArgumentException if the key exceeds 32 characters
115+
* @throws IllegalArgumentException if the value exceeds 92 characters
116+
*/
117+
public static void set(String key, String val) {
118+
if (key.length() > PROP_NAME_MAX) {
119+
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
120+
}
121+
if (val != null && val.length() > PROP_VALUE_MAX) {
122+
throw new IllegalArgumentException("val.length > " +
123+
PROP_VALUE_MAX);
124+
}
125+
native_set(key, val);
126+
}
127+
}

src/com/noshufou/android/su/HomeActivity.java

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import java.util.ArrayList;
44

5+
import android.app.AlertDialog;
56
import android.content.ComponentName;
67
import android.content.Context;
8+
import android.content.DialogInterface;
79
import android.content.Intent;
810
import android.content.SharedPreferences;
911
import android.graphics.drawable.Drawable;
1012
import android.graphics.drawable.TransitionDrawable;
1113
import android.net.Uri;
1214
import android.os.AsyncTask;
1315
import android.os.Bundle;
16+
import android.os.SystemProperties;
1417
import android.preference.PreferenceManager;
1518
import android.support.v4.app.Fragment;
1619
import android.support.v4.app.FragmentActivity;
@@ -19,7 +22,6 @@
1922
import android.support.v4.app.FragmentTransaction;
2023
import android.support.v4.view.ViewPager;
2124
import android.util.Log;
22-
import android.view.View;
2325
import android.widget.AbsListView;
2426

2527
import com.actionbarsherlock.app.SherlockFragmentActivity;
@@ -32,7 +34,7 @@
3234
import com.noshufou.android.su.widget.ChangeLog;
3335
import com.noshufou.android.su.widget.PagerHeader;
3436

35-
public class HomeActivity extends SherlockFragmentActivity {
37+
public class HomeActivity extends SherlockFragmentActivity implements DialogInterface.OnClickListener {
3638
private static final String TAG = "Su.HomeActivity";
3739

3840
private static final String STATE_SHOW_DETAILS = "show_details";
@@ -45,6 +47,9 @@ public class HomeActivity extends SherlockFragmentActivity {
4547
private MenuItem mOtaSurviveItem = null;
4648

4749
private ViewPager mPager;
50+
51+
private static final String CM_VERSION = SystemProperties.get("ro.cm.version", "");
52+
private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
4853

4954
@Override
5055
protected void onCreate(Bundle savedInstanceState) {
@@ -91,6 +96,30 @@ protected void onCreate(Bundle savedInstanceState) {
9196
if (cl.firstRun()) {
9297
cl.getLogDialog().show();
9398
}
99+
100+
// Check for root enabled on CyanogenMod 9
101+
if (CM_VERSION.length() > 0) {
102+
String root = SystemProperties.get(ROOT_ACCESS_PROPERTY, "1");
103+
// 0: off, 1: apps, 2:adb, 3:both
104+
if ("0".equals(root) || "2".equals(root)) {
105+
new AlertDialog.Builder(this).setMessage(R.string.root_disabled_summary)
106+
.setTitle(R.string.root_disabled_title)
107+
.setIcon(android.R.drawable.ic_dialog_alert)
108+
.setPositiveButton(android.R.string.yes, this)
109+
.setNegativeButton(android.R.string.no, this)
110+
.show();
111+
}
112+
}
113+
}
114+
115+
@Override
116+
public void onClick(DialogInterface dialog, int which) {
117+
if (which == DialogInterface.BUTTON_POSITIVE) {
118+
Intent settings = new Intent("android.settings.APPLICATION_DEVELOPMENT_SETTINGS");
119+
settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
120+
startActivity(settings);
121+
finish();
122+
}
94123
}
95124

96125
@Override

0 commit comments

Comments
 (0)