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
17package com.android.tests.servicecrashtest;
18
19import android.app.Activity;
20import android.app.Service;
21import android.content.ComponentName;
22import android.content.Intent;
23import android.content.ServiceConnection;
24import android.os.Bundle;
25import android.os.IBinder;
26import android.util.Log;
27import android.widget.TextView;
28
29import java.util.concurrent.CountDownLatch;
30
31public 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
57    public void onCreate(Bundle savedInstance) {
58        super.onCreate(savedInstance);
59
60        setContentView(new TextView(this));
61    }
62
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