• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.android.tests.servicecrashtest;
18 
19 import android.app.Activity;
20 import android.app.Service;
21 import android.content.ComponentName;
22 import android.content.Intent;
23 import android.content.ServiceConnection;
24 import android.os.Bundle;
25 import android.os.IBinder;
26 import android.util.Log;
27 import android.widget.TextView;
28 
29 import java.util.concurrent.CountDownLatch;
30 
31 public class MainActivity extends Activity {
32 
33     private static final String TAG = "ServiceCrashTest";
34 
35     static final CountDownLatch sBindingDiedLatch = new CountDownLatch(1);
36 
37     private ServiceConnection mServiceConnection = new ServiceConnection() {
38 
39         @Override
40         public void onServiceConnected(ComponentName name, IBinder service) {
41             Log.i(TAG, "Service connected");
42         }
43 
44         @Override
45         public void onServiceDisconnected(ComponentName name) {
46             Log.i(TAG, "Service disconnected");
47         }
48 
49         @Override
50         public void onBindingDied(ComponentName componentName) {
51             Log.i(TAG, "Binding died");
52             sBindingDiedLatch.countDown();
53         }
54     };
55 
56     @Override
onCreate(Bundle savedInstance)57     public void onCreate(Bundle savedInstance) {
58         super.onCreate(savedInstance);
59 
60         setContentView(new TextView(this));
61     }
62 
onResume()63     public void onResume() {
64         Intent intent = new Intent();
65         intent.setClass(this, CrashingService.class);
66         bindService(intent, mServiceConnection, Service.BIND_AUTO_CREATE);
67 
68         super.onResume();
69     }
70 }
71