Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Replace the mass of intent actions with a single action and a string …
Browse files Browse the repository at this point in the history
…extra

- instead of 2 actions per service, replaced with a single action that should be accompanied by a
extras: the service name (as written in the service enum) for the key and "enabled" or "disabled" as the value
- this lets the user specify a combination of 1 or more services with one command
- if the user specifies the same service in the same command, it'll still work, but will settle on the last value
  • Loading branch information
ataulm committed Jan 25, 2018
1 parent f124c8d commit 0a17e6e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 128 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ You can run the demo tests with the following command:
```bash
./gradlew demo:installDebug;\
adb shell pm grant com.novoda.movies android.permission.WRITE_SECURE_SETTINGS;\
adb shell am start -a "com.novoda.espresso.DISABLE_TALKBACK";\
adb shell am start -a com.novoda.espresso.SET_SERVICE -e talkback disabled -e select_to_speak disabled -e switch_access disabled;\
./gradlew demo:cAT;
```

1. First the app is installed
2. The `WRITE_SECURE_SETTINGS` permission is set for the app (`com.novoda.movies` - replace this with your app's package name)
3. Disable TalkBack (does nothing if it wasn't running)
3. Disable all the services initially
4. Run all the connected Android tests

## Links
Expand Down

This file was deleted.

8 changes: 5 additions & 3 deletions core/src/main/java/com/novoda/espresso/TalkBackTestRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.support.test.InstrumentationRegistry;
import android.view.accessibility.AccessibilityManager;

import com.novoda.espresso.AccessibilityServiceToggler.Service;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
Expand All @@ -24,7 +26,7 @@ private static class TalkBackStatement extends Statement {
private static final int MAX_RETRIES_TO_WAIT_FOR_TALK_BACK = 15;

private final Statement baseStatement;
private final TalkBackStateSettingRequester talkBackStateSettingRequester = new TalkBackStateSettingRequester(0);
private final AccessibilityServiceToggler serviceToggler = AccessibilityServiceToggler.create(InstrumentationRegistry.getTargetContext().getContentResolver());
private final AccessibilityManager a11yManager = (AccessibilityManager) InstrumentationRegistry.getInstrumentation().getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);

TalkBackStatement(Statement baseStatement) {
Expand All @@ -33,12 +35,12 @@ private static class TalkBackStatement extends Statement {

@Override
public void evaluate() throws Throwable {
talkBackStateSettingRequester.requestEnableTalkBack();
serviceToggler.enable(Service.TALKBACK);
sleepUntil(talkBackIsEnabled());

baseStatement.evaluate();

talkBackStateSettingRequester.requestDisableTalkBack();
serviceToggler.disable(Service.TALKBACK);
sleepUntil(talkBackIsDisabled());
}

Expand Down
4 changes: 4 additions & 0 deletions extras/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ android {
}
}

dependencies {
compile libraries.supportAnnotations
}

publish {
userOrg = artifactsPublish.userOrg
groupId = artifactsPublish.groupId
Expand Down
27 changes: 1 addition & 26 deletions extras/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,7 @@
<activity android:name=".AccessibilityServiceTogglingActivity">

<intent-filter>
<action android:name="com.novoda.espresso.ENABLE_TALKBACK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="com.novoda.espresso.DISABLE_TALKBACK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="com.novoda.espresso.ENABLE_SWITCH_ACCESS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="com.novoda.espresso.DISABLE_SWITCH_ACCESS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="com.novoda.espresso.ENABLE_SELECT_TO_SPEAK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="com.novoda.espresso.DISABLE_SELECT_TO_SPEAK" />
<action android:name="com.novoda.espresso.SET_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,38 @@

import com.novoda.espresso.AccessibilityServiceToggler.Service;

import java.util.Locale;

public class AccessibilityServiceTogglingActivity extends Activity {

public static final String ACTION_ENABLE_TALKBACK = "com.novoda.espresso.ENABLE_TALKBACK";
public static final String ACTION_DISABLE_TALKBACK = "com.novoda.espresso.DISABLE_TALKBACK";
public static final String ACTION_ENABLE_SWITCH_ACCESS= "com.novoda.espresso.ENABLE_SWITCH_ACCESS";
public static final String ACTION_DISABLE_SWITCH_ACCESS = "com.novoda.espresso.DISABLE_SWITCH_ACCESS";
public static final String ACTION_ENABLE_SELECT_TO_SPEAK= "com.novoda.espresso.ENABLE_SELECT_TO_SPEAK";
public static final String ACTION_DISABLE_SELECT_TO_SPEAK = "com.novoda.espresso.DISABLE_SELECT_TO_SPEAK";
private static final String ACTION_SET = "com.novoda.espresso.SET_SERVICE";
private static final String VALUE_ENABLED = "enabled";
private static final String VALUE_DISABLED = "disabled";

private AccessibilityServiceToggler serviceToggler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
serviceToggler = AccessibilityServiceToggler.create(getContentResolver());

Intent intent = getIntent();
if (intent == null || intent.getAction() == null) {
finish();
return;
String action = intent.getAction();
if (action != null && action.equalsIgnoreCase(ACTION_SET)) {
performAction(intent);
}

AccessibilityServiceToggler serviceToggler = AccessibilityServiceToggler.create(getContentResolver());
switch (intent.getAction()) {
case ACTION_ENABLE_TALKBACK:
serviceToggler.enable(Service.TALKBACK);
break;
case ACTION_DISABLE_TALKBACK:
serviceToggler.disable(Service.TALKBACK);
break;
case ACTION_ENABLE_SWITCH_ACCESS:
serviceToggler.enable(Service.SWITCH_ACCESS);
break;
case ACTION_DISABLE_SWITCH_ACCESS:
serviceToggler.disable(Service.SWITCH_ACCESS);
break;
case ACTION_ENABLE_SELECT_TO_SPEAK:
serviceToggler.enable(Service.SELECT_TO_SPEAK);
break;
case ACTION_DISABLE_SELECT_TO_SPEAK:
serviceToggler.disable(Service.SELECT_TO_SPEAK);
break;
}
finish();
}

private void performAction(Intent intent) {
for (Service service : Service.values()) {
String value = intent.getStringExtra(service.name().toLowerCase(Locale.US));
if (VALUE_ENABLED.equalsIgnoreCase(value)) {
serviceToggler.enable(service);
} else if (VALUE_DISABLED.equalsIgnoreCase(value)) {
serviceToggler.disable(service);
}
}
}
}

0 comments on commit 0a17e6e

Please sign in to comment.