Skip to content

Commit f097b16

Browse files
committed
Content Providers: change default for android:exported
Change the default value of android:exported to true for applications which target a newer API version. This will help stop inadvertent content provider exposure to untrusted apps. Bug: 3306452 Change-Id: I8cb34e823aef9551319951ce92217345c54cee63
1 parent 6624afe commit f097b16

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,8 +2428,28 @@ private Provider parseProvider(Package owner, Resources res,
24282428
return null;
24292429
}
24302430

2431+
boolean providerExportedDefault = false;
2432+
2433+
if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
2434+
// For compatibility, applications targeting API level 16 or lower
2435+
// should have their content providers exported by default, unless they
2436+
// specify otherwise.
2437+
providerExportedDefault = true;
2438+
}
2439+
2440+
if (((owner.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
2441+
&& (owner.applicationInfo.targetSdkVersion == Build.VERSION_CODES.JELLY_BEAN)) {
2442+
// STOPSHIP: REMOVE THIS IF BLOCK
2443+
// To expose more bugs, pre-installed system apps targeting API level 16
2444+
// should not have their content providers exported by default.
2445+
// This is only a short term check, and should be removed when the
2446+
// default SDK version changes to 17.
2447+
providerExportedDefault = false;
2448+
}
2449+
24312450
p.info.exported = sa.getBoolean(
2432-
com.android.internal.R.styleable.AndroidManifestProvider_exported, true);
2451+
com.android.internal.R.styleable.AndroidManifestProvider_exported,
2452+
providerExportedDefault);
24332453

24342454
String cpname = sa.getNonConfigurationString(
24352455
com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);
@@ -2487,7 +2507,7 @@ private Provider parseProvider(Package owner, Resources res,
24872507
}
24882508

24892509
if (cpname == null) {
2490-
outError[0] = "<provider> does not incude authorities attribute";
2510+
outError[0] = "<provider> does not include authorities attribute";
24912511
return null;
24922512
}
24932513
p.info.authority = cpname.intern();

core/java/android/os/Build.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ public static class VERSION_CODES {
414414

415415
/**
416416
* Moar jelly beans!
417+
*
418+
* <p>Applications targeting this or a later release will get these
419+
* new changes in behavior:</p>
420+
* <ul>
421+
* <li>Content Providers: The default value of {@code android:exported} is now
422+
* {@code false}. See
423+
* <a href="{docRoot}guide/topics/manifest/provider-element.html#exported">
424+
* the android:exported section</a> in the provider documentation for more details.</li>
425+
* </ul>
417426
*/
418427
public static final int JELLY_BEAN_MR1 = 17;
419428
}

docs/html/guide/topics/manifest/provider-element.jd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ are by default) for the content provider to be enabled. If either is
9797
applications &mdash; "{@code true}" if it can be, and "{@code false}" if not.
9898
If "{@code false}", the provider is available only to components of the
9999
same application or applications with the same user ID. The default value
100-
is "{@code true}".
100+
is "{@code true}" for applications which target API level 16 (Jelly Bean)
101+
and below, and "{@code false}" otherwise.
101102

102103
<p>
103104
You can export a content provider but still limit access to it with the

0 commit comments

Comments
 (0)