diff --git a/apps/SettingInjectorSample/AndroidManifest.xml b/apps/SettingInjectorSample/AndroidManifest.xml index 1a55700a8..3142860ae 100644 --- a/apps/SettingInjectorSample/AndroidManifest.xml +++ b/apps/SettingInjectorSample/AndroidManifest.xml @@ -38,5 +38,36 @@ android:name="com.android.settings.InjectedLocationSetting" android:resource="@xml/my_injected_location_setting" /> + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apps/SettingInjectorSample/res/values/strings.xml b/apps/SettingInjectorSample/res/values/strings.xml index 777c22e73..a7b73dd3f 100644 --- a/apps/SettingInjectorSample/res/values/strings.xml +++ b/apps/SettingInjectorSample/res/values/strings.xml @@ -20,5 +20,7 @@ Injected setting Disabled injected setting + Slow injected setting + Updating injected setting diff --git a/apps/SettingInjectorSample/res/xml/disabled_injected_location_setting.xml b/apps/SettingInjectorSample/res/xml/disabled_injected_location_setting.xml new file mode 100644 index 000000000..b44e2f86d --- /dev/null +++ b/apps/SettingInjectorSample/res/xml/disabled_injected_location_setting.xml @@ -0,0 +1,7 @@ + + + diff --git a/apps/SettingInjectorSample/res/xml/slow_injected_location_setting.xml b/apps/SettingInjectorSample/res/xml/slow_injected_location_setting.xml new file mode 100644 index 000000000..dfa587239 --- /dev/null +++ b/apps/SettingInjectorSample/res/xml/slow_injected_location_setting.xml @@ -0,0 +1,7 @@ + + + diff --git a/apps/SettingInjectorSample/res/xml/updating_injected_location_setting.xml b/apps/SettingInjectorSample/res/xml/updating_injected_location_setting.xml new file mode 100644 index 000000000..852e59505 --- /dev/null +++ b/apps/SettingInjectorSample/res/xml/updating_injected_location_setting.xml @@ -0,0 +1,7 @@ + + + diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java new file mode 100644 index 000000000..70e3615f8 --- /dev/null +++ b/apps/SettingInjectorSample/src/com/example/android/injector/DisabledInjectorService.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.injector; + +import android.location.SettingInjectorService; +import android.util.Log; + +/** + * Receiver that returns the status disabled for an injected setting. + */ +public class DisabledInjectorService extends SettingInjectorService { + + private static final String TAG = "DisabledInjectorService"; + + public DisabledInjectorService() { + super(TAG); + } + + @Override + protected Status getStatus() { + try { + // Simulate a delay while reading the setting from disk + Thread.sleep(500); + } catch (InterruptedException e) { + Log.e(TAG, "", e); + } + + return new Status(null, false); + } +} diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java index 255d991b0..3318bc2d2 100644 --- a/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java +++ b/apps/SettingInjectorSample/src/com/example/android/injector/MyInjectorService.java @@ -24,7 +24,7 @@ import android.util.Log; */ public class MyInjectorService extends SettingInjectorService { - private static final String TAG = "ClientService"; + private static final String TAG = "MyInjectorService"; public MyInjectorService() { super(TAG); @@ -34,7 +34,7 @@ public class MyInjectorService extends SettingInjectorService { protected Status getStatus() { try { // Simulate a delay while reading the setting from disk - Thread.sleep(1000); + Thread.sleep(500); } catch (InterruptedException e) { Log.e(TAG, "", e); } diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java new file mode 100644 index 000000000..9984df0c4 --- /dev/null +++ b/apps/SettingInjectorSample/src/com/example/android/injector/SlowInjectorService.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.injector; + +import android.location.SettingInjectorService; +import android.util.Log; + +/** + * Receiver that returns the status of the injected setting. + */ +public class SlowInjectorService extends SettingInjectorService { + + private static final String TAG = "SlowInjectorService"; + + public SlowInjectorService() { + super(TAG); + } + + @Override + protected Status getStatus() { + try { + // Simulate a delay while reading the setting from disk + Thread.sleep(5000); + } catch (InterruptedException e) { + Log.e(TAG, "", e); + } + + return new Status("Dang that took a long time!", true); + } +} diff --git a/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java b/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java new file mode 100644 index 000000000..e12184e00 --- /dev/null +++ b/apps/SettingInjectorSample/src/com/example/android/injector/UpdatingInjectorService.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.injector; + +import android.content.Intent; +import android.location.SettingInjectorService; +import android.util.Log; + +/** + * Receiver that returns a constantly-updating status for an injected setting. + */ +public class UpdatingInjectorService extends SettingInjectorService { + + private static final String TAG = "UpdatingInjectorService"; + + public UpdatingInjectorService() { + super(TAG); + } + + @Override + protected Status getStatus() { + // 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(UPDATE_INTENT); + sendBroadcast(intent); + Log.d(TAG, "Broadcasting: " + intent); + return new Status(String.valueOf(System.currentTimeMillis()), true); + } +}