Skip to content

Commit 7ff3144

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Add new feature for running services in "isolated" sandbox processes."
2 parents 1c90e73 + a0c283e commit 7ff3144

File tree

13 files changed

+326
-119
lines changed

13 files changed

+326
-119
lines changed

api/16.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15052,7 +15052,7 @@ package android.os {
1505215052
method public static final deprecated boolean supportsProcesses();
1505315053
field public static final int BLUETOOTH_GID = 2000; // 0x7d0
1505415054
field public static final int FIRST_APPLICATION_UID = 10000; // 0x2710
15055-
field public static final int LAST_APPLICATION_UID = 99999; // 0x1869f
15055+
field public static final int LAST_APPLICATION_UID = 89999; // 0x1869f
1505615056
field public static final int PHONE_UID = 1001; // 0x3e9
1505715057
field public static final int SIGNAL_KILL = 9; // 0x9
1505815058
field public static final int SIGNAL_QUIT = 3; // 0x3

api/current.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ package android {
562562
field public static final int isRepeatable = 16843336; // 0x1010248
563563
field public static final int isScrollContainer = 16843342; // 0x101024e
564564
field public static final int isSticky = 16843335; // 0x1010247
565+
field public static final int isolatedProcess = 16843687; // 0x10103a7
565566
field public static final int itemBackground = 16843056; // 0x1010130
566567
field public static final int itemIconDisabledAlpha = 16843057; // 0x1010131
567568
field public static final int itemPadding = 16843565; // 0x101032d
@@ -6469,6 +6470,7 @@ package android.content.pm {
64696470
method public int describeContents();
64706471
method public void dump(android.util.Printer, java.lang.String);
64716472
field public static final android.os.Parcelable.Creator CREATOR;
6473+
field public static final int FLAG_ISOLATED_PROCESS = 2; // 0x2
64726474
field public static final int FLAG_STOP_WITH_TASK = 1; // 0x1
64736475
field public int flags;
64746476
field public java.lang.String permission;
@@ -15178,7 +15180,7 @@ package android.os {
1517815180
method public static final deprecated boolean supportsProcesses();
1517915181
field public static final int BLUETOOTH_GID = 2000; // 0x7d0
1518015182
field public static final int FIRST_APPLICATION_UID = 10000; // 0x2710
15181-
field public static final int LAST_APPLICATION_UID = 99999; // 0x1869f
15183+
field public static final int LAST_APPLICATION_UID = 89999; // 0x15f8f
1518215184
field public static final int PHONE_UID = 1001; // 0x3e9
1518315185
field public static final int SIGNAL_KILL = 9; // 0x9
1518415186
field public static final int SIGNAL_QUIT = 3; // 0x3

core/java/android/app/ActivityThread.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public final class ActivityThread {
134134
private static final boolean DEBUG_RESULTS = false;
135135
private static final boolean DEBUG_BACKUP = true;
136136
private static final boolean DEBUG_CONFIGURATION = false;
137-
private static final boolean DEBUG_SERVICE = true;
137+
private static final boolean DEBUG_SERVICE = false;
138138
private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
139139
private static final Pattern PATTERN_SEMICOLON = Pattern.compile(";");
140140
private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
@@ -3764,13 +3764,17 @@ final void handleTrimMemory(int level) {
37643764
}
37653765

37663766
private void setupGraphicsSupport(LoadedApk info) {
3767+
if (Process.isIsolated()) {
3768+
// Isolated processes aren't going to do UI.
3769+
return;
3770+
}
37673771
try {
37683772
int uid = Process.myUid();
37693773
String[] packages = getPackageManager().getPackagesForUid(uid);
37703774

37713775
// If there are several packages in this application we won't
37723776
// initialize the graphics disk caches
3773-
if (packages.length == 1) {
3777+
if (packages != null && packages.length == 1) {
37743778
ContextImpl appContext = new ContextImpl();
37753779
appContext.init(info, null, this);
37763780

core/java/android/app/LoadedApk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public LoadedApk(ActivityThread activityThread, ApplicationInfo aInfo,
119119
final int myUid = Process.myUid();
120120
mResDir = aInfo.uid == myUid ? aInfo.sourceDir
121121
: aInfo.publicSourceDir;
122-
if (!UserId.isSameUser(aInfo.uid, myUid)) {
122+
if (!UserId.isSameUser(aInfo.uid, myUid) && !Process.isIsolated()) {
123123
aInfo.dataDir = PackageManager.getDataDirForUser(UserId.getUserId(myUid),
124124
mPackageName);
125125
}

core/java/android/content/pm/PackageParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,11 @@ private Service parseService(Package owner, Resources res,
25812581
false)) {
25822582
s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
25832583
}
2584+
if (sa.getBoolean(
2585+
com.android.internal.R.styleable.AndroidManifestService_isolatedProcess,
2586+
false)) {
2587+
s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
2588+
}
25842589

25852590
sa.recycle();
25862591

core/java/android/content/pm/ServiceInfo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ public class ServiceInfo extends ComponentInfo
4141
*/
4242
public static final int FLAG_STOP_WITH_TASK = 0x0001;
4343

44+
/**
45+
* Bit in {@link #flags}: If set, the service will run in its own
46+
* isolated process. Set from the
47+
* {@link android.R.attr#isolatedProcess} attribute.
48+
*/
49+
public static final int FLAG_ISOLATED_PROCESS = 0x0002;
50+
4451
/**
4552
* Options that have been set in the service declaration in the
4653
* manifest.
4754
* These include:
48-
* {@link #FLAG_STOP_WITH_TASK}
55+
* {@link #FLAG_STOP_WITH_TASK}, {@link #FLAG_ISOLATED_PROCESS}.
4956
*/
5057
public int flags;
5158

core/java/android/os/Process.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,19 @@ public class Process {
119119
* Last of application-specific UIDs starting at
120120
* {@link #FIRST_APPLICATION_UID}.
121121
*/
122-
public static final int LAST_APPLICATION_UID = 99999;
122+
public static final int LAST_APPLICATION_UID = 89999;
123+
124+
/**
125+
* First uid used for fully isolated sandboxed processes (with no permissions of their own)
126+
* @hide
127+
*/
128+
public static final int FIRST_ISOLATED_UID = 99000;
129+
130+
/**
131+
* Last uid used for fully isolated sandboxed processes (with no permissions of their own)
132+
* @hide
133+
*/
134+
public static final int LAST_ISOLATED_UID = 99999;
123135

124136
/**
125137
* Defines a secondary group id for access to the bluetooth hardware.
@@ -575,6 +587,15 @@ private static ProcessStartResult startViaZygote(final String processClass,
575587
*/
576588
public static final native int myUid();
577589

590+
/**
591+
* Returns whether the current process is in an isolated sandbox.
592+
* @hide
593+
*/
594+
public static final boolean isIsolated() {
595+
int uid = UserId.getAppId(myUid());
596+
return uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID;
597+
}
598+
578599
/**
579600
* Returns the UID assigned to a particular user name, or -1 if there is
580601
* none. If the given string consists of only numbers, it is converted

core/res/res/values/attrs_manifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,10 @@
12351235
when the user remove a task rooted in an activity owned by
12361236
the application. The default is false. -->
12371237
<attr name="stopWithTask" format="boolean" />
1238+
<!-- If set to true, this service will run under a special process
1239+
that is isolated from the rest of the system. The only communication
1240+
with it is through the Service API (binding and starting). -->
1241+
<attr name="isolatedProcess" format="boolean" />
12381242
</declare-styleable>
12391243

12401244
<!-- The <code>receiver</code> tag declares an

core/res/res/values/public.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,4 +3482,10 @@
34823482
<public type="color" name="holo_orange_dark" id="0x01060019" />
34833483
<public type="color" name="holo_purple" id="0x0106001a" />
34843484
<public type="color" name="holo_blue_bright" id="0x0106001b" />
3485+
3486+
<!-- ===============================================================
3487+
Resources added in version 16 of the platform (Jelly Bean)
3488+
=============================================================== -->
3489+
<public type="attr" name="isolatedProcess" id="0x010103a7" />
3490+
34853491
</resources>

0 commit comments

Comments
 (0)