• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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 android.net;
18 
19 /**
20  * A UNIX-domain (AF_LOCAL) socket address. For use with
21  * android.net.LocalSocket and android.net.LocalServerSocket.
22  *
23  * On the Android system, these names refer to names in the Linux
24  * abstract (non-filesystem) UNIX domain namespace.
25  */
26 public class LocalSocketAddress
27 {
28     /**
29      * The namespace that this address exists in. See also
30      * include/cutils/sockets.h ANDROID_SOCKET_NAMESPACE_*
31      */
32     public enum Namespace {
33         /** A socket in the Linux abstract namespace */
34         ABSTRACT(0),
35         /**
36          * A socket in the Android reserved namespace in /dev/socket.
37          * Only the init process may create a socket here.
38          */
39         RESERVED(1),
40         /**
41          * A socket named with a normal filesystem path.
42          */
43         FILESYSTEM(2);
44 
45         /** The id matches with a #define in include/cutils/sockets.h */
46         private int id;
Namespace(int id)47         Namespace (int id) {
48             this.id = id;
49         }
50 
51         /**
52          * @return int constant shared with native code
53          */
getId()54         /*package*/ int getId() {
55             return id;
56         }
57     }
58 
59     private final String name;
60     private final Namespace namespace;
61 
62     /**
63      * Creates an instance with a given name.
64      *
65      * @param name non-null name
66      * @param namespace namespace the name should be created in.
67      */
LocalSocketAddress(String name, Namespace namespace)68     public LocalSocketAddress(String name, Namespace namespace) {
69         this.name = name;
70         this.namespace = namespace;
71     }
72 
73     /**
74      * Creates an instance with a given name in the {@link Namespace#ABSTRACT}
75      * namespace
76      *
77      * @param name non-null name
78      */
LocalSocketAddress(String name)79     public LocalSocketAddress(String name) {
80         this(name,Namespace.ABSTRACT);
81     }
82 
83     /**
84      * Retrieves the string name of this address
85      * @return string name
86      */
getName()87     public String getName()
88     {
89         return name;
90     }
91 
92     /**
93      * Returns the namespace used by this address.
94      *
95      * @return non-null a namespace
96      */
getNamespace()97     public Namespace getNamespace() {
98         return namespace;
99     }
100 }
101