Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
215 commits
Select commit Hold shift + click to select a range
80b003a
Themes: Find wp asset when APK has dir entries
euclidgeo Jul 15, 2014
7c58cf7
Catch all exceptions when retrieving ComposedIconInfo
0xD34D Jul 17, 2014
78377f3
Add SET_WALLPAPER permission to SystemUI
0xD34D Jul 17, 2014
61bb3ad
Themes: Add STYLE_THUMBNAIL to PreviewColumns
0xD34D Jul 22, 2014
6bff2fd
Themes: Add helper methods for creating complete component maps
0xD34D Jul 22, 2014
08ea77c
Fix HeadsUp toggle doesn't change
Jul 23, 2014
f1e2a8a
server: make clat interface name public
Oct 12, 2013
49ab641
Add CAP_BLOCK_SUSPEND Linux capability to system server
Nov 12, 2013
a28f277
Reduce total number of background apps for low memory devices
Nov 18, 2013
0e0d3cf
frameworks/base: Update timelapse quality check
Aug 7, 2013
2a52b66
libmediaplayer: update MIME types to include DASH support
Feb 7, 2012
85b049e
When mInputText isn't on focus, hide the soft keyboard
Nov 21, 2012
81e5255
Make sure that items are visible
Nov 13, 2012
a8edd39
framework/base: Create surface based on the panel orientation.
May 7, 2013
bc62d58
DialogFragement: Add null pointer check for mDialog for protection
Sep 27, 2013
ac610ca
ChooseTypeAndAccountActivity: Fix the Null pointer Exception of monke…
Jul 26, 2013
08d879a
Bluetooth: Fix to avoid object leaks during BT OFF
Dec 11, 2013
193e467
Audio: SetForceUse config check in AudioService
Dec 12, 2013
3d090e9
Mms: Fix FC issue that when tapping contact icon many times
Jan 7, 2014
e69860a
framework/base: Handle P2P-REMOVE-AND-REFORM-GROUP event
Oct 10, 2013
4e41fdf
wlan: Fix to handle the failure status on supplicant start.
Jan 27, 2014
2aa9db8
Revert "Add support for BeiDou and Glonass"
Dec 4, 2013
649b02f
Add support for BeiDou and Glonass
Aug 6, 2013
345e1dc
framework/base: Do not kill the supplicant on a request to stop it
Feb 5, 2014
98118fa
P2P : Flush P2P scan results on group fomation failed event
Feb 17, 2014
0043c6f
[video] : added mime-type for mov files
Aug 30, 2013
234b2e8
Show submenu from menu list on hardware MENU key press
Mar 12, 2014
7d19172
wifi: Disable the network based on the Deauth reason code.
Mar 5, 2014
2fc1a55
IndexOutOfBoundsException observed in ProcessStats
Apr 8, 2014
7143b4a
Tunning max allowed background services
Mar 3, 2014
ef1b908
Bluetooth: Avoid fd leak for Bluetooth server socket connections
May 20, 2014
5a14b96
wifi: Support for AP with Chinese GBK Charset SSID
Aug 8, 2013
586992f
Frameworks: Fix ap list issue while wifi turns on
Jun 4, 2014
70056aa
Bluetooth-OBEX: Reduce the MTU size if default OBEX MTU > 8k
Feb 10, 2014
a2016d1
Bluetooth-OBEX: Fine tune OBEX Tx MTU for better performace/power
Apr 4, 2014
cb16e46
[HWUI]: fix residual line on FrameBuffer
Jul 2, 2014
44afb7e
[HWUI] Fix invisible views are still shown in popup window
Jul 3, 2014
97afaa6
[ActivityManager]: Update home process when home activity resumed
Apr 28, 2014
78c3adc
[ActivityManager] Move top task to top in window manager
Jul 16, 2014
148d20c
[ActivityManager] Do not finish root activity when reset task
Jul 16, 2014
28784ef
Themes: Make notification list bg themeable
kaluoshi Jul 13, 2014
11253f1
IconPackHelper: Don't respect an icons original size if too large.
Jul 25, 2014
3acc60d
Virgin Mobile (MNC07) considered non-roaming on Movistar (MNC02)
neatchee Jun 27, 2014
ecffec5
Themes: Whitelist animations
euclidgeo Jul 29, 2014
77ff12e
Load original drawable if cached icon throws NotFoundException
0xD34D Jul 28, 2014
618f9ea
WallpaperCropper: fix lockscreen wallpaper "Set wallpaper" string
romanbb Jul 30, 2014
898fa5c
Merge "Virgin Mobile (MNC07) considered non-roaming on Movistar (MNC0…
MarcLandis Jul 30, 2014
e38c945
Merge "DocumentUtils: Properly check the type of Document" into kitkat
Aug 5, 2014
71aea5d
Import translations from crowdin.net
MarcLandis Jul 30, 2014
2a5f084
Recents: allow apps to be excluded from removing all apps
MarcLandis Jul 29, 2014
063397b
Merge "Recents: allow apps to be excluded from removing all apps" int…
MarcLandis Aug 5, 2014
ff22556
SystemUI: 4G/LTE icon toggle
romanbb Sep 30, 2013
d6581a2
Revert "Fix problem where PhoneWindowManager waits for keyguard to draw"
MarcLandis Aug 1, 2014
2021a13
Merge "Revert "Fix problem where PhoneWindowManager waits for keyguar…
MarcLandis Aug 1, 2014
a96178f
[View] Clear Hardware-Layers before system destroys HardwareRenderer​.
Jul 18, 2014
f970a0c
Fix a bug that the RecentTask list of other’s may show up to non-prim…
EunaeKim1009 Jul 25, 2014
1696790
[ActivityManager] Avoid mistaking visibility by finishing task.
Jul 30, 2014
94683d8
[1/3] Add MobileNetwork toggle
May 17, 2014
61355ea
Add msim stubs to satisfy com.qualcomm.location linkage
tdm Jul 29, 2014
549451f
Move 3rd party wallpaper pickers to the front
0xD34D Jul 28, 2014
cbcc8fc
Include default wallpaper in LockscreenWallpaperPickerActivity
0xD34D Jul 28, 2014
e95bdd1
Add navbar background preview to ThemesContract
0xD34D Jul 30, 2014
da5c008
Ensure to add Persistent Apps to LruProcess List on app restart
boedhack Jun 19, 2014
3b87d8e
Wifi: Fix 2 ip addresses issue
Jun 23, 2014
e1b303c
NetworkManagementService: Change exception type thrown on IPv6
May 16, 2014
fec966b
Broadcast upstream interface change event independently for IPv4 & IPv6
Jun 23, 2014
91c4542
Revert " Audio: SetForceUse config check in AudioService"
Jun 23, 2014
ab229ec
[ActivityManager] Ensure alive process is not killedByAm.
Jul 4, 2014
c0ab9cb
[ActivityManager] Prevent kill a restarted process again.
Jul 4, 2014
bba1233
[ActivityManager] Avoid keeping restarting home when only home activi…
Jul 4, 2014
4d60688
[ActivityManager] Prevent potential deadlock from system error dialog…
Jul 7, 2014
37de727
[ActivityManager] Prevent coredump file may not complete for testing.
Jul 30, 2014
285b7b8
Merge "DocumentsUI: Allow installing APKs from internal storage" into…
Aug 5, 2014
e7c9e13
DocumentsUI: Allow installing APKs from internal storage
Jul 8, 2014
0a6fe2f
DocumentUtils: Properly check the type of Document
Jul 8, 2014
92c3f54
DocumentsUI: Differentiate USBs from SDcards
Jul 8, 2014
b872665
DocumentsUI: Allow installation of apps from external storage
Jul 9, 2014
9cb4bf6
Merge topic 'docui_update' into kitkat
Aug 5, 2014
ea92b7b
network-toggle: add 3g-only mode
Aug 5, 2014
ab0a433
Merge "network-toggle: add 3g-only mode" into kitkat
Aug 5, 2014
7e89d37
Fix: wallpaper changes when changing lockscreen WP
0xD34D Aug 4, 2014
0b80c44
don't disable lockscreen widgets on low memory devices (1/2)
KonstaT Jan 15, 2014
f429255
Merge "don't disable lockscreen widgets on low memory devices (1/2)" …
MarcLandis Aug 7, 2014
30c1924
Gesture Lockscreen [1/2]
0xD34D Jan 27, 2014
80ee8d6
Add column for tracking when a theme was installed
0xD34D Aug 6, 2014
2dc444c
Themes: Build icon cache when applying icons
0xD34D Aug 9, 2014
85fffba
Themes: Pass resource IDs instead of bitmaps [1/2]
0xD34D Aug 10, 2014
7ce7a17
Themes: Allow clearing the wallpaper and ls wallpaper
0xD34D Aug 12, 2014
92a6dda
Themes: setUserRequired(false) when updating audibles
0xD34D Aug 13, 2014
f117ad3
Fix ressource leak in getFileCrC
Flamefire Aug 14, 2014
273c4df
Make sure ThemeConfig is non-null when loading resources
0xD34D Aug 14, 2014
af2bc23
Themes: Add ability to apply color filters to composed icons
0xD34D Aug 5, 2014
f27615a
Themes: Fix icon filters clamping to wrong values
0xD34D Aug 17, 2014
3a5fab9
Themes: Make sure composed icon info is meaningful
0xD34D Aug 17, 2014
532dbda
Themes: Fix blurry composed icons
euclidgeo Aug 18, 2014
94730e8
Themes: Load missing style attributes from original style
0xD34D Aug 18, 2014
1779642
Vectone/Delight (MNC07) considered non-roaming on NOS (MNC03)
neatchee Aug 22, 2014
6ef2ef9
Lycamobile (MNC04) considered non-roaming on Vodafone (MNC01)
neatchee Aug 22, 2014
7372540
Move idmap to frameworks/base [2/2]
0xD34D Aug 20, 2014
81cb87f
Use hidden API to validate APK chains
kruton Apr 17, 2014
cced464
tether: tethering chooses wrong upstream when mobile_dun is required
Jun 5, 2014
b1092b5
Themes: Avoid NPE when setting text in TickerView
0xD34D Aug 20, 2014
8fc31f5
ProximityWake : Add support for checking proximity when waking device
Danesh Jun 26, 2014
b9f244b
Framework : Fix proximity wakeup reference
Danesh Jul 26, 2014
250c377
Be sure to shutdown the proximity sensor after display wake
Der-Schubi Jul 29, 2014
5908393
Proximity : Check proximity flags only if from native
Danesh Aug 5, 2014
0ad2303
PowerManager : Make proximity check opt-in
Danesh Aug 5, 2014
314d625
Themes: Fix setting wallpaper from a legacy theme
0xD34D Aug 23, 2014
64934a9
Themes: Track NotFoundException on app launch failure
0xD34D Aug 23, 2014
1446b3e
Themes: Remove listener if exception is thrown
0xD34D Aug 25, 2014
cd11abc
frameworks: add persistent notification when USB OTG is connected
romanbb Aug 21, 2014
ce1871c
Themes: Fix native crash in libandroidfw
0xD34D Aug 27, 2014
fe3b0e0
Add config_batterySdCardAccessibility to symbols.xml
mikeNG Apr 18, 2014
c408a91
Don't unnecessarily set LayoutParams on children
satur9nine Jun 29, 2014
25fa441
WifiP2pWfdInfo set device type bugfix
Aug 16, 2014
4a68f05
Import translations from crowdin.net
MarcLandis Sep 2, 2014
ec010a9
systemui: networkcontroller update default networks resources
jruesga Aug 31, 2014
4b2d161
Restore untrusted glStencilMask value on resume after functor
ChrisCraik Jul 22, 2014
6d91be6
Broadcast tethered client inteface along with upstream interface name
Aug 13, 2014
911dcc0
WiFi: Check data length before extracting
Aug 12, 2014
f78fa73
Themes: Only kill launchers if overlays or icons changed
0xD34D Sep 2, 2014
4ce92e6
Add ANT to the list of toggleable airplane mode radios
bkhurshi Feb 19, 2014
02083b0
watermark: Place watermark in the bottom-right when both deltax and d…
defer Sep 4, 2014
b88eaad
Optimize drawBitmapMesh using TRIANGLE_STRIP
Jul 23, 2014
69c0119
Revert "framework: fix up AOKP version (1/2)"
mikeNG Jul 3, 2014
2b38392
Settings: Add AOKP PlatLogo & AOKPCaseView (1/2)
mikeNG Dec 3, 2013
ebc66b4
fix lights out layout
MarcLandis Sep 8, 2014
eb5834d
Add System sound option for quiet hours (1/2)
invisiblek Jul 5, 2014
41e3a33
(1/3) Contact details on incoming call
Jun 8, 2014
d6ca228
Themes: Update provider with components that were applied
0xD34D Sep 4, 2014
6207e5a
Themes: Load correct common resources
0xD34D Sep 9, 2014
64a1020
ActivityManagerService: Penalise large apps going to background
Mar 20, 2014
e0ec8aa
ActivityManagerService: Fix heavy games kill during incoming call
Jun 23, 2014
e6d07f5
Prevent killing of process during service bringup
Jun 17, 2014
a20f957
base: Change mobile provision checking to 3 times' HTTP connection
Sep 3, 2014
7d7f7ac
[Resources] fix preload drawables low issue
Jul 15, 2014
ef4c5fc
[AssetAtlas]: Fix AssetAtlas not consider all size of texture.
Jul 17, 2014
27a20a7
[AssetAtlas] Avoid packing 1-pixel width or height asset into AssetAtlas
Jul 25, 2014
99faddc
[ActivityManager] Fix race condition in pss collection
Aug 25, 2014
b8dceb8
[ActivityManager] Finish the failed-to-pause activity
Aug 25, 2014
7fb13c1
[ActivityManager] Fix ServiceRecord leakage
Aug 25, 2014
3dcbff6
[ActivityManager] Ensure provider external access count will be relea…
Aug 27, 2014
02bf423
[ActivityManager] Fix NullPointerException when dumping ContentProvid…
Aug 27, 2014
739357f
[ActivityManager] Prevent provider creating twice.
Jul 30, 2014
0cdae41
[ActivityManager] Fix index out of bounds when updating next pss time.
Jul 30, 2014
ce610ee
ContentProvider: Avoid duplicate initialization of AsyncTask
Ethan1983 Aug 23, 2012
a4e0984
[HWUI] The IBO state should be reset after glDeleteBuffers.
Jul 22, 2014
300ddfb
[HWUI] Infinite recursion in PathTessellator::recursiveQuadraticBezie…
Jul 25, 2014
8cad401
[HWUI]: Bind wrong VBO when drawing text
Jul 3, 2014
287138e
Import translations from crowdin.net
MarcLandis Sep 10, 2014
a4cf1ac
Auto brightness configuration UI (1/2)
rmcc Nov 4, 2013
d5693ba
add ability to unlink notification volume from ringtone volume
Sep 9, 2014
f6f51ff
Allow granting permissions based on signature in <allow-permission/>
0xD34D Sep 6, 2014
ee77b89
base: fix ACTION_NOTIFICATION_LISTENER_SETTINGS intent name
jruesga Sep 8, 2014
7577860
Keyguard: do not play sounds while phone call is active
romanbb Sep 8, 2014
ab71269
Revert "Improve AOSP Download/Upload animation"
Sep 9, 2014
88c438f
Fix broken arc drawing in Camera app.
maniac103 Sep 12, 2014
fb32e73
Revert "ContentProvider: Avoid duplicate initialization of AsyncTask"
amartinz Sep 14, 2014
40aa95f
Solve three memory leaks related to PatchCache
Feb 4, 2014
02509a1
hwui: Fix a sporadic crash seen during CTS runs
hyperb1iss Sep 15, 2014
e55dc62
advanced reboot: add soft reboot option
romanbb Jul 10, 2014
a8a6bbe
Fix attribute resolution in theme lookup
euclidgeo Sep 16, 2014
3bcae1c
Move strings of gesture unlock to correct location
Sep 20, 2014
36750d7
Fix unbound prefix in latest patch
Sep 20, 2014
17409f5
Add double tap sleep feature to secure lockscreens.
travp624 Jan 10, 2014
5c3bdd8
Import translations from crowdin.net
MarcLandis Sep 20, 2014
a99cfd5
Telephony: Add TD-SCDMA network modes
May 30, 2013
a63b1da
Themes: Only process themes that are applied during boot
0xD34D Sep 16, 2014
52c80a1
WallpaperCropper: respect max wallpaper width
pawitp Sep 19, 2014
ee2ea5f
AppWidget: Make widget update quickly
Sep 6, 2014
49cf082
systemui: Unbreak the planet
hyperb1iss Sep 30, 2014
2b41e82
framework: Close system windows when performing 'switch to last app' …
doopl Sep 30, 2014
ce2b9e8
Add PowerManager integration for button and keyboard backlight.
maniac103 Aug 22, 2013
a767bfc
Import translations from crowdin.net
MarcLandis Oct 1, 2014
3b6a198
Themes: Let ThemeService handle all theme processing [1/3]
0xD34D Sep 18, 2014
f07240f
frameworks/base: Fix delay in sending AUDIO_BECOMING_NOISY intent
May 9, 2014
87a1a57
Merge "Add double tap sleep feature to secure lockscreens." into kitkat
Oct 16, 2014
1257cf7
P2P:initiate provisioning on persistant group removed.
May 10, 2014
dca17f8
P2P: Disable 5GHz channels in 2.4 GHz only mode
Jul 8, 2014
c017eea
Wi-Fi: Set BTCOEXMODE_DISABLED irrespective of BT's connection state
Jul 16, 2014
98836d1
Wifi: Handle P2P-REMOVE-AND-REFORM-GROUP event in GroupNegotiationState
Aug 22, 2014
ffdcc3c
wlan: Modify sequence of events sent during DHCP phase.
Sep 4, 2014
ca7dd1d
base: display live wallpaper settings instead of wallpaper picker
jruesga Sep 9, 2014
1f4211e
Themes: Force recompiling common resources when scanning theme
0xD34D Oct 6, 2014
0208cf2
extmediaplayer: miscellaneous fix
Aug 7, 2014
c20b0f8
Fix memory leak in nativeDecodeFileDescriptor
Aug 28, 2014
e0c5ee5
AudioService: Fix monitorRotation for landscape applications
Jan 23, 2014
a481653
Tethering: Enable NAT only when tether and upstream ifaces are differ…
Aug 26, 2014
d07a1e8
lowmemorykiller: Overwrite LMK parameters for low-tier devices
Mar 20, 2014
0be1c2e
MTU should be 1358 as per 3GPP standards, especially for LTE radio i…
Oct 14, 2014
5899e18
Update SET_ACTIVITY_WATCHER protection to signature|system
dreams-of-nextbit-sheep Sep 28, 2014
fbcad06
linearlayout: fix measurement of childrens when parent and childrens …
jruesga Oct 3, 2014
bed02ff
SystemUI: Fix crash during notification/theme change
euclidgeo Oct 29, 2014
c9765e2
radio: Treat REGULAR_DEACTIVATION events as transient errors on AT&T
rmcc Nov 4, 2014
31df5b9
Fix crash while installing themes rapidly
euclidgeo Oct 31, 2014
5523e10
ThemeManager: Synchronize access to listeners
0xD34D Nov 12, 2014
eacdca5
Revert 'base: Add P2P interface "p2p0" to tethering support list'
marado Nov 13, 2014
fbd76bf
Revert "Themes: Build icon cache when applying icons"
0xD34D Nov 13, 2014
2b1dab5
Protect windowNoTitle and windowActionBar attributes
euclidgeo Nov 4, 2014
42f6825
Revert "ActivityTrigger: New class to invoke when activity starts/re…
MarcLandis Nov 16, 2014
34a54a7
Themes: Handle processing themes in separate thread
0xD34D Nov 14, 2014
fa939dd
Installer: Use nanoTime instead of currentTimeMillis
0xD34D Nov 18, 2014
08ec377
Fix issue #16794553: Duplicate ArrayMap entries in Bundle...
Aug 13, 2014
8acdfc0
Do not persist and restore the media button event receiver
jmtrivi Aug 26, 2014
b66d519
lights: fix notification and attention lights
Nov 19, 2014
aa492c6
Pass all theme apks to themeservice for processing
euclidgeo Nov 20, 2014
ce6bae0
Vectone UK (MNC01) considered non-roaming on T-Mobile (MNC30)
dh-harald Nov 21, 2014
c516b7b
Crop wallpaper and lockscreen images before saving them
Nov 17, 2014
6e52a38
Themes: Remove an app's icons from cache when installing
euclidgeo Dec 1, 2014
9dc2480
Themes: Fix memory corruption from closing asset before XMLTree
euclidgeo Dec 5, 2014
23b7e99
core: Fix typos in AOSP EN resources
mikeNG Dec 16, 2014
13b61ba
Themes: Make notification action text color themeable
0xD34D Dec 17, 2014
6906e0f
Keyguard: Fix lockscreen selection view in landscape mode
zweif Nov 12, 2014
8d00d7b
SysUI: Use system theme when currentTheme is null
0xD34D Jan 8, 2015
7b8a8c0
SystemUpdateService: enable service but lock its receivers [1/2]
gianmarcorev Mar 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ LOCAL_SRC_FILES += \
core/java/android/content/pm/IPackageMoveObserver.aidl \
core/java/android/content/pm/IPackageStatsObserver.aidl \
core/java/android/content/res/IThemeChangeListener.aidl \
core/java/android/content/res/IThemeProcessingListener.aidl \
core/java/android/content/res/IThemeService.aidl \
core/java/android/database/IContentObserver.aidl \
core/java/android/hardware/ICameraService.aidl \
Expand Down
3 changes: 3 additions & 0 deletions Gesture.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package android.gesture;

