diff options
| author | Tom O'Neill <tomo@google.com> | 2013-09-05 08:17:40 -0700 |
|---|---|---|
| committer | Tom O'Neill <tomo@google.com> | 2013-09-05 08:17:40 -0700 |
| commit | 6ae72772c076b602eb71c3e0b680d6b514323c07 (patch) | |
| tree | 7e7c5c853b8eaa407bf97f62c0733db433a5dc63 /apps/SettingInjectorSample | |
| parent | 79392cbf67fd250e1bfa23f9abcb408ae69f6a69 (diff) | |
| download | android_development-6ae72772c076b602eb71c3e0b680d6b514323c07.tar.gz android_development-6ae72772c076b602eb71c3e0b680d6b514323c07.tar.bz2 android_development-6ae72772c076b602eb71c3e0b680d6b514323c07.zip | |
React to split of getStatus() into onGetSummary() and onGetEnabled()
- Part of b/10461474
Change-Id: I1dbee915692aab93d56d85203cee3133a8e0e058
Diffstat (limited to 'apps/SettingInjectorSample')
5 files changed, 43 insertions, 10 deletions
diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java index 70e3615f8..c122639cd 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java @@ -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; } } diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/FailingInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/FailingInjectorService.java index f13d7e040..bdd15eb4a 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/FailingInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/FailingInjectorService.java @@ -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); } - throw new RuntimeException("Simulated failure reading setting"); + if (ACTUALLY_THROW) { + throw new RuntimeException("Simulated failure reading setting"); + } + return "Decided not to throw exception after all"; + } + + @Override + protected boolean onGetEnabled() { + return false; } } diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java index 3318bc2d2..8797d694a 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java @@ -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; } } diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java index 9984df0c4..7cb32c92f 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java @@ -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; } } diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java index 632066768..3db619a9b 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java @@ -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; } } |
