Commit Graph

574 Commits

Author SHA1 Message Date
Jeff Sharkey
e628b7d446 Add Binder support for Parcelable exceptions.
If an Exception thrown by a Binder call implements the Parcelable
interface, then parcel it and rethrow back at the caller.  There is
strict requirement that these Parcelable exceptions must be defined
by the system (as determined by checking the ClassLoader).  We prefix
the Parcelable contents with a length so that native code can skip
over the blobs.

Define a new ParcelableException class that can be used to transport
exceptions that cannot be modified to add Parcelable behavior, and
switch ExceptionUtils to use this new class for sending IOExceptions.

Test: builds, boots, wrapped exceptions work
Bug: 33749182
Change-Id: I1352ea1566ddf01120d9d0e819ba6f70fc407e11
2017-01-17 14:22:07 -07:00
Mark Salyzyn
52eb4e01a4 Replace cutils/log.h and log/logger.h with log/log.h
Test: compile
Bug: 26552300
Bug: 31289077
Change-Id: I578b15b48f0fc2807a92abbc69a377c3d2191496
2017-01-09 14:31:34 -08:00
Alex Klyubin
9694657967 Permit 65535 byte ZIP comments and empty Central Directory
This fixes two cosmetic issues in APK Signature Scheme v2 signature
verifier in Android Package Manager:
* Accept APKs with ZIP End of Central Directory comment of length
  65535. Previously, only comments of length 65534 were accepted due
  to a off by one bug.
* Accept APKs with empty ZIP Central Directory.

These issues should not affect actual APKs because they cannot have an
empty ZIP Central Directory (they must contain at least the
AndroidManifest.xml entry) and shouldn't contain any comments in ZIP
End of Central Directory.

Test: cts-tradefed run singleCommand cts --skip-device-info --skip-preconditions --skip-connectivity-check --abi arm64-v8a --module CtsAppSecurityHostTestCases -t android.appsecurity.cts.PkgInstallSignatureVerificationTest
Change-Id: I461c43472fa97c04e7579d129a6053e44233adb7
2016-12-19 12:53:32 -08:00
Treehugger Robot
68ea36243d Merge "Fix crashing StrictJarFile due to doubled closing." 2016-12-07 01:40:48 +00:00
Tomasz Mikolajewski
b061fc2bb5 Fix crashing StrictJarFile due to doubled closing.
If the constuctor throws, then the handles would be closed without
setting "closed" to true. As a result, the finalizer would close
the handles again, which would cause a crash on the native side.

Test: Unit tests are no longer flaky.
Bug: 33301253
Change-Id: I527ba38d5d65ce844258d894441d4fe16bac6e23
2016-12-06 10:05:05 +09:00
Tobias Thierer
6e2d3fa82f Merge "Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64"
am: 1e498a96c1

Change-Id: I28b8deadc9386b8772bd94870809213fdddad7e6
2016-12-05 09:35:10 +00:00
Tobias Thierer
9f00d71787 Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64
Previously, they weres using libcore.io.Base64, which is @deprecated.

The two implementations' encoders produce the exact same result.

The two implementations' decoders' behavior differs for malformed
input:
 - In case of error, libcore.io.Base64.decode() returns null while
   java.util.Base64.getDecoder().decode() throws.
 - java.util.Base64 tends to be stricter about rejecting malformed
   input; specifically, it allows neither whitespace nor unexpected
   '=' characters (should only occur in the padding) whereas
   libcore.io.Base64.decode() leniently allows them throughout the
   input.
 - if the input terminates prematurely, libcore.io.Base64 tends to
   return fewer bytes (stops at a four byte boundary).

The behavior differences for malformed Base64 encoded data should
not affect ShortcutPackageInfo because it should only need to deal
with XML attribute values written by itself, which are well-formed.
Note that this CL does not lead to any known changes of the encoding
step, so values written by earlier versions should not cause problems
when read by later versions of ShortcutPackageInfo.

StrictJarVerifier may now reject or behave differently for .jar /
.zip files with malformed attribute values but this seems okay since,
per its name, it is meant to be strict. For example, after this CL,
StrictJarVerifier will no longer accept algorithm + "-Digest"
attribute values with extra whitespace or padding characters as valid.

Test: Confirmed that the two implementations' encoders produce the
      same result by running the following code just before this CL:
      assertEquals(
          libcore.io.Base64.encode(allBytes()),
          Base64.getEncoder().encodeToString(allBytes()));
      where allBytes() returns a byte[] with values (byte) 0 .. (byte) 255