parcelable Gesture;
12 changes: 12 additions & 0 deletions cmds/bootanimation/BootAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ status_t BootAnimation::readyToRun() {
status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
if (status)
return -1;
char value[PROPERTY_VALUE_MAX];
property_get("persist.panel.orientation", value, "0");
int orient = atoi(value) / 90;

if(orient == eOrientation90 || orient == eOrientation270) {
int temp = dinfo.h;
dinfo.h = dinfo.w;
dinfo.w = temp;
}

Rect destRect(dinfo.w, dinfo.h);
mSession->setDisplayProjection(dtoken, orient, destRect, destRect);

// create the native surface
sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
Expand Down
6 changes: 6 additions & 0 deletions cmds/bootanimation/BootAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class SurfaceControl;
class BootAnimation : public Thread, public IBinder::DeathRecipient
{
public:
enum {
eOrientationDefault = 0,
eOrientation90 = 1,
eOrientation180 = 2,
eOrientation270 = 3,
};
BootAnimation();
virtual ~BootAnimation();

Expand Down
28 changes: 28 additions & 0 deletions cmds/idmap/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := idmap.cpp create.cpp scan.cpp inspect.cpp

LOCAL_SHARED_LIBRARIES := liblog libutils libandroidfw

LOCAL_MODULE := idmap

LOCAL_C_INCLUDES := external/zlib

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)
243 changes: 243 additions & 0 deletions cmds/idmap/create.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
#include "idmap.h"

#include <androidfw/AssetManager.h>
#include <androidfw/ResourceTypes.h>
#include <androidfw/ZipFileRO.h>
#include <utils/String8.h>

#include <fcntl.h>
#include <sys/stat.h>

using namespace android;

namespace {
int get_zip_entry_crc(const char *zip_path, const char *entry_name, uint32_t *crc)
{
ZipFileRO zip;
if (zip.open(zip_path) != NO_ERROR) {
return -1;
}
const ZipEntryRO entry = zip.findEntryByName(entry_name);
if (entry == NULL) {
return -1;
}
if (!zip.getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)crc)) {
return -1;
}
return 0;
}

