React to split of getStatus() into onGetSummary() and onGetEnabled()
- Part of b/10461474 Change-Id: I1dbee915692aab93d56d85203cee3133a8e0e058
This commit is contained in:
@@ -31,14 +31,18 @@ public class DisabledInjectorService extends SettingInjectorService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Status getStatus() {
|
||||
protected String onGetSummary() {
|
||||
try {
|
||||
// Simulate a delay while reading the setting from disk
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Status(null, false);
|
||||
@Override
|
||||
protected boolean onGetEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,20 @@ public class FailingInjectorService extends SettingInjectorService {
|
||||
|
||||
private static final String TAG = "FailingInjectorService";
|
||||
|
||||
/**
|
||||
* Whether to actually throw an exception here. Pretty disruptive when true, because it causes
|
||||
* a "Unfortunately, My Setting Activity! has stopped" dialog to appear and also blocks the
|
||||
* update of other settings from this app. So only set true when need to test the handling
|
||||
* of the exception.
|
||||
*/
|
||||
private static final boolean ACTUALLY_THROW = false;
|
||||
|
||||
public FailingInjectorService() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Status getStatus() {
|
||||
protected String onGetSummary() {
|
||||
try {
|
||||
// Simulate a delay while reading the setting from disk
|
||||
Thread.sleep(100);
|
||||
@@ -39,6 +47,14 @@ public class FailingInjectorService extends SettingInjectorService {
|
||||
Log.e(TAG, "", e);
|
||||
}
|
||||
|
||||
if (ACTUALLY_THROW) {
|
||||
throw new RuntimeException("Simulated failure reading setting");
|
||||
}
|
||||
return "Decided not to throw exception after all";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onGetEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,18 @@ public class MyInjectorService extends SettingInjectorService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Status getStatus() {
|
||||
protected String onGetSummary() {
|
||||
try {
|
||||
// Simulate a delay while reading the setting from disk
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "", e);
|
||||
}
|
||||
return "Example status value";
|
||||
}
|
||||
|
||||
return new Status("Example status value", true);
|
||||
@Override
|
||||
protected boolean onGetEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,18 @@ public class SlowInjectorService extends SettingInjectorService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Status getStatus() {
|
||||
protected String onGetSummary() {
|
||||
try {
|
||||
// Simulate a delay while reading the setting from disk
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "", e);
|
||||
}
|
||||
return "Dang that took a long time!";
|
||||
}
|
||||
|
||||
return new Status("Dang that took a long time!", true);
|
||||
@Override
|
||||
protected boolean onGetEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +32,18 @@ public class UpdatingInjectorService extends SettingInjectorService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Status getStatus() {
|
||||
protected String onGetSummary() {
|
||||
// Every time it asks for our status, we tell it the setting has just changed. This will
|
||||
// test the handling of races where we're getting many UPDATE_INTENT broadcasts in a short
|
||||
// period of time
|
||||
Intent intent = new Intent(ACTION_INJECTED_SETTING_CHANGED);
|
||||
sendBroadcast(intent);
|
||||
Log.d(TAG, "Broadcasting: " + intent);
|
||||
return new Status(String.valueOf(System.currentTimeMillis()), true);
|
||||
return String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onGetEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user