1 /*
2  * Copyright (C) 2019 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.domainsocketapp;
18 
19 import android.app.Activity;
20 import android.net.LocalServerSocket;
21 import android.net.LocalSocket;
22 import android.os.Bundle;
23 import android.util.Log;
24 
25 import java.io.OutputStream;
26 import java.io.IOException;
27 
28 public class DomainSocketActivity extends Activity {
29 
30     private static final String DOMAIN_SOCKET_NAME = "RunasConnectAppSocket";
31 
32     private static final String MAGIC_MESSAGE = "Connection Succeeded.";
33 
34     private static final String TAG = DomainSocketActivity.class.getSimpleName();
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         new Thread() {
41             public void run() {
42                 try {
43                     new LocalServerSocket(DOMAIN_SOCKET_NAME).accept().getOutputStream()
44                             .write(MAGIC_MESSAGE.getBytes());
45                 } catch (IOException e) {
46                     Log.e(TAG, e.getMessage());
47                 }
48             }
49         }.start();
50     }
51 }
52