diff options
Diffstat (limited to 'services')
40 files changed, 473 insertions, 243 deletions
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp index 795ab47..9e7a15d 100644 --- a/services/input/InputDispatcher.cpp +++ b/services/input/InputDispatcher.cpp @@ -3405,6 +3405,7 @@ void InputDispatcher::onANRLocked( & InputDispatcher::doNotifyANRLockedInterruptible); commandEntry->inputApplicationHandle = applicationHandle; commandEntry->inputWindowHandle = windowHandle; + commandEntry->reason = reason; } void InputDispatcher::doNotifyConfigurationChangedInterruptible( @@ -3434,7 +3435,8 @@ void InputDispatcher::doNotifyANRLockedInterruptible( mLock.unlock(); nsecs_t newTimeout = mPolicy->notifyANR( - commandEntry->inputApplicationHandle, commandEntry->inputWindowHandle); + commandEntry->inputApplicationHandle, commandEntry->inputWindowHandle, + commandEntry->reason); mLock.lock(); diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h index 0273dc4..190e7b2 100644 --- a/services/input/InputDispatcher.h +++ b/services/input/InputDispatcher.h @@ -202,7 +202,8 @@ public: /* Notifies the system that an application is not responding. * Returns a new timeout to continue waiting, or 0 to abort dispatch. */ virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, - const sp<InputWindowHandle>& inputWindowHandle) = 0; + const sp<InputWindowHandle>& inputWindowHandle, + const String8& reason) = 0; /* Notifies the system that an input channel is unrecoverably broken. */ virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) = 0; @@ -596,6 +597,7 @@ private: KeyEntry* keyEntry; sp<InputApplicationHandle> inputApplicationHandle; sp<InputWindowHandle> inputWindowHandle; + String8 reason; int32_t userActivityEventType; uint32_t seq; bool handled; diff --git a/services/input/tests/InputDispatcher_test.cpp b/services/input/tests/InputDispatcher_test.cpp index ed2b4a5..26b4fab 100644 --- a/services/input/tests/InputDispatcher_test.cpp +++ b/services/input/tests/InputDispatcher_test.cpp @@ -50,7 +50,8 @@ private: } virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, - const sp<InputWindowHandle>& inputWindowHandle) { + const sp<InputWindowHandle>& inputWindowHandle, + const String8& reason) { return 0; } diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 4e3faca..3f8d7eb 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -58,8 +58,8 @@ import android.net.INetworkPolicyManager; import android.net.INetworkStatsService; import android.net.LinkAddress; import android.net.LinkProperties; -import android.net.LinkQualityInfo; import android.net.LinkProperties.CompareResult; +import android.net.LinkQualityInfo; import android.net.MobileDataStateTracker; import android.net.NetworkConfig; import android.net.NetworkInfo; @@ -89,7 +89,6 @@ import android.os.ParcelFileDescriptor; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; -import android.os.ResultReceiver; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; @@ -114,7 +113,6 @@ import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.XmlUtils; -import com.android.net.IProxyService; import com.android.server.am.BatteryStatsService; import com.android.server.connectivity.DataConnectionStats; import com.android.server.connectivity.Nat464Xlat; @@ -3209,12 +3207,6 @@ public class ConnectivityService extends IConnectivityManager.Stub { return mTethering.getTetheredIfaces(); } - @Override - public String[] getTetheredIfacePairs() { - enforceTetherAccessPermission(); - return mTethering.getTetheredIfacePairs(); - } - public String[] getTetheringErroredIfaces() { enforceTetherAccessPermission(); return mTethering.getErroredIfaces(); @@ -4684,12 +4676,12 @@ public class ConnectivityService extends IConnectivityManager.Stub { @Override public void setAirplaneMode(boolean enable) { enforceConnectivityInternalPermission(); - final ContentResolver cr = mContext.getContentResolver(); - Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0); - Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", enable); final long ident = Binder.clearCallingIdentity(); try { + final ContentResolver cr = mContext.getContentResolver(); + Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0); + Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); + intent.putExtra("state", enable); mContext.sendBroadcast(intent); } finally { Binder.restoreCallingIdentity(ident); diff --git a/services/java/com/android/server/ConsumerIrService.java b/services/java/com/android/server/ConsumerIrService.java new file mode 100644 index 0000000..07f2a41 --- /dev/null +++ b/services/java/com/android/server/ConsumerIrService.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2013 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; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageManager; +import android.database.ContentObserver; +import android.hardware.input.InputManager; +import android.hardware.IConsumerIrService; +import android.os.Handler; +import android.os.PowerManager; +import android.os.Process; +import android.os.RemoteException; +import android.os.IBinder; +import android.os.Binder; +import android.os.ServiceManager; +import android.os.SystemClock; +import android.os.UserHandle; +import android.os.WorkSource; +import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; +import android.util.Slog; +import android.view.InputDevice; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.ListIterator; + +public class ConsumerIrService extends IConsumerIrService.Stub { + private static final String TAG = "ConsumerIrService"; + + private static final int MAX_XMIT_TIME = 2000000; /* in microseconds */ + + private static native int halOpen(); + private static native int halTransmit(int halObject, int carrierFrequency, int[] pattern); + private static native int[] halGetCarrierFrequencies(int halObject); + + private final Context mContext; + private final PowerManager.WakeLock mWakeLock; + private final int mHal; + private final Object mHalLock = new Object(); + + ConsumerIrService(Context context) { + mContext = context; + PowerManager pm = (PowerManager)context.getSystemService( + Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); + mWakeLock.setReferenceCounted(true); + + mHal = halOpen(); + if (mHal == 0) { + Slog.w(TAG, "No IR HAL loaded"); + } + } + + @Override + public boolean hasIrEmitter() { + return mHal != 0; + } + + private void throwIfNoIrEmitter() { + if (mHal == 0) { + throw new UnsupportedOperationException("IR emitter not available"); + } + } + + + @Override + public void transmit(String packageName, int carrierFrequency, int[] pattern) { + if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.TRANSMIT_IR) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Requires TRANSMIT_IR permission"); + } + + long totalXmitTime = 0; + + for (int slice : pattern) { + if (slice <= 0) { + throw new IllegalArgumentException("Non-positive IR slice"); + } + totalXmitTime += slice; + } + + if (totalXmitTime > MAX_XMIT_TIME ) { + throw new IllegalArgumentException("IR pattern too long"); + } + + throwIfNoIrEmitter(); + + // Right now there is no mechanism to ensure fair queing of IR requests + synchronized (mHalLock) { + int err = halTransmit(mHal, carrierFrequency, pattern); + + if (err < 0) { + Slog.e(TAG, "Error transmitting: " + err); + } + } + } + + @Override + public int[] getCarrierFrequencies() { + if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.TRANSMIT_IR) + != PackageManager.PERMISSION_GRANTED) { + throw new SecurityException("Requires TRANSMIT_IR permission"); + } + + throwIfNoIrEmitter(); + + synchronized(mHalLock) { + return halGetCarrierFrequencies(mHal); + } + } +} diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java index de29155..f70f4db 100644 --- a/services/java/com/android/server/LocationManagerService.java +++ b/services/java/com/android/server/LocationManagerService.java @@ -1773,8 +1773,12 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public boolean isProviderEnabled(String provider) { + // TODO: remove this check in next release, see b/10696351 checkResolutionLevelIsSufficientForProviderUse(getCallerAllowedResolutionLevel(), provider); + + // Fused provider is accessed indirectly via criteria rather than the provider-based APIs, + // so we discourage its use if (LocationManager.FUSED_PROVIDER.equals(provider)) return false; int uid = Binder.getCallingUid(); diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 82cc540..92f99c2 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -24,15 +24,15 @@ import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; import static android.net.TrafficStats.UID_TETHERING; import static com.android.server.NetworkManagementService.NetdResponseCode.ClatdStatusResult; +import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult; import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult; import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.IpFwdStatusResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherDnsFwdTgtListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherInterfaceListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TetherStatusResult; -import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsResult; +import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsListResult; import static com.android.server.NetworkManagementService.NetdResponseCode.TtyListResult; -import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult; import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED; import android.content.Context; @@ -118,6 +118,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub public static final int TetherInterfaceListResult = 111; public static final int TetherDnsFwdTgtListResult = 112; public static final int TtyListResult = 113; + public static final int TetheringStatsListResult = 114; public static final int TetherStatusResult = 210; public static final int IpFwdStatusResult = 211; @@ -523,7 +524,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub throw new IllegalStateException(msg); } - int flags, scope; + int flags; + int scope; try { flags = Integer.parseInt(cooked[5]); scope = Integer.parseInt(cooked[6]); @@ -1373,55 +1375,42 @@ public class NetworkManagementService extends INetworkManagementService.Stub } @Override - public NetworkStats getNetworkStatsTethering(String[] ifacePairs) { + public NetworkStats getNetworkStatsTethering() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); - if (ifacePairs.length % 2 != 0) { - throw new IllegalArgumentException( - "unexpected ifacePairs; length=" + ifacePairs.length); - } - final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1); - for (int i = 0; i < ifacePairs.length; i += 2) { - final String ifaceIn = ifacePairs[i]; - final String ifaceOut = ifacePairs[i + 1]; - if (ifaceIn != null && ifaceOut != null) { - stats.combineValues(getNetworkStatsTethering(ifaceIn, ifaceOut)); - } - } - return stats; - } - - private NetworkStats.Entry getNetworkStatsTethering(String ifaceIn, String ifaceOut) { - final NativeDaemonEvent event; try { - event = mConnector.execute("bandwidth", "gettetherstats", ifaceIn, ifaceOut); + final NativeDaemonEvent[] events = mConnector.executeForList( + "bandwidth", "gettetherstats"); + for (NativeDaemonEvent event : events) { + if (event.getCode() != TetheringStatsListResult) continue; + + // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets + final StringTokenizer tok = new StringTokenizer(event.getMessage()); + try { + final String ifaceIn = tok.nextToken(); + final String ifaceOut = tok.nextToken(); + + final NetworkStats.Entry entry = new NetworkStats.Entry(); + entry.iface = ifaceOut; + entry.uid = UID_TETHERING; + entry.set = SET_DEFAULT; + entry.tag = TAG_NONE; + entry.rxBytes = Long.parseLong(tok.nextToken()); + entry.rxPackets = Long.parseLong(tok.nextToken()); + entry.txBytes = Long.parseLong(tok.nextToken()); + entry.txPackets = Long.parseLong(tok.nextToken()); + stats.combineValues(entry); + } catch (NoSuchElementException e) { + throw new IllegalStateException("problem parsing tethering stats: " + event); + } catch (NumberFormatException e) { + throw new IllegalStateException("problem parsing tethering stats: " + event); + } + } } catch (NativeDaemonConnectorException e) { throw e.rethrowAsParcelableException(); } - - event.checkCode(TetheringStatsResult); - - // 221 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets - final StringTokenizer tok = new StringTokenizer(event.getMessage()); - tok.nextToken(); - tok.nextToken(); - - try { - final NetworkStats.Entry entry = new NetworkStats.Entry(); - entry.iface = ifaceIn; - entry.uid = UID_TETHERING; - entry.set = SET_DEFAULT; - entry.tag = TAG_NONE; - entry.rxBytes = Long.parseLong(tok.nextToken()); - entry.rxPackets = Long.parseLong(tok.nextToken()); - entry.txBytes = Long.parseLong(tok.nextToken()); - entry.txPackets = Long.parseLong(tok.nextToken()); - return entry; - } catch (NumberFormatException e) { - throw new IllegalStateException( - "problem parsing tethering stats for " + ifaceIn + " " + ifaceOut + ": " + e); - } + return stats; } @Override diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 0bbdcfb..d38756f 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -154,6 +154,7 @@ class ServerThread { CommonTimeManagementService commonTimeMgmtService = null; InputManagerService inputManager = null; TelephonyRegistry telephonyRegistry = null; + ConsumerIrService consumerIr = null; // Create a handler thread just for the window manager to enjoy. HandlerThread wmHandlerThread = new HandlerThread("WindowManager"); @@ -284,6 +285,10 @@ class ServerThread { vibrator = new VibratorService(context); ServiceManager.addService("vibrator", vibrator); + Slog.i(TAG, "Consumer IR Service"); + consumerIr = new ConsumerIrService(context); + ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); + // only initialize the power service after we have started the // lights service, content providers and the battery service. power.init(context, lights, ActivityManagerService.self(), battery, diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 1e3fb40..96b7030 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -187,7 +187,6 @@ import java.io.StringWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -314,10 +313,6 @@ public final class ActivityManagerService extends ActivityManagerNative // to respond with the result. static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500; - // Index for assist context bundle pertaining to the top activity. Non-negative indices - // correspond to assist context bundles from foreground services. - static final int TOP_ACTIVITY_ASSIST_EXTRAS_INDEX = -1; - static final int MY_PID = Process.myPid(); static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -394,30 +389,16 @@ public final class ActivityManagerService extends ActivityManagerNative public class PendingAssistExtras extends Binder implements Runnable { public final ActivityRecord activity; - public final List<ServiceRecord> services; - public int numPending; - public int numRespondedServices = 0; - public Bundle activityExtras = null; - public Bundle[] servicesExtras; - public PendingAssistExtras(ActivityRecord _activity, List<ServiceRecord> _services) { + public boolean haveResult = false; + public Bundle result = null; + public PendingAssistExtras(ActivityRecord _activity) { activity = _activity; - services = _services; - numPending = services.size() + 1; } @Override public void run() { - if (activityExtras == null) { - Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from activtity " - + activity); - } - for (int i = 0; i < services.size(); i++) { - if (servicesExtras[i] == null) { - Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from service " - + i + " " + services.get(i)); - } - } + Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity); synchronized (this) { - numPending = 0; + haveResult = true; notifyAll(); } } @@ -7970,8 +7951,8 @@ public final class ActivityManagerService extends ActivityManagerNative return KEY_DISPATCHING_TIMEOUT; } - - public long inputDispatchingTimedOut(int pid, final boolean aboveSystem) { + @Override + public long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) { if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Requires permission " @@ -7986,7 +7967,7 @@ public final class ActivityManagerService extends ActivityManagerNative timeout = getInputDispatchingTimeoutLocked(proc); } - if (!inputDispatchingTimedOut(proc, null, null, aboveSystem)) { + if (!inputDispatchingTimedOut(proc, null, null, aboveSystem, reason)) { return -1; } @@ -7999,13 +7980,20 @@ public final class ActivityManagerService extends ActivityManagerNative */ public boolean inputDispatchingTimedOut(final ProcessRecord proc, final ActivityRecord activity, final ActivityRecord parent, - final boolean aboveSystem) { + final boolean aboveSystem, String reason) { if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Requires permission " + android.Manifest.permission.FILTER_EVENTS); } + final String annotation; + if (reason == null) { + annotation = "Input dispatching timed out"; + } else { + annotation = "Input dispatching timed out (" + reason + ")"; + } + if (proc != null) { synchronized (this) { if (proc.debugging) { @@ -8021,7 +8009,7 @@ public final class ActivityManagerService extends ActivityManagerNative if (proc.instrumentationClass != null) { Bundle info = new Bundle(); info.putString("shortMsg", "keyDispatchingTimedOut"); - info.putString("longMsg", "Timed out while dispatching key event"); + info.putString("longMsg", annotation); finishInstrumentationLocked(proc, Activity.RESULT_CANCELED, info); return true; } @@ -8029,7 +8017,7 @@ public final class ActivityManagerService extends ActivityManagerNative mHandler.post(new Runnable() { @Override public void run() { - appNotResponding(proc, activity, parent, aboveSystem, "keyDispatchingTimedOut"); + appNotResponding(proc, activity, parent, aboveSystem, annotation); } }); } @@ -8042,81 +8030,41 @@ public final class ActivityManagerService extends ActivityManagerNative "getAssistContextExtras()"); PendingAssistExtras pae; Bundle extras = new Bundle(); - List<ServiceRecord> foregroundServices; synchronized (this) { - Collection<ServiceRecord> allServices = mServices.mServiceMap.getAllServices( - Binder.getCallingUid()); - foregroundServices = new ArrayList<ServiceRecord>(); - for (ServiceRecord record : allServices) { - if ((record.serviceInfo.flags & ServiceInfo.FLAG_PROVIDE_ASSIST_DATA) > 0 && - record.isForeground) { - if (record.app == null || record.app.thread == null) { - Slog.w(TAG, "getAssistContextExtras error: no process for " + record); - continue; - } - if (record.app.pid == Binder.getCallingPid()) { - Slog.w(TAG, "getAssistContextExtras error: request process same as " + - record); - continue; - } - foregroundServices.add(record); - } - } - ActivityRecord activity = getFocusedStack().mResumedActivity; - boolean validActivity = true; if (activity == null) { - Slog.w(TAG, "getAssistContextExtras error: no resumed activity"); - validActivity = false; - } else if (activity.app == null || activity.app.thread == null) { - Slog.w(TAG, "getAssistContextExtras error: no process for " + activity); - validActivity = false; - } else if (activity.app.pid == Binder.getCallingPid()) { - Slog.w(TAG, "getAssistContextExtras error: request process same as " + activity); - validActivity = false; + Slog.w(TAG, "getAssistContextExtras failed: no resumed activity"); + return null; } - - pae = new PendingAssistExtras(activity, foregroundServices); + extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName); + if (activity.app == null || activity.app.thread == null) { + Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity); + return extras; + } + if (activity.app.pid == Binder.getCallingPid()) { + Slog.w(TAG, "getAssistContextExtras failed: request process same as " + activity); + return extras; + } + pae = new PendingAssistExtras(activity); try { - if (validActivity) { - activity.app.thread.requestAssistContextExtras(activity.appToken, pae, - requestType, -1); - } - for (int i = 0; i < foregroundServices.size(); i++) { - ServiceRecord record = foregroundServices.get(i); - record.app.thread.requestAssistContextExtras(record, pae, requestType, i); - } + activity.app.thread.requestAssistContextExtras(activity.appToken, pae, + requestType); mPendingAssistExtras.add(pae); mHandler.postDelayed(pae, PENDING_ASSIST_EXTRAS_TIMEOUT); } catch (RemoteException e) { - Slog.w(TAG, "getAssistContextExtras failed: crash fetching extras.", e); + Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity); + return extras; } } synchronized (pae) { - while (pae.numPending > 0) { + while (!pae.haveResult) { try { pae.wait(); } catch (InterruptedException e) { } } - if (pae.activityExtras != null) { - extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, pae.activityExtras); - extras.putString(Intent.EXTRA_ASSIST_PACKAGE, pae.activity.packageName); - } - if (pae.numRespondedServices > 0) { - Bundle[] servicesExtras = new Bundle[pae.numRespondedServices]; - String[] servicesPackages = new String[pae.numRespondedServices]; - int extrasIndex = 0; - for (int i = 0; i < foregroundServices.size(); i++) { - if (pae.servicesExtras[i] != null) { - servicesExtras[extrasIndex] = pae.servicesExtras[i]; - ServiceRecord record = foregroundServices.get(i); - servicesPackages[extrasIndex] = record.packageName; - extrasIndex++; - } - } - extras.putParcelableArray(Intent.EXTRA_ASSIST_SERVICES_CONTEXTS, servicesExtras); - extras.putStringArray(Intent.EXTRA_ASSIST_SERVICES_PACKAGES, servicesPackages); + if (pae.result != null) { + extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, pae.result); } } synchronized (this) { @@ -8126,19 +8074,12 @@ public final class ActivityManagerService extends ActivityManagerNative return extras; } - public void reportAssistContextExtras(IBinder token, Bundle extras, int index) { + public void reportAssistContextExtras(IBinder token, Bundle extras) { PendingAssistExtras pae = (PendingAssistExtras)token; synchronized (pae) { - if (index == TOP_ACTIVITY_ASSIST_EXTRAS_INDEX) { - pae.activityExtras = extras; - } else { - pae.servicesExtras[index] = extras; - pae.numRespondedServices++; - } - pae.numPending--; - if (pae.numPending == 0) { - pae.notifyAll(); - } + pae.result = extras; + pae.haveResult = true; + pae.notifyAll(); } } diff --git a/services/java/com/android/server/am/ActivityRecord.java b/services/java/com/android/server/am/ActivityRecord.java index bf3713b..6e50808 100644 --- a/services/java/com/android/server/am/ActivityRecord.java +++ b/services/java/com/android/server/am/ActivityRecord.java @@ -305,9 +305,9 @@ final class ActivityRecord { } } - @Override public boolean keyDispatchingTimedOut() { + @Override public boolean keyDispatchingTimedOut(String reason) { ActivityRecord activity = weakActivity.get(); - return activity != null && activity.keyDispatchingTimedOut(); + return activity != null && activity.keyDispatchingTimedOut(reason); } @Override public long getKeyDispatchingTimeout() { @@ -960,14 +960,14 @@ final class ActivityRecord { return r; } - public boolean keyDispatchingTimedOut() { + public boolean keyDispatchingTimedOut(String reason) { ActivityRecord r; ProcessRecord anrApp; synchronized(service) { r = getWaitingHistoryRecordLocked(); anrApp = r != null ? r.app : null; } - return service.inputDispatchingTimedOut(anrApp, r, this, false); + return service.inputDispatchingTimedOut(anrApp, r, this, false, reason); } /** Returns the key dispatching timeout for this application token. */ diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java index 2b76e71..e994c23 100644 --- a/services/java/com/android/server/am/ActivityStack.java +++ b/services/java/com/android/server/am/ActivityStack.java @@ -620,7 +620,13 @@ final class ActivityStack { } void clearLaunchTime(ActivityRecord r) { - r.displayStartTime = r.fullyDrawnStartTime = 0; + // Make sure that there is no activity waiting for this to launch. + if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { + r.displayStartTime = r.fullyDrawnStartTime = 0; + } else { + mStackSupervisor.removeTimeoutsForActivityLocked(r); + mStackSupervisor.scheduleIdleTimeoutLocked(r); + } } void awakeFromSleepingLocked() { diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index fb4c1cf..231a40a 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -688,19 +688,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub { return retVal; } - public String[] getTetheredIfacePairs() { - final ArrayList<String> list = Lists.newArrayList(); - synchronized (mPublicSync) { - for (TetherInterfaceSM sm : mIfaces.values()) { - if (sm.isTethered()) { - list.add(sm.mMyUpstreamIfaceName); - list.add(sm.mIfaceName); - } - } - } - return list.toArray(new String[list.size()]); - } - public String[] getTetherableIfaces() { ArrayList<String> list = new ArrayList<String>(); synchronized (mPublicSync) { diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java index 7b4c077..d749e6c 100644 --- a/services/java/com/android/server/input/InputManagerService.java +++ b/services/java/com/android/server/input/InputManagerService.java @@ -1292,8 +1292,9 @@ public class InputManagerService extends IInputManager.Stub // Native callback. private long notifyANR(InputApplicationHandle inputApplicationHandle, - InputWindowHandle inputWindowHandle) { - return mWindowManagerCallbacks.notifyANR(inputApplicationHandle, inputWindowHandle); + InputWindowHandle inputWindowHandle, String reason) { + return mWindowManagerCallbacks.notifyANR( + inputApplicationHandle, inputWindowHandle, reason); } // Native callback. @@ -1477,7 +1478,7 @@ public class InputManagerService extends IInputManager.Stub public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle); public long notifyANR(InputApplicationHandle inputApplicationHandle, - InputWindowHandle inputWindowHandle); + InputWindowHandle inputWindowHandle, String reason); public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn); diff --git a/services/java/com/android/server/location/FlpHardwareProvider.java b/services/java/com/android/server/location/FlpHardwareProvider.java index ebeccfb..60893b8 100644 --- a/services/java/com/android/server/location/FlpHardwareProvider.java +++ b/services/java/com/android/server/location/FlpHardwareProvider.java @@ -141,10 +141,16 @@ public class FlpHardwareProvider { } private void onGeofenceMonitorStatus(int status, int source, Location location) { + // allow the location to be optional in this event + Location updatedLocation = null; + if(location != null) { + updatedLocation = updateLocationInformation(location); + } + getGeofenceHardwareSink().reportGeofenceMonitorStatus( GeofenceHardware.MONITORING_TYPE_FUSED_HARDWARE, status, - updateLocationInformation(location), + updatedLocation, source); } diff --git a/services/java/com/android/server/net/NetworkStatsRecorder.java b/services/java/com/android/server/net/NetworkStatsRecorder.java index 2b32b41..cea084b 100644 --- a/services/java/com/android/server/net/NetworkStatsRecorder.java +++ b/services/java/com/android/server/net/NetworkStatsRecorder.java @@ -135,6 +135,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem completely reading network stats", e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem completely reading network stats", e); + recoverFromWtf(); } } return complete; @@ -226,6 +229,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem persisting pending stats", e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem persisting pending stats", e); + recoverFromWtf(); } } } @@ -241,6 +247,9 @@ public class NetworkStatsRecorder { } catch (IOException e) { Log.wtf(TAG, "problem removing UIDs " + Arrays.toString(uids), e); recoverFromWtf(); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem removing UIDs " + Arrays.toString(uids), e); + recoverFromWtf(); } // Remove any pending stats diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 05eeb36..1e8a7b0 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -412,6 +412,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } catch (IOException e) { Log.wtf(TAG, "problem during legacy upgrade", e); + } catch (OutOfMemoryError e) { + Log.wtf(TAG, "problem during legacy upgrade", e); } } @@ -1186,8 +1188,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { */ private NetworkStats getNetworkStatsTethering() throws RemoteException { try { - final String[] tetheredIfacePairs = mConnManager.getTetheredIfacePairs(); - return mNetworkManager.getNetworkStatsTethering(tetheredIfacePairs); + return mNetworkManager.getNetworkStatsTethering(); } catch (IllegalStateException e) { Log.wtf(TAG, "problem reading network stats", e); return new NetworkStats(0L, 10); diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java index 415cda1..92026b2 100644 --- a/services/java/com/android/server/pm/Settings.java +++ b/services/java/com/android/server/pm/Settings.java @@ -1395,9 +1395,8 @@ final class Settings { final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; final int[] gids = pkg.getGids(); - // Avoid any application that has a space in its path - // or that is handled by the system. - if (dataPath.indexOf(" ") >= 0 || ai.uid < Process.FIRST_APPLICATION_UID) + // Avoid any application that has a space in its path. + if (dataPath.indexOf(" ") >= 0) continue; // we store on each line the following information for now: diff --git a/services/java/com/android/server/power/ElectronBeam.java b/services/java/com/android/server/power/ElectronBeam.java index 0d92f66..729bd16 100644 --- a/services/java/com/android/server/power/ElectronBeam.java +++ b/services/java/com/android/server/power/ElectronBeam.java @@ -35,6 +35,7 @@ import android.util.FloatMath; import android.util.Slog; import android.view.Display; import android.view.DisplayInfo; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -94,7 +95,7 @@ final class ElectronBeam { // Texture names. We only use one texture, which contains the screenshot. private final int[] mTexNames = new int[1]; private boolean mTexNamesGenerated; - private float mTexMatrix[] = new float[16]; + private final float mTexMatrix[] = new float[16]; // Vertex and corresponding texture coordinates. // We have 4 2D vertices, so 8 elements. The vertices form a quad. @@ -515,7 +516,7 @@ final class ElectronBeam { mSurfaceControl = new SurfaceControl(mSurfaceSession, "ElectronBeam", mDisplayWidth, mDisplayHeight, PixelFormat.OPAQUE, flags); - } catch (SurfaceControl.OutOfResourcesException ex) { + } catch (OutOfResourcesException ex) { Slog.e(TAG, "Unable to create surface.", ex); return false; } @@ -525,7 +526,7 @@ final class ElectronBeam { mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight); mSurface = new Surface(); mSurface.copyFrom(mSurfaceControl); - + mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManager, mSurfaceControl); mSurfaceLayout.onDisplayTransaction(); } finally { diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index 777ffe7..2167f67 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -650,8 +650,8 @@ public final class PowerManagerService extends IPowerManager.Stub } private void applyWakeLockFlagsOnAcquireLocked(WakeLock wakeLock) { - if ((wakeLock.mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0 && - isScreenLock(wakeLock)) { + if ((wakeLock.mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0 + && isScreenLock(wakeLock)) { wakeUpNoUpdateLocked(SystemClock.uptimeMillis()); } } @@ -725,7 +725,8 @@ public final class PowerManagerService extends IPowerManager.Stub } private void applyWakeLockFlagsOnReleaseLocked(WakeLock wakeLock) { - if ((wakeLock.mFlags & PowerManager.ON_AFTER_RELEASE) != 0) { + if ((wakeLock.mFlags & PowerManager.ON_AFTER_RELEASE) != 0 + && isScreenLock(wakeLock)) { userActivityNoUpdateLocked(SystemClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS, diff --git a/services/java/com/android/server/power/WirelessChargerDetector.java b/services/java/com/android/server/power/WirelessChargerDetector.java index ac6dc3e..35920f7 100644 --- a/services/java/com/android/server/power/WirelessChargerDetector.java +++ b/services/java/com/android/server/power/WirelessChargerDetector.java @@ -21,6 +21,7 @@ import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.BatteryManager; +import android.os.SystemClock; import android.util.Slog; import java.io.PrintWriter; @@ -130,6 +131,10 @@ final class WirelessChargerDetector { private long mFirstSampleTime; private float mFirstSampleX, mFirstSampleY, mFirstSampleZ; + // The time and value of the last sample that was collected (for debugging only). + private long mLastSampleTime; + private float mLastSampleX, mLastSampleY, mLastSampleZ; + public WirelessChargerDetector(SensorManager sensorManager, SuspendBlocker suspendBlocker) { mSensorManager = sensorManager; @@ -153,6 +158,9 @@ final class WirelessChargerDetector { pw.println(" mFirstSampleTime=" + mFirstSampleTime); pw.println(" mFirstSampleX=" + mFirstSampleX + ", mFirstSampleY=" + mFirstSampleY + ", mFirstSampleZ=" + mFirstSampleZ); + pw.println(" mLastSampleTime=" + mLastSampleTime); + pw.println(" mLastSampleX=" + mLastSampleX + + ", mLastSampleY=" + mLastSampleY + ", mLastSampleZ=" + mLastSampleZ); } } @@ -224,6 +232,11 @@ final class WirelessChargerDetector { return; } + mLastSampleTime = timeNanos; + mLastSampleX = x; + mLastSampleY = y; + mLastSampleZ = z; + mTotalSamples += 1; if (mTotalSamples == 1) { // Save information about the first sample collected. @@ -310,7 +323,10 @@ final class WirelessChargerDetector { private final SensorEventListener mListener = new SensorEventListener() { @Override public void onSensorChanged(SensorEvent event) { - processSample(event.timestamp, event.values[0], event.values[1], event.values[2]); + // We use SystemClock.elapsedRealtimeNanos() instead of event.timestamp because + // on some devices the sensor HAL may produce timestamps that are not monotonic. + processSample(SystemClock.elapsedRealtimeNanos(), + event.values[0], event.values[1], event.values[2]); } @Override diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/java/com/android/server/wm/BlackFrame.java index 737d854..5aa266d 100644 --- a/services/java/com/android/server/wm/BlackFrame.java +++ b/services/java/com/android/server/wm/BlackFrame.java @@ -22,6 +22,7 @@ import android.graphics.Matrix; import android.graphics.PixelFormat; import android.graphics.Rect; import android.util.Slog; +import android.view.Surface.OutOfResourcesException; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -36,7 +37,7 @@ public class BlackFrame { final SurfaceControl surface; BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b, int layerStack) - throws SurfaceControl.OutOfResourcesException { + throws OutOfResourcesException { left = l; top = t; this.layer = layer; @@ -112,7 +113,7 @@ public class BlackFrame { } public BlackFrame(SurfaceSession session, Rect outer, Rect inner, int layer, int layerStack, - boolean forceDefaultOrientation) throws SurfaceControl.OutOfResourcesException { + boolean forceDefaultOrientation) throws OutOfResourcesException { boolean success = false; mForceDefaultOrientation = forceDefaultOrientation; diff --git a/services/java/com/android/server/wm/DisplayMagnifier.java b/services/java/com/android/server/wm/DisplayMagnifier.java index 0f51028..382d7b4 100644 --- a/services/java/com/android/server/wm/DisplayMagnifier.java +++ b/services/java/com/android/server/wm/DisplayMagnifier.java @@ -496,7 +496,7 @@ final class DisplayMagnifier { mWindowManager.getDefaultDisplay().getRealSize(mTempPoint); surfaceControl = new SurfaceControl(mWindowManagerService.mFxSession, SURFACE_TITLE, mTempPoint.x, mTempPoint.y, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN); - } catch (SurfaceControl.OutOfResourcesException oore) { + } catch (OutOfResourcesException oore) { /* ignore */ } mSurfaceControl = surfaceControl; @@ -629,7 +629,7 @@ final class DisplayMagnifier { } } catch (IllegalArgumentException iae) { /* ignore */ - } catch (OutOfResourcesException oore) { + } catch (Surface.OutOfResourcesException oore) { /* ignore */ } if (canvas == null) { @@ -644,7 +644,7 @@ final class DisplayMagnifier { canvas.drawPath(path, mPaint); mSurface.unlockCanvasAndPost(canvas); - + if (mAlpha > 0) { mSurfaceControl.show(); } else { diff --git a/services/java/com/android/server/wm/FocusedStackFrame.java b/services/java/com/android/server/wm/FocusedStackFrame.java index 9c18331..365b277 100644 --- a/services/java/com/android/server/wm/FocusedStackFrame.java +++ b/services/java/com/android/server/wm/FocusedStackFrame.java @@ -26,6 +26,7 @@ import android.graphics.Rect; import android.graphics.Region; import android.util.Slog; import android.view.Display; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -39,9 +40,9 @@ class FocusedStackFrame { private final SurfaceControl mSurfaceControl; private final Surface mSurface = new Surface(); - private Rect mLastBounds = new Rect(); - private Rect mBounds = new Rect(); - private Rect mTmpDrawRect = new Rect(); + private final Rect mLastBounds = new Rect(); + private final Rect mBounds = new Rect(); + private final Rect mTmpDrawRect = new Rect(); public FocusedStackFrame(Display display, SurfaceSession session) { SurfaceControl ctrl = null; @@ -56,7 +57,7 @@ class FocusedStackFrame { ctrl.setLayerStack(display.getLayerStack()); ctrl.setAlpha(ALPHA); mSurface.copyFrom(ctrl); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { } mSurfaceControl = ctrl; } diff --git a/services/java/com/android/server/wm/InputMonitor.java b/services/java/com/android/server/wm/InputMonitor.java index 9620612..ea3af263 100644 --- a/services/java/com/android/server/wm/InputMonitor.java +++ b/services/java/com/android/server/wm/InputMonitor.java @@ -88,7 +88,7 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { */ @Override public long notifyANR(InputApplicationHandle inputApplicationHandle, - InputWindowHandle inputWindowHandle) { + InputWindowHandle inputWindowHandle, String reason) { AppWindowToken appWindowToken = null; WindowState windowState = null; boolean aboveSystem = false; @@ -105,7 +105,8 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { if (windowState != null) { Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " - + "sending to " + windowState.mAttrs.getTitle()); + + "sending to " + windowState.mAttrs.getTitle() + + ". Reason: " + reason); // Figure out whether this window is layered above system windows. // We need to do this here to help the activity manager know how to // layer its ANR dialog. @@ -114,19 +115,21 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { aboveSystem = windowState.mBaseLayer > systemAlertLayer; } else if (appWindowToken != null) { Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " - + "sending to application " + appWindowToken.stringName); + + "sending to application " + appWindowToken.stringName + + ". Reason: " + reason); } else { - Slog.i(WindowManagerService.TAG, "Input event dispatching timed out."); + Slog.i(WindowManagerService.TAG, "Input event dispatching timed out " + + ". Reason: " + reason); } - mService.saveANRStateLocked(appWindowToken, windowState); + mService.saveANRStateLocked(appWindowToken, windowState, reason); } if (appWindowToken != null && appWindowToken.appToken != null) { try { // Notify the activity manager about the timeout and let it decide whether // to abort dispatching or keep waiting. - boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); + boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason); if (! abort) { // The activity manager declined to abort dispatching. // Wait a bit longer and timeout again later. @@ -139,7 +142,7 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { // Notify the activity manager about the timeout and let it decide whether // to abort dispatching or keep waiting. long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut( - windowState.mSession.mPid, aboveSystem); + windowState.mSession.mPid, aboveSystem, reason); if (timeout >= 0) { // The activity manager declined to abort dispatching. // Wait a bit longer and timeout again later. diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/java/com/android/server/wm/ScreenRotationAnimation.java index 7d90858..e630737 100644 --- a/services/java/com/android/server/wm/ScreenRotationAnimation.java +++ b/services/java/com/android/server/wm/ScreenRotationAnimation.java @@ -27,6 +27,7 @@ import android.graphics.Rect; import android.util.Slog; import android.view.Display; import android.view.DisplayInfo; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -262,7 +263,7 @@ class ScreenRotationAnimation { mSurfaceControl.setAlpha(0); mSurfaceControl.show(); sur.destroy(); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Slog.w(TAG, "Unable to allocate freeze surface", e); } @@ -547,7 +548,7 @@ class ScreenRotationAnimation { mCustomBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 3, layerStack, false); mCustomBlackFrame.setMatrix(mFrameInitialMatrix); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Slog.w(TAG, "Unable to allocate black surface", e); } finally { SurfaceControl.closeTransaction(); @@ -587,7 +588,7 @@ class ScreenRotationAnimation { mExitingBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 2, layerStack, mForceDefaultOrientation); mExitingBlackFrame.setMatrix(mFrameInitialMatrix); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Slog.w(TAG, "Unable to allocate black surface", e); } finally { SurfaceControl.closeTransaction(); @@ -609,7 +610,7 @@ class ScreenRotationAnimation { Rect inner = new Rect(0, 0, finalWidth, finalHeight); mEnteringBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER, layerStack, false); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Slog.w(TAG, "Unable to allocate black surface", e); } finally { SurfaceControl.closeTransaction(); @@ -894,7 +895,7 @@ class ScreenRotationAnimation { && (mMoreStartEnter || mMoreStartExit || mMoreFinishEnter || mMoreFinishExit)) || (USE_CUSTOM_BLACK_FRAME && (mMoreStartFrame || mMoreRotateFrame || mMoreFinishFrame)) - || mMoreRotateEnter || mMoreRotateExit + || mMoreRotateEnter || mMoreRotateExit || !mFinishAnimReady; mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix); diff --git a/services/java/com/android/server/wm/StrictModeFlash.java b/services/java/com/android/server/wm/StrictModeFlash.java index 31628e3..fb5876b 100644 --- a/services/java/com/android/server/wm/StrictModeFlash.java +++ b/services/java/com/android/server/wm/StrictModeFlash.java @@ -23,6 +23,7 @@ import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.Region; import android.view.Display; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -47,7 +48,7 @@ class StrictModeFlash { ctrl.setPosition(0, 0); ctrl.show(); mSurface.copyFrom(ctrl); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { } mSurfaceControl = ctrl; mDrawNeeded = true; diff --git a/services/java/com/android/server/wm/Watermark.java b/services/java/com/android/server/wm/Watermark.java index fedd314..e226e3d 100644 --- a/services/java/com/android/server/wm/Watermark.java +++ b/services/java/com/android/server/wm/Watermark.java @@ -27,10 +27,10 @@ import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.Display; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; -import android.view.Surface.OutOfResourcesException; /** * Displays a watermark on top of the window manager's windows. @@ -119,7 +119,7 @@ class Watermark { ctrl.setPosition(0, 0); ctrl.show(); mSurface.copyFrom(ctrl); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { } mSurfaceControl = ctrl; } @@ -144,11 +144,11 @@ class Watermark { try { c = mSurface.lockCanvas(dirty); } catch (IllegalArgumentException e) { - } catch (OutOfResourcesException e) { + } catch (Surface.OutOfResourcesException e) { } if (c != null) { c.drawColor(0, PorterDuff.Mode.CLEAR); - + int deltaX = mDeltaX; int deltaY = mDeltaY; diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index 34d8973..f5e0531 100644 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -116,6 +116,7 @@ import android.view.InputEventReceiver; import android.view.KeyEvent; import android.view.MagnificationSpec; import android.view.MotionEvent; +import android.view.Surface.OutOfResourcesException; import android.view.Surface; import android.view.SurfaceControl; import android.view.SurfaceSession; @@ -461,7 +462,7 @@ public class WindowManagerService extends IWindowManager.Stub // This is held as long as we have the screen frozen, to give us time to // perform a rotation animation when turning off shows the lock screen which // changes the orientation. - private PowerManager.WakeLock mScreenFrozenLock; + private final PowerManager.WakeLock mScreenFrozenLock; final AppTransition mAppTransition; boolean mStartingIconInTransition = false; @@ -664,7 +665,7 @@ public class WindowManagerService extends IWindowManager.Stub boolean mInTouchMode = true; private ViewServer mViewServer; - private ArrayList<WindowChangeListener> mWindowChangeListeners = + private final ArrayList<WindowChangeListener> mWindowChangeListeners = new ArrayList<WindowChangeListener>(); private boolean mWindowsChanged = false; @@ -6812,7 +6813,7 @@ public class WindowManagerService extends IWindowManager.Stub } else { Slog.w(TAG, "Drag already in progress"); } - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); if (mDragState != null) { mDragState.reset(); @@ -8580,12 +8581,8 @@ public class WindowManagerService extends IWindowManager.Stub mAppTransition.getStartingPoint(p); appAnimator.thumbnailX = p.x; appAnimator.thumbnailY = p.y; - } catch (SurfaceControl.OutOfResourcesException e) { - Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() - + " h=" + dirty.height(), e); - appAnimator.clearThumbnail(); - } catch (Surface.OutOfResourcesException e) { - Slog.e(TAG, "Can't allocate Canvas surface w=" + dirty.width() + } catch (OutOfResourcesException e) { + Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w=" + dirty.width() + " h=" + dirty.height(), e); appAnimator.clearThumbnail(); } @@ -10541,8 +10538,10 @@ public class WindowManagerService extends IWindowManager.Stub * * @param appWindowToken The application that ANR'd, may be null. * @param windowState The window that ANR'd, may be null. + * @param reason The reason for the ANR, may be null. */ - public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState) { + public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState, + String reason) { StringWriter sw = new StringWriter(); PrintWriter pw = new FastPrintWriter(sw, false, 1024); pw.println(" ANR time: " + DateFormat.getInstance().format(new Date())); @@ -10552,6 +10551,9 @@ public class WindowManagerService extends IWindowManager.Stub if (windowState != null) { pw.println(" Window at fault: " + windowState.mAttrs.getTitle()); } + if (reason != null) { + pw.println(" Reason: " + reason); + } pw.println(); dumpWindowsNoHeaderLocked(pw, true, null); pw.close(); diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java index 73325cb..9245542 100644 --- a/services/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/java/com/android/server/wm/WindowStateAnimator.java @@ -29,6 +29,7 @@ import android.util.Slog; import android.view.Display; import android.view.DisplayInfo; import android.view.MagnificationSpec; +import android.view.Surface.OutOfResourcesException; import android.view.SurfaceControl; import android.view.SurfaceSession; import android.view.WindowManager; @@ -480,7 +481,7 @@ class WindowStateAnimator { private final Rect mWindowCrop = new Rect(); private boolean mShown = false; private int mLayerStack; - private String mName; + private final String mName; public SurfaceTrace(SurfaceSession s, String name, int w, int h, int format, int flags) @@ -694,7 +695,7 @@ class WindowStateAnimator { + attrs.format + " flags=0x" + Integer.toHexString(flags) + " / " + this); - } catch (SurfaceControl.OutOfResourcesException e) { + } catch (OutOfResourcesException e) { mWin.mHasSurface = false; Slog.w(TAG, "OutOfResourcesException creating surface"); mService.reclaimSomeSurfaceMemoryLocked(this, "create", true); diff --git a/services/jni/Android.mk b/services/jni/Android.mk index 93d8e07..98e9b30 100644 --- a/services/jni/Android.mk +++ b/services/jni/Android.mk @@ -4,6 +4,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ com_android_server_AlarmManagerService.cpp \ com_android_server_AssetAtlasService.cpp \ + com_android_server_ConsumerIrService.cpp \ com_android_server_input_InputApplicationHandle.cpp \ com_android_server_input_InputManagerService.cpp \ com_android_server_input_InputWindowHandle.cpp \ diff --git a/services/jni/com_android_server_AssetAtlasService.cpp b/services/jni/com_android_server_AssetAtlasService.cpp index 62e950f..885d21e 100644 --- a/services/jni/com_android_server_AssetAtlasService.cpp +++ b/services/jni/com_android_server_AssetAtlasService.cpp @@ -20,6 +20,7 @@ #include "JNIHelp.h" #include <android_view_GraphicBuffer.h> +#include <cutils/log.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> diff --git a/services/jni/com_android_server_ConsumerIrService.cpp b/services/jni/com_android_server_ConsumerIrService.cpp new file mode 100644 index 0000000..004c0aa --- /dev/null +++ b/services/jni/com_android_server_ConsumerIrService.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2013 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. + */ + +#define LOG_TAG "ConsumerIrService" + +#include "jni.h" +#include "JNIHelp.h" +#include "android_runtime/AndroidRuntime.h" + +#include <stdlib.h> +#include <utils/misc.h> +#include <utils/Log.h> +#include <hardware/hardware.h> +#include <hardware/consumerir.h> +#include <ScopedPrimitiveArray.h> + +namespace android { + +static jint halOpen(JNIEnv *env, jobject obj) { + hw_module_t const* module; + consumerir_device_t *dev; + int err; + + err = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &module); + if (err != 0) { + ALOGE("Can't open consumer IR HW Module, error: %d", err); + return 0; + } + + err = module->methods->open(module, CONSUMERIR_TRANSMITTER, + (hw_device_t **) &dev); + if (err < 0) { + ALOGE("Can't open consumer IR transmitter, error: %d", err); + return 0; + } + + return reinterpret_cast<jint>(dev); +} + +static jint halTransmit(JNIEnv *env, jobject obj, jint halObject, + jint carrierFrequency, jintArray pattern) { + int ret; + + consumerir_device_t *dev = reinterpret_cast<consumerir_device_t*>(halObject); + ScopedIntArrayRO cPattern(env, pattern); + if (cPattern.get() == NULL) { + return -EINVAL; + } + jsize patternLength = cPattern.size(); + + ret = dev->transmit(dev, carrierFrequency, cPattern.get(), patternLength); + + return reinterpret_cast<jint>(ret); +} + +static jintArray halGetCarrierFrequencies(JNIEnv *env, jobject obj, + jint halObject) { + consumerir_device_t *dev = (consumerir_device_t *) halObject; + consumerir_freq_range_t *ranges; + int len; + + len = dev->get_num_carrier_freqs(dev); + if (len <= 0) + return NULL; + + ranges = new consumerir_freq_range_t[len]; + + len = dev->get_carrier_freqs(dev, len, ranges); + if (len <= 0) { + delete[] ranges; + return NULL; + } + + int i; + ScopedIntArrayRW freqsOut(env, env->NewIntArray(len*2)); + jint *arr = freqsOut.get(); + if (arr == NULL) { + delete[] ranges; + return NULL; + } + for (i = 0; i < len; i++) { + arr[i*2] = ranges[i].min; + arr[i*2+1] = ranges[i].max; + } + + delete[] ranges; + return freqsOut.getJavaArray(); +} + +static JNINativeMethod method_table[] = { + { "halOpen", "()I", (void *)halOpen }, + { "halTransmit", "(II[I)I", (void *)halTransmit }, + { "halGetCarrierFrequencies", "(I)[I", (void *)halGetCarrierFrequencies}, +}; + +int register_android_server_ConsumerIrService(JNIEnv *env) { + return jniRegisterNativeMethods(env, "com/android/server/ConsumerIrService", + method_table, NELEM(method_table)); +} + +}; diff --git a/services/jni/com_android_server_UsbDeviceManager.cpp b/services/jni/com_android_server_UsbDeviceManager.cpp index 0014db5..3551733 100644 --- a/services/jni/com_android_server_UsbDeviceManager.cpp +++ b/services/jni/com_android_server_UsbDeviceManager.cpp @@ -20,6 +20,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" +#include "android_runtime/Log.h" #include <stdio.h> #include <asm/byteorder.h> diff --git a/services/jni/com_android_server_UsbHostManager.cpp b/services/jni/com_android_server_UsbHostManager.cpp index d0a6cdf..639790b 100644 --- a/services/jni/com_android_server_UsbHostManager.cpp +++ b/services/jni/com_android_server_UsbHostManager.cpp @@ -20,6 +20,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" +#include "android_runtime/Log.h" #include "utils/Vector.h" #include <usbhost/usbhost.h> diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp index 09e5be4..4ab2086 100644 --- a/services/jni/com_android_server_input_InputManagerService.cpp +++ b/services/jni/com_android_server_input_InputManagerService.cpp @@ -29,6 +29,7 @@ #include "jni.h" #include <limits.h> #include <android_runtime/AndroidRuntime.h> +#include <android_runtime/Log.h> #include <utils/Log.h> #include <utils/Looper.h> @@ -191,7 +192,8 @@ public: uint32_t policyFlags); virtual void notifyConfigurationChanged(nsecs_t when); virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, - const sp<InputWindowHandle>& inputWindowHandle); + const sp<InputWindowHandle>& inputWindowHandle, + const String8& reason); virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle); virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags); virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig); @@ -553,7 +555,7 @@ void NativeInputManager::notifyConfigurationChanged(nsecs_t when) { } nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, - const sp<InputWindowHandle>& inputWindowHandle) { + const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) { #if DEBUG_INPUT_DISPATCHER_POLICY ALOGD("notifyANR"); #endif @@ -564,15 +566,18 @@ nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApp getInputApplicationHandleObjLocalRef(env, inputApplicationHandle); jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); + jstring reasonObj = env->NewStringUTF(reason.string()); jlong newTimeout = env->CallLongMethod(mServiceObj, - gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj); + gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj, + reasonObj); if (checkAndClearExceptionFromCallback(env, "notifyANR")) { newTimeout = 0; // abort dispatch } else { assert(newTimeout >= 0); } + env->DeleteLocalRef(reasonObj); env->DeleteLocalRef(inputWindowHandleObj); env->DeleteLocalRef(inputApplicationHandleObj); return newTimeout; @@ -1379,7 +1384,7 @@ int register_android_server_InputManager(JNIEnv* env) { GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz, "notifyANR", - "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J"); + "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J"); GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz, "filterInputEvent", "(Landroid/view/InputEvent;I)Z"); diff --git a/services/jni/com_android_server_location_FlpHardwareProvider.cpp b/services/jni/com_android_server_location_FlpHardwareProvider.cpp index b403ee6..ac269eb 100644 --- a/services/jni/com_android_server_location_FlpHardwareProvider.cpp +++ b/services/jni/com_android_server_location_FlpHardwareProvider.cpp @@ -23,6 +23,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" +#include "android_runtime/Log.h" #include "hardware/fused_location.h" #include "hardware_legacy/power.h" @@ -318,7 +319,7 @@ static void TranslateGeofenceFromGeofenceHardwareRequestParcelable( jmethodID getNotificationResponsiveness = env->GetMethodID( geofenceRequestClass, "getNotificationResponsiveness", - "()D"); + "()I"); options->notification_responsivenes_ms = env->CallIntMethod( geofenceRequestObject, getNotificationResponsiveness); diff --git a/services/jni/com_android_server_location_GpsLocationProvider.cpp b/services/jni/com_android_server_location_GpsLocationProvider.cpp index 98de12a..aec254b 100644 --- a/services/jni/com_android_server_location_GpsLocationProvider.cpp +++ b/services/jni/com_android_server_location_GpsLocationProvider.cpp @@ -26,6 +26,7 @@ #include "utils/Log.h" #include "utils/misc.h" #include "android_runtime/AndroidRuntime.h" +#include "android_runtime/Log.h" #include <string.h> #include <pthread.h> diff --git a/services/jni/com_android_server_power_PowerManagerService.cpp b/services/jni/com_android_server_power_PowerManagerService.cpp index 88b13b5..151e134 100644 --- a/services/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/jni/com_android_server_power_PowerManagerService.cpp @@ -26,6 +26,7 @@ #include <limits.h> #include <android_runtime/AndroidRuntime.h> +#include <android_runtime/Log.h> #include <utils/Timers.h> #include <utils/misc.h> #include <utils/String8.h> diff --git a/services/jni/onload.cpp b/services/jni/onload.cpp index 5427277..efc34a2 100644 --- a/services/jni/onload.cpp +++ b/services/jni/onload.cpp @@ -21,6 +21,7 @@ namespace android { int register_android_server_AlarmManagerService(JNIEnv* env); +int register_android_server_ConsumerIrService(JNIEnv *env); int register_android_server_InputApplicationHandle(JNIEnv* env); int register_android_server_InputWindowHandle(JNIEnv* env); int register_android_server_InputManager(JNIEnv* env); @@ -65,6 +66,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) register_android_server_location_FlpHardwareProvider(env); register_android_server_connectivity_Vpn(env); register_android_server_AssetAtlasService(env); + register_android_server_ConsumerIrService(env); + return JNI_VERSION_1_4; } diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java index a9909b2..a1af8cb 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java @@ -40,7 +40,6 @@ import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.WEEK_IN_MILLIS; import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL; import static org.easymock.EasyMock.anyLong; -import static org.easymock.EasyMock.aryEq; import static org.easymock.EasyMock.capture; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; @@ -74,13 +73,13 @@ import com.android.server.net.NetworkStatsService; import com.android.server.net.NetworkStatsService.NetworkStatsSettings; import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config; +import libcore.io.IoUtils; + import org.easymock.Capture; import org.easymock.EasyMock; import java.io.File; -import libcore.io.IoUtils; - /** * Tests for {@link NetworkStatsService}. */ @@ -919,8 +918,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase { expect(mNetManager.getNetworkStatsUidDetail(eq(UID_ALL))).andReturn(detail).atLeastOnce(); // also include tethering details, since they are folded into UID - expect(mConnManager.getTetheredIfacePairs()).andReturn(tetherIfacePairs).atLeastOnce(); - expect(mNetManager.getNetworkStatsTethering(aryEq(tetherIfacePairs))) + expect(mNetManager.getNetworkStatsTethering()) .andReturn(tetherStats).atLeastOnce(); } |