1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.injector; 18 19 import android.location.SettingInjectorService; 20 import android.util.Log; 21 22 /** 23 * Receiver that returns the status of the injected setting. 24 */ 25 public class FailingInjectorService extends SettingInjectorService { 26 27 private static final String TAG = "FailingInjectorService"; 28 29 /** 30 * Whether to actually throw an exception here. Pretty disruptive when true, because it causes 31 * a "Unfortunately, My Setting Activity! has stopped" dialog to appear and also blocks the 32 * update of other settings from this app. So only set true when need to test the handling 33 * of the exception. 34 */ 35 private static final boolean ACTUALLY_THROW = false; 36 FailingInjectorService()37 public FailingInjectorService() { 38 super(TAG); 39 } 40 41 @Override onGetSummary()42 protected String onGetSummary() { 43 try { 44 // Simulate a delay while reading the setting from disk 45 Thread.sleep(100); 46 } catch (InterruptedException e) { 47 Log.e(TAG, "", e); 48 } 49 50 if (ACTUALLY_THROW) { 51 throw new RuntimeException("Simulated failure reading setting"); 52 } 53 return "Decided not to throw exception after all"; 54 } 55 56 @Override onGetEnabled()57 protected boolean onGetEnabled() { 58 return false; 59 } 60 } 61