1 /*
2  * Copyright (C) 2022 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.install.lib.testapp;
18 
19 import android.app.Activity;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.ServiceConnection;
24 import android.os.Bundle;
25 import android.os.IBinder;
26 
27 /**
28  * A test app binding a service to test install constraints.
29  */
30 public class TestServiceActivity extends Activity {
31     private static final String SERVICE_PACKAGE_NAME = "com.android.cts.install.lib.testapp.S";
32     private IBinder mBinder;
33 
34     @Override
onCreate(Bundle savedInstanceState)35     public void onCreate(Bundle savedInstanceState) {
36         super.onCreate(savedInstanceState);
37 
38         Intent serviceIntent = new Intent().setClassName(
39                 SERVICE_PACKAGE_NAME, TestService.class.getName());
40         bindService(serviceIntent, new ServiceConnection() {
41             @Override
42             public void onServiceConnected(ComponentName name, IBinder service) {
43                 mBinder = service;
44             }
45             @Override
46             public void onServiceDisconnected(ComponentName name) {
47                 mBinder = null;
48 
49             }
50         }, Context.BIND_AUTO_CREATE);
51     }
52 }
53 
54