diff options
Diffstat (limited to 'services/java')
31 files changed, 1357 insertions, 1317 deletions
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java index 158c778..0b15221 100644 --- a/services/java/com/android/server/AppWidgetService.java +++ b/services/java/com/android/server/AppWidgetService.java @@ -1072,7 +1072,7 @@ class AppWidgetService extends IAppWidgetService.Stub throw new IllegalArgumentException("packageName and uid don't match packageName=" + packageName); } - if (callingUid != packageUid && Process.supportsProcesses()) { + if (callingUid != packageUid) { throw new IllegalArgumentException("packageName and uid don't match packageName=" + packageName); } diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 6afccec..168b894 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -76,6 +76,7 @@ import com.android.internal.backup.IBackupTransport; import com.android.internal.backup.LocalTransport; import com.android.server.PackageManagerBackupAgent.Metadata; +import java.io.DataInputStream; import java.io.EOFException; import java.io.File; import java.io.FileDescriptor; @@ -96,6 +97,10 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; class BackupManagerService extends IBackupManager.Stub { private static final String TAG = "BackupManagerService"; @@ -224,6 +229,7 @@ class BackupManagerService extends IBackupManager.Stub { public PackageInfo pkgInfo; public int pmToken; // in post-install restore, the PM's token for this transaction public boolean needFullBackup; + public String[] filterSet; RestoreParams(IBackupTransport _transport, IRestoreObserver _obs, long _token, PackageInfo _pkg, int _pmToken, boolean _needFullBackup) { @@ -233,6 +239,7 @@ class BackupManagerService extends IBackupManager.Stub { pkgInfo = _pkg; pmToken = _pmToken; needFullBackup = _needFullBackup; + filterSet = null; } RestoreParams(IBackupTransport _transport, IRestoreObserver _obs, long _token, @@ -243,6 +250,18 @@ class BackupManagerService extends IBackupManager.Stub { pkgInfo = null; pmToken = 0; needFullBackup = _needFullBackup; + filterSet = null; + } + + RestoreParams(IBackupTransport _transport, IRestoreObserver _obs, long _token, + String[] _filterSet, boolean _needFullBackup) { + transport = _transport; + observer = _obs; + token = _token; + pkgInfo = null; + pmToken = 0; + needFullBackup = _needFullBackup; + filterSet = _filterSet; } } @@ -404,7 +423,7 @@ class BackupManagerService extends IBackupManager.Stub { Slog.d(TAG, "MSG_RUN_RESTORE observer=" + params.observer); (new PerformRestoreTask(params.transport, params.observer, params.token, params.pkgInfo, params.pmToken, - params.needFullBackup)).run(); + params.needFullBackup, params.filterSet)).run(); break; } @@ -1665,6 +1684,7 @@ class BackupManagerService extends IBackupManager.Stub { class PerformFullBackupTask implements Runnable { ParcelFileDescriptor mOutputFile; + DeflaterOutputStream mDeflater; IFullBackupRestoreObserver mObserver; boolean mIncludeApks; boolean mIncludeShared; @@ -1674,6 +1694,55 @@ class BackupManagerService extends IBackupManager.Stub { File mFilesDir; File mManifestFile; + class FullBackupRunner implements Runnable { + PackageInfo mPackage; + IBackupAgent mAgent; + ParcelFileDescriptor mPipe; + int mToken; + boolean mSendApk; + + FullBackupRunner(PackageInfo pack, IBackupAgent agent, ParcelFileDescriptor pipe, + int token, boolean sendApk) throws IOException { + mPackage = pack; + mAgent = agent; + mPipe = ParcelFileDescriptor.dup(pipe.getFileDescriptor()); + mToken = token; + mSendApk = sendApk; + } + + @Override + public void run() { + try { + BackupDataOutput output = new BackupDataOutput( + mPipe.getFileDescriptor()); + + if (DEBUG) Slog.d(TAG, "Writing manifest for " + mPackage.packageName); + writeAppManifest(mPackage, mManifestFile, mSendApk); + FullBackup.backupToTar(mPackage.packageName, null, null, + mFilesDir.getAbsolutePath(), + mManifestFile.getAbsolutePath(), + output); + + if (mSendApk) { + writeApkToBackup(mPackage, output); + } + + if (DEBUG) Slog.d(TAG, "Calling doFullBackup()"); + prepareOperationTimeout(mToken, TIMEOUT_FULL_BACKUP_INTERVAL); + mAgent.doFullBackup(mPipe, mToken, mBackupManagerBinder); + } catch (IOException e) { + Slog.e(TAG, "Error running full backup for " + mPackage.packageName); + } catch (RemoteException e) { + Slog.e(TAG, "Remote agent vanished during full backup of " + + mPackage.packageName); + } finally { + try { + mPipe.close(); + } catch (IOException e) {} + } + } + } + PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer, boolean includeApks, boolean includeShared, boolean doAllApps, String[] packages, AtomicBoolean latch) { @@ -1722,13 +1791,21 @@ class BackupManagerService extends IBackupManager.Stub { } } + // Set up the compression stage + FileOutputStream ofstream = new FileOutputStream(mOutputFile.getFileDescriptor()); + Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION); + DeflaterOutputStream out = new DeflaterOutputStream(ofstream, deflater, true); + + // !!! TODO: if using encryption, set up the encryption stage + // and emit the tar header stating the password salt. + PackageInfo pkg = null; try { // Now back up the app data via the agent mechanism int N = packagesToBackup.size(); for (int i = 0; i < N; i++) { pkg = packagesToBackup.get(i); - backupOnePackage(pkg); + backupOnePackage(pkg, out); } // Finally, shared storage if requested @@ -1740,6 +1817,7 @@ class BackupManagerService extends IBackupManager.Stub { } finally { tearDown(pkg); try { + out.close(); mOutputFile.close(); } catch (IOException e) { /* nothing we can do about this */ @@ -1757,13 +1835,17 @@ class BackupManagerService extends IBackupManager.Stub { } } - private void backupOnePackage(PackageInfo pkg) throws RemoteException { + private void backupOnePackage(PackageInfo pkg, DeflaterOutputStream out) + throws RemoteException { Slog.d(TAG, "Binding to full backup agent : " + pkg.packageName); IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo, IApplicationThread.BACKUP_MODE_FULL); if (agent != null) { + ParcelFileDescriptor[] pipes = null; try { + pipes = ParcelFileDescriptor.createPipe(); + ApplicationInfo app = pkg.applicationInfo; final boolean sendApk = mIncludeApks && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0) @@ -1772,31 +1854,54 @@ class BackupManagerService extends IBackupManager.Stub { sendOnBackupPackage(pkg.packageName); - BackupDataOutput output = new BackupDataOutput( - mOutputFile.getFileDescriptor()); - - if (DEBUG) Slog.d(TAG, "Writing manifest for " + pkg.packageName); - writeAppManifest(pkg, mManifestFile, sendApk); - FullBackup.backupToTar(pkg.packageName, null, null, - mFilesDir.getAbsolutePath(), - mManifestFile.getAbsolutePath(), - output); - - if (sendApk) { - writeApkToBackup(pkg, output); + final int token = generateToken(); + FullBackupRunner runner = new FullBackupRunner(pkg, agent, pipes[1], + token, sendApk); + pipes[1].close(); // the runner has dup'd it + pipes[1] = null; + Thread t = new Thread(runner); + t.start(); + + // Now pull data from the app and stuff it into the compressor + try { + FileInputStream raw = new FileInputStream(pipes[0].getFileDescriptor()); + DataInputStream in = new DataInputStream(raw); + + byte[] buffer = new byte[16 * 1024]; + int chunkTotal; + while ((chunkTotal = in.readInt()) > 0) { + while (chunkTotal > 0) { + int toRead = (chunkTotal > buffer.length) + ? buffer.length : chunkTotal; + int nRead = in.read(buffer, 0, toRead); + out.write(buffer, 0, nRead); + chunkTotal -= nRead; + } + } + } catch (IOException e) { + Slog.i(TAG, "Caught exception reading from agent", e); } - if (DEBUG) Slog.d(TAG, "Calling doFullBackup()"); - final int token = generateToken(); - prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL); - agent.doFullBackup(mOutputFile, token, mBackupManagerBinder); if (!waitUntilOperationComplete(token)) { Slog.e(TAG, "Full backup failed on package " + pkg.packageName); } else { - if (DEBUG) Slog.d(TAG, "Full backup success: " + pkg.packageName); + if (DEBUG) Slog.d(TAG, "Full package backup success: " + pkg.packageName); } + } catch (IOException e) { Slog.e(TAG, "Error backing up " + pkg.packageName, e); + } finally { + try { + if (pipes != null) { + if (pipes[0] != null) pipes[0].close(); + if (pipes[1] != null) pipes[1].close(); + } + + // Apply a full sync/flush after each application's data + out.flush(); + } catch (IOException e) { + Slog.w(TAG, "Error bringing down backup stack"); + } } } else { Slog.w(TAG, "Unable to bind to full agent for " + pkg.packageName); @@ -2070,11 +2175,12 @@ class BackupManagerService extends IBackupManager.Stub { try { mBytes = 0; byte[] buffer = new byte[32 * 1024]; - FileInputStream instream = new FileInputStream(mInputFile.getFileDescriptor()); + FileInputStream rawInStream = new FileInputStream(mInputFile.getFileDescriptor()); + InflaterInputStream in = new InflaterInputStream(rawInStream); boolean didRestore; do { - didRestore = restoreOneFile(instream, buffer); + didRestore = restoreOneFile(in, buffer); } while (didRestore); if (DEBUG) Slog.v(TAG, "Done consuming input tarfile, total bytes=" + mBytes); @@ -3020,6 +3126,7 @@ class BackupManagerService extends IBackupManager.Stub { private File mStateDir; private int mPmToken; private boolean mNeedFullBackup; + private HashSet<String> mFilterSet; class RestoreRequest { public PackageInfo app; @@ -3033,7 +3140,7 @@ class BackupManagerService extends IBackupManager.Stub { PerformRestoreTask(IBackupTransport transport, IRestoreObserver observer, long restoreSetToken, PackageInfo targetPackage, int pmToken, - boolean needFullBackup) { + boolean needFullBackup, String[] filterSet) { mTransport = transport; mObserver = observer; mToken = restoreSetToken; @@ -3041,6 +3148,15 @@ class BackupManagerService extends IBackupManager.Stub { mPmToken = pmToken; mNeedFullBackup = needFullBackup; + if (filterSet != null) { + mFilterSet = new HashSet<String>(); + for (String pkg : filterSet) { + mFilterSet.add(pkg); + } + } else { + mFilterSet = null; + } + try { mStateDir = new File(mBaseStateDir, transport.transportDirName()); } catch (RemoteException e) { @@ -3052,7 +3168,8 @@ class BackupManagerService extends IBackupManager.Stub { long startRealtime = SystemClock.elapsedRealtime(); if (DEBUG) Slog.v(TAG, "Beginning restore process mTransport=" + mTransport + " mObserver=" + mObserver + " mToken=" + Long.toHexString(mToken) - + " mTargetPackage=" + mTargetPackage + " mPmToken=" + mPmToken); + + " mTargetPackage=" + mTargetPackage + " mFilterSet=" + mFilterSet + + " mPmToken=" + mPmToken); PackageManagerBackupAgent pmAgent = null; int error = -1; // assume error @@ -3071,6 +3188,22 @@ class BackupManagerService extends IBackupManager.Stub { List<PackageInfo> agentPackages = allAgentPackages(); if (mTargetPackage == null) { + // if there's a filter set, strip out anything that isn't + // present before proceeding + if (mFilterSet != null) { + for (int i = agentPackages.size() - 1; i >= 0; i--) { + final PackageInfo pkg = agentPackages.get(i); + if (! mFilterSet.contains(pkg.packageName)) { + agentPackages.remove(i); + } + } + if (DEBUG) { + Slog.i(TAG, "Post-filter package set for restore:"); + for (PackageInfo p : agentPackages) { + Slog.i(TAG, " " + p); + } + } + } restorePackages.addAll(agentPackages); } else { // Just one package to attempt restore of @@ -4266,6 +4399,67 @@ class BackupManagerService extends IBackupManager.Stub { return -1; } + public synchronized int restoreSome(long token, IRestoreObserver observer, + String[] packages) { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, + "performRestore"); + + if (DEBUG) { + StringBuilder b = new StringBuilder(128); + b.append("restoreSome token="); + b.append(Long.toHexString(token)); + b.append(" observer="); + b.append(observer.toString()); + b.append(" packages="); + if (packages == null) { + b.append("null"); + } else { + b.append('{'); + boolean first = true; + for (String s : packages) { + if (!first) { + b.append(", "); + } else first = false; + b.append(s); + } + b.append('}'); + } + Slog.d(TAG, b.toString()); + } + + if (mEnded) { + throw new IllegalStateException("Restore session already ended"); + } + + if (mRestoreTransport == null || mRestoreSets == null) { + Slog.e(TAG, "Ignoring restoreAll() with no restore set"); + return -1; + } + + if (mPackageName != null) { + Slog.e(TAG, "Ignoring restoreAll() on single-package session"); + return -1; + } + + synchronized (mQueueLock) { + for (int i = 0; i < mRestoreSets.length; i++) { + if (token == mRestoreSets[i].token) { + long oldId = Binder.clearCallingIdentity(); + mWakelock.acquire(); + Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE); + msg.obj = new RestoreParams(mRestoreTransport, observer, token, + packages, true); + mBackupHandler.sendMessage(msg); + Binder.restoreCallingIdentity(oldId); + return 0; + } + } + } + + Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); + return -1; + } + public synchronized int restorePackage(String packageName, IRestoreObserver observer) { if (DEBUG) Slog.v(TAG, "restorePackage pkg=" + packageName + " obs=" + observer); diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index b98d2a2..85891a2 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -33,7 +33,9 @@ import android.net.EthernetDataTracker; import android.net.IConnectivityManager; import android.net.INetworkPolicyListener; import android.net.INetworkPolicyManager; +import android.net.LinkAddress; import android.net.LinkProperties; +import android.net.LinkProperties.CompareAddressesResult; import android.net.MobileDataStateTracker; import android.net.NetworkConfig; import android.net.NetworkInfo; @@ -76,6 +78,8 @@ import com.google.android.collect.Sets; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; +import java.net.Inet4Address; +import java.net.Inet6Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -92,6 +96,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class ConnectivityService extends IConnectivityManager.Stub { private static final boolean DBG = true; + private static final boolean VDBG = true; private static final String TAG = "ConnectivityService"; private static final boolean LOGD_RULES = false; @@ -126,6 +131,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { private NetworkStateTracker mNetTrackers[]; /** + * The link properties that define the current links + */ + private LinkProperties mCurrentLinkProperties[]; + + /** * A per Net list of the PID's that requested access to the net * used both as a refcount and for per-PID DNS selection */ @@ -332,6 +342,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetTrackers = new NetworkStateTracker[ ConnectivityManager.MAX_NETWORK_TYPE+1]; + mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1]; mNetworkPreference = getPersistedNetworkPreference(); @@ -468,6 +479,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { mNetConfigs[netType].radio); continue; } + mCurrentLinkProperties[netType] = mNetTrackers[netType].getLinkProperties(); } IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); @@ -1563,6 +1575,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { * right routing table entries exist. */ private void handleConnectivityChange(int netType, boolean doReset) { + int resetMask = doReset ? NetworkUtils.RESET_ALL_ADDRESSES : 0; + /* * If a non-default network is enabled, add the host routes that * will allow it's DNS servers to be accessed. @@ -1570,6 +1584,45 @@ public class ConnectivityService extends IConnectivityManager.Stub { handleDnsConfigurationChange(netType); if (mNetTrackers[netType].getNetworkInfo().isConnected()) { + LinkProperties newLp = mNetTrackers[netType].getLinkProperties(); + LinkProperties curLp = mCurrentLinkProperties[netType]; + mCurrentLinkProperties[netType] = newLp; + if (VDBG) { + log("handleConnectivityChange: changed linkProperty[" + netType + "]:" + + " doReset=" + doReset + " resetMask=" + resetMask + + "\n curLp=" + curLp + + "\n newLp=" + newLp); + } + + if (curLp.isIdenticalInterfaceName(newLp)) { + CompareAddressesResult car = curLp.compareAddresses(newLp); + if ((car.removed.size() != 0) || (car.added.size() != 0)) { + for (LinkAddress linkAddr : car.removed) { + if (linkAddr.getAddress() instanceof Inet4Address) { + resetMask |= NetworkUtils.RESET_IPV4_ADDRESSES; + } + if (linkAddr.getAddress() instanceof Inet6Address) { + resetMask |= NetworkUtils.RESET_IPV6_ADDRESSES; + } + } + if (DBG) { + log("handleConnectivityChange: addresses changed" + + " linkProperty[" + netType + "]:" + " resetMask=" + resetMask + + "\n car=" + car); + } + } else { + if (DBG) { + log("handleConnectivityChange: address are the same reset per doReset" + + " linkProperty[" + netType + "]:" + + " resetMask=" + resetMask); + } + } + } else { + resetMask = NetworkUtils.RESET_ALL_ADDRESSES; + log("handleConnectivityChange: interface not not equivalent reset both" + + " linkProperty[" + netType + "]:" + + " resetMask=" + resetMask); + } if (mNetConfigs[netType].isDefault()) { handleApplyDefaultProxy(netType); addDefaultRoute(mNetTrackers[netType]); @@ -1597,13 +1650,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } - if (doReset) { + if (doReset || resetMask != 0) { LinkProperties linkProperties = mNetTrackers[netType].getLinkProperties(); if (linkProperties != null) { String iface = linkProperties.getInterfaceName(); if (TextUtils.isEmpty(iface) == false) { - if (DBG) log("resetConnections(" + iface + ")"); - NetworkUtils.resetConnections(iface); + if (DBG) log("resetConnections(" + iface + ", " + resetMask + ")"); + NetworkUtils.resetConnections(iface, resetMask); } } } diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index 2d55433..18d393f 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -531,10 +531,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mImeSwitcherNotification.sound = null; mImeSwitcherNotification.vibrate = null; Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - mImeSwitchPendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); + mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); mShowOngoingImeSwitcherForPhones = mRes.getBoolean( com.android.internal.R.bool.show_ongoing_ime_switcher); diff --git a/services/java/com/android/server/LoadAverageService.java b/services/java/com/android/server/LoadAverageService.java index da9fc99..e05b570 100644 --- a/services/java/com/android/server/LoadAverageService.java +++ b/services/java/com/android/server/LoadAverageService.java @@ -28,7 +28,6 @@ import android.os.Message; import android.view.Gravity; import android.view.View; import android.view.WindowManager; -import android.view.WindowManagerImpl; public class LoadAverageService extends Service { private View mView; @@ -91,32 +90,46 @@ public class LoadAverageService extends Service { setPadding(4, 4, 4, 4); //setBackgroundResource(com.android.internal.R.drawable.load_average_background); + // Need to scale text size by density... but we won't do it + // linearly, because with higher dps it is nice to squeeze the + // text a bit to fit more of it. And with lower dps, trying to + // go much smaller will result in unreadable text. + int textSize = 10; + float density = c.getResources().getDisplayMetrics().density; + if (density < 1) { + textSize = 9; + } else { + textSize = (int)(10*density); + if (textSize < 10) { + textSize = 10; + } + } mLoadPaint = new Paint(); mLoadPaint.setAntiAlias(true); - mLoadPaint.setTextSize(10); + mLoadPaint.setTextSize(textSize); mLoadPaint.setARGB(255, 255, 255, 255); mAddedPaint = new Paint(); mAddedPaint.setAntiAlias(true); - mAddedPaint.setTextSize(10); + mAddedPaint.setTextSize(textSize); mAddedPaint.setARGB(255, 128, 255, 128); mRemovedPaint = new Paint(); mRemovedPaint.setAntiAlias(true); mRemovedPaint.setStrikeThruText(true); - mRemovedPaint.setTextSize(10); + mRemovedPaint.setTextSize(textSize); mRemovedPaint.setARGB(255, 255, 128, 128); mShadowPaint = new Paint(); mShadowPaint.setAntiAlias(true); - mShadowPaint.setTextSize(10); + mShadowPaint.setTextSize(textSize); //mShadowPaint.setFakeBoldText(true); mShadowPaint.setARGB(192, 0, 0, 0); mLoadPaint.setShadowLayer(4, 0, 0, 0xff000000); mShadow2Paint = new Paint(); mShadow2Paint.setAntiAlias(true); - mShadow2Paint.setTextSize(10); + mShadow2Paint.setTextSize(textSize); //mShadow2Paint.setFakeBoldText(true); mShadow2Paint.setARGB(192, 0, 0, 0); mLoadPaint.setShadowLayer(2, 0, 0, 0xff000000); @@ -153,14 +166,16 @@ public class LoadAverageService extends Service { } @Override - protected void onMeasure(int widthMeasureSpect, int heightMeasureSpec) { - setMeasuredDimension(mNeededWidth, mNeededHeight); + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension(resolveSize(mNeededWidth, widthMeasureSpec), + resolveSize(mNeededHeight, heightMeasureSpec)); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); - final int W = getWidth(); + final int W = mNeededWidth; + final int RIGHT = getWidth()-1; final Stats stats = mStats; final int userTime = stats.getLastUserTime(); @@ -178,7 +193,7 @@ public class LoadAverageService extends Service { int systemW = (systemTime*W)/totalTime; int irqW = ((iowaitTime+irqTime+softIrqTime)*W)/totalTime; - int x = W - mPaddingRight; + int x = RIGHT - mPaddingRight; int top = mPaddingTop + 2; int bottom = mPaddingTop + mFH - 2; @@ -196,15 +211,15 @@ public class LoadAverageService extends Service { } int y = mPaddingTop - (int)mAscent; - canvas.drawText(stats.mLoadText, W-mPaddingRight-stats.mLoadWidth-1, + canvas.drawText(stats.mLoadText, RIGHT-mPaddingRight-stats.mLoadWidth-1, y-1, mShadowPaint); - canvas.drawText(stats.mLoadText, W-mPaddingRight-stats.mLoadWidth-1, + canvas.drawText(stats.mLoadText, RIGHT-mPaddingRight-stats.mLoadWidth-1, y+1, mShadowPaint); - canvas.drawText(stats.mLoadText, W-mPaddingRight-stats.mLoadWidth+1, + canvas.drawText(stats.mLoadText, RIGHT-mPaddingRight-stats.mLoadWidth+1, y-1, mShadow2Paint); - canvas.drawText(stats.mLoadText, W-mPaddingRight-stats.mLoadWidth+1, + canvas.drawText(stats.mLoadText, RIGHT-mPaddingRight-stats.mLoadWidth+1, y+1, mShadow2Paint); - canvas.drawText(stats.mLoadText, W-mPaddingRight-stats.mLoadWidth, + canvas.drawText(stats.mLoadText, RIGHT-mPaddingRight-stats.mLoadWidth, y, mLoadPaint); int N = stats.countWorkingStats(); @@ -216,7 +231,7 @@ public class LoadAverageService extends Service { userW = (st.rel_utime*W)/totalTime; systemW = (st.rel_stime*W)/totalTime; - x = W - mPaddingRight; + x = RIGHT - mPaddingRight; if (systemW > 0) { canvas.drawRect(x-systemW, top, x, bottom, mSystemPaint); x -= systemW; @@ -226,18 +241,18 @@ public class LoadAverageService extends Service { x -= userW; } - canvas.drawText(st.name, W-mPaddingRight-st.nameWidth-1, + canvas.drawText(st.name, RIGHT-mPaddingRight-st.nameWidth-1, y-1, mShadowPaint); - canvas.drawText(st.name, W-mPaddingRight-st.nameWidth-1, + canvas.drawText(st.name, RIGHT-mPaddingRight-st.nameWidth-1, y+1, mShadowPaint); - canvas.drawText(st.name, W-mPaddingRight-st.nameWidth+1, + canvas.drawText(st.name, RIGHT-mPaddingRight-st.nameWidth+1, y-1, mShadow2Paint); - canvas.drawText(st.name, W-mPaddingRight-st.nameWidth+1, + canvas.drawText(st.name, RIGHT-mPaddingRight-st.nameWidth+1, y+1, mShadow2Paint); Paint p = mLoadPaint; if (st.added) p = mAddedPaint; if (st.removed) p = mRemovedPaint; - canvas.drawText(st.name, W-mPaddingRight-st.nameWidth, y, p); + canvas.drawText(st.name, RIGHT-mPaddingRight-st.nameWidth, y, p); } } @@ -270,7 +285,7 @@ public class LoadAverageService extends Service { super.onCreate(); mView = new LoadView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams( - WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 54e5432..94465fd 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -1075,18 +1075,22 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC com.android.internal.R.styleable.Storage_mtpReserve, 0); boolean allowMassStorage = a.getBoolean( com.android.internal.R.styleable.Storage_allowMassStorage, false); + // resource parser does not support longs, so XML value is in megabytes + long maxFileSize = a.getInt( + com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L; Slog.d(TAG, "got storage path: " + path + " description: " + description + " primary: " + primary + " removable: " + removable + " emulated: " + emulated + " mtpReserve: " + mtpReserve + - " allowMassStorage: " + allowMassStorage); + " allowMassStorage: " + allowMassStorage + + " maxFileSize: " + maxFileSize); if (path == null || description == null) { Slog.e(TAG, "path or description is null in readStorageList"); } else { String pathString = path.toString(); StorageVolume volume = new StorageVolume(pathString, description.toString(), removable, emulated, - mtpReserve, allowMassStorage); + mtpReserve, allowMassStorage, maxFileSize); if (primary) { if (mPrimaryVolume == null) { mPrimaryVolume = volume; @@ -2357,6 +2361,19 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC pw.print(" -> "); pw.println(e.getValue().toString()); } } + + pw.println(""); + + synchronized (mVolumes) { + pw.println(" mVolumes:"); + + final int N = mVolumes.size(); + for (int i = 0; i < N; i++) { + final StorageVolume v = mVolumes.get(i); + pw.print(" "); + pw.println(v.toString()); + } + } } } diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index da1bf83..41e8a31 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -77,11 +77,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { /** Path to {@code /proc/uid_stat}. */ @Deprecated - private final File mProcStatsUidstat; + private final File mStatsUid; + /** Path to {@code /proc/net/dev}. */ + private final File mStatsIface; /** Path to {@code /proc/net/xt_qtaguid/stats}. */ - private final File mProcStatsNetfilter; + private final File mStatsXtUid; + /** Path to {@code /proc/net/xt_qtaguid/iface_stat}. */ + private final File mStatsXtIface; - /** {@link #mProcStatsNetfilter} headers. */ + /** {@link #mStatsXtUid} headers. */ private static final String KEY_IFACE = "iface"; private static final String KEY_TAG_HEX = "acct_tag_hex"; private static final String KEY_UID = "uid_tag_int"; @@ -137,8 +141,10 @@ class NetworkManagementService extends INetworkManagementService.Stub { mContext = context; mObservers = new ArrayList<INetworkManagementEventObserver>(); - mProcStatsUidstat = new File(procRoot, "uid_stat"); - mProcStatsNetfilter = new File(procRoot, "net/xt_qtaguid/stats"); + mStatsUid = new File(procRoot, "uid_stat"); + mStatsIface = new File(procRoot, "net/dev"); + mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats"); + mStatsXtIface = new File(procRoot, "net/xt_qtaguid/iface_stat"); if ("simulator".equals(SystemProperties.get("ro.product.device"))) { return; @@ -161,9 +167,12 @@ class NetworkManagementService extends INetworkManagementService.Stub { } // @VisibleForTesting - public static NetworkManagementService createForTest(Context context, File procRoot) { + public static NetworkManagementService createForTest( + Context context, File procRoot, boolean bandwidthControlEnabled) { // TODO: eventually connect with mock netd - return new NetworkManagementService(context, procRoot); + final NetworkManagementService service = new NetworkManagementService(context, procRoot); + service.mBandwidthControlEnabled = bandwidthControlEnabled; + return service; } public void systemReady() { @@ -187,6 +196,9 @@ class NetworkManagementService extends INetworkManagementService.Stub { } else { Slog.d(TAG, "not enabling bandwidth control"); } + + SystemProperties.set(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, + mBandwidthControlEnabled ? "1" : "0"); } public void registerObserver(INetworkManagementEventObserver obs) { @@ -930,13 +942,68 @@ class NetworkManagementService extends INetworkManagementService.Stub { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService"); - final String[] ifaces = listInterfaces(); - final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), ifaces.length); + final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + + final HashSet<String> activeIfaces = Sets.newHashSet(); + final ArrayList<String> values = Lists.newArrayList(); + + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(mStatsIface)); + + // skip first two header lines + reader.readLine(); + reader.readLine(); - for (String iface : ifaces) { - final long rx = getInterfaceCounter(iface, true); - final long tx = getInterfaceCounter(iface, false); - stats.addEntry(iface, UID_ALL, TAG_NONE, rx, tx); + // parse remaining lines + String line; + while ((line = reader.readLine()) != null) { + splitLine(line, values); + + try { + entry.iface = values.get(0); + entry.uid = UID_ALL; + entry.tag = TAG_NONE; + entry.rxBytes = Long.parseLong(values.get(1)); + entry.rxPackets = Long.parseLong(values.get(2)); + entry.txBytes = Long.parseLong(values.get(9)); + entry.txPackets = Long.parseLong(values.get(10)); + + activeIfaces.add(entry.iface); + stats.addValues(entry); + } catch (NumberFormatException e) { + Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); + } + } + } catch (IOException e) { + Slog.w(TAG, "problem parsing stats: " + e); + } finally { + IoUtils.closeQuietly(reader); + } + + if (DBG) Slog.d(TAG, "recorded active stats from " + activeIfaces); + + // splice in stats from any disabled ifaces + if (mBandwidthControlEnabled) { + final HashSet<String> xtIfaces = Sets.newHashSet(fileListWithoutNull(mStatsXtIface)); + xtIfaces.removeAll(activeIfaces); + + for (String iface : xtIfaces) { + final File ifacePath = new File(mStatsXtIface, iface); + + entry.iface = iface; + entry.uid = UID_ALL; + entry.tag = TAG_NONE; + entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes")); + entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets")); + entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes")); + entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets")); + + stats.addValues(entry); + } + + if (DBG) Slog.d(TAG, "recorded stale stats from " + xtIfaces); } return stats; @@ -1063,13 +1130,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { */ private NetworkStats getNetworkStatsDetailNetfilter(int limitUid) { final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 24); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + final ArrayList<String> keys = Lists.newArrayList(); final ArrayList<String> values = Lists.newArrayList(); final HashMap<String, String> parsed = Maps.newHashMap(); BufferedReader reader = null; try { - reader = new BufferedReader(new FileReader(mProcStatsNetfilter)); + reader = new BufferedReader(new FileReader(mStatsXtUid)); // parse first line as header String line = reader.readLine(); @@ -1081,15 +1150,16 @@ class NetworkManagementService extends INetworkManagementService.Stub { parseLine(keys, values, parsed); try { - final String iface = parsed.get(KEY_IFACE); - final int tag = NetworkManagementSocketTagger.kernelToTag( + // TODO: add rxPackets/txPackets once kernel exports + entry.iface = parsed.get(KEY_IFACE); + entry.tag = NetworkManagementSocketTagger.kernelToTag( parsed.get(KEY_TAG_HEX)); - final int uid = Integer.parseInt(parsed.get(KEY_UID)); - final long rx = Long.parseLong(parsed.get(KEY_RX)); - final long tx = Long.parseLong(parsed.get(KEY_TX)); + entry.uid = Integer.parseInt(parsed.get(KEY_UID)); + entry.rxBytes = Long.parseLong(parsed.get(KEY_RX)); + entry.txBytes = Long.parseLong(parsed.get(KEY_TX)); - if (limitUid == UID_ALL || limitUid == uid) { - stats.addEntry(iface, uid, tag, rx, tx); + if (limitUid == UID_ALL || limitUid == entry.uid) { + stats.addValues(entry); } } catch (NumberFormatException e) { Slog.w(TAG, "problem parsing stats row '" + line + "': " + e); @@ -1114,19 +1184,27 @@ class NetworkManagementService extends INetworkManagementService.Stub { private NetworkStats getNetworkStatsDetailUidstat(int limitUid) { final String[] knownUids; if (limitUid == UID_ALL) { - knownUids = mProcStatsUidstat.list(); + knownUids = fileListWithoutNull(mStatsUid); } else { knownUids = new String[] { String.valueOf(limitUid) }; } final NetworkStats stats = new NetworkStats( SystemClock.elapsedRealtime(), knownUids.length); + final NetworkStats.Entry entry = new NetworkStats.Entry(); for (String uid : knownUids) { final int uidInt = Integer.parseInt(uid); - final File uidPath = new File(mProcStatsUidstat, uid); - final long rx = readSingleLongFromFile(new File(uidPath, "tcp_rcv")); - final long tx = readSingleLongFromFile(new File(uidPath, "tcp_snd")); - stats.addEntry(IFACE_ALL, uidInt, TAG_NONE, rx, tx); + final File uidPath = new File(mStatsUid, uid); + + entry.iface = IFACE_ALL; + entry.uid = uidInt; + entry.tag = TAG_NONE; + entry.rxBytes = readSingleLongFromFile(new File(uidPath, "tcp_rcv")); + entry.rxPackets = readSingleLongFromFile(new File(uidPath, "tcp_rcv_pkt")); + entry.txBytes = readSingleLongFromFile(new File(uidPath, "tcp_snd")); + entry.txPackets = readSingleLongFromFile(new File(uidPath, "tcp_snd_pkt")); + + stats.addValues(entry); } return stats; @@ -1197,7 +1275,7 @@ class NetworkManagementService extends INetworkManagementService.Stub { private static void splitLine(String line, ArrayList<String> outSplit) { outSplit.clear(); - final StringTokenizer t = new StringTokenizer(line); + final StringTokenizer t = new StringTokenizer(line, " \t\n\r\f:"); while (t.hasMoreTokens()) { outSplit.add(t.nextToken()); } @@ -1232,6 +1310,15 @@ class NetworkManagementService extends INetworkManagementService.Stub { } } + /** + * Wrapper for {@link File#list()} that returns empty array instead of + * {@code null}. + */ + private static String[] fileListWithoutNull(File file) { + final String[] list = file.list(); + return list != null ? list : new String[0]; + } + public void setDefaultInterfaceForDns(String iface) throws IllegalStateException { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); diff --git a/services/java/com/android/server/NetworkTimeUpdateService.java b/services/java/com/android/server/NetworkTimeUpdateService.java index 15f22c0..f7fe39e 100644 --- a/services/java/com/android/server/NetworkTimeUpdateService.java +++ b/services/java/com/android/server/NetworkTimeUpdateService.java @@ -16,8 +16,6 @@ package com.android.server; -import com.android.internal.telephony.TelephonyIntents; - import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -28,7 +26,6 @@ import android.content.IntentFilter; import android.database.ContentObserver; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.net.SntpClient; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; @@ -36,12 +33,10 @@ import android.os.Message; import android.os.SystemClock; import android.provider.Settings; import android.util.Log; -import android.util.Slog; +import android.util.NtpTrustedTime; +import android.util.TrustedTime; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; +import com.android.internal.telephony.TelephonyIntents; /** * Monitors the network time and updates the system time if it is out of sync @@ -68,14 +63,11 @@ public class NetworkTimeUpdateService { private static final long POLLING_INTERVAL_SHORTER_MS = 60 * 1000L; // 60 seconds /** Number of times to try again */ private static final int TRY_AGAIN_TIMES_MAX = 3; - /** How long to wait for the NTP server to respond. */ - private static final int MAX_NTP_FETCH_WAIT_MS = 20 * 1000; /** If the time difference is greater than this threshold, then update the time. */ private static final int TIME_ERROR_THRESHOLD_MS = 5 * 1000; private static final String ACTION_POLL = "com.android.server.NetworkTimeUpdateService.action.POLL"; - private static final String PROPERTIES_FILE = "/etc/gps.conf"; private static int POLL_REQUEST = 0; private static final long NOT_SET = -1; @@ -84,14 +76,14 @@ public class NetworkTimeUpdateService { private long mNitzZoneSetTime = NOT_SET; private Context mContext; + private TrustedTime mTime; + // NTP lookup is done on this thread and handler private Handler mHandler; private HandlerThread mThread; private AlarmManager mAlarmManager; private PendingIntent mPendingPollIntent; private SettingsObserver mSettingsObserver; - // Address of the NTP server - private String mNtpServer; // The last time that we successfully fetched the NTP time. private long mLastNtpFetchTime = NOT_SET; // Keeps track of how many quick attempts were made to fetch NTP time. @@ -101,6 +93,7 @@ public class NetworkTimeUpdateService { public NetworkTimeUpdateService(Context context) { mContext = context; + mTime = NtpTrustedTime.getInstance(context); mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Intent pollIntent = new Intent(ACTION_POLL, null); mPendingPollIntent = PendingIntent.getBroadcast(mContext, POLL_REQUEST, pollIntent, 0); @@ -108,12 +101,6 @@ public class NetworkTimeUpdateService { /** Initialize the receivers and initiate the first NTP request */ public void systemReady() { - mNtpServer = getNtpServerAddress(); - if (mNtpServer == null) { - Slog.e(TAG, "NTP server address not found, not syncing to NTP time"); - return; - } - registerForTelephonyIntents(); registerForAlarms(); registerForConnectivityIntents(); @@ -128,27 +115,6 @@ public class NetworkTimeUpdateService { mSettingsObserver.observe(mContext); } - private String getNtpServerAddress() { - String serverAddress = null; - FileInputStream stream = null; - try { - Properties properties = new Properties(); - File file = new File(PROPERTIES_FILE); - stream = new FileInputStream(file); - properties.load(stream); - serverAddress = properties.getProperty("NTP_SERVER", null); - } catch (IOException e) { - Slog.e(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (Exception e) {} - } - } - return serverAddress; - } - private void registerForTelephonyIntents() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIME); @@ -189,9 +155,15 @@ public class NetworkTimeUpdateService { if (mLastNtpFetchTime == NOT_SET || refTime >= mLastNtpFetchTime + POLLING_INTERVAL_MS || event == EVENT_AUTO_TIME_CHANGED) { if (DBG) Log.d(TAG, "Before Ntp fetch"); - long ntp = getNtpTime(); - if (DBG) Log.d(TAG, "Ntp = " + ntp); - if (ntp > 0) { + + // force refresh NTP cache when outdated + if (mTime.getCacheAge() >= POLLING_INTERVAL_MS) { + mTime.forceRefresh(); + } + + // only update when NTP time is fresh + if (mTime.getCacheAge() < POLLING_INTERVAL_MS) { + final long ntp = mTime.currentTimeMillis(); mTryAgainCounter = 0; mLastNtpFetchTime = SystemClock.elapsedRealtime(); if (Math.abs(ntp - currentTime) > TIME_ERROR_THRESHOLD_MS) { @@ -232,15 +204,6 @@ public class NetworkTimeUpdateService { mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, next, mPendingPollIntent); } - private long getNtpTime() { - SntpClient client = new SntpClient(); - if (client.requestTime(mNtpServer, MAX_NTP_FETCH_WAIT_MS)) { - return client.getNtpTime(); - } else { - return 0; - } - } - /** * Checks if the user prefers to automatically set the time. */ diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java index d81dfdb..b8890aa 100644 --- a/services/java/com/android/server/ThrottleService.java +++ b/services/java/com/android/server/ThrottleService.java @@ -16,9 +16,6 @@ package com.android.server; -import com.android.internal.R; -import com.android.internal.telephony.TelephonyProperties; - import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; @@ -54,6 +51,9 @@ import android.util.NtpTrustedTime; import android.util.Slog; import android.util.TrustedTime; +import com.android.internal.R; +import com.android.internal.telephony.TelephonyProperties; + import java.io.BufferedWriter; import java.io.File; import java.io.FileDescriptor; @@ -63,7 +63,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.Calendar; import java.util.GregorianCalendar; -import java.util.Properties; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -87,7 +86,6 @@ public class ThrottleService extends IThrottleManager.Stub { private static final long TESTING_THRESHOLD = 1 * 1024 * 1024; private static final long MAX_NTP_CACHE_AGE = 24 * 60 * 60 * 1000; - private static final long MAX_NTP_FETCH_WAIT = 20 * 1000; private long mMaxNtpCacheAge = MAX_NTP_CACHE_AGE; @@ -127,8 +125,6 @@ public class ThrottleService extends IThrottleManager.Stub { private static final int THROTTLE_INDEX_UNINITIALIZED = -1; private static final int THROTTLE_INDEX_UNTHROTTLED = 0; - private static final String PROPERTIES_FILE = "/etc/gps.conf"; - private Intent mPollStickyBroadcast; private TrustedTime mTime; @@ -139,8 +135,7 @@ public class ThrottleService extends IThrottleManager.Stub { } public ThrottleService(Context context) { - // TODO: move to using cached NtpTrustedTime - this(context, getNetworkManagementService(), new NtpTrustedTime(), + this(context, getNetworkManagementService(), NtpTrustedTime.getInstance(context), context.getResources().getString(R.string.config_datause_iface)); } @@ -341,26 +336,6 @@ public class ThrottleService extends IThrottleManager.Stub { } }, new IntentFilter(ACTION_RESET)); - FileInputStream stream = null; - try { - Properties properties = new Properties(); - File file = new File(PROPERTIES_FILE); - stream = new FileInputStream(file); - properties.load(stream); - final String ntpServer = properties.getProperty("NTP_SERVER", null); - if (mTime instanceof NtpTrustedTime) { - ((NtpTrustedTime) mTime).setNtpServer(ntpServer, MAX_NTP_FETCH_WAIT); - } - } catch (IOException e) { - Slog.e(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (Exception e) {} - } - } - // use a new thread as we don't want to stall the system for file writes mThread = new HandlerThread(TAG); mThread.start(); @@ -540,8 +515,9 @@ public class ThrottleService extends IThrottleManager.Stub { mIface, NetworkStats.UID_ALL, NetworkStats.TAG_NONE); if (index != -1) { - incRead = stats.rx[index] - mLastRead; - incWrite = stats.tx[index] - mLastWrite; + final NetworkStats.Entry entry = stats.getValues(index, null); + incRead = entry.rxBytes - mLastRead; + incWrite = entry.txBytes - mLastWrite; } else { // missing iface, assume stats are 0 Slog.w(TAG, "unable to find stats for iface " + mIface); diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java index 80cdf6b..f99951fa 100644 --- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -1155,9 +1155,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub | AccessibilityNodeInfo.ACTION_CLEAR_SELECTION; private static final int RETRIEVAL_ALLOWING_EVENT_TYPES = - AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END - | AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START - | AccessibilityEvent.TYPE_VIEW_CLICKED | AccessibilityEvent.TYPE_VIEW_FOCUSED + AccessibilityEvent.TYPE_VIEW_CLICKED | AccessibilityEvent.TYPE_VIEW_FOCUSED | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_VIEW_SELECTED diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/java/com/android/server/accessibility/TouchExplorer.java index 1af7015..dbd9474 100644 --- a/services/java/com/android/server/accessibility/TouchExplorer.java +++ b/services/java/com/android/server/accessibility/TouchExplorer.java @@ -838,8 +838,6 @@ public class TouchExplorer implements Explorer { */ private void sendAccessibilityEvent(int eventType) { AccessibilityEvent event = AccessibilityEvent.obtain(eventType); - event.setPackageName(mContext.getPackageName()); - event.setClassName(getClass().getName()); mAccessibilityManager.sendAccessibilityEvent(event); } diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 29cccb6..fd93bcf 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -45,7 +45,6 @@ import android.app.INotificationManager; import android.app.IProcessObserver; import android.app.IServiceConnection; import android.app.IThumbnailReceiver; -import android.app.IThumbnailRetriever; import android.app.Instrumentation; import android.app.Notification; import android.app.NotificationManager; @@ -54,6 +53,7 @@ import android.app.Service; import android.app.backup.IBackupManager; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; +import android.content.ComponentCallbacks; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; @@ -181,22 +181,8 @@ public final class ActivityManagerService extends ActivityManagerNative // The flags that are set for all calls we make to the package manager. static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES; - private static final String SYSTEM_SECURE = "ro.secure"; private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; - // This is the maximum number of application processes we would like - // to have running. Due to the asynchronous nature of things, we can - // temporarily go beyond this limit. - static final int MAX_PROCESSES = 2; - - // Set to false to leave processes running indefinitely, relying on - // the kernel killing them as resources are required. - static final boolean ENFORCE_PROCESS_LIMIT = false; - - // This is the maximum number of activities that we would like to have - // running at a given time. - static final int MAX_ACTIVITIES = 20; - // Maximum number of recent tasks that we can remember. static final int MAX_RECENT_TASKS = 20; @@ -208,6 +194,12 @@ public final class ActivityManagerService extends ActivityManagerNative // before we decide it's never going to come up for real. static final int PROC_START_TIMEOUT = 10*1000; + // How long we wait for a launched process to attach to the activity manager + // before we decide it's never going to come up for real, when the process was + // started with a wrapper for instrumentation (such as Valgrind) because it + // could take much longer than usual. + static final int PROC_START_TIMEOUT_WITH_WRAPPER = 300*1000; + // How long to wait after going idle before forcing apps to GC. static final int GC_TIMEOUT = 5*1000; @@ -502,15 +494,6 @@ public final class ActivityManagerService extends ActivityManagerNative = new ArrayList<ProcessRecord>(); /** - * List of records for processes that we have started and are waiting - * for them to call back. This is really only needed when running in - * single processes mode, in which case we do not have a unique pid for - * each process. - */ - final ArrayList<ProcessRecord> mStartingProcesses - = new ArrayList<ProcessRecord>(); - - /** * List of persistent applications that are in the process * of being started. */ @@ -917,7 +900,8 @@ public final class ActivityManagerService extends ActivityManagerNative */ boolean mBooted = false; - int mProcessLimit = 0; + int mProcessLimit = MAX_HIDDEN_APPS; + int mProcessLimitOverride = -1; WindowManagerService mWindowManager; @@ -1959,8 +1943,13 @@ public final class ActivityManagerService extends ActivityManagerNative if ("1".equals(SystemProperties.get("debug.assert"))) { debugFlags |= Zygote.DEBUG_ENABLE_ASSERT; } - int pid = Process.start("android.app.ActivityThread", - app.processName, uid, uid, gids, debugFlags, null); + + // 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, + app.info.targetSdkVersion, null); + BatteryStatsImpl bs = app.batteryStats.getBatteryStats(); synchronized (bs) { if (bs.isOnBattery()) { @@ -1968,12 +1957,12 @@ public final class ActivityManagerService extends ActivityManagerNative } } - EventLog.writeEvent(EventLogTags.AM_PROC_START, pid, uid, + EventLog.writeEvent(EventLogTags.AM_PROC_START, startResult.pid, uid, app.processName, hostingType, hostingNameStr != null ? hostingNameStr : ""); if (app.persistent) { - Watchdog.getInstance().processStarted(app.processName, pid); + Watchdog.getInstance().processStarted(app.processName, startResult.pid); } StringBuilder buf = mStringBuilder; @@ -1987,7 +1976,7 @@ public final class ActivityManagerService extends ActivityManagerNative buf.append(hostingNameStr); } buf.append(": pid="); - buf.append(pid); + buf.append(startResult.pid); buf.append(" uid="); buf.append(uid); buf.append(" gids={"); @@ -2000,26 +1989,15 @@ public final class ActivityManagerService extends ActivityManagerNative } buf.append("}"); Slog.i(TAG, buf.toString()); - if (pid == 0 || pid == MY_PID) { - // Processes are being emulated with threads. - app.pid = MY_PID; - app.removed = false; - mStartingProcesses.add(app); - } else if (pid > 0) { - app.pid = pid; - app.removed = false; - synchronized (mPidsSelfLocked) { - this.mPidsSelfLocked.put(pid, app); - Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); - msg.obj = app; - mHandler.sendMessageDelayed(msg, PROC_START_TIMEOUT); - } - } else { - app.pid = 0; - RuntimeException e = new RuntimeException( - "Failure starting process " + app.processName - + ": returned pid=" + pid); - Slog.e(TAG, e.getMessage(), e); + app.pid = startResult.pid; + app.usingWrapper = startResult.usingWrapper; + app.removed = false; + synchronized (mPidsSelfLocked) { + this.mPidsSelfLocked.put(startResult.pid, app); + Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); + msg.obj = app; + mHandler.sendMessageDelayed(msg, startResult.usingWrapper + ? PROC_START_TIMEOUT_WITH_WRAPPER : PROC_START_TIMEOUT); } } catch (RuntimeException e) { // XXX do better error recovery. @@ -2300,11 +2278,10 @@ public final class ActivityManagerService extends ActivityManagerNative } synchronized (this) { - int index = mMainStack.indexOfTokenLocked(callingActivity); - if (index < 0) { + ActivityRecord r = mMainStack.isInStackLocked(callingActivity); + if (r == null) { return false; } - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); if (r.app == null || r.app.thread == null) { // The caller is not running... d'oh! return false; @@ -2451,11 +2428,10 @@ public final class ActivityManagerService extends ActivityManagerNative public void setRequestedOrientation(IBinder token, int requestedOrientation) { synchronized (this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { return; } - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); final long origId = Binder.clearCallingIdentity(); mWindowManager.setAppOrientation(r, requestedOrientation); Configuration config = mWindowManager.updateOrientationFromAppTokens( @@ -2473,11 +2449,10 @@ public final class ActivityManagerService extends ActivityManagerNative public int getRequestedOrientation(IBinder token) { synchronized (this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; } - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); return mWindowManager.getAppOrientation(r); } } @@ -2618,11 +2593,10 @@ public final class ActivityManagerService extends ActivityManagerNative public final void finishSubActivity(IBinder token, String resultWho, int requestCode) { synchronized(this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + ActivityRecord self = mMainStack.isInStackLocked(token); + if (self == null) { return; } - ActivityRecord self = (ActivityRecord)mMainStack.mHistory.get(index); final long origId = Binder.clearCallingIdentity(); @@ -2661,11 +2635,10 @@ public final class ActivityManagerService extends ActivityManagerNative public void overridePendingTransition(IBinder token, String packageName, int enterAnim, int exitAnim) { synchronized(this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + ActivityRecord self = mMainStack.isInStackLocked(token); + if (self == null) { return; } - ActivityRecord self = (ActivityRecord)mMainStack.mHistory.get(index); final long origId = Binder.clearCallingIdentity(); @@ -2744,8 +2717,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } - r.stack.cleanUpActivityLocked(r, true); - r.state = ActivityState.STOPPED; + r.stack.cleanUpActivityLocked(r, true, true); } atTop = false; } @@ -3605,9 +3577,6 @@ public final class ActivityManagerService extends ActivityManagerNative synchronized (mPidsSelfLocked) { app = mPidsSelfLocked.get(pid); } - } else if (mStartingProcesses.size() > 0) { - app = mStartingProcesses.remove(0); - app.setPid(pid); } else { app = null; } @@ -3932,20 +3901,9 @@ public final class ActivityManagerService extends ActivityManagerNative final long origId = Binder.clearCallingIdentity(); synchronized (this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index >= 0) { - r = (ActivityRecord)mMainStack.mHistory.get(index); - r.icicle = icicle; - r.haveState = true; - r.updateThumbnail(thumbnail, description); - r.stopped = true; - r.state = ActivityState.STOPPED; - if (!r.finishing) { - if (r.configDestroy) { - r.stack.destroyActivityLocked(r, true); - r.stack.resumeTopActivityLocked(null); - } - } + r = mMainStack.isInStackLocked(token); + if (r != null) { + r.stack.activityStoppedLocked(r, icicle, thumbnail, description); } } @@ -3978,35 +3936,30 @@ public final class ActivityManagerService extends ActivityManagerNative } private ActivityRecord getCallingRecordLocked(IBinder token) { - int index = mMainStack.indexOfTokenLocked(token); - if (index >= 0) { - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); - if (r != null) { - return r.resultTo; - } + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { + return null; } - return null; + return r.resultTo; } public ComponentName getActivityClassForToken(IBinder token) { synchronized(this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index >= 0) { - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); - return r.intent.getComponent(); + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { + return null; } - return null; + return r.intent.getComponent(); } } public String getPackageForToken(IBinder token) { synchronized(this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index >= 0) { - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); - return r.packageName; + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { + return null; } - return null; + return r.packageName; } } @@ -4041,8 +3994,7 @@ public final class ActivityManagerService extends ActivityManagerNative synchronized(this) { int callingUid = Binder.getCallingUid(); try { - if (callingUid != 0 && callingUid != Process.SYSTEM_UID && - Process.supportsProcesses()) { + if (callingUid != 0 && callingUid != Process.SYSTEM_UID) { int uid = AppGlobals.getPackageManager() .getPackageUid(packageName); if (uid != Binder.getCallingUid()) { @@ -4070,11 +4022,10 @@ public final class ActivityManagerService extends ActivityManagerNative int requestCode, Intent[] intents, String[] resolvedTypes, int flags) { ActivityRecord activity = null; if (type == INTENT_SENDER_ACTIVITY_RESULT) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + activity = mMainStack.isInStackLocked(token); + if (activity == null) { return null; } - activity = (ActivityRecord)mMainStack.mHistory.get(index); if (activity.finishing) { return null; } @@ -4196,11 +4147,17 @@ public final class ActivityManagerService extends ActivityManagerNative public void setProcessLimit(int max) { enforceCallingPermission(android.Manifest.permission.SET_PROCESS_LIMIT, "setProcessLimit()"); - mProcessLimit = max; + synchronized (this) { + mProcessLimit = max < 0 ? MAX_HIDDEN_APPS : max; + mProcessLimitOverride = max; + } + trimApplications(); } public int getProcessLimit() { - return mProcessLimit; + synchronized (this) { + return mProcessLimitOverride; + } } void foregroundTokenDied(ForegroundToken token) { @@ -4301,8 +4258,7 @@ public final class ActivityManagerService extends ActivityManagerNative } // Root, system server and our own process get to do everything. - if (uid == 0 || uid == Process.SYSTEM_UID || pid == MY_PID || - !Process.supportsProcesses()) { + if (uid == 0 || uid == Process.SYSTEM_UID || pid == MY_PID) { return PackageManager.PERMISSION_GRANTED; } // If there is a uid that owns whatever is being accessed, it has @@ -4446,7 +4402,7 @@ public final class ActivityManagerService extends ActivityManagerNative private final boolean checkUriPermissionLocked(Uri uri, int uid, int modeFlags) { // Root gets to do everything. - if (uid == 0 || !Process.supportsProcesses()) { + if (uid == 0) { return true; } HashMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(uid); @@ -5465,11 +5421,10 @@ public final class ActivityManagerService extends ActivityManagerNative synchronized(this) { if (r == null) { - int index = mMainStack.indexOfTokenLocked(token); - if (index < 0) { + r = mMainStack.isInStackLocked(token); + if (r == null) { return; } - r = (ActivityRecord)mMainStack.mHistory.get(index); } if (thumbnail == null && r.thumbHolder != null) { thumbnail = r.thumbHolder.lastThumbnail; @@ -5527,8 +5482,8 @@ public final class ActivityManagerService extends ActivityManagerNative // CONTENT PROVIDERS // ========================================================= - private final List generateApplicationProvidersLocked(ProcessRecord app) { - List providers = null; + private final List<ProviderInfo> generateApplicationProvidersLocked(ProcessRecord app) { + List<ProviderInfo> providers = null; try { providers = AppGlobals.getPackageManager(). queryContentProviders(app.processName, app.info.uid, @@ -5966,7 +5921,7 @@ public final class ActivityManagerService extends ActivityManagerNative } public static final void installSystemProviders() { - List providers; + List<ProviderInfo> providers; synchronized (mSelf) { ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID); providers = mSelf.generateApplicationProvidersLocked(app); @@ -6183,9 +6138,8 @@ public final class ActivityManagerService extends ActivityManagerNative final long origId = Binder.clearCallingIdentity(); synchronized (this) { - int index = mMainStack.indexOfTokenLocked(token); - if (index >= 0) { - r = (ActivityRecord)mMainStack.mHistory.get(index); + r = mMainStack.isInStackLocked(token); + if (r != null) { mMainStack.activitySleptLocked(r); } } @@ -6336,22 +6290,20 @@ public final class ActivityManagerService extends ActivityManagerNative public void setImmersive(IBinder token, boolean immersive) { synchronized(this) { - int index = (token != null) ? mMainStack.indexOfTokenLocked(token) : -1; - if (index < 0) { + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { throw new IllegalArgumentException(); } - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); r.immersive = immersive; } } public boolean isImmersive(IBinder token) { synchronized (this) { - int index = (token != null) ? mMainStack.indexOfTokenLocked(token) : -1; - if (index < 0) { + ActivityRecord r = mMainStack.isInStackLocked(token); + if (r == null) { throw new IllegalArgumentException(); } - ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index); return r.immersive; } } @@ -6584,13 +6536,6 @@ public final class ActivityManagerService extends ActivityManagerNative } public void systemReady(final Runnable goingCallback) { - // In the simulator, startRunning will never have been called, which - // normally sets a few crucial variables. Do it here instead. - if (!Process.supportsProcesses()) { - mStartRunning = true; - mTopAction = Intent.ACTION_MAIN; - } - synchronized(this) { if (mSystemReady) { if (goingCallback != null) goingCallback.run(); @@ -7954,14 +7899,6 @@ public final class ActivityManagerService extends ActivityManagerNative "Starting Norm", "Restarting PERS"); } - if (mStartingProcesses.size() > 0) { - if (needSep) pw.println(" "); - needSep = true; - pw.println(" Processes that are starting:"); - dumpProcessList(pw, this, mStartingProcesses, " ", - "Starting Norm", "Starting PERS"); - } - if (mRemovedProcesses.size() > 0) { if (needSep) pw.println(" "); needSep = true; @@ -8829,9 +8766,10 @@ public final class ActivityManagerService extends ActivityManagerNative } else { foreground = " "; } - pw.println(String.format("%s%s #%2d: adj=%s/%s%s %s (%s)", + pw.println(String.format("%s%s #%2d: adj=%s/%s%s trm=%2d %s (%s)", prefix, (r.persistent ? persistentLabel : normalLabel), - N-i, oomAdj, schedGroup, foreground, r.toShortString(), r.adjType)); + N-i, oomAdj, schedGroup, foreground, r.trimMemoryLevel, + r.toShortString(), r.adjType)); if (r.adjSource != null || r.adjTarget != null) { pw.print(prefix); pw.print(" "); @@ -10366,12 +10304,11 @@ public final class ActivityManagerService extends ActivityManagerNative ActivityRecord activity = null; if (token != null) { - int aindex = mMainStack.indexOfTokenLocked(token); - if (aindex < 0) { + activity = mMainStack.isInStackLocked(token); + if (activity == null) { Slog.w(TAG, "Binding with unknown activity: " + token); return 0; } - activity = (ActivityRecord)mMainStack.mHistory.get(aindex); } int clientLabel = 0; @@ -11585,8 +11522,8 @@ public final class ActivityManagerService extends ActivityManagerNative return false; } int state = r.state; - r.state = r.IDLE; - if (state == r.IDLE) { + r.state = BroadcastRecord.IDLE; + if (state == BroadcastRecord.IDLE) { if (explicit) { Slog.w(TAG, "finishReceiver called but state is IDLE"); } @@ -12970,7 +12907,7 @@ public final class ActivityManagerService extends ActivityManagerNative ProcessRecord proc = mProcessesToGc.get(0); Message msg = mHandler.obtainMessage(GC_BACKGROUND_PROCESSES_MSG); - long when = mProcessesToGc.get(0).lastRequestedGc + GC_MIN_INTERVAL; + long when = proc.lastRequestedGc + GC_MIN_INTERVAL; long now = SystemClock.uptimeMillis(); if (when < (now+GC_TIMEOUT)) { when = now + GC_TIMEOUT; @@ -13113,95 +13050,88 @@ public final class ActivityManagerService extends ActivityManagerNative } } - private final boolean updateOomAdjLocked( + private final void updateOomAdjLocked( ProcessRecord app, int hiddenAdj, ProcessRecord TOP_APP) { app.hiddenAdj = hiddenAdj; if (app.thread == null) { - return true; + return; } - boolean success = true; - final boolean wasKeeping = app.keeping; int adj = computeOomAdjLocked(app, hiddenAdj, TOP_APP, false); - if ((app.pid != 0 && app.pid != MY_PID) || Process.supportsProcesses()) { - if (app.curRawAdj != app.setRawAdj) { - if (app.curRawAdj > FOREGROUND_APP_ADJ - && app.setRawAdj <= FOREGROUND_APP_ADJ) { - // If this app is transitioning from foreground to - // non-foreground, have it do a gc. - scheduleAppGcLocked(app); - } else if (app.curRawAdj >= HIDDEN_APP_MIN_ADJ - && app.setRawAdj < HIDDEN_APP_MIN_ADJ) { - // Likewise do a gc when an app is moving in to the - // background (such as a service stopping). - scheduleAppGcLocked(app); - } - - if (wasKeeping && !app.keeping) { - // This app is no longer something we want to keep. Note - // its current wake lock time to later know to kill it if - // it is not behaving well. - BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics(); - synchronized (stats) { - app.lastWakeTime = stats.getProcessWakeTime(app.info.uid, - app.pid, SystemClock.elapsedRealtime()); - } - app.lastCpuTime = app.curCpuTime; + if (app.curRawAdj != app.setRawAdj) { + if (app.curRawAdj > FOREGROUND_APP_ADJ + && app.setRawAdj <= FOREGROUND_APP_ADJ) { + // If this app is transitioning from foreground to + // non-foreground, have it do a gc. + scheduleAppGcLocked(app); + } else if (app.curRawAdj >= HIDDEN_APP_MIN_ADJ + && app.setRawAdj < HIDDEN_APP_MIN_ADJ) { + // Likewise do a gc when an app is moving in to the + // background (such as a service stopping). + scheduleAppGcLocked(app); + } + + if (wasKeeping && !app.keeping) { + // This app is no longer something we want to keep. Note + // its current wake lock time to later know to kill it if + // it is not behaving well. + BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics(); + synchronized (stats) { + app.lastWakeTime = stats.getProcessWakeTime(app.info.uid, + app.pid, SystemClock.elapsedRealtime()); } - - app.setRawAdj = app.curRawAdj; + app.lastCpuTime = app.curCpuTime; } - if (adj != app.setAdj) { - if (Process.setOomAdj(app.pid, adj)) { - if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v( - TAG, "Set app " + app.processName + - " oom adj to " + adj); - app.setAdj = adj; - } else { - success = false; - } + + app.setRawAdj = app.curRawAdj; + } + if (adj != app.setAdj) { + if (Process.setOomAdj(app.pid, adj)) { + if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v( + TAG, "Set app " + app.processName + + " oom adj to " + adj + " because " + app.adjType); + app.setAdj = adj; + } else { + Slog.w(TAG, "Failed setting oom adj of " + app + " to " + adj); } - if (app.setSchedGroup != app.curSchedGroup) { - app.setSchedGroup = app.curSchedGroup; - if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG, - "Setting process group of " + app.processName - + " to " + app.curSchedGroup); - if (app.waitingToKill != null && - app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) { - Slog.i(TAG, "Killing " + app.toShortString() + ": " + app.waitingToKill); - EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, - app.processName, app.setAdj, app.waitingToKill); - Process.killProcessQuiet(app.pid); + } + if (app.setSchedGroup != app.curSchedGroup) { + app.setSchedGroup = app.curSchedGroup; + if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG, + "Setting process group of " + app.processName + + " to " + app.curSchedGroup); + if (app.waitingToKill != null && + app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) { + Slog.i(TAG, "Killing " + app.toShortString() + ": " + app.waitingToKill); + EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, + app.processName, app.setAdj, app.waitingToKill); + Process.killProcessQuiet(app.pid); + } else { + if (true) { + long oldId = Binder.clearCallingIdentity(); + try { + Process.setProcessGroup(app.pid, app.curSchedGroup); + } catch (Exception e) { + Slog.w(TAG, "Failed setting process group of " + app.pid + + " to " + app.curSchedGroup); + e.printStackTrace(); + } finally { + Binder.restoreCallingIdentity(oldId); + } } else { - if (true) { - long oldId = Binder.clearCallingIdentity(); + if (app.thread != null) { try { - Process.setProcessGroup(app.pid, app.curSchedGroup); - } catch (Exception e) { - Slog.w(TAG, "Failed setting process group of " + app.pid - + " to " + app.curSchedGroup); - e.printStackTrace(); - } finally { - Binder.restoreCallingIdentity(oldId); - } - } - if (false) { - if (app.thread != null) { - try { - app.thread.setSchedulingGroup(app.curSchedGroup); - } catch (RemoteException e) { - } + app.thread.setSchedulingGroup(app.curSchedGroup); + } catch (RemoteException e) { } } } } } - - return success; } private final ActivityRecord resumedAppLocked() { @@ -13215,30 +13145,26 @@ public final class ActivityManagerService extends ActivityManagerNative return resumedActivity; } - private final boolean updateOomAdjLocked(ProcessRecord app) { + private final void updateOomAdjLocked(ProcessRecord app) { final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; int curAdj = app.curAdj; - final boolean wasHidden = app.curAdj >= HIDDEN_APP_MIN_ADJ - && app.curAdj <= HIDDEN_APP_MAX_ADJ; + final boolean wasHidden = curAdj >= HIDDEN_APP_MIN_ADJ + && curAdj <= HIDDEN_APP_MAX_ADJ; mAdjSeq++; - final boolean res = updateOomAdjLocked(app, app.hiddenAdj, TOP_APP); - if (res) { - final boolean nowHidden = app.curAdj >= HIDDEN_APP_MIN_ADJ - && app.curAdj <= HIDDEN_APP_MAX_ADJ; - if (nowHidden != wasHidden) { - // Changed to/from hidden state, so apps after it in the LRU - // list may also be changed. - updateOomAdjLocked(); - } + updateOomAdjLocked(app, app.hiddenAdj, TOP_APP); + final boolean nowHidden = app.curAdj >= HIDDEN_APP_MIN_ADJ + && app.curAdj <= HIDDEN_APP_MAX_ADJ; + if (nowHidden != wasHidden) { + // Changed to/from hidden state, so apps after it in the LRU + // list may also be changed. + updateOomAdjLocked(); } - return res; } - final boolean updateOomAdjLocked() { - boolean didOomAdj = true; + final void updateOomAdjLocked() { final ActivityRecord TOP_ACT = resumedAppLocked(); final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null; @@ -13260,45 +13186,104 @@ public final class ActivityManagerService extends ActivityManagerNative int step = 0; int numHidden = 0; - // First try updating the OOM adjustment for each of the + // First update the OOM adjustment for each of the // application processes based on their current state. int i = mLruProcesses.size(); int curHiddenAdj = HIDDEN_APP_MIN_ADJ; + int numBg = 0; while (i > 0) { i--; ProcessRecord app = mLruProcesses.get(i); //Slog.i(TAG, "OOM " + app + ": cur hidden=" + curHiddenAdj); - if (updateOomAdjLocked(app, curHiddenAdj, TOP_APP)) { - if (curHiddenAdj < EMPTY_APP_ADJ - && app.curAdj == curHiddenAdj) { + updateOomAdjLocked(app, curHiddenAdj, TOP_APP); + if (curHiddenAdj < EMPTY_APP_ADJ + && app.curAdj == curHiddenAdj) { + step++; + if (step >= factor) { + step = 0; + curHiddenAdj++; + } + } + if (!app.killedBackground) { + if (app.curAdj >= HIDDEN_APP_MIN_ADJ) { + numHidden++; + if (numHidden > mProcessLimit) { + Slog.i(TAG, "No longer want " + app.processName + + " (pid " + app.pid + "): hidden #" + numHidden); + EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, + app.processName, app.setAdj, "too many background"); + app.killedBackground = true; + Process.killProcessQuiet(app.pid); + } else { + numBg++; + } + } else if (app.curAdj >= HOME_APP_ADJ) { + numBg++; + } + } + } + + // Now determine the memory trimming level of background processes. + // Unfortunately we need to start at the back of the list to do this + // properly. We only do this if the number of background apps we + // are managing to keep around is less than half the maximum we desire; + // if we are keeping a good number around, we'll let them use whatever + // memory they want. + if (numHidden <= (MAX_HIDDEN_APPS/2)) { + final int N = mLruProcesses.size(); + factor = numBg/3; + step = 0; + int curLevel = ComponentCallbacks.TRIM_MEMORY_COMPLETE; + for (i=0; i<N; i++) { + ProcessRecord app = mLruProcesses.get(i); + if (app.curAdj >= HIDDEN_APP_MIN_ADJ && !app.killedBackground) { + if (app.trimMemoryLevel < curLevel && app.thread != null) { + try { + app.thread.scheduleTrimMemory(curLevel); + } catch (RemoteException e) { + } + if (curLevel >= ComponentCallbacks.TRIM_MEMORY_COMPLETE) { + // For these apps we will also finish their activities + // to help them free memory. + mMainStack.destroyActivitiesLocked(app, false); + } + } + app.trimMemoryLevel = curLevel; step++; if (step >= factor) { - step = 0; - curHiddenAdj++; + switch (curLevel) { + case ComponentCallbacks.TRIM_MEMORY_COMPLETE: + curLevel = ComponentCallbacks.TRIM_MEMORY_MODERATE; + break; + case ComponentCallbacks.TRIM_MEMORY_MODERATE: + curLevel = ComponentCallbacks.TRIM_MEMORY_BACKGROUND; + break; + } } - } - if (app.curAdj >= HIDDEN_APP_MIN_ADJ) { - if (!app.killedBackground) { - numHidden++; - if (numHidden > MAX_HIDDEN_APPS) { - Slog.i(TAG, "No longer want " + app.processName - + " (pid " + app.pid + "): hidden #" + numHidden); - EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, - app.processName, app.setAdj, "too many background"); - app.killedBackground = true; - Process.killProcessQuiet(app.pid); + } else if (app.curAdj >= PERCEPTIBLE_APP_ADJ) { + if (app.trimMemoryLevel < ComponentCallbacks.TRIM_MEMORY_INVISIBLE + && app.thread != null) { + try { + app.thread.scheduleTrimMemory(ComponentCallbacks.TRIM_MEMORY_INVISIBLE); + } catch (RemoteException e) { } } + app.trimMemoryLevel = ComponentCallbacks.TRIM_MEMORY_INVISIBLE; + } else { + app.trimMemoryLevel = 0; } - } else { - didOomAdj = false; + } + } else { + final int N = mLruProcesses.size(); + for (i=0; i<N; i++) { + ProcessRecord app = mLruProcesses.get(i); + app.trimMemoryLevel = 0; } } - // If we return false, we will fall back on killing processes to - // have a fixed limit. Do this if a limit has been requested; else - // only return false if one of the adjustments failed. - return ENFORCE_PROCESS_LIMIT || mProcessLimit > 0 ? false : didOomAdj; + if (mAlwaysFinishActivities) { + mMainStack.destroyActivitiesLocked(null, false); + } } final void trimApplications() { @@ -13338,165 +13323,8 @@ public final class ActivityManagerService extends ActivityManagerNative } } - // Now try updating the OOM adjustment for each of the - // application processes based on their current state. - // If the setOomAdj() API is not supported, then go with our - // back-up plan... - if (!updateOomAdjLocked()) { - - // Count how many processes are running services. - int numServiceProcs = 0; - for (i=mLruProcesses.size()-1; i>=0; i--) { - final ProcessRecord app = mLruProcesses.get(i); - - if (app.persistent || app.services.size() != 0 - || app.curReceiver != null) { - // Don't count processes holding services against our - // maximum process count. - if (localLOGV) Slog.v( - TAG, "Not trimming app " + app + " with services: " - + app.services); - numServiceProcs++; - } - } - - int curMaxProcs = mProcessLimit; - if (curMaxProcs <= 0) curMaxProcs = MAX_PROCESSES; - if (mAlwaysFinishActivities) { - curMaxProcs = 1; - } - curMaxProcs += numServiceProcs; - - // Quit as many processes as we can to get down to the desired - // process count. First remove any processes that no longer - // have activites running in them. - for ( i=0; - i<mLruProcesses.size() - && mLruProcesses.size() > curMaxProcs; - i++) { - final ProcessRecord app = mLruProcesses.get(i); - // Quit an application only if it is not currently - // running any activities. - if (!app.persistent && app.activities.size() == 0 - && app.curReceiver == null && app.services.size() == 0) { - Slog.i( - TAG, "Exiting empty application process " - + app.processName + " (" - + (app.thread != null ? app.thread.asBinder() : null) - + ")\n"); - if (app.pid > 0 && app.pid != MY_PID) { - EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, - app.processName, app.setAdj, "empty"); - Process.killProcessQuiet(app.pid); - } else { - try { - app.thread.scheduleExit(); - } catch (Exception e) { - // Ignore exceptions. - } - } - // todo: For now we assume the application is not buggy - // or evil, and will quit as a result of our request. - // Eventually we need to drive this off of the death - // notification, and kill the process if it takes too long. - cleanUpApplicationRecordLocked(app, false, i); - i--; - } - } - - // If we still have too many processes, now from the least - // recently used process we start finishing activities. - if (false) Slog.v( - TAG, "*** NOW HAVE " + mLruProcesses.size() + - " of " + curMaxProcs + " processes"); - for ( i=0; - i<mLruProcesses.size() - && mLruProcesses.size() > curMaxProcs; - i++) { - final ProcessRecord app = mLruProcesses.get(i); - // Quit the application only if we have a state saved for - // all of its activities. - boolean canQuit = !app.persistent && app.curReceiver == null - && app.services.size() == 0; - int NUMA = app.activities.size(); - int j; - if (false) Slog.v( - TAG, "Looking to quit " + app.processName); - for (j=0; j<NUMA && canQuit; j++) { - ActivityRecord r = app.activities.get(j); - if (false) Slog.v( - TAG, " " + r.intent.getComponent().flattenToShortString() - + ": frozen=" + r.haveState + ", visible=" + r.visible); - canQuit = (r.haveState || !r.stateNotNeeded) - && !r.visible && r.stopped; - } - if (canQuit) { - // Finish all of the activities, and then the app itself. - for (j=0; j<NUMA; j++) { - ActivityRecord r = app.activities.get(j); - if (!r.finishing) { - r.stack.destroyActivityLocked(r, false); - } - r.resultTo = null; - } - Slog.i(TAG, "Exiting application process " - + app.processName + " (" - + (app.thread != null ? app.thread.asBinder() : null) - + ")\n"); - if (app.pid > 0 && app.pid != MY_PID) { - EventLog.writeEvent(EventLogTags.AM_KILL, app.pid, - app.processName, app.setAdj, "old background"); - Process.killProcessQuiet(app.pid); - } else { - try { - app.thread.scheduleExit(); - } catch (Exception e) { - // Ignore exceptions. - } - } - // todo: For now we assume the application is not buggy - // or evil, and will quit as a result of our request. - // Eventually we need to drive this off of the death - // notification, and kill the process if it takes too long. - cleanUpApplicationRecordLocked(app, false, i); - i--; - //dump(); - } - } - - } - - int curMaxActivities = MAX_ACTIVITIES; - if (mAlwaysFinishActivities) { - curMaxActivities = 1; - } - - // Finally, if there are too many activities now running, try to - // finish as many as we can to get back down to the limit. - for ( i=0; - i<mMainStack.mLRUActivities.size() - && mMainStack.mLRUActivities.size() > curMaxActivities; - i++) { - final ActivityRecord r - = (ActivityRecord)mMainStack.mLRUActivities.get(i); - - // We can finish this one if we have its icicle saved and - // it is not persistent. - if ((r.haveState || !r.stateNotNeeded) && !r.visible - && r.stopped && !r.finishing) { - final int origSize = mMainStack.mLRUActivities.size(); - r.stack.destroyActivityLocked(r, true); - - // This will remove it from the LRU list, so keep - // our index at the same value. Note that this check to - // see if the size changes is just paranoia -- if - // something unexpected happens, we don't want to end up - // in an infinite loop. - if (origSize > mMainStack.mLRUActivities.size()) { - i--; - } - } - } + // Now update the oom adj for all processes. + updateOomAdjLocked(); } } diff --git a/services/java/com/android/server/am/ActivityRecord.java b/services/java/com/android/server/am/ActivityRecord.java index 090e26b..73ffafb 100644 --- a/services/java/com/android/server/am/ActivityRecord.java +++ b/services/java/com/android/server/am/ActivityRecord.java @@ -658,12 +658,12 @@ final class ActivityRecord extends IApplicationToken.Stub { public long getKeyDispatchingTimeout() { synchronized(service) { ActivityRecord r = getWaitingHistoryRecordLocked(); - if (r == null || r.app == null - || r.app.instrumentationClass == null) { - return ActivityManagerService.KEY_DISPATCHING_TIMEOUT; + if (r != null && r.app != null + && (r.app.instrumentationClass != null || r.app.usingWrapper)) { + return ActivityManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT; } - - return ActivityManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT; + + return ActivityManagerService.KEY_DISPATCHING_TIMEOUT; } } diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java index b1da69f..93d8164 100644 --- a/services/java/com/android/server/am/ActivityStack.java +++ b/services/java/com/android/server/am/ActivityStack.java @@ -52,6 +52,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.net.Uri; import android.os.Binder; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -83,6 +84,8 @@ final class ActivityStack { static final boolean DEBUG_CONFIGURATION = ActivityManagerService.DEBUG_CONFIGURATION; static final boolean DEBUG_TASKS = ActivityManagerService.DEBUG_TASKS; + static final boolean DEBUG_STATES = false; + static final boolean VALIDATE_TOKENS = ActivityManagerService.VALIDATE_TOKENS; // How long we wait until giving up on the last activity telling us it @@ -392,19 +395,25 @@ final class ActivityStack { } final int indexOfTokenLocked(IBinder token) { - int count = mHistory.size(); - - // convert the token to an entry in the history. - int index = -1; - for (int i=count-1; i>=0; i--) { - Object o = mHistory.get(i); - if (o == token) { - index = i; - break; - } + try { + ActivityRecord r = (ActivityRecord)token; + return mHistory.indexOf(r); + } catch (ClassCastException e) { + Slog.w(TAG, "Bad activity token: " + token, e); + return -1; } + } - return index; + final ActivityRecord isInStackLocked(IBinder token) { + try { + ActivityRecord r = (ActivityRecord)token; + if (mHistory.contains(r)) { + return r; + } + } catch (ClassCastException e) { + Slog.w(TAG, "Bad activity token: " + token, e); + } + return null; } private final boolean updateLRUListLocked(ActivityRecord r) { @@ -604,6 +613,8 @@ final class ActivityStack { // As part of the process of launching, ActivityThread also performs // a resume. r.state = ActivityState.RESUMED; + if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + r + + " (starting new instance)"); r.stopped = false; mResumedActivity = r; r.task.touchActiveTime(); @@ -617,6 +628,8 @@ final class ActivityStack { // should look like we asked it to pause+stop (but remain visible), // and it has done so and reported back the current icicle and // other state. + if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + + " (starting in stopped state)"); r.state = ActivityState.STOPPED; r.stopped = true; } @@ -797,7 +810,8 @@ final class ActivityStack { resumeTopActivityLocked(null); return; } - if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev); + if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSING: " + prev); + else if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev); mResumedActivity = null; mPausingActivity = prev; mLastPausedActivity = prev; @@ -879,6 +893,8 @@ final class ActivityStack { r = mHistory.get(index); mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); if (mPausingActivity == r) { + if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSED: " + r + + (timeout ? " (due to timeout)" : " (pause complete)")); r.state = ActivityState.PAUSED; completePauseLocked(); } else { @@ -891,6 +907,22 @@ final class ActivityStack { } } + final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail, + CharSequence description) { + r.icicle = icicle; + r.haveState = true; + r.updateThumbnail(thumbnail, description); + r.stopped = true; + if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + " (stop complete)"); + r.state = ActivityState.STOPPED; + if (!r.finishing) { + if (r.configDestroy) { + destroyActivityLocked(r, true, false); + resumeTopActivityLocked(null); + } + } + } + private final void completePauseLocked() { ActivityRecord prev = mPausingActivity; if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev); @@ -914,7 +946,7 @@ final class ActivityStack { // instance right now, we need to first completely stop // the current instance before starting the new one. if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev); - destroyActivityLocked(prev, true); + destroyActivityLocked(prev, true, false); } else { mStoppingActivities.add(prev); if (mStoppingActivities.size() > 3) { @@ -1371,6 +1403,7 @@ final class ActivityStack { mService.updateCpuStats(); + if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + next + " (in existing)"); next.state = ActivityState.RESUMED; mResumedActivity = next; next.task.touchActiveTime(); @@ -1447,6 +1480,8 @@ final class ActivityStack { } catch (Exception e) { // Whoops, need to restart this activity! + if (DEBUG_STATES) Slog.v(TAG, "Resume failed; resetting state to " + + lastState + ": " + next); next.state = lastState; mResumedActivity = lastResumedActivity; Slog.i(TAG, "Restarting because process died: " + next); @@ -2960,6 +2995,8 @@ final class ActivityStack { r.resumeKeyDispatchingLocked(); try { r.stopped = false; + if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r + + " (stop requested)"); r.state = ActivityState.STOPPING; if (DEBUG_VISBILITY) Slog.v( TAG, "Stopping visible=" + r.visible + " for " + r); @@ -2977,9 +3014,10 @@ final class ActivityStack { Slog.w(TAG, "Exception thrown during pause", e); // Just in case, assume it to be stopped. r.stopped = true; + if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r); r.state = ActivityState.STOPPED; if (r.configDestroy) { - destroyActivityLocked(r, true); + destroyActivityLocked(r, true, false); } } } @@ -3145,7 +3183,7 @@ final class ActivityStack { for (i=0; i<NF; i++) { ActivityRecord r = (ActivityRecord)finishes.get(i); synchronized (mService) { - destroyActivityLocked(r, true); + destroyActivityLocked(r, true, false); } } @@ -3340,6 +3378,8 @@ final class ActivityStack { checkReadyForSleepLocked(); } } + if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r + + " (finish requested)"); r.state = ActivityState.STOPPING; mService.updateOomAdjLocked(); return r; @@ -3353,6 +3393,7 @@ final class ActivityStack { mResumedActivity = null; } final ActivityState prevState = r.state; + if (DEBUG_STATES) Slog.v(TAG, "Moving to FINISHING: " + r); r.state = ActivityState.FINISHING; if (mode == FINISH_IMMEDIATELY @@ -3360,7 +3401,7 @@ final class ActivityStack { || prevState == ActivityState.INITIALIZING) { // If this activity is already stopped, we can just finish // it right now. - return destroyActivityLocked(r, true) ? null : r; + return destroyActivityLocked(r, true, true) ? null : r; } else { // Need to go through the full pause cycle to get this // activity into the stopped state and then finish it. @@ -3378,7 +3419,8 @@ final class ActivityStack { * processing going away, in which case there is no remaining client-side * state to destroy so only the cleanup here is needed. */ - final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices) { + final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, + boolean setState) { if (mResumedActivity == r) { mResumedActivity = null; } @@ -3389,6 +3431,11 @@ final class ActivityStack { r.configDestroy = false; r.frozenBeforeDestroy = false; + if (setState) { + if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (cleaning up)"); + r.state = ActivityState.DESTROYED; + } + // Make sure this record is no longer in the pending finishes list. // This could happen, for example, if we are trimming activities // down to the max limit while they are still waiting to finish. @@ -3428,6 +3475,8 @@ final class ActivityStack { r.makeFinishing(); mHistory.remove(r); r.takeFromHistory(); + if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + + " (removed from history)"); r.state = ActivityState.DESTROYED; mService.mWindowManager.removeAppToken(r); if (VALIDATE_TOKENS) { @@ -3453,6 +3502,22 @@ final class ActivityStack { } } + final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj) { + for (int i=mHistory.size()-1; i>=0; i--) { + ActivityRecord r = mHistory.get(i); + if (owner != null && r.app != owner) { + continue; + } + // We can destroy this one if we have its icicle saved and + // it is not in the process of pausing/stopping/finishing. + if (r.app != null && r.haveState && !r.visible && r.stopped && !r.finishing + && r.state != ActivityState.DESTROYING + && r.state != ActivityState.DESTROYED) { + destroyActivityLocked(r, true, oomAdj); + } + } + } + /** * Destroy the current CLIENT SIDE instance of an activity. This may be * called both when actually finishing an activity, or when performing @@ -3460,7 +3525,7 @@ final class ActivityStack { * but then create a new client-side object for this same HistoryRecord. */ final boolean destroyActivityLocked(ActivityRecord r, - boolean removeFromApp) { + boolean removeFromApp, boolean oomAdj) { if (DEBUG_SWITCH) Slog.v( TAG, "Removing activity: token=" + r + ", app=" + (r.app != null ? r.app.processName : "(null)")); @@ -3470,7 +3535,7 @@ final class ActivityStack { boolean removedFromHistory = false; - cleanUpActivityLocked(r, false); + cleanUpActivityLocked(r, false, false); final boolean hadApp = r.app != null; @@ -3488,7 +3553,7 @@ final class ActivityStack { if (r.app.activities.size() == 0) { // No longer have activities, so update location in // LRU list. - mService.updateLruProcessLocked(r.app, true, false); + mService.updateLruProcessLocked(r.app, oomAdj, false); } } @@ -3513,12 +3578,23 @@ final class ActivityStack { r.app = null; r.nowVisible = false; + // If the activity is finishing, we need to wait on removing it + // from the list to give it a chance to do its cleanup. During + // that time it may make calls back with its token so we need to + // be able to find it on the list and so we don't want to remove + // it from the list yet. Otherwise, we can just immediately put + // it in the destroyed state since we are not removing it from the + // list. if (r.finishing && !skipDestroy) { + if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYING: " + r + + " (destroy requested)"); r.state = ActivityState.DESTROYING; Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG); msg.obj = r; mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); } else { + if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + + " (destroy skipped)"); r.state = ActivityState.DESTROYED; } } else { @@ -3527,6 +3603,8 @@ final class ActivityStack { removeActivityFromHistoryLocked(r); removedFromHistory = true; } else { + if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + + " (no app)"); r.state = ActivityState.DESTROYED; } } @@ -3919,7 +3997,7 @@ final class ActivityStack { if (r.app == null || r.app.thread == null) { if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, "Switch is destroying non-running " + r); - destroyActivityLocked(r, true); + destroyActivityLocked(r, true, false); } else if (r.state == ActivityState.PAUSING) { // A little annoying: we are waiting for this activity to // finish pausing. Let's not do anything now, but just diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java index 3968f66..99830f9 100644 --- a/services/java/com/android/server/am/ProcessRecord.java +++ b/services/java/com/android/server/am/ProcessRecord.java @@ -61,6 +61,7 @@ class ProcessRecord { int setAdj; // Last set OOM adjustment for this process int curSchedGroup; // Currently desired scheduling class int setSchedGroup; // Last set to background scheduling class + int trimMemoryLevel; // Last selected memory trimming level boolean keeping; // Actively running code so don't kill due to that? boolean setIsForeground; // Running foreground UI when last set? boolean foregroundServices; // Running any services that are foreground? @@ -78,6 +79,7 @@ class ProcessRecord { IInstrumentationWatcher instrumentationWatcher; // who is waiting Bundle instrumentationArguments;// as given to us ComponentName instrumentationResultClass;// copy of instrumentationClass + boolean usingWrapper; // Set to true when process was launched with a wrapper attached BroadcastRecord curReceiver;// receiver currently running in the app long lastWakeTime; // How long proc held wake lock at last check long lastCpuTime; // How long proc has run CPU at last check @@ -180,7 +182,8 @@ class ProcessRecord { pw.print(" cur="); pw.print(curAdj); pw.print(" set="); pw.println(setAdj); pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup); - pw.print(" setSchedGroup="); pw.println(setSchedGroup); + pw.print(" setSchedGroup="); pw.print(setSchedGroup); + pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel); pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground); pw.print(" foregroundServices="); pw.print(foregroundServices); pw.print(" forcingToForeground="); pw.println(forcingToForeground); @@ -304,8 +307,6 @@ class ProcessRecord { } void toShortString(StringBuilder sb) { - sb.append(Integer.toHexString(System.identityHashCode(this))); - sb.append(' '); sb.append(pid); sb.append(':'); sb.append(processName); @@ -319,6 +320,8 @@ class ProcessRecord { } StringBuilder sb = new StringBuilder(128); sb.append("ProcessRecord{"); + sb.append(Integer.toHexString(System.identityHashCode(this))); + sb.append(' '); toShortString(sb); sb.append('}'); return stringName = sb.toString(); diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java index 6e8f248..12c8ccf 100644 --- a/services/java/com/android/server/am/UsageStatsService.java +++ b/services/java/com/android/server/am/UsageStatsService.java @@ -63,7 +63,7 @@ public final class UsageStatsService extends IUsageStats.Stub { private static final String TAG = "UsageStats"; // Current on-disk Parcel version - private static final int VERSION = 1005; + private static final int VERSION = 1006; private static final int CHECKIN_VERSION = 4; @@ -145,6 +145,8 @@ public final class UsageStatsService extends IUsageStats.Stub { final HashMap<String, TimeStats> mLaunchTimes = new HashMap<String, TimeStats>(); int mLaunchCount; + final HashMap<String, Long> mLastResumeTimes + = new HashMap<String, Long>(); long mUsageTime; long mPausedTime; long mResumedTime; @@ -160,20 +162,28 @@ public final class UsageStatsService extends IUsageStats.Stub { if (localLOGV) Slog.v(TAG, "Launch count: " + mLaunchCount + ", Usage time:" + mUsageTime); - final int N = in.readInt(); - if (localLOGV) Slog.v(TAG, "Reading comps: " + N); - for (int i=0; i<N; i++) { + final int numTimeStats = in.readInt(); + if (localLOGV) Slog.v(TAG, "Reading comps: " + numTimeStats); + for (int i=0; i<numTimeStats; i++) { String comp = in.readString(); if (localLOGV) Slog.v(TAG, "Component: " + comp); TimeStats times = new TimeStats(in); mLaunchTimes.put(comp, times); } + final int numResumeTimes = in.readInt(); + if (localLOGV) Slog.v(TAG, "Reading last resume times: " + numResumeTimes); + for (int i=0; i<numResumeTimes; i++) { + String comp = in.readString(); + if (localLOGV) Slog.v(TAG, "Component: " + comp); + mLastResumeTimes.put(comp, in.readLong()); + } } - - void updateResume(boolean launched) { + + void updateResume(String comp, boolean launched) { if (launched) { mLaunchCount ++; } + mLastResumeTimes.put(comp, System.currentTimeMillis()); mResumedTime = SystemClock.elapsedRealtime(); } @@ -203,20 +213,29 @@ public final class UsageStatsService extends IUsageStats.Stub { void writeToParcel(Parcel out) { out.writeInt(mLaunchCount); out.writeLong(mUsageTime); - final int N = mLaunchTimes.size(); - out.writeInt(N); - if (N > 0) { + final int numTimeStats = mLaunchTimes.size(); + out.writeInt(numTimeStats); + if (numTimeStats > 0) { for (Map.Entry<String, TimeStats> ent : mLaunchTimes.entrySet()) { out.writeString(ent.getKey()); TimeStats times = ent.getValue(); times.writeToParcel(out); } } + final int numResumeTimes = mLastResumeTimes.size(); + out.writeInt(numResumeTimes); + if (numResumeTimes > 0) { + for (Map.Entry<String, Long> ent : mLastResumeTimes.entrySet()) { + out.writeString(ent.getKey()); + out.writeLong(ent.getValue()); + } + } } void clear() { mLaunchTimes.clear(); mLaunchCount = 0; + mLastResumeTimes.clear(); mUsageTime = 0; } } @@ -546,7 +565,7 @@ public final class UsageStatsService extends IUsageStats.Stub { pus = new PkgUsageStatsExtended(); mStats.put(pkgName, pus); } - pus.updateResume(!samePackage); + pus.updateResume(mLastResumedComp, !samePackage); if (!sameComp) { pus.addLaunchCount(mLastResumedComp); } @@ -624,7 +643,8 @@ public final class UsageStatsService extends IUsageStats.Stub { if (pus == null) { return null; } - return new PkgUsageStats(pkgName, pus.mLaunchCount, pus.mUsageTime); + return new PkgUsageStats(pkgName, pus.mLaunchCount, pus.mUsageTime, + pus.mLastResumeTimes); } } @@ -641,7 +661,8 @@ public final class UsageStatsService extends IUsageStats.Stub { int i = 0; for (String key: keys) { PkgUsageStatsExtended pus = mStats.get(key); - retArr[i] = new PkgUsageStats(key, pus.mLaunchCount, pus.mUsageTime); + retArr[i] = new PkgUsageStats(key, pus.mLaunchCount, pus.mUsageTime, + pus.mLastResumeTimes); i++; } return retArr; diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index 6bb7949..d7d4b03 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -221,8 +221,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub { } public void interfaceLinkStateChanged(String iface, boolean up) { - if (DEBUG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up); - interfaceStatusChanged(iface, up); } private boolean isUsb(String iface) { diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java index 4fa3bda..c813d37 100755 --- a/services/java/com/android/server/location/GpsLocationProvider.java +++ b/services/java/com/android/server/location/GpsLocationProvider.java @@ -32,7 +32,6 @@ import android.location.LocationManager; import android.location.LocationProvider; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.net.SntpClient; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -51,6 +50,7 @@ import android.telephony.SmsMessage; import android.telephony.TelephonyManager; import android.telephony.gsm.GsmCellLocation; import android.util.Log; +import android.util.NtpTrustedTime; import android.util.SparseIntArray; import com.android.internal.app.IBatteryStats; @@ -61,7 +61,7 @@ import com.android.internal.telephony.Phone; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.StringBufferInputStream; +import java.io.StringReader; import java.util.ArrayList; import java.util.Date; import java.util.Map.Entry; @@ -235,13 +235,13 @@ public class GpsLocationProvider implements LocationProviderInterface { // properties loaded from PROPERTIES_FILE private Properties mProperties; - private String mNtpServer; private String mSuplServerHost; private int mSuplServerPort; private String mC2KServerHost; private int mC2KServerPort; private final Context mContext; + private final NtpTrustedTime mNtpTime; private final ILocationManager mLocationManager; private Location mLocation = new Location(LocationManager.GPS_PROVIDER); private Bundle mLocationExtras = new Bundle(); @@ -286,10 +286,6 @@ public class GpsLocationProvider implements LocationProviderInterface { // current setting - 5 minutes private static final long RETRY_INTERVAL = 5*60*1000; - // to avoid injecting bad NTP time, we reject any time fixes that differ from system time - // by more than 5 minutes. - private static final long MAX_NTP_SYSTEM_TIME_OFFSET = 5*60*1000; - private final IGpsStatusProvider mGpsStatusProvider = new IGpsStatusProvider.Stub() { public void addGpsStatusListener(IGpsStatusListener listener) throws RemoteException { if (listener == null) { @@ -378,6 +374,7 @@ public class GpsLocationProvider implements LocationProviderInterface { public GpsLocationProvider(Context context, ILocationManager locationManager) { mContext = context; + mNtpTime = NtpTrustedTime.getInstance(context); mLocationManager = locationManager; mNIHandler = new GpsNetInitiatedHandler(context); @@ -418,7 +415,6 @@ public class GpsLocationProvider implements LocationProviderInterface { FileInputStream stream = new FileInputStream(file); mProperties.load(stream); stream.close(); - mNtpServer = mProperties.getProperty("NTP_SERVER", null); mSuplServerHost = mProperties.getProperty("SUPL_HOST"); String portString = mProperties.getProperty("SUPL_PORT"); @@ -530,13 +526,18 @@ public class GpsLocationProvider implements LocationProviderInterface { } mInjectNtpTimePending = false; - SntpClient client = new SntpClient(); long delay; - if (client.requestTime(mNtpServer, 10000)) { - long time = client.getNtpTime(); - long timeReference = client.getNtpTimeReference(); - int certainty = (int)(client.getRoundTripTime()/2); + // force refresh NTP cache when outdated + if (mNtpTime.getCacheAge() >= NTP_INTERVAL) { + mNtpTime.forceRefresh(); + } + + // only update when NTP time is fresh + if (mNtpTime.getCacheAge() < NTP_INTERVAL) { + long time = mNtpTime.getCachedNtpTime(); + long timeReference = mNtpTime.getCachedNtpTimeReference(); + long certainty = mNtpTime.getCacheCertainty(); long now = System.currentTimeMillis(); Log.d(TAG, "NTP server returned: " @@ -545,7 +546,7 @@ public class GpsLocationProvider implements LocationProviderInterface { + " certainty: " + certainty + " system time offset: " + (time - now)); - native_inject_time(time, timeReference, certainty); + native_inject_time(time, timeReference, (int) certainty); delay = NTP_INTERVAL; } else { if (DEBUG) Log.d(TAG, "requestTime failed"); @@ -1395,7 +1396,7 @@ public class GpsLocationProvider implements LocationProviderInterface { Properties extraProp = new Properties(); try { - extraProp.load(new StringBufferInputStream(extras)); + extraProp.load(new StringReader(extras)); } catch (IOException e) { diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java index 2a17cbe..d30b66b 100644 --- a/services/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java @@ -204,9 +204,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { public NetworkPolicyManagerService(Context context, IActivityManager activityManager, IPowerManager powerManager, INetworkStatsService networkStats, INetworkManagementService networkManagement) { - // TODO: move to using cached NtpTrustedTime this(context, activityManager, powerManager, networkStats, networkManagement, - new NtpTrustedTime(), getSystemDir()); + NtpTrustedTime.getInstance(context), getSystemDir()); } private static File getSystemDir() { @@ -406,7 +405,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { try { final NetworkStats stats = mNetworkStats.getSummaryForNetwork( policy.template, start, end); - total = stats.rx[0] + stats.tx[0]; + final NetworkStats.Entry entry = stats.getValues(0, null); + total = entry.rxBytes + entry.txBytes; } catch (RemoteException e) { Slog.w(TAG, "problem reading summary for template " + policy.template); continue; @@ -606,7 +606,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { final long total; try { stats = mNetworkStats.getSummaryForNetwork(policy.template, start, end); - total = stats.rx[0] + stats.tx[0]; + final NetworkStats.Entry entry = stats.getValues(0, null); + total = entry.rxBytes + entry.txBytes; } catch (RemoteException e) { Slog.w(TAG, "problem reading summary for template " + policy.template); continue; diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index b4bd176..54e94db 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -27,7 +27,6 @@ import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_REMOVED; -import static android.provider.Settings.Secure.NETSTATS_ENABLED; import static android.provider.Settings.Secure.NETSTATS_NETWORK_BUCKET_DURATION; import static android.provider.Settings.Secure.NETSTATS_NETWORK_MAX_HISTORY; import static android.provider.Settings.Secure.NETSTATS_PERSIST_THRESHOLD; @@ -71,7 +70,6 @@ import android.util.Slog; import android.util.TrustedTime; import com.android.internal.os.AtomicFile; -import com.android.server.NativeDaemonConnectorException; import com.google.android.collect.Maps; import com.google.android.collect.Sets; @@ -175,9 +173,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { public NetworkStatsService( Context context, INetworkManagementService networkManager, IAlarmManager alarmManager) { - // TODO: move to using cached NtpTrustedTime - this(context, networkManager, alarmManager, new NtpTrustedTime(), getSystemDir(), - new DefaultNetworkStatsSettings(context)); + this(context, networkManager, alarmManager, NtpTrustedTime.getInstance(context), + getSystemDir(), new DefaultNetworkStatsSettings(context)); } private static File getSystemDir() { @@ -316,22 +313,29 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG); synchronized (mStatsLock) { - long rx = 0; - long tx = 0; - long[] networkTotal = new long[2]; + // use system clock to be externally consistent + final long now = System.currentTimeMillis(); + + final NetworkStats stats = new NetworkStats(end - start, 1); + final NetworkStats.Entry entry = new NetworkStats.Entry(); + NetworkStatsHistory.Entry historyEntry = null; // combine total from all interfaces that match template for (NetworkIdentitySet ident : mNetworkStats.keySet()) { if (templateMatches(template, ident)) { final NetworkStatsHistory history = mNetworkStats.get(ident); - networkTotal = history.getTotalData(start, end, networkTotal); - rx += networkTotal[0]; - tx += networkTotal[1]; + historyEntry = history.getValues(start, end, now, historyEntry); + + entry.iface = IFACE_ALL; + entry.uid = UID_ALL; + entry.tag = TAG_NONE; + entry.rxBytes = historyEntry.rxBytes; + entry.txBytes = historyEntry.txBytes; + + stats.combineValues(entry); } } - final NetworkStats stats = new NetworkStats(end - start, 1); - stats.addEntry(IFACE_ALL, UID_ALL, TAG_NONE, rx, tx); return stats; } } @@ -344,8 +348,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub { synchronized (mStatsLock) { ensureUidStatsLoadedLocked(); + // use system clock to be externally consistent + final long now = System.currentTimeMillis(); + final NetworkStats stats = new NetworkStats(end - start, 24); - long[] total = new long[2]; + final NetworkStats.Entry entry = new NetworkStats.Entry(); + NetworkStatsHistory.Entry historyEntry = null; for (NetworkIdentitySet ident : mUidStats.keySet()) { if (templateMatches(template, ident)) { @@ -359,11 +367,16 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // other tags when requested. if (tag == TAG_NONE || includeTags) { final NetworkStatsHistory history = uidStats.valueAt(i); - total = history.getTotalData(start, end, total); - final long rx = total[0]; - final long tx = total[1]; - if (rx > 0 || tx > 0) { - stats.combineEntry(IFACE_ALL, uid, tag, rx, tx); + historyEntry = history.getValues(start, end, now, historyEntry); + + entry.iface = IFACE_ALL; + entry.uid = uid; + entry.tag = tag; + entry.rxBytes = historyEntry.rxBytes; + entry.txBytes = historyEntry.txBytes; + + if (entry.rxBytes > 0 || entry.txBytes > 0) { + stats.combineValues(entry); } } } @@ -418,6 +431,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // broadcast. final int uid = intent.getIntExtra(EXTRA_UID, 0); synchronized (mStatsLock) { + // TODO: perform one last stats poll for UID removeUidLocked(uid); } } @@ -515,10 +529,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub { final NetworkStats persistDelta = computeStatsDelta( mLastPersistNetworkSnapshot, networkSnapshot); final long persistThreshold = mSettings.getPersistThreshold(); + + NetworkStats.Entry entry = null; for (String iface : persistDelta.getUniqueIfaces()) { final int index = persistDelta.findIndex(iface, UID_ALL, TAG_NONE); - if (forcePersist || persistDelta.rx[index] > persistThreshold - || persistDelta.tx[index] > persistThreshold) { + entry = persistDelta.getValues(index, entry); + if (forcePersist || entry.rxBytes > persistThreshold + || entry.txBytes > persistThreshold) { writeNetworkStatsLocked(); if (mUidStatsLoaded) { writeUidStatsLocked(); @@ -541,20 +558,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub { final HashSet<String> unknownIface = Sets.newHashSet(); final NetworkStats delta = computeStatsDelta(mLastNetworkSnapshot, networkSnapshot); - final long timeStart = currentTime - delta.elapsedRealtime; - for (int i = 0; i < delta.size; i++) { - final String iface = delta.iface[i]; - final NetworkIdentitySet ident = mActiveIfaces.get(iface); + final long timeStart = currentTime - delta.getElapsedRealtime(); + + NetworkStats.Entry entry = null; + for (int i = 0; i < delta.size(); i++) { + entry = delta.getValues(i, entry); + final NetworkIdentitySet ident = mActiveIfaces.get(entry.iface); if (ident == null) { - unknownIface.add(iface); + unknownIface.add(entry.iface); continue; } - final long rx = delta.rx[i]; - final long tx = delta.tx[i]; - final NetworkStatsHistory history = findOrCreateNetworkStatsLocked(ident); - history.recordData(timeStart, currentTime, rx, tx); + history.recordData(timeStart, currentTime, entry.rxBytes, entry.txBytes); } // trim any history beyond max @@ -577,22 +593,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub { ensureUidStatsLoadedLocked(); final NetworkStats delta = computeStatsDelta(mLastUidSnapshot, uidSnapshot); - final long timeStart = currentTime - delta.elapsedRealtime; + final long timeStart = currentTime - delta.getElapsedRealtime(); - for (int i = 0; i < delta.size; i++) { - final String iface = delta.iface[i]; - final NetworkIdentitySet ident = mActiveIfaces.get(iface); + NetworkStats.Entry entry = null; + for (int i = 0; i < delta.size(); i++) { + entry = delta.getValues(i, entry); + final NetworkIdentitySet ident = mActiveIfaces.get(entry.iface); if (ident == null) { continue; } - final int uid = delta.uid[i]; - final int tag = delta.tag[i]; - final long rx = delta.rx[i]; - final long tx = delta.tx[i]; - - final NetworkStatsHistory history = findOrCreateUidStatsLocked(ident, uid, tag); - history.recordData(timeStart, currentTime, rx, tx); + final NetworkStatsHistory history = findOrCreateUidStatsLocked( + ident, entry.uid, entry.tag); + history.recordData(timeStart, currentTime, entry.rxBytes, entry.txBytes); } // trim any history beyond max @@ -654,7 +667,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { NetworkStatsHistory updated = null; if (existing == null) { updated = new NetworkStatsHistory(bucketDuration, 10); - } else if (existing.bucketDuration != bucketDuration) { + } else if (existing.getBucketDuration() != bucketDuration) { updated = new NetworkStatsHistory( bucketDuration, estimateResizeBuckets(existing, bucketDuration)); updated.recordEntireHistory(existing); @@ -686,7 +699,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { NetworkStatsHistory updated = null; if (existing == null) { updated = new NetworkStatsHistory(bucketDuration, 10); - } else if (existing.bucketDuration != bucketDuration) { + } else if (existing.getBucketDuration() != bucketDuration) { updated = new NetworkStatsHistory( bucketDuration, estimateResizeBuckets(existing, bucketDuration)); updated.recordEntireHistory(existing); @@ -1006,7 +1019,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } private static int estimateResizeBuckets(NetworkStatsHistory existing, long newBucketDuration) { - return (int) (existing.bucketCount * existing.bucketDuration / newBucketDuration); + return (int) (existing.size() * existing.getBucketDuration() / newBucketDuration); } // @VisibleForTesting diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index ea5d26b..d6a15e6 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -778,16 +778,7 @@ public class PackageManagerService extends IPackageManager.Stub { mSeparateProcesses = null; } - Installer installer = new Installer(); - // Little hacky thing to check if installd is here, to determine - // whether we are running on the simulator and thus need to take - // care of building the /data file structure ourself. - // (apparently the sim now has a working installer) - if (installer.ping() && Process.supportsProcesses()) { - mInstaller = installer; - } else { - mInstaller = null; - } + mInstaller = new Installer(); WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); Display d = wm.getDefaultDisplay(); @@ -806,17 +797,6 @@ public class PackageManagerService extends IPackageManager.Stub { mUserManager = new UserManager(mInstaller, mUserAppDataDir); - if (mInstaller == null) { - // Make sure these dirs exist, when we are running in - // the simulator. - // Make a wide-open directory for random misc stuff. - File miscDir = new File(dataDir, "misc"); - miscDir.mkdirs(); - mAppDataDir.mkdirs(); - mUserAppDataDir.mkdirs(); - mDrmAppPrivateInstallDir.mkdirs(); - } - readPermissions(); mRestoredSettings = mSettings.readLPw(); @@ -838,104 +818,102 @@ public class PackageManagerService extends IPackageManager.Stub { mFrameworkDir = new File(Environment.getRootDirectory(), "framework"); mDalvikCacheDir = new File(dataDir, "dalvik-cache"); - if (mInstaller != null) { - boolean didDexOpt = false; - - /** - * Out of paranoia, ensure that everything in the boot class - * path has been dexed. - */ - String bootClassPath = System.getProperty("java.boot.class.path"); - if (bootClassPath != null) { - String[] paths = splitString(bootClassPath, ':'); - for (int i=0; i<paths.length; i++) { - try { - if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { - libFiles.add(paths[i]); - mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); - didDexOpt = true; - } - } catch (FileNotFoundException e) { - Slog.w(TAG, "Boot class path not found: " + paths[i]); - } catch (IOException e) { - Slog.w(TAG, "Exception reading boot class path: " + paths[i], e); + boolean didDexOpt = false; + + /** + * Out of paranoia, ensure that everything in the boot class + * path has been dexed. + */ + String bootClassPath = System.getProperty("java.boot.class.path"); + if (bootClassPath != null) { + String[] paths = splitString(bootClassPath, ':'); + for (int i=0; i<paths.length; i++) { + try { + if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { + libFiles.add(paths[i]); + mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); + didDexOpt = true; } + } catch (FileNotFoundException e) { + Slog.w(TAG, "Boot class path not found: " + paths[i]); + } catch (IOException e) { + Slog.w(TAG, "Exception reading boot class path: " + paths[i], e); } - } else { - Slog.w(TAG, "No BOOTCLASSPATH found!"); } + } else { + Slog.w(TAG, "No BOOTCLASSPATH found!"); + } - /** - * Also ensure all external libraries have had dexopt run on them. - */ - if (mSharedLibraries.size() > 0) { - Iterator<String> libs = mSharedLibraries.values().iterator(); - while (libs.hasNext()) { - String lib = libs.next(); - try { - if (dalvik.system.DexFile.isDexOptNeeded(lib)) { - libFiles.add(lib); - mInstaller.dexopt(lib, Process.SYSTEM_UID, true); - didDexOpt = true; - } - } catch (FileNotFoundException e) { - Slog.w(TAG, "Library not found: " + lib); - } catch (IOException e) { - Slog.w(TAG, "Exception reading library: " + lib, e); + /** + * Also ensure all external libraries have had dexopt run on them. + */ + if (mSharedLibraries.size() > 0) { + Iterator<String> libs = mSharedLibraries.values().iterator(); + while (libs.hasNext()) { + String lib = libs.next(); + try { + if (dalvik.system.DexFile.isDexOptNeeded(lib)) { + libFiles.add(lib); + mInstaller.dexopt(lib, Process.SYSTEM_UID, true); + didDexOpt = true; } + } catch (FileNotFoundException e) { + Slog.w(TAG, "Library not found: " + lib); + } catch (IOException e) { + Slog.w(TAG, "Exception reading library: " + lib, e); } } + } - // Gross hack for now: we know this file doesn't contain any - // code, so don't dexopt it to avoid the resulting log spew. - libFiles.add(mFrameworkDir.getPath() + "/framework-res.apk"); - - /** - * And there are a number of commands implemented in Java, which - * we currently need to do the dexopt on so that they can be - * run from a non-root shell. - */ - String[] frameworkFiles = mFrameworkDir.list(); - if (frameworkFiles != null) { - for (int i=0; i<frameworkFiles.length; i++) { - File libPath = new File(mFrameworkDir, frameworkFiles[i]); - String path = libPath.getPath(); - // Skip the file if we alrady did it. - if (libFiles.contains(path)) { - continue; - } - // Skip the file if it is not a type we want to dexopt. - if (!path.endsWith(".apk") && !path.endsWith(".jar")) { - continue; - } - try { - if (dalvik.system.DexFile.isDexOptNeeded(path)) { - mInstaller.dexopt(path, Process.SYSTEM_UID, true); - didDexOpt = true; - } - } catch (FileNotFoundException e) { - Slog.w(TAG, "Jar not found: " + path); - } catch (IOException e) { - Slog.w(TAG, "Exception reading jar: " + path, e); + // Gross hack for now: we know this file doesn't contain any + // code, so don't dexopt it to avoid the resulting log spew. + libFiles.add(mFrameworkDir.getPath() + "/framework-res.apk"); + + /** + * And there are a number of commands implemented in Java, which + * we currently need to do the dexopt on so that they can be + * run from a non-root shell. + */ + String[] frameworkFiles = mFrameworkDir.list(); + if (frameworkFiles != null) { + for (int i=0; i<frameworkFiles.length; i++) { + File libPath = new File(mFrameworkDir, frameworkFiles[i]); + String path = libPath.getPath(); + // Skip the file if we alrady did it. + if (libFiles.contains(path)) { + continue; + } + // Skip the file if it is not a type we want to dexopt. + if (!path.endsWith(".apk") && !path.endsWith(".jar")) { + continue; + } + try { + if (dalvik.system.DexFile.isDexOptNeeded(path)) { + mInstaller.dexopt(path, Process.SYSTEM_UID, true); + didDexOpt = true; } + } catch (FileNotFoundException e) { + Slog.w(TAG, "Jar not found: " + path); + } catch (IOException e) { + Slog.w(TAG, "Exception reading jar: " + path, e); } } + } - if (didDexOpt) { - // If we had to do a dexopt of one of the previous - // things, then something on the system has changed. - // Consider this significant, and wipe away all other - // existing dexopt files to ensure we don't leave any - // dangling around. - String[] files = mDalvikCacheDir.list(); - if (files != null) { - for (int i=0; i<files.length; i++) { - String fn = files[i]; - if (fn.startsWith("data@app@") - || fn.startsWith("data@app-private@")) { - Slog.i(TAG, "Pruning dalvik file: " + fn); - (new File(mDalvikCacheDir, fn)).delete(); - } + if (didDexOpt) { + // If we had to do a dexopt of one of the previous + // things, then something on the system has changed. + // Consider this significant, and wipe away all other + // existing dexopt files to ensure we don't leave any + // dangling around. + String[] files = mDalvikCacheDir.list(); + if (files != null) { + for (int i=0; i<files.length; i++) { + String fn = files[i]; + if (fn.startsWith("data@app@") + || fn.startsWith("data@app-private@")) { + Slog.i(TAG, "Pruning dalvik file: " + fn); + (new File(mDalvikCacheDir, fn)).delete(); } } } @@ -965,11 +943,9 @@ public class PackageManagerService extends IPackageManager.Stub { scanDirLI(mVendorAppDir, PackageParser.PARSE_IS_SYSTEM | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0); - if (mInstaller != null) { - if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands"); - mInstaller.moveFiles(); - } - + if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands"); + mInstaller.moveFiles(); + // Prune any system packages that no longer exist. Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator(); while (psit.hasNext()) { @@ -981,19 +957,12 @@ public class PackageManagerService extends IPackageManager.Stub { String msg = "System package " + ps.name + " no longer exists; wiping its data"; reportSettingsProblem(Log.WARN, msg); - if (mInstaller != null) { - mInstaller.remove(ps.name, 0); - mUserManager.removePackageForAllUsers(ps.name); - } + mInstaller.remove(ps.name, 0); + mUserManager.removePackageForAllUsers(ps.name); } } mAppInstallDir = new File(dataDir, "app"); - if (mInstaller == null) { - // Make sure these dirs exist, when we are running in - // the simulator. - mAppInstallDir.mkdirs(); // scanDirLI() assumes this dir exists - } //look for any incomplete package installations ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackagesLPr(); //clean up list @@ -1067,19 +1036,12 @@ public class PackageManagerService extends IPackageManager.Stub { void cleanupInstallFailedPackage(PackageSetting ps) { Slog.i(TAG, "Cleaning up incompletely installed app: " + ps.name); - if (mInstaller != null) { - int retCode = mInstaller.remove(ps.name, 0); - if (retCode < 0) { - Slog.w(TAG, "Couldn't remove app data directory for package: " - + ps.name + ", retcode=" + retCode); - } else { - mUserManager.removePackageForAllUsers(ps.name); - } + int retCode = mInstaller.remove(ps.name, 0); + if (retCode < 0) { + Slog.w(TAG, "Couldn't remove app data directory for package: " + + ps.name + ", retcode=" + retCode); } else { - //for emulator - PackageParser.Package pkg = mPackages.get(ps.name); - File dataDir = new File(pkg.applicationInfo.dataDir); - dataDir.delete(); + mUserManager.removePackageForAllUsers(ps.name); } if (ps.codePath != null) { if (!ps.codePath.delete()) { @@ -1562,12 +1524,10 @@ public class PackageManagerService extends IPackageManager.Stub { public void run() { mHandler.removeCallbacks(this); int retCode = -1; - if (mInstaller != null) { - retCode = mInstaller.freeCache(freeStorageSize); - if (retCode < 0) { - Slog.w(TAG, "Couldn't clear application caches"); - } - } //end if mInstaller + retCode = mInstaller.freeCache(freeStorageSize); + if (retCode < 0) { + Slog.w(TAG, "Couldn't clear application caches"); + } if (observer != null) { try { observer.onRemoveCompleted(null, (retCode >= 0)); @@ -1587,11 +1547,9 @@ public class PackageManagerService extends IPackageManager.Stub { public void run() { mHandler.removeCallbacks(this); int retCode = -1; - if (mInstaller != null) { - retCode = mInstaller.freeCache(freeStorageSize); - if (retCode < 0) { - Slog.w(TAG, "Couldn't clear application caches"); - } + retCode = mInstaller.freeCache(freeStorageSize); + if (retCode < 0) { + Slog.w(TAG, "Couldn't clear application caches"); } if(pi != null) { try { @@ -2850,7 +2808,7 @@ public class PackageManagerService extends IPackageManager.Stub { private int performDexOptLI(PackageParser.Package pkg, boolean forceDex) { boolean performed = false; - if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0 && mInstaller != null) { + if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) { String path = pkg.mScanPath; int ret = 0; try { @@ -3235,42 +3193,39 @@ public class PackageManagerService extends IPackageManager.Stub { mOutPermissions[1] = 0; FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); - // If we have mismatched owners for the data path, we have a - // problem (unless we're running in the simulator.) - if (mOutPermissions[1] != pkg.applicationInfo.uid && Process.supportsProcesses()) { + // If we have mismatched owners for the data path, we have a problem. + if (mOutPermissions[1] != pkg.applicationInfo.uid) { boolean recovered = false; if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { // If this is a system app, we can at least delete its // current data so the application will still work. - if (mInstaller != null) { - int ret = mInstaller.remove(pkgName, 0); - if (ret >= 0) { - // TODO: Kill the processes first - // Remove the data directories for all users - mUserManager.removePackageForAllUsers(pkgName); - // Old data gone! - String msg = "System package " + pkg.packageName - + " has changed from uid: " - + mOutPermissions[1] + " to " - + pkg.applicationInfo.uid + "; old data erased"; + int ret = mInstaller.remove(pkgName, 0); + if (ret >= 0) { + // TODO: Kill the processes first + // Remove the data directories for all users + mUserManager.removePackageForAllUsers(pkgName); + // Old data gone! + String msg = "System package " + pkg.packageName + + " has changed from uid: " + + mOutPermissions[1] + " to " + + pkg.applicationInfo.uid + "; old data erased"; + reportSettingsProblem(Log.WARN, msg); + recovered = true; + + // And now re-install the app. + ret = mInstaller.install(pkgName, pkg.applicationInfo.uid, + pkg.applicationInfo.uid); + if (ret == -1) { + // Ack should not happen! + msg = "System package " + pkg.packageName + + " could not have data directory re-created after delete."; reportSettingsProblem(Log.WARN, msg); - recovered = true; - - // And now re-install the app. - ret = mInstaller.install(pkgName, pkg.applicationInfo.uid, - pkg.applicationInfo.uid); - if (ret == -1) { - // Ack should not happen! - msg = "System package " + pkg.packageName - + " could not have data directory re-created after delete."; - reportSettingsProblem(Log.WARN, msg); - mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; - return null; - } - // Create data directories for all users - mUserManager.installPackageForAllUsers(pkgName, - pkg.applicationInfo.uid); + mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; + return null; } + // Create data directories for all users + mUserManager.installPackageForAllUsers(pkgName, + pkg.applicationInfo.uid); } if (!recovered) { mHasSystemUidErrors = true; @@ -3303,25 +3258,16 @@ public class PackageManagerService extends IPackageManager.Stub { Log.v(TAG, "Want this data dir: " + dataPath); } //invoke installer to do the actual installation - if (mInstaller != null) { - int ret = mInstaller.install(pkgName, pkg.applicationInfo.uid, - pkg.applicationInfo.uid); - if (ret < 0) { - // Error from installer - mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; - return null; - } - // Create data directories for all users - mUserManager.installPackageForAllUsers(pkgName, pkg.applicationInfo.uid); - } else { - dataPath.mkdirs(); - if (dataPath.exists()) { - FileUtils.setPermissions( - dataPath.toString(), - FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, - pkg.applicationInfo.uid, pkg.applicationInfo.uid); - } + int ret = mInstaller.install(pkgName, pkg.applicationInfo.uid, + pkg.applicationInfo.uid); + if (ret < 0) { + // Error from installer + mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; + return null; } + // Create data directories for all users + mUserManager.installPackageForAllUsers(pkgName, pkg.applicationInfo.uid); + if (dataPath.exists()) { pkg.applicationInfo.dataDir = dataPath.getPath(); } else { @@ -3352,65 +3298,62 @@ public class PackageManagerService extends IPackageManager.Stub { pkgSetting.uidError = uidError; } - // If we're running in the simulator, we don't need to unpack anything. - if (mInstaller != null) { - String path = scanFile.getPath(); - /* Note: We don't want to unpack the native binaries for - * system applications, unless they have been updated - * (the binaries are already under /system/lib). - * Also, don't unpack libs for apps on the external card - * since they should have their libraries in the ASEC - * container already. - * - * In other words, we're going to unpack the binaries - * only for non-system apps and system app upgrades. - */ - if (pkg.applicationInfo.nativeLibraryDir != null) { - try { - final File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); - final String dataPathString = dataPath.getCanonicalFile().getPath(); + String path = scanFile.getPath(); + /* Note: We don't want to unpack the native binaries for + * system applications, unless they have been updated + * (the binaries are already under /system/lib). + * Also, don't unpack libs for apps on the external card + * since they should have their libraries in the ASEC + * container already. + * + * In other words, we're going to unpack the binaries + * only for non-system apps and system app upgrades. + */ + if (pkg.applicationInfo.nativeLibraryDir != null) { + try { + final File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); + final String dataPathString = dataPath.getCanonicalFile().getPath(); - if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { - /* - * Upgrading from a previous version of the OS sometimes - * leaves native libraries in the /data/data/<app>/lib - * directory for system apps even when they shouldn't be. - * Recent changes in the JNI library search path - * necessitates we remove those to match previous behavior. - */ - if (NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryDir)) { - Log.i(TAG, "removed obsolete native libraries for system package " - + path); - } - } else if (nativeLibraryDir.getCanonicalFile().getParent() - .equals(dataPathString)) { - /* - * If this is an internal application or our - * nativeLibraryPath points to our data directory, unpack - * the libraries. The native library path pointing to the - * data directory for an application in an ASEC container - * can happen for older apps that existed before an OTA to - * Gingerbread. - */ - Slog.i(TAG, "Unpacking native libraries for " + path); - mInstaller.unlinkNativeLibraryDirectory(dataPathString); - NativeLibraryHelper.copyNativeBinariesLI(scanFile, nativeLibraryDir); - } else { - Slog.i(TAG, "Linking native library dir for " + path); - mInstaller.linkNativeLibraryDirectory(dataPathString, - pkg.applicationInfo.nativeLibraryDir); + if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { + /* + * Upgrading from a previous version of the OS sometimes + * leaves native libraries in the /data/data/<app>/lib + * directory for system apps even when they shouldn't be. + * Recent changes in the JNI library search path + * necessitates we remove those to match previous behavior. + */ + if (NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryDir)) { + Log.i(TAG, "removed obsolete native libraries for system package " + + path); } - } catch (IOException ioe) { - Log.e(TAG, "Unable to get canonical file " + ioe.toString()); + } else if (nativeLibraryDir.getCanonicalFile().getParent() + .equals(dataPathString)) { + /* + * If this is an internal application or our + * nativeLibraryPath points to our data directory, unpack + * the libraries. The native library path pointing to the + * data directory for an application in an ASEC container + * can happen for older apps that existed before an OTA to + * Gingerbread. + */ + Slog.i(TAG, "Unpacking native libraries for " + path); + mInstaller.unlinkNativeLibraryDirectory(dataPathString); + NativeLibraryHelper.copyNativeBinariesLI(scanFile, nativeLibraryDir); + } else { + Slog.i(TAG, "Linking native library dir for " + path); + mInstaller.linkNativeLibraryDirectory(dataPathString, + pkg.applicationInfo.nativeLibraryDir); } + } catch (IOException ioe) { + Log.e(TAG, "Unable to get canonical file " + ioe.toString()); } - pkg.mScanPath = path; + } + pkg.mScanPath = path; - if ((scanMode&SCAN_NO_DEX) == 0) { - if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { - mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; - return null; - } + if ((scanMode&SCAN_NO_DEX) == 0) { + if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { + mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; + return null; } } @@ -5434,7 +5377,7 @@ public class PackageManagerService extends IPackageManager.Stub { void cleanUpResourcesLI() { String sourceDir = getCodePath(); - if (cleanUp() && mInstaller != null) { + if (cleanUp()) { int retCode = mInstaller.rmdex(sourceDir); if (retCode < 0) { Slog.w(TAG, "Couldn't remove dex file for package: " @@ -5662,14 +5605,12 @@ public class PackageManagerService extends IPackageManager.Stub { void cleanUpResourcesLI() { String sourceFile = getCodePath(); // Remove dex file - if (mInstaller != null) { - int retCode = mInstaller.rmdex(sourceFile); - if (retCode < 0) { - Slog.w(TAG, "Couldn't remove dex file for package: " - + " at location " - + sourceFile.toString() + ", retcode=" + retCode); - // we don't consider this to be a failure of the core package deletion - } + int retCode = mInstaller.rmdex(sourceFile); + if (retCode < 0) { + Slog.w(TAG, "Couldn't remove dex file for package: " + + " at location " + + sourceFile.toString() + ", retcode=" + retCode); + // we don't consider this to be a failure of the core package deletion } cleanUp(); } @@ -6077,9 +6018,7 @@ public class PackageManagerService extends IPackageManager.Stub { } if((res.returnCode = setPermissionsLI(newPackage)) != PackageManager.INSTALL_SUCCEEDED) { - if (mInstaller != null) { - mInstaller.rmdex(newPackage.mScanPath); - } + mInstaller.rmdex(newPackage.mScanPath); return; } else { Log.d(TAG, "New package installed in " + newPackage.mPath); @@ -6207,15 +6146,8 @@ public class PackageManagerService extends IPackageManager.Stub { } finally { //TODO clean up the extracted public files } - if (mInstaller != null) { - retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), - newPackage.applicationInfo.uid); - } else { - final int filePermissions = - FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP; - retCode = FileUtils.setPermissions(newPackage.mPath, filePermissions, -1, - newPackage.applicationInfo.uid); - } + retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), + newPackage.applicationInfo.uid); } else { // The permissions on the resource file was set when it was copied for // non forward locked apps and apps on sdcard @@ -6478,25 +6410,14 @@ public class PackageManagerService extends IPackageManager.Stub { deletedPs = mSettings.mPackages.get(packageName); } if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { - if (mInstaller != null) { - int retCode = mInstaller.remove(packageName, 0); - if (retCode < 0) { - Slog.w(TAG, "Couldn't remove app data or cache directory for package: " - + packageName + ", retcode=" + retCode); - // we don't consider this to be a failure of the core package deletion - } else { - // TODO: Kill the processes first - mUserManager.removePackageForAllUsers(packageName); - } + int retCode = mInstaller.remove(packageName, 0); + if (retCode < 0) { + Slog.w(TAG, "Couldn't remove app data or cache directory for package: " + + packageName + ", retcode=" + retCode); + // we don't consider this to be a failure of the core package deletion } else { - // for simulator - File dataDir; - // reader - synchronized (mPackages) { - PackageParser.Package pkg = mPackages.get(packageName); - dataDir = new File(pkg.applicationInfo.dataDir); - } - dataDir.delete(); + // TODO: Kill the processes first + mUserManager.removePackageForAllUsers(packageName); } schedulePackageCleaning(packageName); } @@ -6745,13 +6666,11 @@ public class PackageManagerService extends IPackageManager.Stub { return false; } } - if (mInstaller != null) { - int retCode = mInstaller.clearUserData(packageName, 0); // TODO - correct userId - if (retCode < 0) { - Slog.w(TAG, "Couldn't remove cache files for package: " - + packageName); - return false; - } + int retCode = mInstaller.clearUserData(packageName, 0); // TODO - correct userId + if (retCode < 0) { + Slog.w(TAG, "Couldn't remove cache files for package: " + + packageName); + return false; } return true; } @@ -6797,13 +6716,11 @@ public class PackageManagerService extends IPackageManager.Stub { Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); return false; } - if (mInstaller != null) { - int retCode = mInstaller.deleteCacheFiles(packageName); - if (retCode < 0) { - Slog.w(TAG, "Couldn't remove cache files for package: " - + packageName); - return false; - } + int retCode = mInstaller.deleteCacheFiles(packageName); + if (retCode < 0) { + Slog.w(TAG, "Couldn't remove cache files for package: " + + packageName); + return false; } return true; } @@ -6867,14 +6784,10 @@ public class PackageManagerService extends IPackageManager.Stub { publicSrcDir = applicationInfo.publicSourceDir; } } - if (mInstaller != null) { - int res = mInstaller.getSizeInfo(packageName, p.mPath, publicSrcDir, - asecPath, pStats); - if (res < 0) { - return false; - } else { - return true; - } + int res = mInstaller.getSizeInfo(packageName, p.mPath, publicSrcDir, + asecPath, pStats); + if (res < 0) { + return false; } return true; } diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java index d645160..3139798 100644 --- a/services/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/java/com/android/server/usb/UsbDeviceManager.java @@ -138,12 +138,9 @@ public class UsbDeviceManager { // create a thread for our Handler HandlerThread thread = new HandlerThread("UsbDeviceManager", - Process.THREAD_PRIORITY_BACKGROUND) { - protected void onLooperPrepared() { - mHandler = new UsbHandler(); - } - }; + Process.THREAD_PRIORITY_BACKGROUND); thread.start(); + mHandler = new UsbHandler(thread.getLooper()); } public void systemReady() { @@ -249,21 +246,21 @@ public class UsbDeviceManager { private static final int NOTIFICATION_INSTALLER = 3; private static final int NOTIFICATION_ADB = 4; - public UsbHandler() { + public UsbHandler(Looper looper) { + super(looper); try { + // persist.sys.usb.config should never be unset. But if it is, set it to "adb" + // so we have a chance of debugging what happened. + mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb"); // sanity check the sys.usb.config system property // this may be necessary if we crashed while switching USB configurations String config = SystemProperties.get("sys.usb.config", "none"); - if (config.equals("none")) { - String persistConfig = SystemProperties.get("persist.sys.usb.config", "none"); - Slog.w(TAG, "resetting config to persistent property: " + persistConfig); - SystemProperties.set("sys.usb.config", persistConfig); + if (!config.equals(mDefaultFunctions)) { + Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions); + SystemProperties.set("sys.usb.config", mDefaultFunctions); } - // Read initial USB state - mCurrentFunctions = FileUtils.readTextFile( - new File(FUNCTIONS_PATH), 0, null).trim(); - mDefaultFunctions = mCurrentFunctions; + mCurrentFunctions = mDefaultFunctions; String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); updateState(state); mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB); @@ -621,6 +618,16 @@ public class UsbDeviceManager { pw.println(" mConnected: " + mConnected); pw.println(" mConfigured: " + mConfigured); pw.println(" mCurrentAccessory: " + mCurrentAccessory); + try { + pw.println(" Kernel state: " + + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim()); + pw.println(" Kernel function list: " + + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim()); + pw.println(" Mass storage backing file: " + + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim()); + } catch (IOException e) { + pw.println("IOException: " + e); + } } } @@ -630,20 +637,20 @@ public class UsbDeviceManager { } /* opens the currently attached USB accessory */ - public ParcelFileDescriptor openAccessory(UsbAccessory accessory) { - UsbAccessory currentAccessory = mHandler.getCurrentAccessory(); - if (currentAccessory == null) { - throw new IllegalArgumentException("no accessory attached"); - } - if (!currentAccessory.equals(accessory)) { - String error = accessory.toString() - + " does not match current accessory " - + currentAccessory; - throw new IllegalArgumentException(error); - } - mSettingsManager.checkPermission(accessory); - return nativeOpenAccessory(); + public ParcelFileDescriptor openAccessory(UsbAccessory accessory) { + UsbAccessory currentAccessory = mHandler.getCurrentAccessory(); + if (currentAccessory == null) { + throw new IllegalArgumentException("no accessory attached"); + } + if (!currentAccessory.equals(accessory)) { + String error = accessory.toString() + + " does not match current accessory " + + currentAccessory; + throw new IllegalArgumentException(error); } + mSettingsManager.checkPermission(accessory); + return nativeOpenAccessory(); + } public void setCurrentFunction(String function, boolean makeDefault) { if (DEBUG) Slog.d(TAG, "setCurrentFunction(" + function + ") default: " + makeDefault); diff --git a/services/java/com/android/server/wm/AppWindowToken.java b/services/java/com/android/server/wm/AppWindowToken.java index d3d9df4..bfa2b39 100644 --- a/services/java/com/android/server/wm/AppWindowToken.java +++ b/services/java/com/android/server/wm/AppWindowToken.java @@ -101,7 +101,7 @@ class AppWindowToken extends WindowToken { boolean firstWindowDrawn; // Input application handle used by the input dispatcher. - InputApplicationHandle mInputApplicationHandle; + final InputApplicationHandle mInputApplicationHandle; AppWindowToken(WindowManagerService _service, IApplicationToken _token) { super(_service, _token.asBinder(), diff --git a/services/java/com/android/server/wm/InputApplication.java b/services/java/com/android/server/wm/InputApplication.java deleted file mode 100644 index e04fd31..0000000 --- a/services/java/com/android/server/wm/InputApplication.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -package com.android.server.wm; - - -/** - * Describes input-related application properties for use by the input dispatcher. - * @hide - */ -public final class InputApplication { - // Application handle. - public InputApplicationHandle inputApplicationHandle; - - // Application name. - public String name; - - // Dispatching timeout. - public long dispatchingTimeoutNanos; - - public void recycle() { - inputApplicationHandle = null; - } -} diff --git a/services/java/com/android/server/wm/InputApplicationHandle.java b/services/java/com/android/server/wm/InputApplicationHandle.java index 64c8e7e..d78b1d9 100644 --- a/services/java/com/android/server/wm/InputApplicationHandle.java +++ b/services/java/com/android/server/wm/InputApplicationHandle.java @@ -32,6 +32,12 @@ public final class InputApplicationHandle { // The window manager's application window token. public final AppWindowToken appWindowToken; + // Application name. + public String name; + + // Dispatching timeout. + public long dispatchingTimeoutNanos; + private native void nativeDispose(); public InputApplicationHandle(AppWindowToken appWindowToken) { diff --git a/services/java/com/android/server/wm/InputManager.java b/services/java/com/android/server/wm/InputManager.java index 65007f9..3133a19 100644 --- a/services/java/com/android/server/wm/InputManager.java +++ b/services/java/com/android/server/wm/InputManager.java @@ -25,7 +25,6 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.database.ContentObserver; import android.os.Environment; -import android.os.Handler; import android.os.Looper; import android.os.MessageQueue; import android.os.SystemProperties; @@ -83,10 +82,10 @@ public class InputManager { private static native int nativeInjectInputEvent(InputEvent event, int injectorPid, int injectorUid, int syncMode, int timeoutMillis, int policyFlags); - private static native void nativeSetInputWindows(InputWindow[] windows); + private static native void nativeSetInputWindows(InputWindowHandle[] windowHandles); private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen); private static native void nativeSetSystemUiVisibility(int visibility); - private static native void nativeSetFocusedApplication(InputApplication application); + private static native void nativeSetFocusedApplication(InputApplicationHandle application); private static native InputDevice nativeGetInputDevice(int deviceId); private static native void nativeGetInputConfiguration(Configuration configuration); private static native int[] nativeGetInputDeviceIds(); @@ -372,11 +371,11 @@ public class InputManager { return nativeGetInputDeviceIds(); } - public void setInputWindows(InputWindow[] windows) { - nativeSetInputWindows(windows); + public void setInputWindows(InputWindowHandle[] windowHandles) { + nativeSetInputWindows(windowHandles); } - public void setFocusedApplication(InputApplication application) { + public void setFocusedApplication(InputApplicationHandle application) { nativeSetFocusedApplication(application); } diff --git a/services/java/com/android/server/wm/InputMonitor.java b/services/java/com/android/server/wm/InputMonitor.java index 6806634..08a3560 100644 --- a/services/java/com/android/server/wm/InputMonitor.java +++ b/services/java/com/android/server/wm/InputMonitor.java @@ -17,7 +17,6 @@ package com.android.server.wm; import android.graphics.Rect; -import android.os.Binder; import android.os.Process; import android.os.RemoteException; import android.util.Log; @@ -26,6 +25,7 @@ import android.view.KeyEvent; import android.view.WindowManager; import java.util.ArrayList; +import java.util.Arrays; final class InputMonitor { private final WindowManagerService mService; @@ -42,12 +42,14 @@ final class InputMonitor { // When true, need to call updateInputWindowsLw(). private boolean mUpdateInputWindowsNeeded = true; - // Temporary list of windows information to provide to the input dispatcher. - private InputWindowList mTempInputWindows = new InputWindowList(); - - // Temporary input application object to provide to the input dispatcher. - private InputApplication mTempInputApplication = new InputApplication(); - + // Fake handles for the drag surface, lazily initialized. + private InputApplicationHandle mDragApplicationHandle; + private InputWindowHandle mDragWindowHandle; + + // Array of window handles to provide to the input dispatcher. + private InputWindowHandle[] mInputWindowHandles; + private int mInputWindowHandleCount; + // Set to true when the first input device configuration change notification // is received to indicate that the input devices are ready. private final Object mInputDevicesReadyMonitor = new Object(); @@ -68,8 +70,10 @@ final class InputMonitor { synchronized (mService.mWindowMap) { WindowState windowState = (WindowState) inputWindowHandle.windowState; - Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState); - mService.removeWindowLocked(windowState.mSession, windowState); + if (windowState != null) { + Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState); + mService.removeWindowLocked(windowState.mSession, windowState); + } } } @@ -94,8 +98,11 @@ final class InputMonitor { if (appWindowToken == null && inputApplicationHandle != null) { appWindowToken = inputApplicationHandle.appWindowToken; - Slog.i(WindowManagerService.TAG, "Input event dispatching timed out sending to application " - + appWindowToken.stringName); + if (appWindowToken != null) { + Slog.i(WindowManagerService.TAG, + "Input event dispatching timed out sending to application " + + appWindowToken.stringName); + } } if (appWindowToken != null && appWindowToken.appToken != null) { @@ -114,32 +121,59 @@ final class InputMonitor { return 0; // abort dispatching } - private void addDragInputWindowLw(InputWindowList windowList) { - final InputWindow inputWindow = windowList.add(); - inputWindow.inputChannel = mService.mDragState.mServerChannel; - inputWindow.name = "drag"; - inputWindow.layoutParamsFlags = 0; - inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; - inputWindow.dispatchingTimeoutNanos = WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; - inputWindow.visible = true; - inputWindow.canReceiveKeys = false; - inputWindow.hasFocus = true; - inputWindow.hasWallpaper = false; - inputWindow.paused = false; - inputWindow.layer = mService.mDragState.getDragLayerLw(); - inputWindow.ownerPid = Process.myPid(); - inputWindow.ownerUid = Process.myUid(); - inputWindow.inputFeatures = 0; - inputWindow.scaleFactor = 1.0f; + private void addDragInputWindowLw() { + if (mDragWindowHandle == null) { + mDragApplicationHandle = new InputApplicationHandle(null); + mDragApplicationHandle.name = "drag"; + mDragApplicationHandle.dispatchingTimeoutNanos = + WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; + + mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null); + mDragWindowHandle.name = "drag"; + mDragWindowHandle.layoutParamsFlags = 0; + mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; + mDragWindowHandle.dispatchingTimeoutNanos = + WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; + mDragWindowHandle.visible = true; + mDragWindowHandle.canReceiveKeys = false; + mDragWindowHandle.hasFocus = true; + mDragWindowHandle.hasWallpaper = false; + mDragWindowHandle.paused = false; + mDragWindowHandle.ownerPid = Process.myPid(); + mDragWindowHandle.ownerUid = Process.myUid(); + mDragWindowHandle.inputFeatures = 0; + mDragWindowHandle.scaleFactor = 1.0f; + + // The drag window cannot receive new touches. + mDragWindowHandle.touchableRegion.setEmpty(); + } + + mDragWindowHandle.layer = mService.mDragState.getDragLayerLw(); // The drag window covers the entire display - inputWindow.frameLeft = 0; - inputWindow.frameTop = 0; - inputWindow.frameRight = mService.mDisplay.getRealWidth(); - inputWindow.frameBottom = mService.mDisplay.getRealHeight(); + mDragWindowHandle.frameLeft = 0; + mDragWindowHandle.frameTop = 0; + mDragWindowHandle.frameRight = mService.mDisplay.getRealWidth(); + mDragWindowHandle.frameBottom = mService.mDisplay.getRealHeight(); + + addInputWindowHandleLw(mDragWindowHandle); + } - // The drag window cannot receive new touches. - inputWindow.touchableRegion.setEmpty(); + private void addInputWindowHandleLw(InputWindowHandle windowHandle) { + if (mInputWindowHandles == null) { + mInputWindowHandles = new InputWindowHandle[16]; + } + if (mInputWindowHandleCount >= mInputWindowHandles.length) { + mInputWindowHandles = Arrays.copyOf(mInputWindowHandles, + mInputWindowHandleCount * 2); + } + mInputWindowHandles[mInputWindowHandleCount++] = windowHandle; + } + + private void clearInputWindowHandlesLw() { + while (mInputWindowHandleCount != 0) { + mInputWindowHandles[--mInputWindowHandleCount] = null; + } } public void setUpdateInputWindowsNeededLw() { @@ -154,7 +188,7 @@ final class InputMonitor { mUpdateInputWindowsNeeded = false; if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw"); - + // Populate the input window list with information about all of the windows that // could potentially receive input. // As an optimization, we could try to prune the list of windows but this turns @@ -168,7 +202,7 @@ final class InputMonitor { if (WindowManagerService.DEBUG_DRAG) { Log.d(WindowManagerService.TAG, "Inserting drag window"); } - addDragInputWindowLw(mTempInputWindows); + addDragInputWindowLw(); } final int N = windows.size(); @@ -194,48 +228,48 @@ final class InputMonitor { } // Add a window to our list of input windows. - final InputWindow inputWindow = mTempInputWindows.add(); - inputWindow.inputWindowHandle = child.mInputWindowHandle; - inputWindow.inputChannel = child.mInputChannel; - inputWindow.name = child.toString(); - inputWindow.layoutParamsFlags = flags; - inputWindow.layoutParamsType = type; - inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); - inputWindow.visible = isVisible; - inputWindow.canReceiveKeys = child.canReceiveKeys(); - inputWindow.hasFocus = hasFocus; - inputWindow.hasWallpaper = hasWallpaper; - inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; - inputWindow.layer = child.mLayer; - inputWindow.ownerPid = child.mSession.mPid; - inputWindow.ownerUid = child.mSession.mUid; - inputWindow.inputFeatures = child.mAttrs.inputFeatures; + final InputWindowHandle inputWindowHandle = child.mInputWindowHandle; + inputWindowHandle.inputChannel = child.mInputChannel; + inputWindowHandle.name = child.toString(); + inputWindowHandle.layoutParamsFlags = flags; + inputWindowHandle.layoutParamsType = type; + inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); + inputWindowHandle.visible = isVisible; + inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); + inputWindowHandle.hasFocus = hasFocus; + inputWindowHandle.hasWallpaper = hasWallpaper; + inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; + inputWindowHandle.layer = child.mLayer; + inputWindowHandle.ownerPid = child.mSession.mPid; + inputWindowHandle.ownerUid = child.mSession.mUid; + inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; final Rect frame = child.mFrame; - inputWindow.frameLeft = frame.left; - inputWindow.frameTop = frame.top; - inputWindow.frameRight = frame.right; - inputWindow.frameBottom = frame.bottom; + inputWindowHandle.frameLeft = frame.left; + inputWindowHandle.frameTop = frame.top; + inputWindowHandle.frameRight = frame.right; + inputWindowHandle.frameBottom = frame.bottom; if (child.mGlobalScale != 1) { // If we are scaling the window, input coordinates need // to be inversely scaled to map from what is on screen // to what is actually being touched in the UI. - inputWindow.scaleFactor = 1.0f/child.mGlobalScale; + inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; } else { - inputWindow.scaleFactor = 1; + inputWindowHandle.scaleFactor = 1; } - child.getTouchableRegion(inputWindow.touchableRegion); + child.getTouchableRegion(inputWindowHandle.touchableRegion); + + addInputWindowHandleLw(inputWindowHandle); } // Send windows to native code. - mService.mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); - + mService.mInputManager.setInputWindows(mInputWindowHandles); + // Clear the list in preparation for the next round. - // Also avoids keeping InputChannel objects referenced unnecessarily. - mTempInputWindows.clear(); - + clearInputWindowHandlesLw(); + if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw"); } @@ -329,14 +363,11 @@ final class InputMonitor { if (newApp == null) { mService.mInputManager.setFocusedApplication(null); } else { - mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; - mTempInputApplication.name = newApp.toString(); - mTempInputApplication.dispatchingTimeoutNanos = - newApp.inputDispatchingTimeoutNanos; - - mService.mInputManager.setFocusedApplication(mTempInputApplication); + final InputApplicationHandle handle = newApp.mInputApplicationHandle; + handle.name = newApp.toString(); + handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos; - mTempInputApplication.recycle(); + mService.mInputManager.setFocusedApplication(handle); } } diff --git a/services/java/com/android/server/wm/InputWindow.java b/services/java/com/android/server/wm/InputWindow.java deleted file mode 100644 index 655d734..0000000 --- a/services/java/com/android/server/wm/InputWindow.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -package com.android.server.wm; - -import android.graphics.Region; -import android.view.InputChannel; - -/** - * Describes input-related window properties for use by the input dispatcher. - * @hide - */ -public final class InputWindow { - // The window handle. - public InputWindowHandle inputWindowHandle; - - // The input channel associated with the window. - public InputChannel inputChannel; - - // The window name. - public String name; - - // Window layout params attributes. (WindowManager.LayoutParams) - public int layoutParamsFlags; - public int layoutParamsType; - - // Dispatching timeout. - public long dispatchingTimeoutNanos; - - // Window frame. - public int frameLeft; - public int frameTop; - public int frameRight; - public int frameBottom; - - // Global scaling factor applied to touch events when they are dispatched - // to the window - public float scaleFactor; - - // Window touchable region. - public final Region touchableRegion = new Region(); - - // Window is visible. - public boolean visible; - - // Window can receive keys. - public boolean canReceiveKeys; - - // Window has focus. - public boolean hasFocus; - - // Window has wallpaper. (window is the current wallpaper target) - public boolean hasWallpaper; - - // Input event dispatching is paused. - public boolean paused; - - // Window layer. - public int layer; - - // Id of process and user that owns the window. - public int ownerPid; - public int ownerUid; - - // Window input features. - public int inputFeatures; - - public void recycle() { - inputWindowHandle = null; - inputChannel = null; - } -} diff --git a/services/java/com/android/server/wm/InputWindowHandle.java b/services/java/com/android/server/wm/InputWindowHandle.java index cc508c6..abf68d9 100644 --- a/services/java/com/android/server/wm/InputWindowHandle.java +++ b/services/java/com/android/server/wm/InputWindowHandle.java @@ -16,6 +16,8 @@ package com.android.server.wm; +import android.graphics.Region; +import android.view.InputChannel; import android.view.WindowManagerPolicy; /** @@ -35,6 +37,57 @@ public final class InputWindowHandle { // The window manager's window state. public final WindowManagerPolicy.WindowState windowState; + // The input channel associated with the window. + public InputChannel inputChannel; + + // The window name. + public String name; + + // Window layout params attributes. (WindowManager.LayoutParams) + public int layoutParamsFlags; + public int layoutParamsType; + + // Dispatching timeout. + public long dispatchingTimeoutNanos; + + // Window frame. + public int frameLeft; + public int frameTop; + public int frameRight; + public int frameBottom; + + // Global scaling factor applied to touch events when they are dispatched + // to the window + public float scaleFactor; + + // Window touchable region. + public final Region touchableRegion = new Region(); + + // Window is visible. + public boolean visible; + + // Window can receive keys. + public boolean canReceiveKeys; + + // Window has focus. + public boolean hasFocus; + + // Window has wallpaper. (window is the current wallpaper target) + public boolean hasWallpaper; + + // Input event dispatching is paused. + public boolean paused; + + // Window layer. + public int layer; + + // Id of process and user that owns the window. + public int ownerPid; + public int ownerUid; + + // Window input features. + public int inputFeatures; + private native void nativeDispose(); public InputWindowHandle(InputApplicationHandle inputApplicationHandle, diff --git a/services/java/com/android/server/wm/InputWindowList.java b/services/java/com/android/server/wm/InputWindowList.java deleted file mode 100644 index 6077337..0000000 --- a/services/java/com/android/server/wm/InputWindowList.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -package com.android.server.wm; - - -/** - * A specialized list of window information objects backed by an array. - * - * This class is part of an InputManager optimization to avoid allocating objects and arrays - * unnecessarily. Internally, it keeps an array full of demand-allocated objects that it - * recycles each time the list is cleared. The used portion of the array is padded with a null. - * - * The contents of the list are intended to be Z-ordered from top to bottom. - * - * @hide - */ -public final class InputWindowList { - private InputWindow[] mArray; - private int mCount; - - /** - * Creates an empty list. - */ - public InputWindowList() { - mArray = new InputWindow[8]; - } - - /** - * Clears the list. - */ - public void clear() { - if (mCount == 0) { - return; - } - - int count = mCount; - mCount = 0; - mArray[count] = mArray[0]; - while (count > 0) { - count -= 1; - mArray[count].recycle(); - } - mArray[0] = null; - } - - /** - * Adds an uninitialized input window object to the list and returns it. - */ - public InputWindow add() { - if (mCount + 1 == mArray.length) { - InputWindow[] oldArray = mArray; - mArray = new InputWindow[oldArray.length * 2]; - System.arraycopy(oldArray, 0, mArray, 0, mCount); - } - - // Grab object from tail (after used section) if available. - InputWindow item = mArray[mCount + 1]; - if (item == null) { - item = new InputWindow(); - } - - mArray[mCount] = item; - mCount += 1; - mArray[mCount] = null; - return item; - } - - /** - * Gets the input window objects as a null-terminated array. - * @return The input window array. - */ - public InputWindow[] toNullTerminatedArray() { - return mArray; - } -}
\ No newline at end of file diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java index b370ec9..d298ff7 100644 --- a/services/java/com/android/server/wm/WindowState.java +++ b/services/java/com/android/server/wm/WindowState.java @@ -272,7 +272,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { float mSurfaceAlpha; // Input channel and input window handle used by the input dispatcher. - InputWindowHandle mInputWindowHandle; + final InputWindowHandle mInputWindowHandle; InputChannel mInputChannel; // Used to improve performance of toString() @@ -306,6 +306,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { mIsFloatingLayer = false; mBaseLayer = 0; mSubLayer = 0; + mInputWindowHandle = null; return; } mDeathRecipient = deathRecipient; |