Test: Test that phone still boots after flashing code that includes
      this CL.
Test: CtsLibcoreTestCases

Bug: 31292683

Change-Id: I775d32f329f693514a8f14d87e1ef0d7a757e6c3
2016-12-02 16:20:53 +00:00
Tomasz Mikolajewski
4c65d49a92 Merge "Add support for opening JAR/ZIP files via FD."
am: 7f64c195f7

Change-Id: I88af6f42ccd5e6edafa57fd0f147f676da8aa096
2016-11-02 00:34:47 +00:00
Tomasz Mikolajewski
6c3df1543c Add support for opening JAR/ZIP files via FD.
Test: Upcoming change in DocumentsUI uses this feature.
Bug: 31783726
Change-Id: Ia74e9bdb66722dfb2855380375a99cc94d288b2e
(cherry picked from commit 5a5c44a2e3)
2016-11-01 09:25:59 +09:00
Svet Ganov
171b77b91e [DO NOT MERGE] Backup account access grants am: 72ed12c55f
am: 0dc4ff0753

Change-Id: Ic6ad395f958b2e09d66467f41bd40e84c34851b9
2016-09-10 00:28:50 +00:00
Svet Ganov
72ed12c55f [DO NOT MERGE] Backup account access grants
Sync adapters without an account access cannot run until the
user approves the account access (for the case the account
access is not allowed by other policy such as being singed
with the same cert as the authenticator). If the sync adapter
does not have permission to access the account we ask the
user to grant access and take a note. This CL adds backup
for the explicit user grants.

bug:31162498

Change-Id: I31e3f3d010475352c7c54255ac2d3a2fed4d0c72
2016-09-09 10:16:57 -07:00
Svetoslav Ganov
a2c1196dc2 Properly close fd backing a MemoryIntArray am: fe2462f3a6
am: b7be22cdaf

Change-Id: Ie598d2310fff4d72f618ecfa9e2efae78c595a10
2016-08-31 01:04:00 +00:00
Svetoslav Ganov
b7be22cdaf Properly close fd backing a MemoryIntArray
am: fe2462f3a6

Change-Id: Iaf35af209d210ba0aa6239bdeb0c81a079d25543
2016-08-31 00:56:32 +00:00
TreeHugger Robot
43896cbc02 Merge "Properly close fd backing a MemoryIntArray" into nyc-mr1-dev 2016-08-31 00:49:42 +00:00
Svetoslav Ganov
fe2462f3a6 Properly close fd backing a MemoryIntArray
Use ParcelFileDescriptor only as an IPC transport
to make sure MemoryIntArray manges its backing fd.

Bug:30310689

Change-Id: Ib3cc13ef4ae2a744e5f7a96099570e0431847bce
2016-08-30 02:26:19 +00:00
Dianne Hackborn
5827257521 Try to mitigate issue #31016187: system_server crash in ArraySet. am: 92aa4b2ba3
am: d43d248848

Change-Id: Ie499c3b715325c23fc5b85442f742453df14e471
2016-08-25 17:30:33 +00:00
Dianne Hackborn
92aa4b2ba3 Try to mitigate issue #31016187: system_server crash in ArraySet.
Instead of crashing, log a wtf and recover.  This is not a problem
in ArraySet, but caused by someone else using an ArraySet without
protecting access to it.  So whoever is calling at this point is
not the cause, and it isn't worthwhile to let them crash.

Change-Id: Iaefa4315b620c9fe24b31507e4aa47a8525c8540
2016-08-25 10:12:02 -07:00
Neil Fuller
ce78eb6b45 Merge "Add a finalize() method to StrictJarFile" am: d0c0c8dcab am: 2ffb7ebae2
am: f952f52013

Change-Id: I0a621a83670f326d218fe3f77bc5fe9bbad6ea6c
2016-08-09 11:02:07 +00:00
Neil Fuller
f952f52013 Merge "Add a finalize() method to StrictJarFile" am: d0c0c8dcab
am: 2ffb7ebae2

Change-Id: Ie947e8447ecd8e9a61b6d1115174180e41d74311
2016-08-09 10:54:32 +00:00
Neil Fuller
2ffb7ebae2 Merge "Add a finalize() method to StrictJarFile"
am: d0c0c8dcab

