• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.os;
18 
19 import android.net.LocalSocketAddress;
20 import android.system.ErrnoException;
21 import android.system.Os;
22 
23 import java.util.concurrent.atomic.AtomicBoolean;
24 
25 /**
26  * Represents a connection to a child-zygote process. A child-zygote is spawend from another
27  * zygote process using {@link startChildZygote()}.
28  *
29  * {@hide}
30  */
31 public class ChildZygoteProcess extends ZygoteProcess {
32     /**
33      * The PID of the child zygote process.
34      */
35     private final int mPid;
36 
37     /**
38      * The UID of the child zygote process.
39      */
40     private final int mUid;
41 
42 
43     /**
44      * If this zygote process was dead;
45      */
46     private AtomicBoolean mDead;
47 
48 
ChildZygoteProcess(LocalSocketAddress socketAddress, int pid, int uid)49     ChildZygoteProcess(LocalSocketAddress socketAddress, int pid, int uid) {
50         super(socketAddress, null);
51         mPid = pid;
52         mUid = uid;
53         mDead = new AtomicBoolean(false);
54     }
55 
56     /**
57      * Returns the PID of the child-zygote process.
58      */
getPid()59     public int getPid() {
60         return mPid;
61     }
62 
63     /**
64      * Check if child-zygote process is dead
65      */
isDead()66     public boolean isDead() {
67         if (mDead.get()) {
68             return true;
69         }
70         StrictMode.ThreadPolicy oldStrictModeThreadPolicy = StrictMode.allowThreadDiskReads();
71         try {
72             if (Os.stat("/proc/" + mPid).st_uid == mUid) {
73                 return false;
74             }
75         } catch (ErrnoException e) {
76             // Do nothing, it's dead.
77         } finally {
78             StrictMode.setThreadPolicy(oldStrictModeThreadPolicy);
79         }
80         mDead.set(true);
81         return true;
82     }
83 }
84