int open_idmap(const char *path)
{
int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644));
if (fd == -1) {
ALOGD("error: open %s: %s\n", path, strerror(errno));
goto fail;
}
if (fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
ALOGD("error: fchmod %s: %s\n", path, strerror(errno));
goto fail;
}
if (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX | LOCK_NB)) != 0) {
ALOGD("error: flock %s: %s\n", path, strerror(errno));
goto fail;
}

return fd;
fail:
if (fd != -1) {
close(fd);
unlink(path);
}
return -1;
}

int write_idmap(int fd, const uint32_t *data, size_t size)
{
if (lseek(fd, SEEK_SET, 0) < 0) {
return -1;
}
size_t bytesLeft = size;
while (bytesLeft > 0) {
ssize_t w = TEMP_FAILURE_RETRY(write(fd, data + size - bytesLeft, bytesLeft));
if (w < 0) {
fprintf(stderr, "error: write: %s\n", strerror(errno));
return -1;
}
bytesLeft -= w;
}
return 0;
}

bool is_idmap_stale_fd(const char *target_apk_path, const char *overlay_apk_path, int idmap_fd)
{
static const size_t N = ResTable::IDMAP_HEADER_SIZE_BYTES;
struct stat st;
if (fstat(idmap_fd, &st) == -1) {
return true;
}
if (st.st_size < N) {
// file is empty or corrupt
return true;
}

char buf[N];
ssize_t bytesLeft = N;
if (lseek(idmap_fd, SEEK_SET, 0) < 0) {
return true;
}
for (;;) {
ssize_t r = TEMP_FAILURE_RETRY(read(idmap_fd, buf + N - bytesLeft, bytesLeft));
if (r < 0) {
return true;
}
bytesLeft -= r;
if (bytesLeft == 0) {
break;
}
if (r == 0) {
// "shouldn't happen"
return true;
}
}

uint32_t cached_target_crc, cached_overlay_crc;
String8 cached_target_path, cached_overlay_path;
if (!ResTable::getIdmapInfo(buf, N, &cached_target_crc, &cached_overlay_crc,
&cached_target_path, &cached_overlay_path)) {
return true;
}

if (cached_target_path != target_apk_path) {
return true;
}
if (cached_overlay_path != overlay_apk_path) {
return true;
}

uint32_t actual_target_crc, actual_overlay_crc;
if (get_zip_entry_crc(target_apk_path, AssetManager::RESOURCES_FILENAME,
&actual_target_crc) == -1) {
return true;
}
if (get_zip_entry_crc(overlay_apk_path, AssetManager::RESOURCES_FILENAME,
&actual_overlay_crc) == -1) {
return true;
}

return cached_target_crc != actual_target_crc || cached_overlay_crc != actual_overlay_crc;
}

