diff options
Diffstat (limited to 'services')
29 files changed, 855 insertions, 159 deletions
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java index 96063d5..c14ed8b 100644 --- a/services/core/java/com/android/server/AlarmManagerService.java +++ b/services/core/java/com/android/server/AlarmManagerService.java @@ -656,12 +656,19 @@ class AlarmManagerService extends SystemService { } @Override - public void setTime(long millis) { + public boolean setTime(long millis) { getContext().enforceCallingOrSelfPermission( "android.permission.SET_TIME", "setTime"); - SystemClock.setCurrentTimeMillis(millis); + if (mNativeData == 0) { + Slog.w(TAG, "Not setting time since no alarm driver is available."); + return false; + } + + synchronized (mLock) { + return setKernelTime(mNativeData, millis) == 0; + } } @Override @@ -1039,6 +1046,7 @@ class AlarmManagerService extends SystemService { private native void close(long nativeData); private native void set(long nativeData, int type, long seconds, long nanoseconds); private native int waitForAlarm(long nativeData); + private native int setKernelTime(long nativeData, long millis); private native int setKernelTimezone(long nativeData, int minuteswest); void triggerAlarmsLocked(ArrayList<Alarm> triggerList, long nowELAPSED, long nowRTC) { diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java index 3fb006b..fc4838c 100644 --- a/services/core/java/com/android/server/AssetAtlasService.java +++ b/services/core/java/com/android/server/AssetAtlasService.java @@ -114,12 +114,11 @@ public class AssetAtlasService extends IAssetAtlas.Stub { // Describes how bitmaps are placed in the atlas. Each bitmap is // represented by several entries in the array: - // int0: SkBitmap*, the native bitmap object - // int1: x position - // int2: y position - // int3: rotated, 1 if the bitmap must be rotated, 0 otherwise - // NOTE: This will need to be handled differently to support 64 bit pointers - private int[] mAtlasMap; + // long0: SkBitmap*, the native bitmap object + // long1: x position + // long2: y position + // long3: rotated, 1 if the bitmap must be rotated, 0 otherwise + private long[] mAtlasMap; /** * Creates a new service. Upon creating, the service will gather the list of @@ -196,7 +195,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub { private final ArrayList<Bitmap> mBitmaps; private final int mPixelCount; - private int mNativeBitmap; + private long mNativeBitmap; // Used for debugging only private Bitmap mAtlasBitmap; @@ -260,8 +259,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { final Atlas.Entry entry = new Atlas.Entry(); - mAtlasMap = new int[packCount * ATLAS_MAP_ENTRY_FIELD_COUNT]; - int[] atlasMap = mAtlasMap; + mAtlasMap = new long[packCount * ATLAS_MAP_ENTRY_FIELD_COUNT]; + long[] atlasMap = mAtlasMap; int mapIndex = 0; boolean result = false; @@ -288,8 +287,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub { } canvas.drawBitmap(bitmap, 0.0f, 0.0f, null); canvas.restore(); - // TODO: Change mAtlasMap to long[] to support 64-bit systems - atlasMap[mapIndex++] = (int) bitmap.mNativeBitmap; + atlasMap[mapIndex++] = bitmap.mNativeBitmap; atlasMap[mapIndex++] = entry.x; atlasMap[mapIndex++] = entry.y; atlasMap[mapIndex++] = entry.rotated ? 1 : 0; @@ -365,9 +363,9 @@ public class AssetAtlasService extends IAssetAtlas.Stub { } } - private static native int nAcquireAtlasCanvas(Canvas canvas, int width, int height); - private static native void nReleaseAtlasCanvas(Canvas canvas, int bitmap); - private static native boolean nUploadAtlas(GraphicBuffer buffer, int bitmap); + private static native long nAcquireAtlasCanvas(Canvas canvas, int width, int height); + private static native void nReleaseAtlasCanvas(Canvas canvas, long bitmap); + private static native boolean nUploadAtlas(GraphicBuffer buffer, long bitmap); @Override public boolean isCompatible(int ppid) { @@ -380,7 +378,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub { } @Override - public int[] getMap() throws RemoteException { + public long[] getMap() throws RemoteException { return mAtlasReady.get() ? mAtlasMap : null; } diff --git a/services/core/java/com/android/server/ConsumerIrService.java b/services/core/java/com/android/server/ConsumerIrService.java index 783dff1..583f1bc 100644 --- a/services/core/java/com/android/server/ConsumerIrService.java +++ b/services/core/java/com/android/server/ConsumerIrService.java @@ -49,13 +49,13 @@ public class ConsumerIrService extends IConsumerIrService.Stub { private static final int MAX_XMIT_TIME = 2000000; /* in microseconds */ - private static native int halOpen(); - private static native int halTransmit(int halObject, int carrierFrequency, int[] pattern); - private static native int[] halGetCarrierFrequencies(int halObject); + private static native long halOpen(); + private static native int halTransmit(long halObject, int carrierFrequency, int[] pattern); + private static native int[] halGetCarrierFrequencies(long halObject); private final Context mContext; private final PowerManager.WakeLock mWakeLock; - private final int mHal; + private final long mNativeHal; private final Object mHalLock = new Object(); ConsumerIrService(Context context) { @@ -65,23 +65,23 @@ public class ConsumerIrService extends IConsumerIrService.Stub { mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.setReferenceCounted(true); - mHal = halOpen(); + mNativeHal = halOpen(); if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONSUMER_IR)) { - if (mHal == 0) { + if (mNativeHal == 0) { throw new RuntimeException("FEATURE_CONSUMER_IR present, but no IR HAL loaded!"); } - } else if (mHal != 0) { + } else if (mNativeHal != 0) { throw new RuntimeException("IR HAL present, but FEATURE_CONSUMER_IR is not set!"); } } @Override public boolean hasIrEmitter() { - return mHal != 0; + return mNativeHal != 0; } private void throwIfNoIrEmitter() { - if (mHal == 0) { + if (mNativeHal == 0) { throw new UnsupportedOperationException("IR emitter not available"); } } @@ -111,7 +111,7 @@ public class ConsumerIrService extends IConsumerIrService.Stub { // Right now there is no mechanism to ensure fair queing of IR requests synchronized (mHalLock) { - int err = halTransmit(mHal, carrierFrequency, pattern); + int err = halTransmit(mNativeHal, carrierFrequency, pattern); if (err < 0) { Slog.e(TAG, "Error transmitting: " + err); @@ -129,7 +129,7 @@ public class ConsumerIrService extends IConsumerIrService.Stub { throwIfNoIrEmitter(); synchronized(mHalLock) { - return halGetCarrierFrequencies(mHal); + return halGetCarrierFrequencies(mNativeHal); } } } diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index eebd1c5..e0b568b 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -452,6 +452,9 @@ public class LocationManagerService extends ILocationManager.Stub { * @param userId the new active user's UserId */ private void switchUser(int userId) { + if (mCurrentUserId == userId) { + return; + } mBlacklist.switchUser(userId); mLocationHandler.removeMessages(MSG_LOCATION_CHANGED); synchronized (mLock) { diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java index 816ae69..f73a92b 100644 --- a/services/core/java/com/android/server/MountService.java +++ b/services/core/java/com/android/server/MountService.java @@ -91,6 +91,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -384,18 +385,37 @@ class MountService extends IMountService.Stub } class ShutdownCallBack extends UnmountCallBack { - IMountShutdownObserver observer; - ShutdownCallBack(String path, IMountShutdownObserver observer) { + MountShutdownLatch mMountShutdownLatch; + ShutdownCallBack(String path, final MountShutdownLatch mountShutdownLatch) { super(path, true, false); - this.observer = observer; + mMountShutdownLatch = mountShutdownLatch; } @Override void handleFinished() { int ret = doUnmountVolume(path, true, removeEncryption); - if (observer != null) { + Slog.i(TAG, "Unmount completed: " + path + ", result code: " + ret); + mMountShutdownLatch.countDown(); + } + } + + static class MountShutdownLatch { + private IMountShutdownObserver mObserver; + private AtomicInteger mCount; + + MountShutdownLatch(final IMountShutdownObserver observer, int count) { + mObserver = observer; + mCount = new AtomicInteger(count); + } + + void countDown() { + boolean sendShutdown = false; + if (mCount.decrementAndGet() == 0) { + sendShutdown = true; + } + if (sendShutdown && mObserver != null) { try { - observer.onShutDownComplete(ret); + mObserver.onShutDownComplete(StorageResultCode.OperationSucceeded); } catch (RemoteException e) { Slog.w(TAG, "RemoteException when shutting down"); } @@ -1426,6 +1446,10 @@ class MountService extends IMountService.Stub Slog.i(TAG, "Shutting down"); synchronized (mVolumesLock) { + // Get all volumes to be unmounted. + MountShutdownLatch mountShutdownLatch = new MountShutdownLatch(observer, + mVolumeStates.size()); + for (String path : mVolumeStates.keySet()) { String state = mVolumeStates.get(path); @@ -1461,19 +1485,16 @@ class MountService extends IMountService.Stub if (state.equals(Environment.MEDIA_MOUNTED)) { // Post a unmount message. - ShutdownCallBack ucb = new ShutdownCallBack(path, observer); + ShutdownCallBack ucb = new ShutdownCallBack(path, mountShutdownLatch); mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb)); } else if (observer != null) { /* - * Observer is waiting for onShutDownComplete when we are done. - * Since nothing will be done send notification directly so shutdown - * sequence can continue. + * Count down, since nothing will be done. The observer will be + * notified when we are done so shutdown sequence can continue. */ - try { - observer.onShutDownComplete(StorageResultCode.OperationSucceeded); - } catch (RemoteException e) { - Slog.w(TAG, "RemoteException when shutting down"); - } + mountShutdownLatch.countDown(); + Slog.i(TAG, "Unmount completed: " + path + + ", result code: " + StorageResultCode.OperationSucceeded); } } } diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index 71e7bac..e83d376 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -82,6 +82,7 @@ import java.net.SocketException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.StringTokenizer; @@ -1022,6 +1023,15 @@ public class NetworkManagementService extends INetworkManagementService.Stub } } + private List<InterfaceAddress> excludeLinkLocal(List<InterfaceAddress> addresses) { + ArrayList<InterfaceAddress> filtered = new ArrayList<InterfaceAddress>(addresses.size()); + for (InterfaceAddress ia : addresses) { + if (!ia.getAddress().isLinkLocalAddress()) + filtered.add(ia); + } + return filtered; + } + private void modifyNat(String action, String internalInterface, String externalInterface) throws SocketException { final Command cmd = new Command("nat", action, internalInterface, externalInterface); @@ -1031,8 +1041,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub if (internalNetworkInterface == null) { cmd.appendArg("0"); } else { - Collection<InterfaceAddress> interfaceAddresses = internalNetworkInterface - .getInterfaceAddresses(); + // Don't touch link-local routes, as link-local addresses aren't routable, + // kernel creates link-local routes on all interfaces automatically + List<InterfaceAddress> interfaceAddresses = excludeLinkLocal( + internalNetworkInterface.getInterfaceAddresses()); cmd.appendArg(interfaceAddresses.size()); for (InterfaceAddress ia : interfaceAddresses) { InetAddress addr = NetworkUtils.getNetworkPart( diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 699d79e..77f5182 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -37,6 +37,10 @@ import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.CellInfo; import android.telephony.TelephonyManager; +import android.telephony.DisconnectCause; +import android.telephony.PreciseCallState; +import android.telephony.PreciseDataConnectionState; +import android.telephony.PreciseDisconnectCause; import android.text.TextUtils; import android.util.Slog; @@ -125,6 +129,17 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private List<CellInfo> mCellInfo = null; + private int mRingingCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; + + private int mForegroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; + + private int mBackgroundCallState = PreciseCallState.PRECISE_CALL_STATE_IDLE; + + private PreciseCallState mPreciseCallState = new PreciseCallState(); + + private PreciseDataConnectionState mPreciseDataConnectionState = + new PreciseDataConnectionState(); + static final int PHONE_STATE_PERMISSION_MASK = PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR | PhoneStateListener.LISTEN_CALL_STATE | @@ -132,6 +147,10 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR; + static final int PRECISE_PHONE_STATE_PERMISSION_MASK = + PhoneStateListener.LISTEN_PRECISE_CALL_STATE | + PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE; + private static final int MSG_USER_SWITCHED = 1; private final Handler mHandler = new Handler() { @@ -305,6 +324,21 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { remove(r.binder); } } + if ((events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { + try { + r.callback.onPreciseCallStateChanged(mPreciseCallState); + } catch (RemoteException ex) { + remove(r.binder); + } + } + if ((events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { + try { + r.callback.onPreciseDataConnectionStateChanged( + mPreciseDataConnectionState); + } catch (RemoteException ex) { + remove(r.binder); + } + } } } } else { @@ -533,30 +567,47 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } handleRemoveListLocked(); } + mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType, + apnType, apn, reason, linkProperties, ""); + for (Record r : mRecords) { + if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { + try { + r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + } + handleRemoveListLocked(); } broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, apnType, linkProperties, linkCapabilities, roaming); + broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason, + linkProperties, ""); } public void notifyDataConnectionFailed(String reason, String apnType) { if (!checkNotifyPermission("notifyDataConnectionFailed()")) { return; } - /* - * This is commented out because there is no onDataConnectionFailed callback - * in PhoneStateListener. There should be. synchronized (mRecords) { - mDataConnectionFailedReason = reason; - final int N = mRecords.size(); - for (int i=N-1; i>=0; i--) { - Record r = mRecords.get(i); - if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_FAILED) != 0) { - // XXX + mPreciseDataConnectionState = new PreciseDataConnectionState( + TelephonyManager.DATA_UNKNOWN,TelephonyManager.NETWORK_TYPE_UNKNOWN, + apnType, "", reason, null, ""); + for (Record r : mRecords) { + if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { + try { + r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } } } + handleRemoveListLocked(); } - */ broadcastDataConnectionFailed(reason, apnType); + broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, + TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, ""); } public void notifyCellLocation(Bundle cellLocation) { @@ -602,6 +653,81 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } } + public void notifyPreciseCallState(int ringingCallState, int foregroundCallState, + int backgroundCallState) { + if (!checkNotifyPermission("notifyPreciseCallState()")) { + return; + } + synchronized (mRecords) { + mRingingCallState = ringingCallState; + mForegroundCallState = foregroundCallState; + mBackgroundCallState = backgroundCallState; + mPreciseCallState = new PreciseCallState(ringingCallState, foregroundCallState, + backgroundCallState, + DisconnectCause.NOT_VALID, + PreciseDisconnectCause.NOT_VALID); + for (Record r : mRecords) { + if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { + try { + r.callback.onPreciseCallStateChanged(mPreciseCallState); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + } + handleRemoveListLocked(); + } + broadcastPreciseCallStateChanged(ringingCallState, foregroundCallState, backgroundCallState, + DisconnectCause.NOT_VALID, + PreciseDisconnectCause.NOT_VALID); + } + + public void notifyDisconnectCause(int disconnectCause, int preciseDisconnectCause) { + if (!checkNotifyPermission("notifyDisconnectCause()")) { + return; + } + synchronized (mRecords) { + mPreciseCallState = new PreciseCallState(mRingingCallState, mForegroundCallState, + mBackgroundCallState, disconnectCause, preciseDisconnectCause); + for (Record r : mRecords) { + if ((r.events & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) { + try { + r.callback.onPreciseCallStateChanged(mPreciseCallState); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + } + handleRemoveListLocked(); + } + broadcastPreciseCallStateChanged(mRingingCallState, mForegroundCallState, + mBackgroundCallState, disconnectCause, preciseDisconnectCause); + } + + public void notifyPreciseDataConnectionFailed(String reason, String apnType, + String apn, String failCause) { + if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) { + return; + } + synchronized (mRecords) { + mPreciseDataConnectionState = new PreciseDataConnectionState( + TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, + apnType, apn, reason, null, failCause); + for (Record r : mRecords) { + if ((r.events & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) { + try { + r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); + } catch (RemoteException ex) { + mRemoveList.add(r.binder); + } + } + } + handleRemoveListLocked(); + } + broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, + TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause); + } + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) @@ -738,6 +864,33 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } + private void broadcastPreciseCallStateChanged(int ringingCallState, int foregroundCallState, + int backgroundCallState, int disconnectCause, int preciseDisconnectCause) { + Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_CALL_STATE_CHANGED); + intent.putExtra(TelephonyManager.EXTRA_RINGING_CALL_STATE, ringingCallState); + intent.putExtra(TelephonyManager.EXTRA_FOREGROUND_CALL_STATE, foregroundCallState); + intent.putExtra(TelephonyManager.EXTRA_BACKGROUND_CALL_STATE, backgroundCallState); + intent.putExtra(TelephonyManager.EXTRA_DISCONNECT_CAUSE, disconnectCause); + intent.putExtra(TelephonyManager.EXTRA_PRECISE_DISCONNECT_CAUSE, preciseDisconnectCause); + mContext.sendBroadcastAsUser(intent, UserHandle.ALL, + android.Manifest.permission.READ_PRECISE_PHONE_STATE); + } + + private void broadcastPreciseDataConnectionStateChanged(int state, int networkType, + String apnType, String apn, String reason, LinkProperties linkProperties, String failCause) { + Intent intent = new Intent(TelephonyManager.ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED); + intent.putExtra(PhoneConstants.STATE_KEY, state); + intent.putExtra(PhoneConstants.DATA_NETWORK_TYPE_KEY, networkType); + if (reason != null) intent.putExtra(PhoneConstants.STATE_CHANGE_REASON_KEY, reason); + if (apnType != null) intent.putExtra(PhoneConstants.DATA_APN_TYPE_KEY, apnType); + if (apn != null) intent.putExtra(PhoneConstants.DATA_APN_KEY, apn); + if (linkProperties != null) intent.putExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY, linkProperties); + if (failCause != null) intent.putExtra(PhoneConstants.DATA_FAILURE_CAUSE_KEY, failCause); + + mContext.sendBroadcastAsUser(intent, UserHandle.ALL, + android.Manifest.permission.READ_PRECISE_PHONE_STATE); + } + private boolean checkNotifyPermission(String method) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { @@ -766,6 +919,12 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.READ_PHONE_STATE, null); } + + if ((events & PRECISE_PHONE_STATE_PERMISSION_MASK) != 0) { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.READ_PRECISE_PHONE_STATE, null); + + } } private void handleRemoveListLocked() { diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 17bb3e0..d66c5a7 100644..100755 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -203,6 +203,7 @@ public final class ActiveServices { Slog.i(TAG, "Waited long enough for: " + r); mStartingBackground.remove(i); N--; + i--; } } while (mDelayedStartList.size() > 0 diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 98cbe7d..1ded05a 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -42,6 +42,7 @@ import com.android.internal.os.BackgroundThread; import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.ProcessCpuTracker; import com.android.internal.os.TransferPipe; +import com.android.internal.os.Zygote; import com.android.internal.util.FastPrintWriter; import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.MemInfoReader; @@ -61,7 +62,6 @@ import com.android.server.wm.WindowManagerService; import com.google.android.collect.Lists; import com.google.android.collect.Maps; -import dalvik.system.Zygote; import libcore.io.IoUtils; import org.xmlpull.v1.XmlPullParser; @@ -930,6 +930,11 @@ public final class ActivityManagerService extends ActivityManagerNative */ boolean mDidDexOpt; + /** + * Set if the systemServer made a call to enterSafeMode. + */ + boolean mSafeMode; + String mDebugApp = null; boolean mWaitForDebugger = false; boolean mDebugTransient = false; @@ -1058,6 +1063,7 @@ public final class ActivityManagerService extends ActivityManagerNative static final int IMMERSIVE_MODE_LOCK_MSG = 37; static final int PERSIST_URI_GRANTS_MSG = 38; static final int REQUEST_ALL_PSS_MSG = 39; + static final int UPDATE_TIME = 40; static final int FIRST_ACTIVITY_STACK_MSG = 100; static final int FIRST_BROADCAST_QUEUE_MSG = 200; @@ -1671,6 +1677,22 @@ public final class ActivityManagerService extends ActivityManagerNative requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false); break; } + case UPDATE_TIME: { + synchronized (ActivityManagerService.this) { + for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) { + ProcessRecord r = mLruProcesses.get(i); + if (r.thread != null) { + try { + r.thread.updateTimePrefs(msg.arg1 == 0 ? false : true); + } catch (RemoteException ex) { + Slog.w(TAG, "Failed to update preferences for: " + r.info.processName); + } + } + } + } + + break; + } } } }; @@ -2703,7 +2725,7 @@ public final class ActivityManagerService extends ActivityManagerNative // Run the app in safe mode if its manifest requests so or the // system is booted in safe mode. if ((app.info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0 || - Zygote.systemInSafeMode == true) { + mSafeMode == true) { debugFlags |= Zygote.DEBUG_ENABLE_SAFEMODE; } if ("1".equals(SystemProperties.get("debug.checkjni"))) { @@ -2716,11 +2738,16 @@ public final class ActivityManagerService extends ActivityManagerNative debugFlags |= Zygote.DEBUG_ENABLE_ASSERT; } + String requiredAbi = app.info.requiredCpuAbi; + if (requiredAbi == null) { + requiredAbi = Build.SUPPORTED_ABIS[0]; + } + // Start the process. It will either succeed and return a result containing // the PID of the new process, or else throw a RuntimeException. Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread", app.processName, uid, uid, gids, debugFlags, mountExternal, - app.info.targetSdkVersion, app.info.seinfo, null); + app.info.targetSdkVersion, app.info.seinfo, requiredAbi, null); BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics(); synchronized (bs) { @@ -8699,6 +8726,8 @@ public final class ActivityManagerService extends ActivityManagerNative } catch (RemoteException e) { } } + + mSafeMode = true; } } @@ -12302,6 +12331,7 @@ public final class ActivityManagerService extends ActivityManagerNative app.foregroundActivities = false; app.hasShownUi = false; app.hasAboveClient = false; + app.hasClientActivities = false; mServices.killServicesLocked(app, allowRestart); @@ -13314,11 +13344,20 @@ public final class ActivityManagerService extends ActivityManagerNative * of all currently running processes. This message will get queued up before the broadcast * happens. */ - if (intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) { + if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) { mHandler.sendEmptyMessage(UPDATE_TIME_ZONE); } - if (intent.ACTION_CLEAR_DNS_CACHE.equals(intent.getAction())) { + /* + * If the user set the time, let all running processes know. + */ + if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) { + final int is24Hour = intent.getBooleanExtra( + Intent.EXTRA_TIME_PREF_24_HOUR_FORMAT, false) ? 1 : 0; + mHandler.sendMessage(mHandler.obtainMessage(UPDATE_TIME, is24Hour, 0)); + } + + if (Intent.ACTION_CLEAR_DNS_CACHE.equals(intent.getAction())) { mHandler.sendEmptyMessage(CLEAR_DNS_CACHE_MSG); } diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index a27288a..aaf5f4d 100644..100755 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -947,8 +947,8 @@ final class ActivityRecord { // for another app to start, then we have paused dispatching // for this activity. ActivityRecord r = this; - final ActivityStack stack = task.stack; if (r.waitingVisible) { + final ActivityStack stack = mStackSupervisor.getFocusedStack(); // Hmmm, who might we be waiting for? r = stack.mResumedActivity; if (r == null) { diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 68ef815..982c9bf 100755 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -1151,6 +1151,7 @@ final class ActivityStack { // At this point, nothing else needs to be shown if (DEBUG_VISBILITY) Slog.v(TAG, "Fullscreen: at " + r); behindFullscreen = true; + showHomeBehindStack = false; } else if (isActivityOverHome(r)) { if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r); showHomeBehindStack = true; @@ -2636,6 +2637,9 @@ final class ActivityStack { if (mResumedActivity == r) { mResumedActivity = null; } + if (mPausingActivity == r) { + mPausingActivity = null; + } if (mService.mFocusedActivity == r) { mService.mFocusedActivity = null; } diff --git a/services/core/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java index 10ea67c..4c887dd 100644 --- a/services/core/java/com/android/server/am/CoreSettingsObserver.java +++ b/services/core/java/com/android/server/am/CoreSettingsObserver.java @@ -37,11 +37,16 @@ final class CoreSettingsObserver extends ContentObserver { private static final String LOG_TAG = CoreSettingsObserver.class.getSimpleName(); // mapping form property name to its type - private static final Map<String, Class<?>> sCoreSettingToTypeMap = new HashMap< + private static final Map<String, Class<?>> sSecureSettingToTypeMap = new HashMap< + String, Class<?>>(); + private static final Map<String, Class<?>> sSystemSettingToTypeMap = new HashMap< String, Class<?>>(); static { - sCoreSettingToTypeMap.put(Settings.Secure.LONG_PRESS_TIMEOUT, int.class); - // add other core settings here... + sSecureSettingToTypeMap.put(Settings.Secure.LONG_PRESS_TIMEOUT, int.class); + // add other secure settings here... + + sSystemSettingToTypeMap.put(Settings.System.TIME_12_24, String.class); + // add other system settings here... } private final Bundle mCoreSettings = new Bundle(); @@ -67,39 +72,62 @@ final class CoreSettingsObserver extends ContentObserver { } private void sendCoreSettings() { - populateCoreSettings(mCoreSettings); + populateSettings(mCoreSettings, sSecureSettingToTypeMap); + populateSettings(mCoreSettings, sSystemSettingToTypeMap); mActivityManagerService.onCoreSettingsChange(mCoreSettings); } private void beginObserveCoreSettings() { - for (String setting : sCoreSettingToTypeMap.keySet()) { + for (String setting : sSecureSettingToTypeMap.keySet()) { Uri uri = Settings.Secure.getUriFor(setting); mActivityManagerService.mContext.getContentResolver().registerContentObserver( uri, false, this); } + + for (String setting : sSystemSettingToTypeMap.keySet()) { + Uri uri = Settings.System.getUriFor(setting); + mActivityManagerService.mContext.getContentResolver().registerContentObserver( + uri, false, this); + } } - private void populateCoreSettings(Bundle snapshot) { + private void populateSettings(Bundle snapshot, Map<String, Class<?>> map) { Context context = mActivityManagerService.mContext; - for (Map.Entry<String, Class<?>> entry : sCoreSettingToTypeMap.entrySet()) { + for (Map.Entry<String, Class<?>> entry : map.entrySet()) { String setting = entry.getKey(); Class<?> type = entry.getValue(); try { if (type == String.class) { - String value = Settings.Secure.getString(context.getContentResolver(), - setting); + final String value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getString(context.getContentResolver(), setting); + } else { + value = Settings.System.getString(context.getContentResolver(), setting); + } snapshot.putString(setting, value); } else if (type == int.class) { - int value = Settings.Secure.getInt(context.getContentResolver(), - setting); + final int value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getInt(context.getContentResolver(), setting); + } else { + value = Settings.System.getInt(context.getContentResolver(), setting); + } snapshot.putInt(setting, value); } else if (type == float.class) { - float value = Settings.Secure.getFloat(context.getContentResolver(), - setting); + final float value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getFloat(context.getContentResolver(), setting); + } else { + value = Settings.System.getFloat(context.getContentResolver(), setting); + } snapshot.putFloat(setting, value); } else if (type == long.class) { - long value = Settings.Secure.getLong(context.getContentResolver(), - setting); + final long value; + if (map == sSecureSettingToTypeMap) { + value = Settings.Secure.getLong(context.getContentResolver(), setting); + } else { + value = Settings.System.getLong(context.getContentResolver(), setting); + } snapshot.putLong(setting, value); } } catch (SettingNotFoundException snfe) { diff --git a/services/core/java/com/android/server/firewall/IntentFirewall.java b/services/core/java/com/android/server/firewall/IntentFirewall.java index 88a2207..eb7a383 100644 --- a/services/core/java/com/android/server/firewall/IntentFirewall.java +++ b/services/core/java/com/android/server/firewall/IntentFirewall.java @@ -270,11 +270,13 @@ public class IntentFirewall { } File[] files = rulesDir.listFiles(); - for (int i=0; i<files.length; i++) { - File file = files[i]; + if (files != null) { + for (int i=0; i<files.length; i++) { + File file = files[i]; - if (file.getName().endsWith(".xml")) { - readRules(file, resolvers); + if (file.getName().endsWith(".xml")) { + readRules(file, resolvers); + } } } diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java index 62c0ec9..94cf668 100644 --- a/services/core/java/com/android/server/lights/LightsService.java +++ b/services/core/java/com/android/server/lights/LightsService.java @@ -78,6 +78,7 @@ public class LightsService extends SystemService { synchronized (this) { if (mColor == 0 && !mFlashing) { setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000, BRIGHTNESS_MODE_USER); + mColor = 0; mH.sendMessageDelayed(Message.obtain(mH, 1, this), onMS); } } diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index 6185e50..ff816ea 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -218,6 +218,30 @@ public final class Installer extends SystemService { builder.append(' '); builder.append(uid); builder.append(isPublic ? " 1" : " 0"); + builder.append(" *"); // No pkgName arg present + return execute(builder.toString()); + } + + public int dexopt(String apkPath, int uid, boolean isPublic, String pkgName) { + StringBuilder builder = new StringBuilder("dexopt"); + builder.append(' '); + builder.append(apkPath); + builder.append(' '); + builder.append(uid); + builder.append(isPublic ? " 1" : " 0"); + builder.append(' '); + builder.append(pkgName); + return execute(builder.toString()); + } + + public int idmap(String targetApkPath, String overlayApkPath, int uid) { + StringBuilder builder = new StringBuilder("idmap"); + builder.append(' '); + builder.append(targetApkPath); + builder.append(' '); + builder.append(overlayApkPath); + builder.append(' '); + builder.append(uid); return execute(builder.toString()); } @@ -382,4 +406,15 @@ public final class Installer extends SystemService { return execute(builder.toString()); } + + public boolean restoreconData(String pkgName, String seinfo, int uid) { + StringBuilder builder = new StringBuilder("restorecondata"); + builder.append(' '); + builder.append(pkgName); + builder.append(' '); + builder.append(seinfo != null ? seinfo : "!"); + builder.append(' '); + builder.append(uid); + return (execute(builder.toString()) == 0); + } } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 0f2bea6..35d1f7d 100755 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -60,8 +60,8 @@ import android.content.IIntentReceiver; import android.content.Intent; import android.content.IntentFilter; import android.content.IntentSender; -import android.content.ServiceConnection; import android.content.IntentSender.SendIntentException; +import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ContainerEncryptionParams; @@ -73,14 +73,15 @@ import android.content.pm.IPackageManager; import android.content.pm.IPackageMoveObserver; import android.content.pm.IPackageStatsObserver; import android.content.pm.InstrumentationInfo; +import android.content.pm.ManifestDigest; import android.content.pm.PackageCleanItem; import android.content.pm.PackageInfo; import android.content.pm.PackageInfoLite; import android.content.pm.PackageManager; import android.content.pm.PackageParser; -import android.content.pm.PackageUserState; import android.content.pm.PackageParser.ActivityIntentInfo; import android.content.pm.PackageStats; +import android.content.pm.PackageUserState; import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; @@ -88,7 +89,6 @@ import android.content.pm.ProviderInfo; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.Signature; -import android.content.pm.ManifestDigest; import android.content.pm.VerificationParams; import android.content.pm.VerifierDeviceIdentity; import android.content.pm.VerifierInfo; @@ -99,6 +99,7 @@ import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.os.Environment.UserEnvironment; import android.os.FileObserver; import android.os.FileUtils; import android.os.Handler; @@ -115,7 +116,6 @@ import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; -import android.os.Environment.UserEnvironment; import android.os.UserManager; import android.security.KeyStore; import android.security.SystemKeyStore; @@ -219,7 +219,8 @@ public class PackageManagerService extends IPackageManager.Stub { static final int SCAN_UPDATE_TIME = 1<<6; static final int SCAN_DEFER_DEX = 1<<7; static final int SCAN_BOOTING = 1<<8; - static final int SCAN_DELETE_DATA_ON_FAILURES = 1<<9; + static final int SCAN_TRUSTED_OVERLAY = 1<<9; + static final int SCAN_DELETE_DATA_ON_FAILURES = 1<<10; static final int REMOVE_CHATTY = 1<<16; @@ -260,9 +261,15 @@ public class PackageManagerService extends IPackageManager.Stub { private static final String LIB_DIR_NAME = "lib"; + private static final String VENDOR_OVERLAY_DIR = "/vendor/overlay"; + static final String mTempContainerPrefix = "smdl2tmp"; final ServiceThread mHandlerThread; + + private static final String IDMAP_PREFIX = "/data/resource-cache/"; + private static final String IDMAP_SUFFIX = "@idmap"; + final PackageHandler mHandler; final int mSdkVersion = Build.VERSION.SDK_INT; @@ -298,6 +305,9 @@ public class PackageManagerService extends IPackageManager.Stub { // This is the object monitoring the system app dir. final FileObserver mVendorInstallObserver; + // This is the object monitoring the vendor overlay package dir. + final FileObserver mVendorOverlayInstallObserver; + // This is the object monitoring mAppInstallDir. final FileObserver mAppInstallObserver; @@ -344,6 +354,10 @@ public class PackageManagerService extends IPackageManager.Stub { final HashMap<String, PackageParser.Package> mPackages = new HashMap<String, PackageParser.Package>(); + // Tracks available target package names -> overlay package paths. + final HashMap<String, HashMap<String, PackageParser.Package>> mOverlays = + new HashMap<String, HashMap<String, PackageParser.Package>>(); + final Settings mSettings; boolean mRestoredSettings; @@ -381,6 +395,9 @@ public class PackageManagerService extends IPackageManager.Stub { // If mac_permissions.xml was found for seinfo labeling. boolean mFoundPolicyFile; + // If a recursive restorecon of /data/data/<pkg> is needed. + private boolean mShouldRestoreconData = SELinuxMMAC.shouldRestorecon(); + // All available activities, for your resolving pleasure. final ActivityIntentResolver mActivities = new ActivityIntentResolver(); @@ -1202,7 +1219,7 @@ public class PackageManagerService extends IPackageManager.Stub { continue; } try { - if (dalvik.system.DexFile.isDexOptNeeded(lib)) { + if (dalvik.system.DexFile.isDexOptNeededInternal(lib, null, false)) { alreadyDexOpted.add(lib); mInstaller.dexopt(lib, Process.SYSTEM_UID, true); didDexOpt = true; @@ -1246,7 +1263,7 @@ public class PackageManagerService extends IPackageManager.Stub { continue; } try { - if (dalvik.system.DexFile.isDexOptNeeded(path)) { + if (dalvik.system.DexFile.isDexOptNeededInternal(path, null, false)) { mInstaller.dexopt(path, Process.SYSTEM_UID, true); didDexOpt = true; } @@ -1279,6 +1296,17 @@ public class PackageManagerService extends IPackageManager.Stub { } } + // Collect vendor overlay packages. + // (Do this before scanning any apps.) + // For security and version matching reason, only consider + // overlay packages if they reside in VENDOR_OVERLAY_DIR. + File vendorOverlayDir = new File(VENDOR_OVERLAY_DIR); + mVendorOverlayInstallObserver = new AppDirObserver( + vendorOverlayDir.getPath(), OBSERVER_EVENTS, true, false); + mVendorOverlayInstallObserver.startWatching(); + scanDirLI(vendorOverlayDir, PackageParser.PARSE_IS_SYSTEM + | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode | SCAN_TRUSTED_OVERLAY, 0); + // Find base frameworks (resource packages without code). mFrameworkInstallObserver = new AppDirObserver( frameworkDir.getPath(), OBSERVER_EVENTS, true, false); @@ -1307,6 +1335,11 @@ public class PackageManagerService extends IPackageManager.Stub { // Collect all vendor packages. File vendorAppDir = new File("/vendor/app"); + try { + vendorAppDir = vendorAppDir.getCanonicalFile(); + } catch (IOException e) { + // failed to look up canonical path, continue with original one + } mVendorInstallObserver = new AppDirObserver( vendorAppDir.getPath(), OBSERVER_EVENTS, true, false); mVendorInstallObserver.startWatching(); @@ -1979,6 +2012,7 @@ public class PackageManagerService extends IPackageManager.Stub { pkg.applicationInfo.dataDir = getDataPathForPackage(packageName, 0).getPath(); pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString; + pkg.applicationInfo.requiredCpuAbi = ps.requiredCpuAbiString; } return generatePackageInfo(pkg, flags, userId); } @@ -3502,6 +3536,56 @@ public class PackageManagerService extends IPackageManager.Stub { return finalList; } + private void createIdmapsForPackageLI(PackageParser.Package pkg) { + HashMap<String, PackageParser.Package> overlays = mOverlays.get(pkg.packageName); + if (overlays == null) { + Slog.w(TAG, "Unable to create idmap for " + pkg.packageName + ": no overlay packages"); + return; + } + for (PackageParser.Package opkg : overlays.values()) { + // Not much to do if idmap fails: we already logged the error + // and we certainly don't want to abort installation of pkg simply + // because an overlay didn't fit properly. For these reasons, + // ignore the return value of createIdmapForPackagePairLI. + createIdmapForPackagePairLI(pkg, opkg); + } + } + + private boolean createIdmapForPackagePairLI(PackageParser.Package pkg, + PackageParser.Package opkg) { + if (!opkg.mTrustedOverlay) { + Slog.w(TAG, "Skipping target and overlay pair " + pkg.mScanPath + " and " + + opkg.mScanPath + ": overlay not trusted"); + return false; + } + HashMap<String, PackageParser.Package> overlaySet = mOverlays.get(pkg.packageName); + if (overlaySet == null) { + Slog.e(TAG, "was about to create idmap for " + pkg.mScanPath + " and " + + opkg.mScanPath + " but target package has no known overlays"); + return false; + } + final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid); + if (mInstaller.idmap(pkg.mScanPath, opkg.mScanPath, sharedGid) != 0) { + Slog.e(TAG, "Failed to generate idmap for " + pkg.mScanPath + " and " + opkg.mScanPath); + return false; + } + PackageParser.Package[] overlayArray = + overlaySet.values().toArray(new PackageParser.Package[0]); + Comparator<PackageParser.Package> cmp = new Comparator<PackageParser.Package>() { + public int compare(PackageParser.Package p1, PackageParser.Package p2) { + return p1.mOverlayPriority - p2.mOverlayPriority; + } + }; + Arrays.sort(overlayArray, cmp); + + pkg.applicationInfo.resourceDirs = new String[overlayArray.length]; + int i = 0; + for (PackageParser.Package p : overlayArray) { + pkg.applicationInfo.resourceDirs[i++] = p.applicationInfo.sourceDir; + } + return true; + } + private void scanDirLI(File dir, int flags, int scanMode, long currentTime) { String[] files = dir.list(); if (files == null) { @@ -3599,7 +3683,7 @@ public class PackageManagerService extends IPackageManager.Stub { pp.setSeparateProcesses(mSeparateProcesses); pp.setOnlyCoreApps(mOnlyCore); final PackageParser.Package pkg = pp.parsePackage(scanFile, - scanPath, mMetrics, parseFlags); + scanPath, mMetrics, parseFlags, (scanMode & SCAN_TRUSTED_OVERLAY) != 0); if (pkg == null) { mLastScanError = pp.getParseError(); @@ -3627,6 +3711,7 @@ public class PackageManagerService extends IPackageManager.Stub { updatedPkg = mSettings.getDisabledSystemPkgLPr(ps != null ? ps.name : pkg.packageName); if (DEBUG_INSTALL && updatedPkg != null) Slog.d(TAG, "updatedPkg = " + updatedPkg); } + boolean updatedPkgBetter = false; // First check if this is a system package that may involve an update if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { if (ps != null && !ps.codePath.equals(scanFile)) { @@ -3681,6 +3766,7 @@ public class PackageManagerService extends IPackageManager.Stub { synchronized (mPackages) { mSettings.enableSystemPackageLPw(ps.name); } + updatedPkgBetter = true; } } } @@ -3757,7 +3843,7 @@ public class PackageManagerService extends IPackageManager.Stub { String codePath = null; String resPath = null; - if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) { + if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0 && !updatedPkgBetter) { if (ps != null && ps.resourcePathString != null) { resPath = ps.resourcePathString; } else { @@ -3771,6 +3857,8 @@ public class PackageManagerService extends IPackageManager.Stub { codePath = pkg.mScanPath; // Set application objects path explicitly. setApplicationInfoPaths(pkg, codePath, resPath); + // Applications can run with the primary Cpu Abi unless otherwise is specified + pkg.applicationInfo.requiredCpuAbi = null; // Note that we invoke the following method only if we are about to unpack an application PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_SIGNATURE, currentTime, user); @@ -3939,7 +4027,8 @@ public class PackageManagerService extends IPackageManager.Stub { String path = pkg.mScanPath; int ret = 0; try { - if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) { + if (forceDex || dalvik.system.DexFile.isDexOptNeededInternal(path, pkg.packageName, + defer)) { if (!forceDex && defer) { if (mDeferredDexOpt == null) { mDeferredDexOpt = new HashSet<PackageParser.Package>(); @@ -3949,7 +4038,8 @@ public class PackageManagerService extends IPackageManager.Stub { } else { Log.i(TAG, "Running dexopt on: " + pkg.applicationInfo.packageName); final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid); - ret = mInstaller.dexopt(path, sharedGid, !isForwardLocked(pkg)); + ret = mInstaller.dexopt(path, sharedGid, !isForwardLocked(pkg), + pkg.packageName); pkg.mDidDexOpt = true; performed = true; } @@ -4340,6 +4430,7 @@ public class PackageManagerService extends IPackageManager.Stub { // the PkgSetting exists already and doesn't have to be created. pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile, destResourceFile, pkg.applicationInfo.nativeLibraryDir, + pkg.applicationInfo.requiredCpuAbi, pkg.applicationInfo.flags, user, false); if (pkgSetting == null) { Slog.w(TAG, "Creating application package " + pkg.packageName + " failed"); @@ -4558,6 +4649,11 @@ public class PackageManagerService extends IPackageManager.Stub { } } pkg.applicationInfo.dataDir = dataPath.getPath(); + if (mShouldRestoreconData) { + Slog.i(TAG, "SELinux relabeling of " + pkg.packageName + " issued."); + mInstaller.restoreconData(pkg.packageName, pkg.applicationInfo.seinfo, + pkg.applicationInfo.uid); + } } else { if (DEBUG_PACKAGE_SCANNING) { if ((parseFlags & PackageParser.PARSE_CHATTY) != 0) @@ -4640,11 +4736,20 @@ public class PackageManagerService extends IPackageManager.Stub { } try { - if (copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir) != PackageManager.INSTALL_SUCCEEDED) { + int copyRet = copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir); + if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) { Slog.e(TAG, "Unable to copy native libraries"); mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; return null; } + + // We've successfully copied native libraries across, so we make a + // note of what ABI we're using + if (copyRet != PackageManager.NO_NATIVE_LIBRARIES) { + pkg.applicationInfo.requiredCpuAbi = Build.SUPPORTED_ABIS[copyRet]; + } else { + pkg.applicationInfo.requiredCpuAbi = null; + } } catch (IOException e) { Slog.e(TAG, "Unable to copy native libraries", e); mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; @@ -5115,6 +5220,29 @@ public class PackageManagerService extends IPackageManager.Stub { } pkgSetting.setTimeStamp(scanFileTime); + + // Create idmap files for pairs of (packages, overlay packages). + // Note: "android", ie framework-res.apk, is handled by native layers. + if (pkg.mOverlayTarget != null) { + // This is an overlay package. + if (pkg.mOverlayTarget != null && !pkg.mOverlayTarget.equals("android")) { + if (!mOverlays.containsKey(pkg.mOverlayTarget)) { + mOverlays.put(pkg.mOverlayTarget, + new HashMap<String, PackageParser.Package>()); + } + HashMap<String, PackageParser.Package> map = mOverlays.get(pkg.mOverlayTarget); + map.put(pkg.packageName, pkg); + PackageParser.Package orig = mPackages.get(pkg.mOverlayTarget); + if (orig != null && !createIdmapForPackagePairLI(orig, pkg)) { + mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; + return null; + } + } + } else if (mOverlays.containsKey(pkg.packageName) && + !pkg.packageName.equals("android")) { + // This is a regular package, with one or more known overlay packages. + createIdmapsForPackageLI(pkg); + } } return pkg; @@ -5176,7 +5304,21 @@ public class PackageManagerService extends IPackageManager.Stub { * If this is an internal application or our nativeLibraryPath points to * the app-lib directory, unpack the libraries if necessary. */ - return NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir); + final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(scanFile); + try { + int abi = NativeLibraryHelper.findSupportedAbi(handle, Build.SUPPORTED_ABIS); + if (abi >= 0) { + int copyRet = NativeLibraryHelper.copyNativeBinariesIfNeededLI(handle, + nativeLibraryDir, Build.SUPPORTED_ABIS[abi]); + if (copyRet != PackageManager.INSTALL_SUCCEEDED) { + return copyRet; + } + } + + return abi; + } finally { + handle.close(); + } } private void killApplication(String pkgName, int appId, String reason) { @@ -8065,7 +8207,7 @@ public class PackageManagerService extends IPackageManager.Stub { } try { int copyRet = copyNativeLibrariesForInternalApp(codeFile, nativeLibraryFile); - if (copyRet != PackageManager.INSTALL_SUCCEEDED) { + if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) { return copyRet; } } catch (IOException e) { @@ -11026,6 +11168,10 @@ public class PackageManagerService extends IPackageManager.Stub { */ public void scanAvailableAsecs() { updateExternalMediaStatusInner(true, false, false); + if (mShouldRestoreconData) { + SELinuxMMAC.setRestoreconDone(); + mShouldRestoreconData = false; + } } /* @@ -11471,8 +11617,17 @@ public class PackageManagerService extends IPackageManager.Stub { final File newNativeDir = new File(newNativePath); if (!isForwardLocked(pkg) && !isExternal(pkg)) { - NativeLibraryHelper.copyNativeBinariesIfNeededLI( - new File(newCodePath), newNativeDir); + // NOTE: We do not report any errors from the APK scan and library + // copy at this point. + NativeLibraryHelper.ApkHandle handle = + new NativeLibraryHelper.ApkHandle(newCodePath); + final int abi = NativeLibraryHelper.findSupportedAbi( + handle, Build.SUPPORTED_ABIS); + if (abi >= 0) { + NativeLibraryHelper.copyNativeBinariesIfNeededLI( + handle, newNativeDir, Build.SUPPORTED_ABIS[abi]); + } + handle.close(); } final int[] users = sUserManager.getUserIds(); for (int user : users) { diff --git a/services/core/java/com/android/server/pm/PackageSetting.java b/services/core/java/com/android/server/pm/PackageSetting.java index b447861..15df3d2 100644 --- a/services/core/java/com/android/server/pm/PackageSetting.java +++ b/services/core/java/com/android/server/pm/PackageSetting.java @@ -30,8 +30,8 @@ final class PackageSetting extends PackageSettingBase { SharedUserSetting sharedUser; PackageSetting(String name, String realName, File codePath, File resourcePath, - String nativeLibraryPathString, int pVersionCode, int pkgFlags) { - super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode, + String nativeLibraryPathString, String requiredCpuAbiString, int pVersionCode, int pkgFlags) { + super(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode, pkgFlags); } diff --git a/services/core/java/com/android/server/pm/PackageSettingBase.java b/services/core/java/com/android/server/pm/PackageSettingBase.java index 7747c8f..ba95b9a 100644 --- a/services/core/java/com/android/server/pm/PackageSettingBase.java +++ b/services/core/java/com/android/server/pm/PackageSettingBase.java @@ -53,6 +53,7 @@ class PackageSettingBase extends GrantedPermissions { File resourcePath; String resourcePathString; String nativeLibraryPathString; + String requiredCpuAbiString; long timeStamp; long firstInstallTime; long lastUpdateTime; @@ -80,11 +81,11 @@ class PackageSettingBase extends GrantedPermissions { /* package name of the app that installed this package */ String installerPackageName; PackageSettingBase(String name, String realName, File codePath, File resourcePath, - String nativeLibraryPathString, int pVersionCode, int pkgFlags) { + String nativeLibraryPathString, String requiredCpuAbiString, int pVersionCode, int pkgFlags) { super(pkgFlags); this.name = name; this.realName = realName; - init(codePath, resourcePath, nativeLibraryPathString, pVersionCode); + init(codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode); } /** @@ -101,6 +102,7 @@ class PackageSettingBase extends GrantedPermissions { resourcePath = base.resourcePath; resourcePathString = base.resourcePathString; nativeLibraryPathString = base.nativeLibraryPathString; + requiredCpuAbiString = base.requiredCpuAbiString; timeStamp = base.timeStamp; firstInstallTime = base.firstInstallTime; lastUpdateTime = base.lastUpdateTime; @@ -128,12 +130,13 @@ class PackageSettingBase extends GrantedPermissions { } void init(File codePath, File resourcePath, String nativeLibraryPathString, - int pVersionCode) { + String requiredCpuAbiString, int pVersionCode) { this.codePath = codePath; this.codePathString = codePath.toString(); this.resourcePath = resourcePath; this.resourcePathString = resourcePath.toString(); this.nativeLibraryPathString = nativeLibraryPathString; + this.requiredCpuAbiString = requiredCpuAbiString; this.versionCode = pVersionCode; } @@ -164,6 +167,7 @@ class PackageSettingBase extends GrantedPermissions { grantedPermissions = base.grantedPermissions; gids = base.gids; + requiredCpuAbiString = base.requiredCpuAbiString; timeStamp = base.timeStamp; firstInstallTime = base.firstInstallTime; lastUpdateTime = base.lastUpdateTime; diff --git a/services/core/java/com/android/server/pm/PendingPackage.java b/services/core/java/com/android/server/pm/PendingPackage.java index c17cc46..36c3a34 100644 --- a/services/core/java/com/android/server/pm/PendingPackage.java +++ b/services/core/java/com/android/server/pm/PendingPackage.java @@ -22,8 +22,8 @@ final class PendingPackage extends PackageSettingBase { final int sharedId; PendingPackage(String name, String realName, File codePath, File resourcePath, - String nativeLibraryPathString, int sharedId, int pVersionCode, int pkgFlags) { - super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode, + String nativeLibraryPathString, String requiredCpuAbiString, int sharedId, int pVersionCode, int pkgFlags) { + super(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode, pkgFlags); this.sharedId = sharedId; } diff --git a/services/core/java/com/android/server/pm/SELinuxMMAC.java b/services/core/java/com/android/server/pm/SELinuxMMAC.java index 1d68afa..af7153f 100644 --- a/services/core/java/com/android/server/pm/SELinuxMMAC.java +++ b/services/core/java/com/android/server/pm/SELinuxMMAC.java @@ -25,11 +25,16 @@ import android.util.Xml; import com.android.internal.util.XmlUtils; +import libcore.io.IoUtils; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.HashMap; @@ -60,6 +65,13 @@ public final class SELinuxMMAC { new File(Environment.getRootDirectory(), "etc/security/mac_permissions.xml"), null}; + // Location of seapp_contexts policy file. + private static final String SEAPP_CONTEXTS_FILE = "/seapp_contexts"; + + // Stores the hash of the last used seapp_contexts file. + private static final String SEAPP_HASH_FILE = + Environment.getDataDirectory().toString() + "/system/seapp_hash"; + // Signature policy stanzas static class Policy { private String seinfo; @@ -103,7 +115,6 @@ public final class SELinuxMMAC { /** * Parses an MMAC install policy from a predefined list of locations. - * @param none * @return boolean indicating whether an install policy was correctly parsed. */ public static boolean readInstallPolicy() { @@ -113,7 +124,7 @@ public final class SELinuxMMAC { /** * Parses an MMAC install policy given as an argument. - * @param File object representing the path of the policy. + * @param policyFile object representing the path of the policy. * @return boolean indicating whether the install policy was correctly parsed. */ public static boolean readInstallPolicy(File policyFile) { @@ -345,8 +356,7 @@ public final class SELinuxMMAC { /** * Labels a package based on an seinfo tag from install policy. * The label is attached to the ApplicationInfo instance of the package. - * @param PackageParser.Package object representing the package - * to labeled. + * @param pkg object representing the package to be labeled. * @return boolean which determines whether a non null seinfo label * was assigned to the package. A null value simply meaning that * no policy matched. @@ -391,4 +401,89 @@ public final class SELinuxMMAC { return (sDefaultSeinfo != null); } + + /** + * Determines if a recursive restorecon on /data/data and /data/user is needed. + * It does this by comparing the SHA-1 of the seapp_contexts file against the + * stored hash at /data/system/seapp_hash. + * + * @return Returns true if the restorecon should occur or false otherwise. + */ + public static boolean shouldRestorecon() { + // Any error with the seapp_contexts file should be fatal + byte[] currentHash = null; + try { + currentHash = returnHash(SEAPP_CONTEXTS_FILE); + } catch (IOException ioe) { + Slog.e(TAG, "Error with hashing seapp_contexts.", ioe); + return false; + } + + // Push past any error with the stored hash file + byte[] storedHash = null; + try { + storedHash = IoUtils.readFileAsByteArray(SEAPP_HASH_FILE); + } catch (IOException ioe) { + Slog.w(TAG, "Error opening " + SEAPP_HASH_FILE + ". Assuming first boot."); + } + + return (storedHash == null || !MessageDigest.isEqual(storedHash, currentHash)); + } + + /** + * Stores the SHA-1 of the seapp_contexts to /data/system/seapp_hash. + */ + public static void setRestoreconDone() { + try { + final byte[] currentHash = returnHash(SEAPP_CONTEXTS_FILE); + dumpHash(new File(SEAPP_HASH_FILE), currentHash); + } catch (IOException ioe) { + Slog.e(TAG, "Error with saving hash to " + SEAPP_HASH_FILE, ioe); + } + } + + /** + * Dump the contents of a byte array to a specified file. + * + * @param file The file that receives the byte array content. + * @param content A byte array that will be written to the specified file. + * @throws IOException if any failed I/O operation occured. + * Included is the failure to atomically rename the tmp + * file used in the process. + */ + private static void dumpHash(File file, byte[] content) throws IOException { + FileOutputStream fos = null; + File tmp = null; + try { + tmp = File.createTempFile("seapp_hash", ".journal", file.getParentFile()); + tmp.setReadable(true); + fos = new FileOutputStream(tmp); + fos.write(content); + fos.getFD().sync(); + if (!tmp.renameTo(file)) { + throw new IOException("Failure renaming " + file.getCanonicalPath()); + } + } finally { + if (tmp != null) { + tmp.delete(); + } + IoUtils.closeQuietly(fos); + } + } + + /** + * Return the SHA-1 of a file. + * + * @param file The path to the file given as a string. + * @return Returns the SHA-1 of the file as a byte array. + * @throws IOException if any failed I/O operations occured. + */ + private static byte[] returnHash(String file) throws IOException { + try { + final byte[] contents = IoUtils.readFileAsByteArray(file); + return MessageDigest.getInstance("SHA-1").digest(contents); + } catch (NoSuchAlgorithmException nsae) { + throw new RuntimeException(nsae); // impossible + } + } } diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java index 8f18b23..f01bb50 100644 --- a/services/core/java/com/android/server/pm/Settings.java +++ b/services/core/java/com/android/server/pm/Settings.java @@ -213,10 +213,10 @@ final class Settings { PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage, String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, - String nativeLibraryPathString, int pkgFlags, UserHandle user, boolean add) { + String nativeLibraryPathString, String requiredCpuAbiString, int pkgFlags, UserHandle user, boolean add) { final String name = pkg.packageName; PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath, - resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags, + resourcePath, nativeLibraryPathString, requiredCpuAbiString, pkg.mVersionCode, pkgFlags, user, add, true /* allowInstall */); return p; } @@ -298,7 +298,7 @@ final class Settings { p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; } PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath, - p.nativeLibraryPathString, p.appId, p.versionCode, p.pkgFlags); + p.nativeLibraryPathString, p.requiredCpuAbiString, p.appId, p.versionCode, p.pkgFlags); mDisabledSysPackages.remove(name); return ret; } @@ -312,7 +312,7 @@ final class Settings { } PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath, - String nativeLibraryPathString, int uid, int vc, int pkgFlags) { + String nativeLibraryPathString, String requiredCpuAbiString, int uid, int vc, int pkgFlags) { PackageSetting p = mPackages.get(name); if (p != null) { if (p.appId == uid) { @@ -322,7 +322,7 @@ final class Settings { "Adding duplicate package, keeping first: " + name); return null; } - p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString, + p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, vc, pkgFlags); p.appId = uid; if (addUserIdLPw(uid, p, name)) { @@ -391,10 +391,11 @@ final class Settings { private PackageSetting getPackageLPw(String name, PackageSetting origPackage, String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, - String nativeLibraryPathString, int vc, int pkgFlags, + String nativeLibraryPathString, String requiredCpuAbiString, int vc, int pkgFlags, UserHandle installUser, boolean add, boolean allowInstall) { PackageSetting p = mPackages.get(name); if (p != null) { + p.requiredCpuAbiString = requiredCpuAbiString; if (!p.codePath.equals(codePath)) { // Check to see if its a disabled system app if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) { @@ -438,7 +439,7 @@ final class Settings { if (origPackage != null) { // We are consuming the data from an existing package. p = new PackageSetting(origPackage.name, name, codePath, resourcePath, - nativeLibraryPathString, vc, pkgFlags); + nativeLibraryPathString, requiredCpuAbiString, vc, pkgFlags); if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package " + name + " is adopting original package " + origPackage.name); // Note that we will retain the new package's signature so @@ -455,7 +456,7 @@ final class Settings { p.setTimeStamp(codePath.lastModified()); } else { p = new PackageSetting(name, realName, codePath, resourcePath, - nativeLibraryPathString, vc, pkgFlags); + nativeLibraryPathString, requiredCpuAbiString, vc, pkgFlags); p.setTimeStamp(codePath.lastModified()); p.sharedUser = sharedUser; // If this is not a system app, it starts out stopped. @@ -581,6 +582,8 @@ final class Settings { && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) { p.nativeLibraryPathString = nativeLibraryPath; } + // Update the required Cpu Abi + p.requiredCpuAbiString = pkg.applicationInfo.requiredCpuAbi; // Update version code if needed if (pkg.mVersionCode != p.versionCode) { p.versionCode = pkg.mVersionCode; @@ -1427,6 +1430,7 @@ final class Settings { // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: // system/core/run-as/run-as.c // system/core/sdcard/sdcard.c + // external/libselinux/src/android.c:package_info_init() // sb.setLength(0); sb.append(ai.packageName); @@ -1497,6 +1501,9 @@ final class Settings { if (pkg.nativeLibraryPathString != null) { serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); } + if (pkg.requiredCpuAbiString != null) { + serializer.attribute(null, "requiredCpuAbi", pkg.requiredCpuAbiString); + } if (pkg.sharedUser == null) { serializer.attribute(null, "userId", Integer.toString(pkg.appId)); } else { @@ -1539,6 +1546,9 @@ final class Settings { if (pkg.nativeLibraryPathString != null) { serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); } + if (pkg.requiredCpuAbiString != null) { + serializer.attribute(null, "requiredCpuAbi", pkg.requiredCpuAbiString); + } serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags)); serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp)); serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime)); @@ -1803,7 +1813,7 @@ final class Settings { if (idObj != null && idObj instanceof SharedUserSetting) { PackageSetting p = getPackageLPw(pp.name, null, pp.realName, (SharedUserSetting) idObj, pp.codePath, pp.resourcePath, - pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags, + pp.nativeLibraryPathString, pp.requiredCpuAbiString, pp.versionCode, pp.pkgFlags, null, true /* add */, false /* allowInstall */); if (p == null) { PackageManagerService.reportSettingsProblem(Log.WARN, @@ -2223,6 +2233,8 @@ final class Settings { String codePathStr = parser.getAttributeValue(null, "codePath"); String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); + String requiredCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi"); + if (resourcePathStr == null) { resourcePathStr = codePathStr; } @@ -2242,7 +2254,7 @@ final class Settings { pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED; } PackageSetting ps = new PackageSetting(name, realName, codePathFile, - new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags); + new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, versionCode, pkgFlags); String timeStampStr = parser.getAttributeValue(null, "ft"); if (timeStampStr != null) { try { @@ -2309,6 +2321,7 @@ final class Settings { String codePathStr = null; String resourcePathStr = null; String nativeLibraryPathStr = null; + String requiredCpuAbiString = null; String systemStr = null; String installerPackageName = null; String uidError = null; @@ -2328,6 +2341,8 @@ final class Settings { codePathStr = parser.getAttributeValue(null, "codePath"); resourcePathStr = parser.getAttributeValue(null, "resourcePath"); nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); + requiredCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi"); + version = parser.getAttributeValue(null, "version"); if (version != null) { try { @@ -2404,7 +2419,7 @@ final class Settings { + parser.getPositionDescription()); } else if (userId > 0) { packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr), - new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode, + new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, userId, versionCode, pkgFlags); if (PackageManagerService.DEBUG_SETTINGS) Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId=" @@ -2422,7 +2437,7 @@ final class Settings { userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; if (userId > 0) { packageSetting = new PendingPackage(name.intern(), realName, new File( - codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId, + codePathStr), new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, userId, versionCode, pkgFlags); packageSetting.setTimeStamp(timeStamp); packageSetting.firstInstallTime = firstInstallTime; @@ -2451,6 +2466,7 @@ final class Settings { packageSetting.uidError = "true".equals(uidError); packageSetting.installerPackageName = installerPackageName; packageSetting.nativeLibraryPathString = nativeLibraryPathStr; + packageSetting.requiredCpuAbiString = requiredCpuAbiString; // Handle legacy string here for single-user mode final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED); if (enabledStr != null) { @@ -2950,6 +2966,7 @@ final class Settings { pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString); pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString); pw.print(prefix); pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString); + pw.print(prefix); pw.print(" requiredCpuAbi="); pw.println(ps.requiredCpuAbiString); pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode); if (ps.pkg != null) { pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion); diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java index e630737..f79896b 100644 --- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java +++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java @@ -199,7 +199,8 @@ class ScreenRotationAnimation { } public ScreenRotationAnimation(Context context, DisplayContent displayContent, - SurfaceSession session, boolean inTransaction, boolean forceDefaultOrientation) { + SurfaceSession session, boolean inTransaction, boolean forceDefaultOrientation, + boolean isSecure) { mContext = context; mDisplayContent = displayContent; displayContent.getLogicalDisplayRect(mOriginalDisplayRect); @@ -241,16 +242,21 @@ class ScreenRotationAnimation { try { try { + int flags = SurfaceControl.HIDDEN; + if (isSecure) { + flags |= SurfaceControl.SECURE; + } + if (WindowManagerService.DEBUG_SURFACE_TRACE) { mSurfaceControl = new SurfaceTrace(session, "ScreenshotSurface", mWidth, mHeight, - PixelFormat.OPAQUE, SurfaceControl.HIDDEN); + PixelFormat.OPAQUE, flags); Slog.w(TAG, "ScreenRotationAnimation ctor: displayOffset=" + mOriginalDisplayRect.toShortString()); } else { mSurfaceControl = new SurfaceControl(session, "ScreenshotSurface", mWidth, mHeight, - PixelFormat.OPAQUE, SurfaceControl.HIDDEN); + PixelFormat.OPAQUE, flags); } // capture a screenshot into the surface we just created Surface sur = new Surface(); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 0a0ffd6..417f414 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -3545,8 +3545,9 @@ public class WindowManagerService extends IWindowManager.Stub Task newTask = mTaskIdToTask.get(groupId); if (newTask == null) { newTask = createTask(groupId, oldTask.mStack.mStackId, oldTask.mUserId, atoken); + } else { + newTask.mAppTokens.add(atoken); } - newTask.mAppTokens.add(atoken); } } @@ -10028,10 +10029,22 @@ public class WindowManagerService extends IWindowManager.Stub screenRotationAnimation.kill(); } + // Check whether the current screen contains any secure content. + boolean isSecure = false; + final WindowList windows = getDefaultWindowListLocked(); + final int N = windows.size(); + for (int i = 0; i < N; i++) { + WindowState ws = windows.get(i); + if (ws.isOnScreen() && (ws.mAttrs.flags & FLAG_SECURE) != 0) { + isSecure = true; + break; + } + } + // TODO(multidisplay): rotation on main screen only. displayContent.updateDisplayInfo(); screenRotationAnimation = new ScreenRotationAnimation(mContext, displayContent, - mFxSession, inTransaction, mPolicy.isDefaultOrientationForced()); + mFxSession, inTransaction, mPolicy.isDefaultOrientationForced(), isSecure); mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation); } } diff --git a/services/core/jni/com_android_server_AlarmManagerService.cpp b/services/core/jni/com_android_server_AlarmManagerService.cpp index 342515b..a58b00bce 100644 --- a/services/core/jni/com_android_server_AlarmManagerService.cpp +++ b/services/core/jni/com_android_server_AlarmManagerService.cpp @@ -36,6 +36,7 @@ #include <unistd.h> #include <linux/ioctl.h> #include <linux/android_alarm.h> +#include <linux/rtc.h> namespace android { @@ -58,6 +59,7 @@ public: virtual ~AlarmImpl(); virtual int set(int type, struct timespec *ts) = 0; + virtual int setTime(struct timeval *tv) = 0; virtual int waitForAlarm() = 0; protected: @@ -71,6 +73,7 @@ public: AlarmImplAlarmDriver(int fd) : AlarmImpl(&fd, 1) { } int set(int type, struct timespec *ts); + int setTime(struct timeval *tv); int waitForAlarm(); }; @@ -82,6 +85,7 @@ public: ~AlarmImplTimerFd(); int set(int type, struct timespec *ts); + int setTime(struct timeval *tv); int waitForAlarm(); private: @@ -107,6 +111,19 @@ int AlarmImplAlarmDriver::set(int type, struct timespec *ts) return ioctl(fds[0], ANDROID_ALARM_SET(type), ts); } +int AlarmImplAlarmDriver::setTime(struct timeval *tv) +{ + struct timespec ts; + int res; + + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + res = ioctl(fds[0], ANDROID_ALARM_SET_RTC, &ts); + if (res < 0) + ALOGV("ANDROID_ALARM_SET_RTC ioctl failed: %s\n", strerror(errno)); + return res; +} + int AlarmImplAlarmDriver::waitForAlarm() { return ioctl(fds[0], ANDROID_ALARM_WAIT); @@ -140,6 +157,50 @@ int AlarmImplTimerFd::set(int type, struct timespec *ts) return timerfd_settime(fds[type], TFD_TIMER_ABSTIME, &spec, NULL); } +int AlarmImplTimerFd::setTime(struct timeval *tv) +{ + struct rtc_time rtc; + struct tm tm, *gmtime_res; + int fd; + int res; + + res = settimeofday(tv, NULL); + if (res < 0) { + ALOGV("settimeofday() failed: %s\n", strerror(errno)); + return -1; + } + + fd = open("/dev/rtc0", O_RDWR); + if (fd < 0) { + ALOGV("Unable to open RTC driver: %s\n", strerror(errno)); + return res; + } + + gmtime_res = gmtime_r(&tv->tv_sec, &tm); + if (!gmtime_res) { + ALOGV("gmtime_r() failed: %s\n", strerror(errno)); + res = -1; + goto done; + } + + memset(&rtc, 0, sizeof(rtc)); + rtc.tm_sec = tm.tm_sec; + rtc.tm_min = tm.tm_min; + rtc.tm_hour = tm.tm_hour; + rtc.tm_mday = tm.tm_mday; + rtc.tm_mon = tm.tm_mon; + rtc.tm_year = tm.tm_year; + rtc.tm_wday = tm.tm_wday; + rtc.tm_yday = tm.tm_yday; + rtc.tm_isdst = tm.tm_isdst; + res = ioctl(fd, RTC_SET_TIME, &rtc); + if (res < 0) + ALOGV("RTC_SET_TIME ioctl failed: %s\n", strerror(errno)); +done: + close(fd); + return res; +} + int AlarmImplTimerFd::waitForAlarm() { epoll_event events[N_ANDROID_TIMERFDS]; @@ -168,6 +229,30 @@ int AlarmImplTimerFd::waitForAlarm() return result; } +static jint android_server_AlarmManagerService_setKernelTime(JNIEnv*, jobject, jlong nativeData, jlong millis) +{ + AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData); + struct timeval tv; + int ret; + + if (millis <= 0 || millis / 1000LL >= INT_MAX) { + return -1; + } + + tv.tv_sec = (time_t) (millis / 1000LL); + tv.tv_usec = (suseconds_t) ((millis % 1000LL) * 1000LL); + + ALOGD("Setting time of day to sec=%d\n", (int) tv.tv_sec); + + ret = impl->setTime(&tv); + + if(ret < 0) { + ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno)); + ret = -1; + } + return ret; +} + static jint android_server_AlarmManagerService_setKernelTimezone(JNIEnv*, jobject, jlong, jint minswest) { struct timezone tz; @@ -280,7 +365,9 @@ static void android_server_AlarmManagerService_set(JNIEnv*, jobject, jlong nativ int result = impl->set(type, &ts); if (result < 0) { - ALOGE("Unable to set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno)); + ALOGE("Unable to set alarm to %lld.%09lld: %s\n", + static_cast<long long>(seconds), + static_cast<long long>(nanoseconds), strerror(errno)); } } @@ -309,6 +396,7 @@ static JNINativeMethod sMethods[] = { {"close", "(J)V", (void*)android_server_AlarmManagerService_close}, {"set", "(JIJJ)V", (void*)android_server_AlarmManagerService_set}, {"waitForAlarm", "(J)I", (void*)android_server_AlarmManagerService_waitForAlarm}, + {"setKernelTime", "(JJ)I", (void*)android_server_AlarmManagerService_setKernelTime}, {"setKernelTimezone", "(JI)I", (void*)android_server_AlarmManagerService_setKernelTimezone}, }; diff --git a/services/core/jni/com_android_server_AssetAtlasService.cpp b/services/core/jni/com_android_server_AssetAtlasService.cpp index 4a1b55d..163692b 100644 --- a/services/core/jni/com_android_server_AssetAtlasService.cpp +++ b/services/core/jni/com_android_server_AssetAtlasService.cpp @@ -73,7 +73,7 @@ static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCa SkSafeUnref(previousCanvas); } -static SkBitmap* com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, jobject, +static jlong com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, jobject, jobject canvas, jint width, jint height) { SkBitmap* bitmap = new SkBitmap; @@ -84,12 +84,13 @@ static SkBitmap* com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, SkCanvas* nativeCanvas = SkNEW_ARGS(SkCanvas, (*bitmap)); swapCanvasPtr(env, canvas, nativeCanvas); - return bitmap; + return reinterpret_cast<jlong>(bitmap); } static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobject, - jobject canvas, SkBitmap* bitmap) { + jobject canvas, jlong bitmapHandle) { + SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkCanvas* nativeCanvas = SkNEW(SkCanvas); swapCanvasPtr(env, canvas, nativeCanvas); @@ -108,21 +109,22 @@ static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobj return result; static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject, - jobject graphicBuffer, SkBitmap* bitmap) { + jobject graphicBuffer, jlong bitmapHandle) { + SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); // The goal of this method is to copy the bitmap into the GraphicBuffer // using the GPU to swizzle the texture content sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); if (buffer != NULL) { EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (display == EGL_NO_DISPLAY) return false; + if (display == EGL_NO_DISPLAY) return JNI_FALSE; EGLint major; EGLint minor; if (!eglInitialize(display, &major, &minor)) { ALOGW("Could not initialize EGL"); - return false; + return JNI_FALSE; } // We're going to use a 1x1 pbuffer surface later on @@ -143,13 +145,13 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject ALOGW("Could not select EGL configuration"); eglReleaseThread(); eglTerminate(display); - return false; + return JNI_FALSE; } if (configCount <= 0) { ALOGW("Could not find EGL configuration"); eglReleaseThread(); eglTerminate(display); - return false; + return JNI_FALSE; } // These objects are initialized below but the default "null" @@ -164,7 +166,7 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject EGLContext context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, attrs); if (context == EGL_NO_CONTEXT) { ALOGW("Could not create EGL context"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } // Create the 1x1 pbuffer @@ -172,12 +174,12 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject surface = eglCreatePbufferSurface(display, configs[0], surfaceAttrs); if (surface == EGL_NO_SURFACE) { ALOGW("Could not create EGL surface"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } if (!eglMakeCurrent(display, surface, surface, context)) { ALOGW("Could not change current EGL context"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } // We use an EGLImage to access the content of the GraphicBuffer @@ -188,7 +190,7 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject EGL_NATIVE_BUFFER_ANDROID, clientBuffer, imageAttrs); if (image == EGL_NO_IMAGE_KHR) { ALOGW("Could not create EGL image"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } glGenTextures(1, &texture); @@ -196,7 +198,7 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); if (glGetError() != GL_NO_ERROR) { ALOGW("Could not create/bind texture"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } // Upload the content of the bitmap in the GraphicBuffer @@ -205,7 +207,7 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels()); if (glGetError() != GL_NO_ERROR) { ALOGW("Could not upload to texture"); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } // The fence is used to wait for the texture upload to finish @@ -214,7 +216,7 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL); if (fence == EGL_NO_SYNC_KHR) { ALOGW("Could not create sync fence %#x", eglGetError()); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } // The flag EGL_SYNC_FLUSH_COMMANDS_BIT_KHR will trigger a @@ -223,13 +225,13 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, FENCE_TIMEOUT); if (waitStatus != EGL_CONDITION_SATISFIED_KHR) { ALOGW("Failed to wait for the fence %#x", eglGetError()); - CLEANUP_GL_AND_RETURN(false); + CLEANUP_GL_AND_RETURN(JNI_FALSE); } - CLEANUP_GL_AND_RETURN(true); + CLEANUP_GL_AND_RETURN(JNI_TRUE); } - return false; + return JNI_FALSE; } // ---------------------------------------------------------------------------- @@ -247,11 +249,11 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject const char* const kClassPathName = "com/android/server/AssetAtlasService"; static JNINativeMethod gMethods[] = { - { "nAcquireAtlasCanvas", "(Landroid/graphics/Canvas;II)I", + { "nAcquireAtlasCanvas", "(Landroid/graphics/Canvas;II)J", (void*) com_android_server_AssetAtlasService_acquireCanvas }, - { "nReleaseAtlasCanvas", "(Landroid/graphics/Canvas;I)V", + { "nReleaseAtlasCanvas", "(Landroid/graphics/Canvas;J)V", (void*) com_android_server_AssetAtlasService_releaseCanvas }, - { "nUploadAtlas", "(Landroid/view/GraphicBuffer;I)Z", + { "nUploadAtlas", "(Landroid/view/GraphicBuffer;J)Z", (void*) com_android_server_AssetAtlasService_upload }, }; diff --git a/services/core/jni/com_android_server_ConsumerIrService.cpp b/services/core/jni/com_android_server_ConsumerIrService.cpp index 004c0aa..3a50ff7 100644 --- a/services/core/jni/com_android_server_ConsumerIrService.cpp +++ b/services/core/jni/com_android_server_ConsumerIrService.cpp @@ -29,7 +29,7 @@ namespace android { -static jint halOpen(JNIEnv *env, jobject obj) { +static jlong halOpen(JNIEnv *env, jobject obj) { hw_module_t const* module; consumerir_device_t *dev; int err; @@ -47,10 +47,10 @@ static jint halOpen(JNIEnv *env, jobject obj) { return 0; } - return reinterpret_cast<jint>(dev); + return reinterpret_cast<jlong>(dev); } -static jint halTransmit(JNIEnv *env, jobject obj, jint halObject, +static jint halTransmit(JNIEnv *env, jobject obj, jlong halObject, jint carrierFrequency, jintArray pattern) { int ret; @@ -67,8 +67,8 @@ static jint halTransmit(JNIEnv *env, jobject obj, jint halObject, } static jintArray halGetCarrierFrequencies(JNIEnv *env, jobject obj, - jint halObject) { - consumerir_device_t *dev = (consumerir_device_t *) halObject; + jlong halObject) { + consumerir_device_t *dev = reinterpret_cast<consumerir_device_t*>(halObject); consumerir_freq_range_t *ranges; int len; @@ -101,9 +101,9 @@ static jintArray halGetCarrierFrequencies(JNIEnv *env, jobject obj, } static JNINativeMethod method_table[] = { - { "halOpen", "()I", (void *)halOpen }, - { "halTransmit", "(II[I)I", (void *)halTransmit }, - { "halGetCarrierFrequencies", "(I)[I", (void *)halGetCarrierFrequencies}, + { "halOpen", "()J", (void *)halOpen }, + { "halTransmit", "(JI[I)I", (void *)halTransmit }, + { "halGetCarrierFrequencies", "(J)[I", (void *)halGetCarrierFrequencies}, }; int register_android_server_ConsumerIrService(JNIEnv *env) { diff --git a/services/core/jni/com_android_server_UsbHostManager.cpp b/services/core/jni/com_android_server_UsbHostManager.cpp index f1fa6cf..fc6de60 100644 --- a/services/core/jni/com_android_server_UsbHostManager.cpp +++ b/services/core/jni/com_android_server_UsbHostManager.cpp @@ -163,8 +163,10 @@ static jobject android_server_UsbHostManager_openDevice(JNIEnv *env, jobject thi return NULL; int fd = usb_device_get_fd(device); - if (fd < 0) + if (fd < 0) { + usb_device_close(device); return NULL; + } int newFD = dup(fd); usb_device_close(device); diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index d5e49a0..208eefb 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -51,6 +51,7 @@ import android.view.WindowManager; import com.android.internal.R; import com.android.internal.os.BinderInternal; +import com.android.internal.os.Zygote; import com.android.internal.os.SamplingProfilerIntegration; import com.android.server.accessibility.AccessibilityManagerService; import com.android.server.accounts.AccountManagerService; @@ -83,7 +84,6 @@ import com.android.server.wifi.WifiService; import com.android.server.wm.WindowManagerService; import dalvik.system.VMRuntime; -import dalvik.system.Zygote; import java.io.File; import java.util.Timer; @@ -168,7 +168,7 @@ public final class SystemServer { // had to fallback to a different runtime because it is // running as root and we need to be the system user to set // the property. http://b/11463182 - SystemProperties.set("persist.sys.dalvik.vm.lib", VMRuntime.getRuntime().vmLibrary()); + SystemProperties.set("persist.sys.dalvik.vm.lib.1", VMRuntime.getRuntime().vmLibrary()); // Enable the sampling profiler. if (SamplingProfilerIntegration.isEnabled()) { @@ -912,8 +912,6 @@ public final class SystemServer { final boolean safeMode = wm.detectSafeMode(); if (safeMode) { mActivityManagerService.enterSafeMode(); - // Post the safe mode state in the Zygote class - Zygote.systemInSafeMode = true; // Disable the JIT for the system_server process VMRuntime.getRuntime().disableJitCompilation(); } else { diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 76a8d17..5d22ffc 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -594,14 +594,19 @@ public class UsbDeviceManager { intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); intent.putExtra("state", (enabled ? 1 : 0)); if (enabled) { + Scanner scanner = null; try { - Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH)); + scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH)); int card = scanner.nextInt(); int device = scanner.nextInt(); intent.putExtra("card", card); intent.putExtra("device", device); } catch (FileNotFoundException e) { Slog.e(TAG, "could not open audio source PCM file", e); + } finally { + if (scanner != null) { + scanner.close(); + } } } mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |