Android

From wiki.gpii
Jump to: navigation, search

Accessibility Service

What Is it?

An Accesibility Service runs in the background and receives callbacks by the system when AccessibilityEvents are fired. The accessibility events are sent by the system when something notable happens in the user interface. For example, when a Button is clicked or a View is focused. The Accessibility Service goal is to provide alternative or augmented feedback to the user.

Normally ATs are loaded into the system as accessibility services. This is the case of screen readers such as TalkBalk or Spiel, or applications that need to define specific accessibility features such as the accessible contact manager of the AEGIS project.

Enable Accessibility Service (ATs)

An Accessibility Service is integrated in an App, when you install the App in your device you can enable the Accessibility Service in Settings->Accessibility.

If you want enable the Accessibility Service automatically you will need a device with superUser permissions (root). Once your device is root you can activate the Accesibility Service through two ways:


Android API

To enabled Accesibility Service you should have your App like an Application System (put your .apk in system/app) and write in your Class:

<source lang="java"> String enableSer=Settings.Secure.getString(getActivity().getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (enableSer.contains("<AccessibilityService Name>")){ // check if the AccessibilityService is enabled //If is enabled we disable the AccessibilityService

               Settings.Secure.putInt(getActivity().getContentResolver(),Settings.Secure.ACCESSIBILITY_ENABLED, 0);//Disable Accessibility
               Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "");  //Clear the enabled accessibility service 

}else{ //If not is enabled we activate the AccessibilityService Service

              Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); // Enable accessibility
              Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                                        "<AccessibilityService Package>/<AccessibilityService Name>"); //Put the package name and the accesibility service
              Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); //Enable accessibility
   }


</source>

Moreover you should write in your AndroidManifest.xml the permissions :

<syntaxhighlight lang="xml">

   <uses-permission android:name="android.permission.WRITE_SETTINGS" />
   <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

</syntaxhighlight>

Modify settings.db

The file settings.db is in /data/data/com.android.providers.settings/databases/, in this file there is a table named Secure. You should use this sql sentence for enabled the accessibility service: <syntaxhighlight lang="sql">

 INSERT INTO Secure 
   (accessibility_enabled, 
    enabled_accessibility_services
 )VALUES
   ('1',
    '<AccessibilityService Package>/<AccessibilityService Name>'
 );

</syntaxhighlight>

Input Method

What Is it?

An input method is a user control that enables users to enter text. To add an IME to the Android system, you should create an Android application containing a class that extends InputMethodService.

In android, some ATs are loaded into the system as Input Method. Usually this ATs are software tools that facilitate switch access to electronic devices for people with mobility impairments. This is the case of Dasher or Tecla Access, developed both into the AEGIS project.


Enable Input Method

A Input Method is integrated in an App, when you install the App in your device you can enable and selected default Input Method in Settings->Language and Input. If you want make this automatically you will need a device with superUser permissions (root). Once your device is root you can modify the input Method selection through two ways:


Android API

To modify the Input Method configuration you should have your App like an Application System (put your .apk in system/app) and write in your Class:

<source lang="java">

       String defaultIn =Settings.Secure.getString(getActivity().getContentResolver(),Settings.Secure.DEFAULT_INPUT_METHOD); 

String enabledIn = Settings.Secure.getString(getActivity().getContentResolver(),Settings.Secure.ENABLED_INPUT_METHODS);


if(!enabledIn.contains("<Package name>/<IME class name>")){ //Check if the input method is enabled enabledIn= enabledIn + "<Package name>/<IME class name>"; Settings.Secure.putString(getActivity().getContentResolver(),Settings.Secure.ENABLED_INPUT_METHODS, enabledIn);//if not is enabled we put the new Input method

}

if(!defaultIn.contains("<Package name>/<IME class name>")){// Check which is the default input method

               Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD,"<Package name>/<IME class name>"); //Selected the default Input Method

}


</source>

Moreover you should write in your AndroidManifest.xml the permissions :

<syntaxhighlight lang="xml">

   <uses-permission android:name="android.permission.WRITE_SETTINGS" />
   <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

</syntaxhighlight>

Modify settings.db

The file settings.db is in /data/data/com.android.providers.settings/databases/, in this file there is a table named Secure. You should use this sql sentence for select default Input Method: <syntaxhighlight lang="sql">

 INSERT INTO Secure 
   (default_input_method, 
    enabled_Input_methods
 )VALUES
   ('<Package name>/<IME class name>',
    '<Package name>/<IME class name>'
 );

</syntaxhighlight>


If you only make one of this process your mobile will be customize whit your chosen input method, but your device maybe be jam using System Settings App. To solver this problem you should to modify the xml file /data/data/com.android.settings/shared_prefs/com.android.settings_preferences.xml. This file is the Shared Preferences of Settings System App: <syntaxhighlight lang="xml">

   <?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<map>

<boolean value="true" name="sound_effects"/>
<boolean value="true" name="vibrate_on_ring"/>
<boolean value="false" name="ca.idi.tekla/.ime.TeclaIME"/>
<boolean value="true" name="24 hour"/>
<boolean value="true" name="com.sec.android.inputmethod.axt9/.AxT9IME"/>
<boolean value="true" name="allow_mock_location"/>
<boolean value="true" name="haptic_feedback"/>
<boolean value="false" name="com.google.android.voicesearch/.ime.VoiceInputMethodService"/>
<string name="recognizer">com.google.android.voicesearch/.GoogleRecognitionService</string>
<boolean value="true" name="show_all_anrs"/>
<boolean value="false" name="pref_siop_clock"/>
<boolean value="false" name="pref_siop_rendering"/>
<string name="date_format">dd-MM-yyyy</string>
<boolean value="true" name="lock_sounds"/> 

<boolean value="true" name="com.swype.android.inputmethod/.SwypeInputMethod"/>

<boolean value="true" name="enable_adb"/>
<boolean value="false" name="pref_siop_brightness"/>
<string name="silent_mode">off</string>
<boolean value="true" name="dtmf_tone"/>
<boolean value="true" name="pref_device_provision"/>

</map> </syntaxhighlight>

You should add a boolean field with name value "<Package name>/<IME class name>".



Note: Be careful with the file permissions, after to modify the files you should introduce the shell:

    comand: chmod 777 <file name>

Related Pages and Useful Links

Back to Android Overview