• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.cts.useembeddeddex;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.ServiceConnection;
23 import android.os.IBinder;
24 import android.test.InstrumentationTestCase;
25 import android.util.Log;
26 import com.android.compatibility.common.util.PollingCheck;
27 
28 public class EmbeddedDexTest extends InstrumentationTestCase {
29     static final String TAG = "EmbeddedDexTest";
30 
31     boolean mServiceConnected = false;
32 
testIsolatedService()33     public void testIsolatedService() throws Exception {
34         // Start and wait for the isolated service.
35         Context context = getInstrumentation().getTargetContext();
36         Intent intent = new Intent(context, IsolatedService.class);
37         ServiceConnection conn = new ServiceConnection() {
38             @Override
39             public void onServiceConnected(ComponentName name, IBinder service) {
40                 Log.i(TAG, "Isolated service connected " + name + " " + service);
41                 EmbeddedDexTest.this.mServiceConnected = true;
42             }
43             @Override
44             public void onServiceDisconnected(ComponentName name) {
45                 Log.i(TAG, "Isolated service disconnected " + name);
46                 EmbeddedDexTest.this.mServiceConnected = false;
47             }
48         };
49         try {
50             assertTrue(context.bindService(intent, conn, Context.BIND_AUTO_CREATE));
51             PollingCheck.waitFor(() -> EmbeddedDexTest.this.mServiceConnected);
52         } finally {
53             context.unbindService(conn);
54         }
55     }
56 }
57