1/* 2 * Copyright (C) 2016 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 17package test.amslam; 18 19import android.app.Service; 20import android.content.Intent; 21import android.os.Handler; 22import android.os.IBinder; 23import android.os.SystemClock; 24 25public class PingReceiver extends Service { 26 27 @Override 28 public int onStartCommand(Intent intent, int flags, int startId) { 29 Intent response = new Intent(this, PongReceiver.class); 30 response.putExtra("start_time", intent.getLongExtra("start_time", 0)); 31 response.putExtra("bounce_time", SystemClock.uptimeMillis()); 32 response.putExtra("receiver", getClass().getSimpleName()); 33 sendBroadcast(response); 34 stopSelf(); 35 // If we exit before returning from onStartCommand the system will 36 // think we crashed and attempt a re-delivery, which we don't want here. 37 // Post'ing the kill deals with this just fine. 38 new Handler().post(() -> System.exit(0)); 39 return START_NOT_STICKY; 40 } 41 42 @Override 43 public IBinder onBind(Intent intent) { 44 return null; 45 } 46} 47