Skip to content

Commit 8631701

Browse files
committed
Allow enabled accessibility service to toggle tocuh exploration after an upgrade to JellyBean.
1. Before JellyBean touch exploration was a global setting controlled by the user via the UI. However, if the enabled accessibility services do not handle touch exploration mode, enabling it makes no sense. Therefore, in JellyBean the services request touch exploration mode and the user is presented with a dialog to allow that and if she does we store that in the database. As a result of the above change a user that has enabled accessibility, touch exploration, and some accessibility services running a pre-JellyBean system version may lose touch exploration state, thus rendering the device useless unless sighted help is provided, since the enabled service(s) are not in the list of services to which the user granted a permission to put the device in touch explore mode. The fix is during a database upgrade to allow allow all enabled accessibility services to toggle touch exploration provided accessibility and touch exploration are enabled and no services can toggle touch exploration. Note that the user has already manually enabled the services and touch exploration which means the she has given consent to have these services work in touch exploration mode bug:6996354 Change-Id: I0af2dc578cc4fbcc90043341035163b876978ab2
1 parent 2d9063b commit 8631701

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
@@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
6363
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
6464
// is properly propagated through your change. Not doing so will result in a loss of user
6565
// settings.
66-
private static final int DATABASE_VERSION = 79;
66+
private static final int DATABASE_VERSION = 80;
6767

6868
private Context mContext;
6969

@@ -1071,6 +1071,52 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
10711071
upgradeVersion = 79;
10721072
}
10731073

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

10761122
if (upgradeVersion != currentVersion) {
@@ -1700,18 +1746,28 @@ private void loadFractionSetting(SQLiteStatement stmt, String key, int resid, in
17001746
}
17011747

17021748
private int getIntValueFromSystem(SQLiteDatabase db, String name, int defaultValue) {
1703-
int value = defaultValue;
1749+
return getIntValueFromTable(db, "system", name, defaultValue);
1750+
}
1751+
1752+
private int getIntValueFromTable(SQLiteDatabase db, String table, String name,
1753+
int defaultValue) {
1754+
String value = getStringValueFromTable(db, table, name, null);
1755+
return (value != null) ? Integer.parseInt(value) : defaultValue;
1756+
}
1757+
1758+
private String getStringValueFromTable(SQLiteDatabase db, String table, String name,
1759+
String defaultValue) {
17041760
Cursor c = null;
17051761
try {
1706-
c = db.query("system", new String[] { Settings.System.VALUE }, "name='" + name + "'",
1762+
c = db.query(table, new String[] { Settings.System.VALUE }, "name='" + name + "'",
17071763
null, null, null, null);
17081764
if (c != null && c.moveToFirst()) {
17091765
String val = c.getString(0);
1710-
value = val == null ? defaultValue : Integer.parseInt(val);
1766+
return val == null ? defaultValue : val;
17111767
}
17121768
} finally {
17131769
if (c != null) c.close();
17141770
}
1715-
return value;
1771+
return defaultValue;
17161772
}
17171773
}

0 commit comments

Comments
 (0)