Change-Id: Iccab49c98b105aff6105e21274fbc099d10ecb55
2016-08-09 10:49:58 +00:00
Neil Fuller
b69f61472a Add a finalize() method to StrictJarFile
Bug: 25896372
Test: Booted device, installed CTS apps
Test: run cts --class android.util.cts.StrictJarFileTest
Change-Id: I35e238dadd48d2c4ca53ac37a4c5aacdd471a93a
2016-07-29 14:26:35 +01:00
Svetoslav Ganov
a22f5a3fb4 Merge \\"Removed warning when objects are added on wrong order.\\" into nyc-dev am: a98e4512df
am: 620936768f

Change-Id: I6986568b24bb4122452314d412b0f3d6422c61b4
2016-06-30 23:44:34 +00:00
Felipe Leme
7524b13642 Merge \"Removed warning when objects are added on wrong order.\" into nyc-dev
am: a98e4512df

Change-Id: Ic93707d6cda6dbdeed851f216eedbd4333d483ae
2016-06-30 23:37:24 +00:00
Felipe Leme
7709041c99 Removed warning when objects are added on wrong order.
append() is used to optimized insertions in the array, but it must
preserve the order of the hashcode array; when it doesn't, it falls back
to append(), but it should not log a warning message

In particular, PendingIntentRecords might have different hashcodes
across different processes.

Fixes: 29912192
Change-Id: I0ab566249829ddb934fd51cf21399b68cb286bd5
2016-06-30 23:19:08 +00:00
Svetoslav Ganov
dc162dde07 Merge \\"Mark app pending intents in notification extras\\" into nyc-dev am: b2cd9c95bf
am: 5f7f3fa7a9

Change-Id: Id4bc3ae0c1d79174a22d669dccab3391c231357d
2016-06-28 00:52:01 +00:00
Svet Ganov
7878e736f7 Merge \"Mark app pending intents in notification extras\" into nyc-dev
am: b2cd9c95bf

Change-Id: Idb515255f224c23d60a513713d9e4f93decd7a9c
2016-06-28 00:46:55 +00:00
Svet Ganov
ddb948896c Mark app pending intents in notification extras
We need to make every peniding intent that went in the notification
system to allow special handling of such intents when fired by a
notification listener. If a pending intent from a notification
is sent from a notification listener, we white-list the source app
to run in data saver mode for a short period of time. The problem is
that actions and the notificaion can have extras which bundles may
contain pending intents but the system cannot look into the bundles
as they may contain custom parcelable objects. To address this we
keep a list of all pending intents in the notification allowing
the system to access them without touching the bundle. Currently
the pending intents are written to the parcel twice, once in the
bundle and once as the explicit list. We can come up with a scheme
to optimize this but since pending itents are just a binder pointer
it is not worth the excecise.

bug:29480440

Change-Id: I7328a47017ca226117adf7054900836619f5679b
2016-06-27 17:32:25 -07:00
Erik Wolsheimer
178bba4589 Add DENSITY_260, DENSITY_300, DENSITY_340
Add supported screen densities to closer match some hardware's physical specifications

BUG: 24132725
Change-Id: I7138d92fa4e1f4320f9068e154bd8318ac0c45c7
2016-06-15 10:33:09 -07:00
Alex Klyubin
7fe19060cf Merge "Use correct cert chain from PKCS#7 SignedData block." into nyc-dev 2016-06-01 21:55:05 +00:00
Dianne Hackborn
e9a988caca Work on issue #28942589: Tune job scheduler
We now have a new settings key that provides all of the existing
tuning parameters, plus some newly redone ones for dealing with
different memory levels.

Changed the minimum batching for overall jobs from 2 to 1, so
we will never get in the way of immediately scheduling jobs
when the developer asks for this.  We should now be able to rely
on the doze modes to do better batching of jobs for us when it
is really important.

Also work on issue #28981330: Excessive JobScheduler wakeup alarms.
Use a work source with scheduled alarms to blame them on the app
whose job they are being scheduled for, and add a check for whether
a job's timing constraint has been satisfied before considering it
a possible candidate for the next alarm.  (If it is satisified,
the time is in the past, so we should not schedule an alarm for it.)

Finally clean up a bunch of the dumpsys output to make it easier
to understand.

Change-Id: I06cf2c1310448f47cf386f393e9b267335fabaeb
2016-05-31 18:16:19 -07:00
Alex Klyubin
29045203f3 Use correct cert chain from PKCS#7 SignedData block.
This fixes a bug where APK JAR signature verifier returned the wrong
certificate chain. Rather than returning the cert chain of the
verified SignerInfo, it was returning the bag of certs of the PKCS#7
SignedData block.

This issue was introduced in Android N and thus does not affect
earlier Android platform versions.