bool is_idmap_stale_path(const char *target_apk_path, const char *overlay_apk_path,
const char *idmap_path)
{
struct stat st;
if (stat(idmap_path, &st) == -1) {
// non-existing idmap is always stale; on other errors, abort idmap generation
return errno == ENOENT;
}

int idmap_fd = TEMP_FAILURE_RETRY(open(idmap_path, O_RDONLY));
if (idmap_fd == -1) {
return false;
}
bool is_stale = is_idmap_stale_fd(target_apk_path, overlay_apk_path, idmap_fd);
close(idmap_fd);
return is_stale;
}

int create_idmap(const char *target_apk_path, const char *overlay_apk_path,
uint32_t target_hash, uint32_t overlay_hash, Vector<String8>& targets,
Vector<String8>& overlays, uint32_t **data, size_t *size)
{
uint32_t target_crc, overlay_crc;

// In the original implementation, crc of the res tables are generated
// theme apks however do not need a restable, everything is in assets/
// instead timestamps are used
target_crc = 0;
overlay_crc = 0;

struct stat statbuf;

AssetManager am;
bool b = am.createIdmap(target_apk_path, overlay_apk_path, target_crc, overlay_crc,
target_hash, overlay_hash, targets, overlays, data, size);
return b ? 0 : -1;
}

