diff options
Diffstat (limited to 'core')
21 files changed, 640 insertions, 83 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index ff6dd32..a4e6219 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -1179,6 +1179,142 @@ public class ConnectivityManager { return true; } + /** @hide */ + public static class PacketKeepaliveCallback { + /** The requested keepalive was successfully started. */ + public void onStarted() {} + /** The keepalive was successfully stopped. */ + public void onStopped() {} + /** An error occurred. */ + public void onError(int error) {} + } + + /** + * Allows applications to request that the system periodically send specific packets on their + * behalf, using hardware offload to save battery power. + * + * To request that the system send keepalives, call one of the methods that return a + * {@link ConnectivityManager.PacketKeepalive} object, such as {@link #startNattKeepalive}, + * passing in a non-null callback. If the callback is successfully started, the callback's + * {@code onStarted} method will be called. If an error occurs, {@code onError} will be called, + * specifying one of the {@code ERROR_*} constants in this class. + * + * To stop an existing keepalive, call {@link stop}. The system will call {@code onStopped} if + * the operation was successfull or {@code onError} if an error occurred. + * + * @hide + */ + public class PacketKeepalive { + + private static final String TAG = "PacketKeepalive"; + + /** @hide */ + public static final int SUCCESS = 0; + + /** @hide */ + public static final int NO_KEEPALIVE = -1; + + /** @hide */ + public static final int BINDER_DIED = -10; + + /** The specified {@code Network} is not connected. */ + public static final int ERROR_INVALID_NETWORK = -20; + /** The specified IP addresses are invalid. For example, the specified source IP address is + * not configured on the specified {@code Network}. */ + public static final int ERROR_INVALID_IP_ADDRESS = -21; + /** The requested port is invalid. */ + public static final int ERROR_INVALID_PORT = -22; + /** The packet length is invalid (e.g., too long). */ + public static final int ERROR_INVALID_LENGTH = -23; + /** The packet transmission interval is invalid (e.g., too short). */ + public static final int ERROR_INVALID_INTERVAL = -24; + + /** The hardware does not support this request. */ + public static final int ERROR_HARDWARE_UNSUPPORTED = -30; + + public static final int NATT_PORT = 4500; + + private final Network mNetwork; + private final PacketKeepaliveCallback mCallback; + private final Looper mLooper; + private final Messenger mMessenger; + + private volatile Integer mSlot; + + void stopLooper() { + mLooper.quit(); + } + + public void stop() { + try { + mService.stopKeepalive(mNetwork, mSlot); + } catch (RemoteException e) { + Log.e(TAG, "Error stopping packet keepalive: ", e); + stopLooper(); + } + } + + private PacketKeepalive(Network network, PacketKeepaliveCallback callback) { + checkNotNull(network, "network cannot be null"); + checkNotNull(callback, "callback cannot be null"); + mNetwork = network; + mCallback = callback; + HandlerThread thread = new HandlerThread(TAG); + thread.start(); + mLooper = thread.getLooper(); + mMessenger = new Messenger(new Handler(mLooper) { + @Override + public void handleMessage(Message message) { + switch (message.what) { + case NetworkAgent.EVENT_PACKET_KEEPALIVE: + int error = message.arg2; + try { + if (error == SUCCESS) { + if (mSlot == null) { + mSlot = message.arg1; + mCallback.onStarted(); + } else { + mSlot = null; + stopLooper(); + mCallback.onStopped(); + } + } else { + stopLooper(); + mCallback.onError(error); + } + } catch (Exception e) { + Log.e(TAG, "Exception in keepalive callback(" + error + ")", e); + } + break; + default: + Log.e(TAG, "Unhandled message " + Integer.toHexString(message.what)); + break; + } + } + }); + } + } + + /** + * Starts an IPsec NAT-T keepalive packet with the specified parameters. + * + * @hide + */ + public PacketKeepalive startNattKeepalive( + Network network, int intervalSeconds, PacketKeepaliveCallback callback, + InetAddress srcAddr, int srcPort, InetAddress dstAddr) { + final PacketKeepalive k = new PacketKeepalive(network, callback); + try { + mService.startNattKeepalive(network, intervalSeconds, k.mMessenger, new Binder(), + srcAddr.getHostAddress(), srcPort, dstAddr.getHostAddress()); + } catch (RemoteException e) { + Log.e(TAG, "Error starting packet keepalive: ", e); + k.stopLooper(); + return null; + } + return k; + } + /** * Ensure that a network route exists to deliver traffic to the specified * host via the specified network interface. An attempt to add a route that diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 46c28a6..d4dd669 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -160,4 +160,9 @@ interface IConnectivityManager boolean setUnderlyingNetworksForVpn(in Network[] networks); void factoryReset(); + + void startNattKeepalive(in Network network, int intervalSeconds, in Messenger messenger, + in IBinder binder, String srcAddr, int srcPort, String dstAddr); + + void stopKeepalive(in Network network, int slot); } diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java index 808a882..20c2168 100644 --- a/core/java/android/net/NetworkAgent.java +++ b/core/java/android/net/NetworkAgent.java @@ -17,6 +17,7 @@ package android.net; import android.content.Context; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -25,6 +26,7 @@ import android.util.Log; import com.android.internal.util.AsyncChannel; import com.android.internal.util.Protocol; +import android.net.ConnectivityManager.PacketKeepalive; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; @@ -143,17 +145,60 @@ public abstract class NetworkAgent extends Handler { */ public static final int CMD_SAVE_ACCEPT_UNVALIDATED = BASE + 9; - /** Sent by ConnectivityService to the NetworkAgent to inform the agent to pull + /** + * Sent by ConnectivityService to the NetworkAgent to inform the agent to pull * the underlying network connection for updated bandwidth information. */ public static final int CMD_REQUEST_BANDWIDTH_UPDATE = BASE + 10; /** + * Sent by ConnectivityService to the NetworkAgent to request that the specified packet be sent + * periodically on the given interval. + * + * arg1 = the slot number of the keepalive to start + * arg2 = interval in seconds + * obj = KeepalivePacketData object describing the data to be sent + * + * Also used internally by ConnectivityService / KeepaliveTracker, with different semantics. + */ + public static final int CMD_START_PACKET_KEEPALIVE = BASE + 11; + + /** + * Requests that the specified keepalive packet be stopped. + * + * arg1 = slot number of the keepalive to stop. + * + * Also used internally by ConnectivityService / KeepaliveTracker, with different semantics. + */ + public static final int CMD_STOP_PACKET_KEEPALIVE = BASE + 12; + + /** + * Sent by the NetworkAgent to ConnectivityService to provide status on a packet keepalive + * request. This may either be the reply to a CMD_START_PACKET_KEEPALIVE, or an asynchronous + * error notification. + * + * This is also sent by KeepaliveTracker to the app's ConnectivityManager.PacketKeepalive to + * so that the app's PacketKeepaliveCallback methods can be called. + * + * arg1 = slot number of the keepalive + * arg2 = error code + */ + public static final int EVENT_PACKET_KEEPALIVE = BASE + 13; + + /** + * Sent by ConnectivityService to inform this network transport of signal strength thresholds + * that when crossed should trigger a system wakeup and a NetworkCapabilities update. + * + * obj = int[] describing signal strength thresholds. + */ + public static final int CMD_SET_SIGNAL_STRENGTH_THRESHOLDS = BASE + 14; + + /** * Sent by ConnectivityService to the NeworkAgent to inform the agent to avoid * automatically reconnecting to this network (e.g. via autojoin). Happens * when user selects "No" option on the "Stay connected?" dialog box. */ - public static final int CMD_PREVENT_AUTOMATIC_RECONNECT = BASE + 11; + public static final int CMD_PREVENT_AUTOMATIC_RECONNECT = BASE + 15; public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni, NetworkCapabilities nc, LinkProperties lp, int score) { @@ -249,6 +294,27 @@ public abstract class NetworkAgent extends Handler { saveAcceptUnvalidated(msg.arg1 != 0); break; } + case CMD_START_PACKET_KEEPALIVE: { + startPacketKeepalive(msg); + break; + } + case CMD_STOP_PACKET_KEEPALIVE: { + stopPacketKeepalive(msg); + break; + } + + case CMD_SET_SIGNAL_STRENGTH_THRESHOLDS: { + ArrayList<Integer> thresholds = + ((Bundle) msg.obj).getIntegerArrayList("thresholds"); + // TODO: Change signal strength thresholds API to use an ArrayList<Integer> + // rather than convert to int[]. + int[] intThresholds = new int[(thresholds != null) ? thresholds.size() : 0]; + for (int i = 0; i < intThresholds.length; i++) { + intThresholds[i] = thresholds.get(i); + } + setSignalStrengthThresholds(intThresholds); + break; + } case CMD_PREVENT_AUTOMATIC_RECONNECT: { preventAutomaticReconnect(); break; @@ -257,13 +323,27 @@ public abstract class NetworkAgent extends Handler { } private void queueOrSendMessage(int what, Object obj) { + queueOrSendMessage(what, 0, 0, obj); + } + + private void queueOrSendMessage(int what, int arg1, int arg2) { + queueOrSendMessage(what, arg1, arg2, null); + } + + private void queueOrSendMessage(int what, int arg1, int arg2, Object obj) { + Message msg = Message.obtain(); + msg.what = what; + msg.arg1 = arg1; + msg.arg2 = arg2; + msg.obj = obj; + queueOrSendMessage(msg); + } + + private void queueOrSendMessage(Message msg) { synchronized (mPreConnectedQueue) { if (mAsyncChannel != null) { - mAsyncChannel.sendMessage(what, obj); + mAsyncChannel.sendMessage(msg); } else { - Message msg = Message.obtain(); - msg.what = what; - msg.obj = obj; mPreConnectedQueue.add(msg); } } @@ -378,6 +458,34 @@ public abstract class NetworkAgent extends Handler { } /** + * Requests that the network hardware send the specified packet at the specified interval. + */ + protected void startPacketKeepalive(Message msg) { + onPacketKeepaliveEvent(msg.arg1, PacketKeepalive.ERROR_HARDWARE_UNSUPPORTED); + } + + /** + * Requests that the network hardware send the specified packet at the specified interval. + */ + protected void stopPacketKeepalive(Message msg) { + onPacketKeepaliveEvent(msg.arg1, PacketKeepalive.ERROR_HARDWARE_UNSUPPORTED); + } + + /** + * Called by the network when a packet keepalive event occurs. + */ + public void onPacketKeepaliveEvent(int slot, int reason) { + queueOrSendMessage(EVENT_PACKET_KEEPALIVE, slot, reason); + } + + /** + * Called by ConnectivityService to inform this network transport of signal strength thresholds + * that when crossed should trigger a system wakeup and a NetworkCapabilities update. + */ + protected void setSignalStrengthThresholds(int[] thresholds) { + } + + /** * Called when the user asks to not stay connected to this network because it was found to not * provide Internet access. Usually followed by call to {@code unwanted}. The transport is * responsible for making sure the device does not automatically reconnect to the same network diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java index 29b063a..a6d477f 100644 --- a/core/java/android/net/NetworkCapabilities.java +++ b/core/java/android/net/NetworkCapabilities.java @@ -48,6 +48,7 @@ public final class NetworkCapabilities implements Parcelable { mLinkUpBandwidthKbps = nc.mLinkUpBandwidthKbps; mLinkDownBandwidthKbps = nc.mLinkDownBandwidthKbps; mNetworkSpecifier = nc.mNetworkSpecifier; + mSignalStrength = nc.mSignalStrength; } } @@ -60,6 +61,7 @@ public final class NetworkCapabilities implements Parcelable { mNetworkCapabilities = mTransportTypes = 0; mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0; mNetworkSpecifier = null; + mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED; } /** @@ -184,6 +186,28 @@ public final class NetworkCapabilities implements Parcelable { private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_CAPTIVE_PORTAL; /** + * Network capabilities that are expected to be mutable, i.e., can change while a particular + * network is connected. + */ + private static final long MUTABLE_CAPABILITIES = + // TRUSTED can change when user explicitly connects to an untrusted network in Settings. + // http://b/18206275 + (1 << NET_CAPABILITY_TRUSTED) | + (1 << NET_CAPABILITY_VALIDATED) | + (1 << NET_CAPABILITY_CAPTIVE_PORTAL); + + /** + * Network capabilities that are not allowed in NetworkRequests. This exists because the + * NetworkFactory / NetworkAgent model does not deal well with the situation where a + * capability's presence cannot be known in advance. If such a capability is requested, then we + * can get into a cycle where the NetworkFactory endlessly churns out NetworkAgents that then + * get immediately torn down because they do not have the requested capability. + */ + private static final long NON_REQUESTABLE_CAPABILITIES = + (1 << NET_CAPABILITY_VALIDATED) | + (1 << NET_CAPABILITY_CAPTIVE_PORTAL); + + /** * Capabilities that are set by default when the object is constructed. */ private static final long DEFAULT_CAPABILITIES = @@ -278,8 +302,31 @@ public final class NetworkCapabilities implements Parcelable { this.mNetworkCapabilities |= nc.mNetworkCapabilities; } - private boolean satisfiedByNetCapabilities(NetworkCapabilities nc) { - return ((nc.mNetworkCapabilities & this.mNetworkCapabilities) == this.mNetworkCapabilities); + /** + * Convenience function that returns a human-readable description of the first mutable + * capability we find. Used to present an error message to apps that request mutable + * capabilities. + * + * @hide + */ + public String describeFirstNonRequestableCapability() { + if (hasCapability(NET_CAPABILITY_VALIDATED)) return "NET_CAPABILITY_VALIDATED"; + if (hasCapability(NET_CAPABILITY_CAPTIVE_PORTAL)) return "NET_CAPABILITY_CAPTIVE_PORTAL"; + // This cannot happen unless the preceding checks are incomplete. + if ((mNetworkCapabilities & NON_REQUESTABLE_CAPABILITIES) != 0) { + return "unknown non-requestable capabilities " + Long.toHexString(mNetworkCapabilities); + } + if (mLinkUpBandwidthKbps != 0 || mLinkDownBandwidthKbps != 0) return "link bandwidth"; + if (hasSignalStrength()) return "signalStrength"; + return null; + } + + private boolean satisfiedByNetCapabilities(NetworkCapabilities nc, boolean onlyImmutable) { + long networkCapabilities = this.mNetworkCapabilities; + if (onlyImmutable) { + networkCapabilities = networkCapabilities & ~MUTABLE_CAPABILITIES; + } + return ((nc.mNetworkCapabilities & networkCapabilities) == networkCapabilities); } /** @hide */ @@ -287,6 +334,11 @@ public final class NetworkCapabilities implements Parcelable { return (nc.mNetworkCapabilities == this.mNetworkCapabilities); } + private boolean equalsNetCapabilitiesImmutable(NetworkCapabilities that) { + return ((this.mNetworkCapabilities & ~MUTABLE_CAPABILITIES) == + (that.mNetworkCapabilities & ~MUTABLE_CAPABILITIES)); + } + /** * Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are * typically provided by restricted networks. @@ -551,26 +603,130 @@ public final class NetworkCapabilities implements Parcelable { } /** + * Magic value that indicates no signal strength provided. A request specifying this value is + * always satisfied. + * + * @hide + */ + public static final int SIGNAL_STRENGTH_UNSPECIFIED = Integer.MIN_VALUE; + + /** + * Signal strength. This is a signed integer, and higher values indicate better signal. + * The exact units are bearer-dependent. For example, Wi-Fi uses RSSI. + */ + private int mSignalStrength; + + /** + * Sets the signal strength. This is a signed integer, with higher values indicating a stronger + * signal. The exact units are bearer-dependent. For example, Wi-Fi uses the same RSSI units + * reported by WifiManager. + * <p> + * Note that when used to register a network callback, this specifies the minimum acceptable + * signal strength. When received as the state of an existing network it specifies the current + * value. A value of code SIGNAL_STRENGTH_UNSPECIFIED} means no value when received and has no + * effect when requesting a callback. + * + * @param signalStrength the bearer-specific signal strength. + * @hide + */ + public void setSignalStrength(int signalStrength) { + mSignalStrength = signalStrength; + } + + /** + * Returns {@code true} if this object specifies a signal strength. + * + * @hide + */ + public boolean hasSignalStrength() { + return mSignalStrength > SIGNAL_STRENGTH_UNSPECIFIED; + } + + /** + * Retrieves the signal strength. + * + * @return The bearer-specific signal strength. + * @hide + */ + public int getSignalStrength() { + return mSignalStrength; + } + + private void combineSignalStrength(NetworkCapabilities nc) { + this.mSignalStrength = Math.max(this.mSignalStrength, nc.mSignalStrength); + } + + private boolean satisfiedBySignalStrength(NetworkCapabilities nc) { + return this.mSignalStrength <= nc.mSignalStrength; + } + + private boolean equalsSignalStrength(NetworkCapabilities nc) { + return this.mSignalStrength == nc.mSignalStrength; + } + + /** * Combine a set of Capabilities to this one. Useful for coming up with the complete set - * {@hide} + * @hide */ public void combineCapabilities(NetworkCapabilities nc) { combineNetCapabilities(nc); combineTransportTypes(nc); combineLinkBandwidths(nc); combineSpecifiers(nc); + combineSignalStrength(nc); } /** - * Check if our requirements are satisfied by the given Capabilities. - * {@hide} + * Check if our requirements are satisfied by the given {@code NetworkCapabilities}. + * + * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements. + * @param onlyImmutable if {@code true}, do not consider mutable requirements such as link + * bandwidth, signal strength, or validation / captive portal status. + * + * @hide */ - public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc) { + private boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc, boolean onlyImmutable) { return (nc != null && - satisfiedByNetCapabilities(nc) && + satisfiedByNetCapabilities(nc, onlyImmutable) && satisfiedByTransportTypes(nc) && - satisfiedByLinkBandwidths(nc) && - satisfiedBySpecifier(nc)); + (onlyImmutable || satisfiedByLinkBandwidths(nc)) && + satisfiedBySpecifier(nc) && + (onlyImmutable || satisfiedBySignalStrength(nc))); + } + + /** + * Check if our requirements are satisfied by the given {@code NetworkCapabilities}. + * + * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements. + * + * @hide + */ + public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc) { + return satisfiedByNetworkCapabilities(nc, false); + } + + /** + * Check if our immutable requirements are satisfied by the given {@code NetworkCapabilities}. + * + * @param nc the {@code NetworkCapabilities} that may or may not satisfy our requirements. + * + * @hide + */ + public boolean satisfiedByImmutableNetworkCapabilities(NetworkCapabilities nc) { + return satisfiedByNetworkCapabilities(nc, true); + } + + /** + * Checks that our immutable capabilities are the same as those of the given + * {@code NetworkCapabilities}. + * + * @hide + */ + public boolean equalImmutableCapabilities(NetworkCapabilities nc) { + if (nc == null) return false; + return (equalsNetCapabilitiesImmutable(nc) && + equalsTransportTypes(nc) && + equalsSpecifier(nc)); } @Override @@ -580,6 +736,7 @@ public final class NetworkCapabilities implements Parcelable { return (equalsNetCapabilities(that) && equalsTransportTypes(that) && equalsLinkBandwidths(that) && + equalsSignalStrength(that) && equalsSpecifier(that)); } @@ -591,7 +748,8 @@ public final class NetworkCapabilities implements Parcelable { ((int)(mTransportTypes >> 32) * 7) + (mLinkUpBandwidthKbps * 11) + (mLinkDownBandwidthKbps * 13) + - (TextUtils.isEmpty(mNetworkSpecifier) ? 0 : mNetworkSpecifier.hashCode() * 17)); + (TextUtils.isEmpty(mNetworkSpecifier) ? 0 : mNetworkSpecifier.hashCode() * 17) + + (mSignalStrength * 19)); } @Override @@ -605,7 +763,9 @@ public final class NetworkCapabilities implements Parcelable { dest.writeInt(mLinkUpBandwidthKbps); dest.writeInt(mLinkDownBandwidthKbps); dest.writeString(mNetworkSpecifier); + dest.writeInt(mSignalStrength); } + public static final Creator<NetworkCapabilities> CREATOR = new Creator<NetworkCapabilities>() { @Override @@ -617,6 +777,7 @@ public final class NetworkCapabilities implements Parcelable { netCap.mLinkUpBandwidthKbps = in.readInt(); netCap.mLinkDownBandwidthKbps = in.readInt(); netCap.mNetworkSpecifier = in.readString(); + netCap.mSignalStrength = in.readInt(); return netCap; } @Override @@ -674,6 +835,8 @@ public final class NetworkCapabilities implements Parcelable { String specifier = (mNetworkSpecifier == null ? "" : " Specifier: <" + mNetworkSpecifier + ">"); - return "[" + transports + capabilities + upBand + dnBand + specifier + "]"; + String signalStrength = (hasSignalStrength() ? " SignalStrength: " + mSignalStrength : ""); + + return "[" + transports + capabilities + upBand + dnBand + specifier + signalStrength + "]"; } } diff --git a/core/java/android/net/NetworkRequest.java b/core/java/android/net/NetworkRequest.java index e184ec4..7da4818 100644 --- a/core/java/android/net/NetworkRequest.java +++ b/core/java/android/net/NetworkRequest.java @@ -191,6 +191,24 @@ public class NetworkRequest implements Parcelable { mNetworkCapabilities.setNetworkSpecifier(networkSpecifier); return this; } + + /** + * Sets the signal strength. This is a signed integer, with higher values indicating a + * stronger signal. The exact units are bearer-dependent. For example, Wi-Fi uses the same + * RSSI units reported by WifiManager. + * <p> + * Note that when used to register a network callback, this specifies the minimum acceptable + * signal strength. When received as the state of an existing network it specifies the + * current value. A value of {@code SIGNAL_STRENGTH_UNSPECIFIED} means no value when + * received and has no effect when requesting a callback. + * + * @param signalStrength the bearer-specific signal strength. + * @hide + */ + public Builder setSignalStrength(int signalStrength) { + mNetworkCapabilities.setSignalStrength(signalStrength); + return this; + } } // implement the Parcelable interface diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java index cccc4be..1f3e9a7 100644 --- a/core/java/android/os/BatteryManager.java +++ b/core/java/android/os/BatteryManager.java @@ -101,6 +101,13 @@ public class BatteryManager { */ public static final String EXTRA_INVALID_CHARGER = "invalid_charger"; + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * Int value set to the maximum charging current supported by the charger in micro amperes. + * {@hide} + */ + public static final String EXTRA_MAX_CHARGING_CURRENT = "max_charging_current"; + // values for "status" field in the ACTION_BATTERY_CHANGED Intent public static final int BATTERY_STATUS_UNKNOWN = 1; public static final int BATTERY_STATUS_CHARGING = 2; diff --git a/core/java/android/os/BatteryProperties.java b/core/java/android/os/BatteryProperties.java index 8f5cf8b..29e868c 100644 --- a/core/java/android/os/BatteryProperties.java +++ b/core/java/android/os/BatteryProperties.java @@ -22,6 +22,7 @@ public class BatteryProperties implements Parcelable { public boolean chargerAcOnline; public boolean chargerUsbOnline; public boolean chargerWirelessOnline; + public int maxChargingCurrent; public int batteryStatus; public int batteryHealth; public boolean batteryPresent; @@ -37,6 +38,7 @@ public class BatteryProperties implements Parcelable { chargerAcOnline = other.chargerAcOnline; chargerUsbOnline = other.chargerUsbOnline; chargerWirelessOnline = other.chargerWirelessOnline; + maxChargingCurrent = other.maxChargingCurrent; batteryStatus = other.batteryStatus; batteryHealth = other.batteryHealth; batteryPresent = other.batteryPresent; @@ -55,6 +57,7 @@ public class BatteryProperties implements Parcelable { chargerAcOnline = p.readInt() == 1 ? true : false; chargerUsbOnline = p.readInt() == 1 ? true : false; chargerWirelessOnline = p.readInt() == 1 ? true : false; + maxChargingCurrent = p.readInt(); batteryStatus = p.readInt(); batteryHealth = p.readInt(); batteryPresent = p.readInt() == 1 ? true : false; @@ -68,6 +71,7 @@ public class BatteryProperties implements Parcelable { p.writeInt(chargerAcOnline ? 1 : 0); p.writeInt(chargerUsbOnline ? 1 : 0); p.writeInt(chargerWirelessOnline ? 1 : 0); + p.writeInt(maxChargingCurrent); p.writeInt(batteryStatus); p.writeInt(batteryHealth); p.writeInt(batteryPresent ? 1 : 0); diff --git a/core/java/android/os/storage/IMountService.java b/core/java/android/os/storage/IMountService.java index fce09dd..9f71ce1 100644 --- a/core/java/android/os/storage/IMountService.java +++ b/core/java/android/os/storage/IMountService.java @@ -1180,6 +1180,37 @@ public interface IMountService extends IInterface { _data.recycle(); } } + + @Override + public void createNewUserDir(int userHandle, String path) throws RemoteException { + Parcel _data = Parcel.obtain(); + Parcel _reply = Parcel.obtain(); + try { + _data.writeInterfaceToken(DESCRIPTOR); + _data.writeInt(userHandle); + _data.writeString(path); + mRemote.transact(Stub.TRANSACTION_createNewUserDir, _data, _reply, 0); + _reply.readException(); + } finally { + _reply.recycle(); + _data.recycle(); + } + } + + @Override + public void deleteUserKey(int userHandle) throws RemoteException { + Parcel _data = Parcel.obtain(); + Parcel _reply = Parcel.obtain(); + try { + _data.writeInterfaceToken(DESCRIPTOR); + _data.writeInt(userHandle); + mRemote.transact(Stub.TRANSACTION_deleteUserKey, _data, _reply, 0); + _reply.readException(); + } finally { + _reply.recycle(); + _data.recycle(); + } + } } private static final String DESCRIPTOR = "IMountService"; @@ -1295,6 +1326,9 @@ public interface IMountService extends IInterface { static final int TRANSACTION_benchmark = IBinder.FIRST_CALL_TRANSACTION + 59; static final int TRANSACTION_setDebugFlags = IBinder.FIRST_CALL_TRANSACTION + 60; + static final int TRANSACTION_createNewUserDir = IBinder.FIRST_CALL_TRANSACTION + 62; + static final int TRANSACTION_deleteUserKey = IBinder.FIRST_CALL_TRANSACTION + 63; + /** * Cast an IBinder object into an IMountService interface, generating a * proxy if needed. @@ -1850,6 +1884,21 @@ public interface IMountService extends IInterface { reply.writeNoException(); return true; } + case TRANSACTION_createNewUserDir: { + data.enforceInterface(DESCRIPTOR); + int userHandle = data.readInt(); + String path = data.readString(); + createNewUserDir(userHandle, path); + reply.writeNoException(); + return true; + } + case TRANSACTION_deleteUserKey: { + data.enforceInterface(DESCRIPTOR); + int userHandle = data.readInt(); + deleteUserKey(userHandle); + reply.writeNoException(); + return true; + } } return super.onTransact(code, data, reply, flags); } @@ -2159,4 +2208,19 @@ public interface IMountService extends IInterface { public String getPrimaryStorageUuid() throws RemoteException; public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback) throws RemoteException; + + /** + * Creates the user data directory, possibly encrypted + * @param userHandle Handle of the user whose directory we are creating + * @param path Path at which to create the directory. + */ + public void createNewUserDir(int userHandle, String path) + throws RemoteException; + + /** + * Securely delete the user's encryption key + * @param userHandle Handle of the user whose key we are deleting + */ + public void deleteUserKey(int userHandle) + throws RemoteException; } diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index d1f3743..1d92453 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -960,6 +960,24 @@ public class StorageManager { } /** {@hide} */ + public void createNewUserDir(int userHandle, File path) { + try { + mMountService.createNewUserDir(userHandle, path.getAbsolutePath()); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } + } + + /** {@hide} */ + public void deleteUserKey(int userHandle) { + try { + mMountService.deleteUserKey(userHandle); + } catch (RemoteException e) { + throw e.rethrowAsRuntimeException(); + } + } + + /** {@hide} */ public static File maybeTranslateEmulatedPathToInternal(File path) { final IMountService mountService = IMountService.Stub.asInterface( ServiceManager.getService("mount")); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index fe95864..78be3cd 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -5712,6 +5712,13 @@ public final class Settings { public static final String ASSISTANT = "assistant"; /** + * Whether the camera launch gesture should be disabled. + * + * @hide + */ + public static final String CAMERA_GESTURE_DISABLED = "camera_gesture_disabled"; + + /** * This are the settings to be backed up. * * NOTE: Settings are backed up and restored in the order they appear @@ -5767,6 +5774,7 @@ public final class Settings { MOUNT_UMS_NOTIFY_ENABLED, SLEEP_TIMEOUT, DOUBLE_TAP_TO_WAKE, + CAMERA_GESTURE_DISABLED, }; /** diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 6b07a47..fc15b964 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -20,6 +20,10 @@ ifneq ($(ENABLE_CPUSETS),) LOCAL_CFLAGS += -DENABLE_CPUSETS endif +ifneq ($(ENABLE_SCHED_BOOST),) + LOCAL_CFLAGS += -DENABLE_SCHED_BOOST +endif + LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -DU_USING_ICU_NAMESPACE=0 diff --git a/core/jni/android_hardware_SensorManager.cpp b/core/jni/android_hardware_SensorManager.cpp index ec56507..7d0afdc 100644 --- a/core/jni/android_hardware_SensorManager.cpp +++ b/core/jni/android_hardware_SensorManager.cpp @@ -138,7 +138,7 @@ nativeCreate (JNIEnv *env, jclass clazz, jstring opPackageName) { ScopedUtfChars opPackageNameUtf(env, opPackageName); - return (jlong) new SensorManager(String16(opPackageNameUtf.c_str())); + return (jlong) &SensorManager::getInstanceForPackage(String16(opPackageNameUtf.c_str())); } static jboolean diff --git a/core/jni/android_hardware_camera2_DngCreator.cpp b/core/jni/android_hardware_camera2_DngCreator.cpp index ba08237..e10a644 100644 --- a/core/jni/android_hardware_camera2_DngCreator.cpp +++ b/core/jni/android_hardware_camera2_DngCreator.cpp @@ -20,6 +20,7 @@ #include <string.h> #include <algorithm> #include <memory> +#include <vector> #include <utils/Log.h> #include <utils/Errors.h> @@ -1659,8 +1660,7 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image lsmHeight = static_cast<uint32_t>(entry1.data.i32[1]); } - camera_metadata_entry entry2 = - results.find(ANDROID_STATISTICS_LENS_SHADING_MAP); + camera_metadata_entry entry2 = results.find(ANDROID_STATISTICS_LENS_SHADING_MAP); camera_metadata_entry entry = characteristics.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); @@ -1685,6 +1685,45 @@ static sp<TiffWriter> DngCreator_setup(JNIEnv* env, jobject thiz, uint32_t image } } + + // Set up bad pixel correction list + camera_metadata_entry entry3 = characteristics.find(ANDROID_STATISTICS_HOT_PIXEL_MAP); + + if ((entry3.count % 2) != 0) { + ALOGE("%s: Hot pixel map contains odd number of values, cannot map to pairs!", + __FUNCTION__); + jniThrowRuntimeException(env, "failed to add hotpixel map."); + return nullptr; + } + + // Adjust the bad pixel coordinates to be relative to the origin of the active area DNG tag + std::vector<uint32_t> v; + for (size_t i = 0; i < entry3.count; i+=2) { + int32_t x = entry3.data.i32[i]; + int32_t y = entry3.data.i32[i + 1]; + x -= static_cast<int32_t>(xmin); + y -= static_cast<int32_t>(ymin); + if (x < 0 || y < 0 || static_cast<uint32_t>(x) >= width || + static_cast<uint32_t>(y) >= width) { + continue; + } + v.push_back(x); + v.push_back(y); + } + const uint32_t* badPixels = &v[0]; + uint32_t badPixelCount = v.size(); + + if (badPixelCount > 0) { + err = builder.addBadPixelListForMetadata(badPixels, badPixelCount, opcodeCfaLayout); + + if (err != OK) { + ALOGE("%s: Could not add hotpixel map.", __FUNCTION__); + jniThrowRuntimeException(env, "failed to add hotpixel map."); + return nullptr; + } + } + + size_t listSize = builder.getSize(); uint8_t opcodeListBuf[listSize]; err = builder.buildOpList(opcodeListBuf); diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 7a725ae..4c920dc 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -408,6 +408,27 @@ void SetThreadName(const char* thread_name) { } } +#ifdef ENABLE_SCHED_BOOST +static void SetForkLoad(bool boost) { + // set scheduler knob to boost forked processes + pid_t currentPid = getpid(); + // fits at most "/proc/XXXXXXX/sched_init_task_load\0" + char schedPath[35]; + snprintf(schedPath, sizeof(schedPath), "/proc/%u/sched_init_task_load", currentPid); + int schedBoostFile = open(schedPath, O_WRONLY); + if (schedBoostFile < 0) { + ALOGW("Unable to set zygote scheduler boost"); + return; + } + if (boost) { + write(schedBoostFile, "100\0", 4); + } else { + write(schedBoostFile, "0\0", 2); + } + close(schedBoostFile); +} +#endif + // Utility routine to fork zygote and specialize the child process. static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGids, jint debug_flags, jobjectArray javaRlimits, @@ -418,6 +439,10 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra jstring instructionSet, jstring dataDir) { SetSigChldHandler(); +#ifdef ENABLE_SCHED_BOOST + SetForkLoad(true); +#endif + pid_t pid = fork(); if (pid == 0) { @@ -558,6 +583,12 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra } } else if (pid > 0) { // the parent process + +#ifdef ENABLE_SCHED_BOOST + // unset scheduler knob + SetForkLoad(false); +#endif + } return pid; } diff --git a/core/res/res/values-fa/strings.xml b/core/res/res/values-fa/strings.xml index f060200..2af30c6 100644 --- a/core/res/res/values-fa/strings.xml +++ b/core/res/res/values-fa/strings.xml @@ -755,7 +755,7 @@ <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"ماندن در این صفحه"</string> <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nمطمئنید میخواهید این صفحه را ترک کنید؟"</string> <string name="save_password_label" msgid="6860261758665825069">"تأیید"</string> - <string name="double_tap_toast" msgid="4595046515400268881">"نکته: برای بزرگنمایی و کوچکنمایی، دو بار ضربه بزنید."</string> + <string name="double_tap_toast" msgid="4595046515400268881">"نکته: برای بزرگنمایی و کوچکنمایی، دو بار ضربه بزنید."</string> <string name="autofill_this_form" msgid="4616758841157816676">"تکمیل خودکار"</string> <string name="setup_autofill" msgid="7103495070180590814">"راهاندازی تکمیل خودکار"</string> <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string> @@ -1097,7 +1097,7 @@ <string name="permdesc_readInstallSessions" msgid="2049771699626019849">"به برنامه اجازه میدهد جلسات نصب را بخواند. این کار به برنامه اجازه میدهد جزئیات نصبهای بسته فعال را ببیند."</string> <string name="permlab_requestInstallPackages" msgid="1772330282283082214">"درخواست نصب بستهبندی"</string> <string name="permdesc_requestInstallPackages" msgid="5740101072486783082">"به برنامه اجازه میدهد درخواست نصب بستهبندی کند."</string> - <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"دوبار لمس کنید تا بزرگنمایی کنترل شود"</string> + <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"دوبار لمس کنید تا بزرگنمایی کنترل شود"</string> <string name="gadget_host_error_inflating" msgid="4882004314906466162">"افزودن ابزارک انجام نشد."</string> <string name="ime_action_go" msgid="8320845651737369027">"برو"</string> <string name="ime_action_search" msgid="658110271822807811">"جستجو"</string> @@ -1274,7 +1274,7 @@ <string name="media_route_status_in_use" msgid="4533786031090198063">"در حال استفاده"</string> <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"صفحه نمایش از خود"</string> <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"صفحه HDMI"</string> - <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"همپوشانی #<xliff:g id="ID">%1$d</xliff:g>"</string> + <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"همپوشانی #<xliff:g id="ID">%1$d</xliff:g>"</string> <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string> <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">"، امن"</string> <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"الگو را فراموش کردهاید"</string> diff --git a/core/res/res/values-mcc310-mnc260-pt-rBR/strings.xml b/core/res/res/values-mcc310-mnc260-pt-rBR/strings.xml deleted file mode 100644 index bad49c3..0000000 --- a/core/res/res/values-mcc310-mnc260-pt-rBR/strings.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/* -** Copyright 2015, 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 my 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. -*/ - --> - -<!-- These resources are around just to allow their values to be customized - for different hardware and product builds. --> - -<resources xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> - <string-array name="wfcOperatorErrorAlertMessages"> - <item msgid="7239039348648848288">"Para fazer chamadas e enviar mensagens por Wi-Fi, primeiro peça à sua operadora para configurar esse serviço. Depois ative novamente as chamadas por Wi-Fi nas configurações."</item> - </string-array> - <string-array name="wfcOperatorErrorNotificationMessages"> - <item msgid="483847327467331298">"Faça registro na sua operadora"</item> - </string-array> - <string name="wfcSpnFormat" msgid="4982938551498609442">"%s chamada Wi-Fi"</string> -</resources> diff --git a/core/res/res/values-pt-rBR-watch/strings.xml b/core/res/res/values-pt-rBR-watch/strings.xml deleted file mode 100644 index 120e4a5..0000000 --- a/core/res/res/values-pt-rBR-watch/strings.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -/* //device/apps/common/assets/res/any/strings.xml -** -** Copyright 2015, 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. -*/ - --> - -<resources xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> - <string name="android_upgrading_apk" msgid="1090732262010398759">"App <xliff:g id="NUMBER_0">%1$d</xliff:g> de <xliff:g id="NUMBER_1">%2$d</xliff:g>."</string> -</resources> diff --git a/core/res/res/values-ro/strings.xml b/core/res/res/values-ro/strings.xml index 5315a7d..a17f352 100644 --- a/core/res/res/values-ro/strings.xml +++ b/core/res/res/values-ro/strings.xml @@ -702,7 +702,7 @@ <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"Pentru a debloca, conectaţi-vă folosind Contul Google."</string> <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"Nume de utilizator (e-mail)"</string> <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"Parolă"</string> - <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Conectaţi-vă"</string> + <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Conectați-vă"</string> <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"Nume de utilizator sau parolă nevalide."</string> <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"Aţi uitat numele de utilizator sau parola?\nAccesaţi "<b>"google.com/accounts/recovery"</b>"."</string> <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"Se verifică..."</string> @@ -969,7 +969,7 @@ <item quantity="other">Rețele Wi-Fi deschise disponibile</item> <item quantity="one">Rețea Wi-Fi deschisă disponibilă</item> </plurals> - <string name="wifi_available_sign_in" msgid="9157196203958866662">"Conectaţi-vă la reţeaua Wi-Fi"</string> + <string name="wifi_available_sign_in" msgid="9157196203958866662">"Conectați-vă la reţeaua Wi-Fi"</string> <string name="network_available_sign_in" msgid="1848877297365446605">"Conectați-vă la rețea"</string> <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) --> <skip /> @@ -1307,7 +1307,7 @@ <string name="kg_login_instructions" msgid="1100551261265506448">"Pentru a debloca, conectaţi-vă cu Contul dvs. Google."</string> <string name="kg_login_username_hint" msgid="5718534272070920364">"Nume de utilizator (e-mail)"</string> <string name="kg_login_password_hint" msgid="9057289103827298549">"Parolă"</string> - <string name="kg_login_submit_button" msgid="5355904582674054702">"Conectaţi-vă"</string> + <string name="kg_login_submit_button" msgid="5355904582674054702">"Conectați-vă"</string> <string name="kg_login_invalid_input" msgid="5754664119319872197">"Nume de utilizator sau parolă nevalide."</string> <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Aţi uitat numele de utilizator sau parola?\nAccesaţi "<b>"google.com/accounts/recovery"</b>"."</string> <string name="kg_login_checking_password" msgid="1052685197710252395">"Se verifică contul…"</string> diff --git a/core/res/res/values-sw/strings.xml b/core/res/res/values-sw/strings.xml index 3800c92..1183cda 100644 --- a/core/res/res/values-sw/strings.xml +++ b/core/res/res/values-sw/strings.xml @@ -229,7 +229,7 @@ <string name="user_owner_label" msgid="2804351898001038951">"Binafsi"</string> <string name="managed_profile_label" msgid="6260850669674791528">"Kazini"</string> <string name="permgrouplab_contacts" msgid="3657758145679177612">"Anwani"</string> - <string name="permgroupdesc_contacts" msgid="6951499528303668046">"fikia anwani zako"</string> + <string name="permgroupdesc_contacts" msgid="6951499528303668046">"ifikie anwani zako"</string> <string name="permgrouplab_location" msgid="7275582855722310164">"Mahali"</string> <string name="permgroupdesc_location" msgid="1346617465127855033">"fikia mahali kilipo kifaa hiki"</string> <string name="permgrouplab_calendar" msgid="5863508437783683902">"Kalenda"</string> diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index cf28490..8e88886 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2270,4 +2270,9 @@ <string-array name="config_cell_retries_per_error_code"> </string-array> + <!-- The OEM specified sensor type for the gesture to launch the camear app. --> + <integer name="config_cameraLaunchGestureSensorType">-1</integer> + <!-- The OEM specified sensor string type for the gesture to launch camera app, this value + must match the value of config_cameraLaunchGestureSensorType in OEM's HAL --> + <string translatable="false" name="config_cameraLaunchGestureSensorStringType"></string> </resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index ee61944..dae5db0 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2318,4 +2318,7 @@ <java-symbol type="array" name="config_cell_retries_per_error_code" /> <java-symbol type="drawable" name="ic_more_items" /> + <!-- Gesture --> + <java-symbol type="integer" name="config_cameraLaunchGestureSensorType" /> + <java-symbol type="string" name="config_cameraLaunchGestureSensorStringType" /> </resources> |