Bug: 29055836
Change-Id: I684c0f8e9ff47b922030645e07b6a114c0eb0963
2016-05-31 16:10:00 -07:00
Phil Weaver
227d33439d Merge "Fix a11y crash when window layer isn't unique." into nyc-dev 2016-05-19 21:50:29 +00:00
Phil Weaver
adaafb2980 Fix a11y crash when window layer isn't unique.
TalkBack is seeing crashes that I can only explain by our assumption
that window layer is unique in all cases. TalkBack reports that it
happens during animation, so I assume that the layer may repeat
transiently.

Reducing our dependence on this assumption by traversing the list of
windows sorted by layer without assuming that the list has the same
length as the list of unsorted windows.

Also documenting the undefined behavior of SparseArray when indexing
beyond its bounds. The undefined behavior itself is intentional for
performance reasons.

Bug: 28679528
Bug: 28815817
Change-Id: I0c9f90b0b458b4cde465f603ba204fe6691e5c2c
2016-05-19 13:32:24 -07:00
Yohei Yukawa
23cbe85610 Move LocaleList to avoid layering violation.
Since LocaleList needs to depend on android.os.Parcelable, we cannot let
that class belong to "android.util" package, which causes layering
violation.

Bug: 28819696
Change-Id: Ia8de2ee9df3dd0a42b1fe84574439519b680fe18
2016-05-17 16:42:58 -07:00
Svetoslav Ganov
04df738bcb Make settings cahches generation mechanism robust.
Settings is using a MemoryIntArray to communicate the settings table
version enabling apps to have up-to-date local caches. However, ashmem
allows an arbitrary process with a handle to the fd (even in read only
mode) to unpin the memory which can then be garbage collected. Here we
make this mechanism fault tolerant against bad apps unpinning the ashmem
region. First, we no longer unpin the ashmem on the client side and if
the ashmem region is purged and cannot be pinned we recreate it and
hook up again with the local app caches. The change also adds a test
that clients can only read while owner can read/write.

bug:28764789

