Skip to content

Commit 80c904d

Browse files
sganovAndroid Git Automerger
authored andcommitted
am 8631701: Allow enabled accessibility service to toggle tocuh exploration after an upgrade to JellyBean.
* commit '8631701bb770f3a4e3b2a139dc282f2244fe86e6': Allow enabled accessibility service to toggle tocuh exploration after an upgrade to JellyBean.
2 parents 91d08fe + 8631701 commit 80c904d

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed

packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
6565
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
6666
// is properly propagated through your change. Not doing so will result in a loss of user
6767
// settings.
68-
private static final int DATABASE_VERSION = 79;
68+
private static final int DATABASE_VERSION = 80;
6969

7070
private Context mContext;
7171

@@ -1073,6 +1073,52 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
10731073
upgradeVersion = 79;
10741074
}
10751075

1076+
if (upgradeVersion == 79) {
1077+
// Before touch exploration was a global setting controlled by the user
1078+
// via the UI. However, if the enabled accessibility services do not
1079+
// handle touch exploration mode, enabling it makes no sense. Therefore,
1080+
// now the services request touch exploration mode and the user is
1081+
// presented with a dialog to allow that and if she does we store that
1082+
// in the database. As a result of this change a user that has enabled
1083+
// accessibility, touch exploration, and some accessibility services
1084+
// may lose touch exploration state, thus rendering the device useless
1085+
// unless sighted help is provided, since the enabled service(s) are
1086+
// not in the list of services to which the user granted a permission
1087+
// to put the device in touch explore mode. Here we are allowing all
1088+
// enabled accessibility services to toggle touch exploration provided
1089+
// accessibility and touch exploration are enabled and no services can
1090+
// toggle touch exploration. Note that the user has already manually
1091+
// enabled the services and touch exploration which means the she has
1092+
// given consent to have these services work in touch exploration mode.
1093+
final boolean accessibilityEnabled = getIntValueFromTable(db, "secure",
1094+
Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
1095+
final boolean touchExplorationEnabled = getIntValueFromTable(db, "secure",
1096+
Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
1097+
if (accessibilityEnabled && touchExplorationEnabled) {
1098+
String enabledServices = getStringValueFromTable(db, "secure",
1099+
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");
1100+
String touchExplorationGrantedServices = getStringValueFromTable(db, "secure",
1101+
Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES, "");
1102+
if (TextUtils.isEmpty(touchExplorationGrantedServices)
1103+
&& !TextUtils.isEmpty(enabledServices)) {
1104+
SQLiteStatement stmt = null;
1105+
try {
1106+
db.beginTransaction();
1107+
stmt = db.compileStatement("INSERT OR REPLACE INTO secure(name,value)"
1108+
+ " VALUES(?,?);");
1109+
loadSetting(stmt,
1110+
Settings.Secure.TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES,
1111+
enabledServices);
1112+
db.setTransactionSuccessful();
1113+
} finally {
1114+
db.endTransaction();
1115+
if (stmt != null) stmt.close();
1116+
}
1117+
}
1118+
}
1119+
upgradeVersion = 80;
1120+
}
1121+
10761122
// *** Remember to update DATABASE_VERSION above!
10771123

10781124
if (upgradeVersion != currentVersion) {
@@ -1708,18 +1754,28 @@ private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, in
17081754
}
17091755

17101756
private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
1711-
int value = defaultValue;
1757+
return getIntValueFromTable(db, "system", name, defaultValue);
1758+
}
1759+
1760+
private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
1761+
int defaultValue) {
1762+
String value = getStringValueFromTable(db, table, name, null);
1763+
return (value != null) ? Integer.parseInt(value) : defaultValue;
1764+
}
1765+
1766+
private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
1767+
String defaultValue) {
17121768
Cursor c = null;
17131769
try {
1714-
c = db.query("system", new String[] { Settings.System.VALUE }, "name='" + name + "'",
1770+
c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
17151771
null, null, null, null);
17161772
if (c != null && c.moveToFirst()) {
17171773
String val = c.getString(0);
1718-
value = val == null ? defaultValue : Integer.parseInt(val);
1774+
return val == null ? defaultValue : val;
17191775
}
17201776
} finally {
17211777
if (c != null) c.close();
17221778
}
1723-
return value;
1779+
return defaultValue;
17241780
}
17251781
}

0 commit comments

Comments
 (0)