int create_and_write_idmap(const char *target_apk_path, const char *overlay_apk_path,
uint32_t target_hash, uint32_t overlay_hash,
const char *redirections, int fd, bool check_if_stale)
{
if (check_if_stale) {
if (!is_idmap_stale_fd(target_apk_path, overlay_apk_path, fd)) {
// already up to date -- nothing to do
return 0;
}
}

Vector<String8> targets;
Vector<String8> overlays;
if (redirections && strlen(redirections)) {
FILE *fp = fopen(redirections, "r");
char target[280];
char overlay[280];
if (fp) {
while (!feof(fp)) {
fscanf(fp, "%279s %279s\n", target, overlay);
targets.push(String8(target));
overlays.push(String8(overlay));
}
}
}

uint32_t *data = NULL;
size_t size;

if (create_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash,
targets, overlays, &data, &size) == -1) {
return -1;
}

if (write_idmap(fd, data, size) == -1) {
free(data);
return -1;
}

free(data);
return 0;
}
}

int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path,
uint32_t target_hash, uint32_t overlay_hash,
const char *redirections, const char *idmap_path)
{
if (!is_idmap_stale_path(target_apk_path, overlay_apk_path, idmap_path)) {
// already up to date -- nothing to do
return EXIT_SUCCESS;
}

int fd = open_idmap(idmap_path);
if (fd == -1) {
return EXIT_FAILURE;
}

int r = create_and_write_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash,
redirections, fd, false);
close(fd);
if (r != 0) {
unlink(idmap_path);
}
return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path,
uint32_t target_hash, uint32_t overlay_hash,
const char *redirections, int fd)
{
return create_and_write_idmap(target_apk_path, overlay_apk_path, target_hash, overlay_hash,
redirections, fd, true) == 0 ?
EXIT_SUCCESS : EXIT_FAILURE;
}
Loading