Change-Id: I1ef79b4b21e976124b268c9126a55d614157059b
2016-05-13 15:14:14 -07:00
Raph Levien
10ea92aefa Make LocaleList constructor non-nullable
This commit makes the LocaleList constructor require non-null
arguments in all cases, and fixes all uses of LocaleList that could
previously pass a null to use getEmptyLocaleList() instead (which is
preferred anyway becaues it avoids an allocation.

Bug: 28460668
Change-Id: I4b8b3cfa82914412731c2b79003951c46cb2afa1
2016-05-02 12:57:56 -07:00
Clara Bayarri
4dc63f78a9 Merge "Cleanup LocaleList docs given API review" into nyc-dev 2016-04-27 15:32:58 +00:00
Clara Bayarri
66f6bd32d8 Cleanup LocaleList docs given API review
-- Remove default constructor from public API since getEmptyLocaleList exists
-- Merge the Locale and Locale[] constructors by providing a single Locale… varargs constructor
-- forLanguageTags, get, toLanguageTags, size, need docs
-- get(int location) should be get(int index)

Plus general docs improvements

Bug: 28296200
Change-Id: I8b4e67184f8c723daebcd251f04947d48bbb5478
2016-04-27 14:55:45 +01:00
Svet Ganov
53a441ca8e Ensure local settings caches are not stale
We used the system proterties as a shared memory mechanism
to propagate information to local settings caches when the
content has changed and the cache should be cleared. The
system properties are unfortunately updated asynchronously
leading to cases where clients may read stale data.

This change adds a simple int array data structure backed
by shared memory which guarantees individual values are
atomically read and updated without memory tear. Multi-
index opearations are not synchronized between each other.

The settings provider is using the new data structure to
propagate the settings generation which drives when caches
are purged.

We have a single memory array keeping the generation for
different settings tables per user. Since memory array is
not a compact data structure and the user space exceeds
the memory array size we use an in-memory map from keys
to indices in the memory array where the generation id of
a key is stored. A key is derived by the setting type in
the 4 most significant bits and the user id in the 28 least
significant bits.

The mapping from a key to an index is cleared if the user is
removed and the corresponding index in the memory arry is
reset to make it available for other users. The size of the
memory array is derived from the max user count that can be
created at the same time.

bug:18826179

Change-Id: I64009cc5105309ef9aa83aba90b82afc8ad8c659
2016-04-26 11:31:55 -07:00
Siyamed Sinir
7903aba3ca Fix Patterns.UCS_CHAR character class
Wrap Patterns.UCS_CHAR character class with brackets. Previously CL
Ie6df818dc4d33dfee6ee54432a2231cca51ec423 broke autoLink email and URL
patterns while excluding the empty spaces.

Bug: 28020781
Change-Id: Ieb7d09cb5e544c1e7cbc1a4d665b979c65e7e773
2016-04-11 18:45:29 -07:00
Siyamed Sinir
4b92594857 Merge "Exclude unicode space characters from autoLink URL patterns" into nyc-dev 2016-04-12 00:35:29 +00:00
Doris Liu
0a1a5167be Improve error logging for parsing failures
Bug: 27043594
Change-Id: I901b65f734c49444a78e0714e007e15e2340ab9d
2016-04-08 18:01:54 +00:00
Siyamed Sinir
911c2694e2 Exclude unicode space characters from autoLink URL patterns
Excludes the following space characters from autoLink URL patterns:
\u00A0: no-break space
\u2000: en quad
\u2001: em quad
\u2002: en space
\u2003: em space
\u2004: three-per-em space
\u2005: four-per-em space
\u2006: six-per-em space
\u2007: figure space
\u2008: punctuation space
\u2009: thin space
\u200A: hair space
\u2028: line separator
\u2029: paragraph separator
\u202F: narrow no-break space
\u3000: ideographic space

Bug: 28020781
Change-Id: Ie6df818dc4d33dfee6ee54432a2231cca51ec423
2016-04-05 16:33:58 -07:00
Alex Klyubin
3a21805aa1 Merge "Remove support for DSA with SHA-512 from v2 sig verification." into nyc-dev 2016-03-31 20:46:04 +00:00
Alex Klyubin
dfb5772447 Remove support for DSA with SHA-512 from v2 sig verification.
Android platform does not support DSA with SHA-512. Thus, it does not
make sense to support this unsupported algorithm in APK Signature
Scheme v2.

Bug: 24331392
Change-Id: Ie90b3dd8dd67bad65c64dfb7f6bf427e8ed282ba
2016-03-31 12:06:18 -07:00
Jeff Sharkey
7732e1e544 Fix RootsCache invalidation bugs.
When RootsCache is still running and it detects a provider/package
change, it needs to force reload roots.  Also fix cache invalidation
bug in ContentService to allow for Uri prefix matches.

Mark internal storage broadcasts with flag to bypass new background
checks.

Bug: 27759529
Change-Id: I9d9c6fe15d8640ff56ae7214afb3bac673682c28
2016-03-30 17:14:25 -06:00
Alex Klyubin
9b59bc459b Ignore signature stripping protection for preinstalled APKs.
The current build process may currently strip APK Signature Scheme v2
signatures from prebuilt APKs to be installed on the system or vendor
partitions. However, it leaves intact the signature scheme rollback
protections introduced by APK Signature Scheme v2. Due to a bug, when
the system extracts signer certificates from preinstalled APKs, it
encounters the rollback protection and aborts the extraction process.
This manifests itself as some preinstalled packages not appearing as
installed.

This change makes the system ignore signature scheme rollback
protections when extracting certificates from preinstalled APKs. This
is fine because the process of extracting certificates from
preinstalled APKs does not care about validity/integrity of signatures
and the APKs. It only cares about extracting signer certificates.

Bug: 27829513
Change-Id: I3bed463e776b057e93a0fce915db4014946be1f9
2016-03-24 12:02:20 -07:00
Alex Klyubin
0722ffcd06 Unbreak verifying v2 signatures of large APKs.
The original implementation of APK Signature Scheme v2 verification
mmapped the whole APK. This does not work on devices with limited
amount of contiguous free logical memory, especially on 32-bit
devices where logical address space is relatively small. For example,
a 500 MB APK is unlikely to mmap on a Nexus 6.

This commit fixes the issue by switching the verification strategy
to mmapping each individual 1 MB chunk of the APK, digesting it, and
then immediately munmapping. This is about 5-10% slower than mmapping
the whole APK in one go.

Bug: 27613575
Change-Id: I4167d5a7720c1bb87a0edad5d4f2607f7d554b56
2016-03-18 17:08:46 -07:00
Alan Viverette
781fbf28c7 Merge "Ensure all Java-side usages of config flags are using Java flags" into nyc-dev 2016-03-14 15:01:51 +00:00
Andrii Kulian
d5db062682 Merge "Update docs for DisplayMetrics pixel size fields" into nyc-dev 2016-03-11 23:50:47 +00:00