2020
2121import android .app .ActivityManagerNative ;
2222import android .app .IActivityManager ;
23- import android .app .backup .BackupDataInput ;
2423import android .app .backup .IBackupManager ;
25- import android .content .ContentResolver ;
2624import android .content .Context ;
27- import android .content .IContentService ;
2825import android .content .res .Configuration ;
2926import android .location .LocationManager ;
3027import android .media .AudioManager ;
3330import android .os .ServiceManager ;
3431import android .provider .Settings ;
3532import android .text .TextUtils ;
36- import android .util .Log ;
3733
3834public class SettingsHelper {
39- private static final String TAG = "SettingsHelper" ;
40-
4135 private Context mContext ;
4236 private AudioManager mAudioManager ;
43- private IContentService mContentService ;
44- private IPowerManager mPowerManager ;
4537
4638 public SettingsHelper (Context context ) {
4739 mContext = context ;
4840 mAudioManager = (AudioManager ) context
4941 .getSystemService (Context .AUDIO_SERVICE );
50- mContentService = ContentResolver .getContentService ();
51- mPowerManager = IPowerManager .Stub .asInterface (
52- ServiceManager .getService ("power" ));
5342 }
5443
5544 /**
@@ -71,10 +60,31 @@ public boolean restoreValue(String name, String value) {
7160 return false ;
7261 } else if (Settings .Secure .BACKUP_AUTO_RESTORE .equals (name )) {
7362 setAutoRestore (Integer .parseInt (value ) == 1 );
63+ } else if (isAlreadyConfiguredCriticalAccessibilitySetting (name )) {
64+ return false ;
7465 }
7566 return true ;
7667 }
7768
69+ private boolean isAlreadyConfiguredCriticalAccessibilitySetting (String name ) {
70+ // These are the critical accessibility settings that are required for a
71+ // blind user to be able to interact with the device. If these settings are
72+ // already configured, we will not overwrite them. If they are already set,
73+ // it means that the user has performed a global gesture to enable accessibility
74+ // and definitely needs these features working after the restore.
75+ if (Settings .Secure .ACCESSIBILITY_ENABLED .equals (name )
76+ || Settings .Secure .ACCESSIBILITY_SCRIPT_INJECTION .equals (name )
77+ || Settings .Secure .ACCESSIBILITY_SPEAK_PASSWORD .equals (name )
78+ || Settings .Secure .TOUCH_EXPLORATION_ENABLED .equals (name )) {
79+ return Settings .Secure .getInt (mContext .getContentResolver (), name , 0 ) != 0 ;
80+ } else if (Settings .Secure .TOUCH_EXPLORATION_GRANTED_ACCESSIBILITY_SERVICES .equals (name )
81+ || Settings .Secure .ENABLED_ACCESSIBILITY_SERVICES .equals (name )) {
82+ return !TextUtils .isEmpty (Settings .Secure .getString (
83+ mContext .getContentResolver (), name ));
84+ }
85+ return false ;
86+ }
87+
7888 private void setAutoRestore (boolean enabled ) {
7989 try {
8090 IBackupManager bm = IBackupManager .Stub .asInterface (
0 commit comments