Merge "Don't propagate level or RTL in LayerDrawable.setDrawable()" into mnc-dev
diff --git a/Android.mk b/Android.mk
index bd8b16a..b71f08c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -197,6 +197,7 @@
core/java/android/os/IBatteryPropertiesListener.aidl \
core/java/android/os/IBatteryPropertiesRegistrar.aidl \
core/java/android/os/ICancellationSignal.aidl \
+ core/java/android/os/IDeviceIdleController.aidl \
core/java/android/os/IMessenger.aidl \
core/java/android/os/INetworkActivityListener.aidl \
core/java/android/os/INetworkManagementService.aidl \
diff --git a/api/current.txt b/api/current.txt
index 1117623..0aeda1c 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -14025,6 +14025,7 @@
method public java.lang.String getProductName();
method public java.lang.String getSerialNumber();
method public int getVendorId();
+ method public java.lang.String getVersion();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.hardware.usb.UsbDevice> CREATOR;
}
@@ -17266,6 +17267,7 @@
field public static final java.lang.String PROPERTY_PRODUCT = "product";
field public static final java.lang.String PROPERTY_SERIAL_NUMBER = "serial_number";
field public static final java.lang.String PROPERTY_USB_DEVICE = "usb_device";
+ field public static final java.lang.String PROPERTY_VERSION = "version";
field public static final int TYPE_BLUETOOTH = 3; // 0x3
field public static final int TYPE_USB = 1; // 0x1
field public static final int TYPE_VIRTUAL = 2; // 0x2
@@ -29201,6 +29203,7 @@
field public static final java.lang.String EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE = "android.speech.extra.ONLY_RETURN_LANGUAGE_PREFERENCE";
field public static final java.lang.String EXTRA_ORIGIN = "android.speech.extra.ORIGIN";
field public static final java.lang.String EXTRA_PARTIAL_RESULTS = "android.speech.extra.PARTIAL_RESULTS";
+ field public static final java.lang.String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE";
field public static final java.lang.String EXTRA_PROMPT = "android.speech.extra.PROMPT";
field public static final java.lang.String EXTRA_RESULTS = "android.speech.extra.RESULTS";
field public static final java.lang.String EXTRA_RESULTS_PENDINGINTENT = "android.speech.extra.RESULTS_PENDINGINTENT";
@@ -30682,11 +30685,34 @@
method public android.os.Bundle getConfigForSubId(int);
method public void reloadCarrierConfigForSubId(int);
field public static final java.lang.String ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
+ field public static final java.lang.String BOOL_ADDITIONAL_CALL_SETTING = "bool_additional_call_setting";
+ field public static final java.lang.String BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG = "bool_allow_emergency_numbers_in_call_log";
+ field public static final java.lang.String BOOL_ALLOW_LOCAL_DTMF_TONES = "bool_allow_local_dtmf_tones";
field public static final java.lang.String BOOL_APN_EXPAND = "bool_apn_expand";
+ field public static final java.lang.String BOOL_AUTO_RETRY_ENABLED = "bool_auto_retry_enabled";
+ field public static final java.lang.String BOOL_CARRIER_SETTINGS_ENABLE = "bool_carrier_settings_enable";
field public static final java.lang.String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
field public static final java.lang.String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
field public static final java.lang.String BOOL_CARRIER_VOLTE_TTY_SUPPORTED = "bool_carrier_volte_tty_supported";
+ field public static final java.lang.String BOOL_DISABLE_CDMA_ACTIVATION_CODE = "bool_disable_cdma_activation_code";
+ field public static final java.lang.String BOOL_DTMF_TYPE_ENABLED = "bool_dtmf_type_enabled";
+ field public static final java.lang.String BOOL_ENABLE_DIALER_KEY_VIBRATION = "bool_enable_dialer_key_vibration";
+ field public static final java.lang.String BOOL_HAS_IN_CALL_NOISE_SUPPRESSION = "bool_has_in_call_noise_suppression";
+ field public static final java.lang.String BOOL_HIDE_CARRIER_NETWORK_SETTINGS = "bool_hide_carrier_network_settings";
+ field public static final java.lang.String BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS = "bool_ignore_sim_network_locked_events";
+ field public static final java.lang.String BOOL_OPERATOR_SELECTION_EXPAND = "bool_operator_selection_expand";
+ field public static final java.lang.String BOOL_PREFER_2G = "bool_prefer_2g";
field public static final java.lang.String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
+ field public static final java.lang.String BOOL_SHOW_CDMA = "bool_show_cdma";
+ field public static final java.lang.String BOOL_SHOW_ONSCREEN_DIAL_BUTTON = "bool_show_onscreen_dial_button";
+ field public static final java.lang.String BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS = "bool_sim_network_unlock_allow_dismiss";
+ field public static final java.lang.String BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS = "bool_support_pause_ims_video_calls";
+ field public static final java.lang.String BOOL_SUPPORT_SWAP_AFTER_MERGE = "bool_support_swap_after_merge";
+ field public static final java.lang.String BOOL_USE_HFA_FOR_PROVISIONING = "bool_use_hfa_for_provisioning";
+ field public static final java.lang.String BOOL_USE_OTASP_FOR_PROVISIONING = "bool_use_otasp_for_provisioning";
+ field public static final java.lang.String BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT = "bool_voicemail_notification_persistent";
+ field public static final java.lang.String BOOL_VOICE_PRIVACY_DISABLE = "bool_voice_privacy_disable";
+ field public static final java.lang.String BOOL_WORLD_PHONE = "bool_world_phone";
field public static final java.lang.String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
}
diff --git a/api/system-current.txt b/api/system-current.txt
index 7210666f..0b887d5 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -3949,6 +3949,7 @@
method public void finishOp(java.lang.String, int, java.lang.String);
method public int noteOp(java.lang.String, int, java.lang.String);
method public int noteOpNoThrow(java.lang.String, int, java.lang.String);
+ method public static java.lang.String permissionToOp(java.lang.String);
method public int startOp(java.lang.String, int, java.lang.String);
method public int startOpNoThrow(java.lang.String, int, java.lang.String);
method public void startWatchingMode(java.lang.String, java.lang.String, android.app.AppOpsManager.OnOpChangedListener);
@@ -14929,6 +14930,7 @@
method public java.lang.String getProductName();
method public java.lang.String getSerialNumber();
method public int getVendorId();
+ method public java.lang.String getVersion();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.hardware.usb.UsbDevice> CREATOR;
}
@@ -15471,6 +15473,7 @@
method public boolean hasPseudorangeUncertaintyInMeters();
method public boolean hasSnrInDb();
method public boolean hasTimeFromLastBitInMs();
+ method public boolean isPseudorangeRateCorrected();
method public boolean isUsedInFix();
method public void reset();
method public void resetAzimuthInDeg();
@@ -15536,6 +15539,7 @@
field public static final byte MULTIPATH_INDICATOR_UNKNOWN = 0; // 0x0
field public static final short STATE_BIT_SYNC = 2; // 0x2
field public static final short STATE_CODE_LOCK = 1; // 0x1
+ field public static final short STATE_MSEC_AMBIGUOUS = 16; // 0x10
field public static final short STATE_SUBFRAME_SYNC = 4; // 0x4
field public static final short STATE_TOW_DECODED = 8; // 0x8
field public static final short STATE_UNKNOWN = 0; // 0x0
@@ -15563,6 +15567,7 @@
method public byte[] getData();
method public short getMessageId();
method public byte getPrn();
+ method public short getStatus();
method public short getSubmessageId();
method public byte getType();
method public void reset();
@@ -15570,10 +15575,14 @@
method public void setData(byte[]);
method public void setMessageId(short);
method public void setPrn(byte);
+ method public void setStatus(short);
method public void setSubmessageId(short);
method public void setType(byte);
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.location.GpsNavigationMessage> CREATOR;
+ field public static final short STATUS_PARITY_PASSED = 1; // 0x1
+ field public static final short STATUS_PARITY_REBUILT = 2; // 0x2
+ field public static final short STATUS_UNKNOWN = 0; // 0x0
field public static final byte TYPE_CNAV2 = 4; // 0x4
field public static final byte TYPE_L1CA = 1; // 0x1
field public static final byte TYPE_L2CNAV = 2; // 0x2
@@ -18551,6 +18560,7 @@
field public static final java.lang.String PROPERTY_PRODUCT = "product";
field public static final java.lang.String PROPERTY_SERIAL_NUMBER = "serial_number";
field public static final java.lang.String PROPERTY_USB_DEVICE = "usb_device";
+ field public static final java.lang.String PROPERTY_VERSION = "version";
field public static final int TYPE_BLUETOOTH = 3; // 0x3
field public static final int TYPE_USB = 1; // 0x1
field public static final int TYPE_VIRTUAL = 2; // 0x2
@@ -31306,6 +31316,7 @@
field public static final java.lang.String EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE = "android.speech.extra.ONLY_RETURN_LANGUAGE_PREFERENCE";
field public static final java.lang.String EXTRA_ORIGIN = "android.speech.extra.ORIGIN";
field public static final java.lang.String EXTRA_PARTIAL_RESULTS = "android.speech.extra.PARTIAL_RESULTS";
+ field public static final java.lang.String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE";
field public static final java.lang.String EXTRA_PROMPT = "android.speech.extra.PROMPT";
field public static final java.lang.String EXTRA_RESULTS = "android.speech.extra.RESULTS";
field public static final java.lang.String EXTRA_RESULTS_PENDINGINTENT = "android.speech.extra.RESULTS_PENDINGINTENT";
@@ -32838,11 +32849,34 @@
method public void reloadCarrierConfigForSubId(int);
method public void updateConfigForPhoneId(int, java.lang.String);
field public static final java.lang.String ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
+ field public static final java.lang.String BOOL_ADDITIONAL_CALL_SETTING = "bool_additional_call_setting";
+ field public static final java.lang.String BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG = "bool_allow_emergency_numbers_in_call_log";
+ field public static final java.lang.String BOOL_ALLOW_LOCAL_DTMF_TONES = "bool_allow_local_dtmf_tones";
field public static final java.lang.String BOOL_APN_EXPAND = "bool_apn_expand";
+ field public static final java.lang.String BOOL_AUTO_RETRY_ENABLED = "bool_auto_retry_enabled";
+ field public static final java.lang.String BOOL_CARRIER_SETTINGS_ENABLE = "bool_carrier_settings_enable";
field public static final java.lang.String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
field public static final java.lang.String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
field public static final java.lang.String BOOL_CARRIER_VOLTE_TTY_SUPPORTED = "bool_carrier_volte_tty_supported";
+ field public static final java.lang.String BOOL_DISABLE_CDMA_ACTIVATION_CODE = "bool_disable_cdma_activation_code";
+ field public static final java.lang.String BOOL_DTMF_TYPE_ENABLED = "bool_dtmf_type_enabled";
+ field public static final java.lang.String BOOL_ENABLE_DIALER_KEY_VIBRATION = "bool_enable_dialer_key_vibration";
+ field public static final java.lang.String BOOL_HAS_IN_CALL_NOISE_SUPPRESSION = "bool_has_in_call_noise_suppression";
+ field public static final java.lang.String BOOL_HIDE_CARRIER_NETWORK_SETTINGS = "bool_hide_carrier_network_settings";
+ field public static final java.lang.String BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS = "bool_ignore_sim_network_locked_events";
+ field public static final java.lang.String BOOL_OPERATOR_SELECTION_EXPAND = "bool_operator_selection_expand";
+ field public static final java.lang.String BOOL_PREFER_2G = "bool_prefer_2g";
field public static final java.lang.String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
+ field public static final java.lang.String BOOL_SHOW_CDMA = "bool_show_cdma";
+ field public static final java.lang.String BOOL_SHOW_ONSCREEN_DIAL_BUTTON = "bool_show_onscreen_dial_button";
+ field public static final java.lang.String BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS = "bool_sim_network_unlock_allow_dismiss";
+ field public static final java.lang.String BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS = "bool_support_pause_ims_video_calls";
+ field public static final java.lang.String BOOL_SUPPORT_SWAP_AFTER_MERGE = "bool_support_swap_after_merge";
+ field public static final java.lang.String BOOL_USE_HFA_FOR_PROVISIONING = "bool_use_hfa_for_provisioning";
+ field public static final java.lang.String BOOL_USE_OTASP_FOR_PROVISIONING = "bool_use_otasp_for_provisioning";
+ field public static final java.lang.String BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT = "bool_voicemail_notification_persistent";
+ field public static final java.lang.String BOOL_VOICE_PRIVACY_DISABLE = "bool_voice_privacy_disable";
+ field public static final java.lang.String BOOL_WORLD_PHONE = "bool_world_phone";
field public static final java.lang.String INT_VOLTE_REPLACEMENT_RAT = "int_volte_replacement_rat";
}
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 223d528..48e380b 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -726,6 +726,16 @@
false
};
+ /**
+ * This is a mapping from a permission name to public app op name.
+ */
+ private static final ArrayMap<String, String> sPermToOp = new ArrayMap<>();
+ static {
+ sPermToOp.put(Manifest.permission.ACCESS_COARSE_LOCATION, OPSTR_COARSE_LOCATION);
+ sPermToOp.put(Manifest.permission.ACCESS_FINE_LOCATION, OPSTR_FINE_LOCATION);
+ sPermToOp.put(Manifest.permission.PACKAGE_USAGE_STATS, OPSTR_GET_USAGE_STATS);
+ }
+
private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
static {
@@ -1066,6 +1076,21 @@
}
/**
+ * Gets the app op name associated with a given permission.
+ * The app op name is one of the public constants defined
+ * in this class such as {@link #OPSTR_COARSE_LOCATION}.
+ *
+ * @param permission The permission.
+ * @return The app op associated with the permission or null.
+ *
+ * @hide
+ */
+ @SystemApi
+ public static String permissionToOp(String permission) {
+ return sPermToOp.get(permission);
+ }
+
+ /**
* Monitor for changes to the operating mode for the given op in the given app package.
* @param op The operation to monitor, one of OPSTR_*.
* @param packageName The name of the application to monitor.
diff --git a/core/java/android/hardware/usb/UsbDevice.java b/core/java/android/hardware/usb/UsbDevice.java
index 1a42319..410d550 100644
--- a/core/java/android/hardware/usb/UsbDevice.java
+++ b/core/java/android/hardware/usb/UsbDevice.java
@@ -45,6 +45,7 @@
private final String mName;
private final String mManufacturerName;
private final String mProductName;
+ private final String mVersion;
private final String mSerialNumber;
private final int mVendorId;
private final int mProductId;
@@ -62,7 +63,7 @@
*/
public UsbDevice(String name, int vendorId, int productId,
int Class, int subClass, int protocol,
- String manufacturerName, String productName, String serialNumber) {
+ String manufacturerName, String productName, String version, String serialNumber) {
mName = name;
mVendorId = vendorId;
mProductId = productId;
@@ -71,6 +72,7 @@
mProtocol = protocol;
mManufacturerName = manufacturerName;
mProductName = productName;
+ mVersion = version;
mSerialNumber = serialNumber;
}
@@ -104,6 +106,15 @@
}
/**
+ * Returns the version number of the device.
+ *
+ * @return the device version
+ */
+ public String getVersion() {
+ return mVersion;
+ }
+
+ /**
* Returns the serial number of the device.
*
* @return the serial number name
@@ -263,7 +274,7 @@
",mVendorId=" + mVendorId + ",mProductId=" + mProductId +
",mClass=" + mClass + ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
",mManufacturerName=" + mManufacturerName + ",mProductName=" + mProductName +
- ",mSerialNumber=" + mSerialNumber + ",mConfigurations=[");
+ ",mVersion=" + mVersion + ",mSerialNumber=" + mSerialNumber + ",mConfigurations=[");
for (int i = 0; i < mConfigurations.length; i++) {
builder.append("\n");
builder.append(mConfigurations[i].toString());
@@ -283,10 +294,11 @@
int protocol = in.readInt();
String manufacturerName = in.readString();
String productName = in.readString();
+ String version = in.readString();
String serialNumber = in.readString();
Parcelable[] configurations = in.readParcelableArray(UsbInterface.class.getClassLoader());
UsbDevice device = new UsbDevice(name, vendorId, productId, clasz, subClass, protocol,
- manufacturerName, productName, serialNumber);
+ manufacturerName, productName, version, serialNumber);
device.setConfigurations(configurations);
return device;
}
@@ -309,6 +321,7 @@
parcel.writeInt(mProtocol);
parcel.writeString(mManufacturerName);
parcel.writeString(mProductName);
+ parcel.writeString(mVersion);
parcel.writeString(mSerialNumber);
parcel.writeParcelableArray(mConfigurations, 0);
}
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl
index c722fbc..7f5f377 100644
--- a/core/java/android/net/INetworkPolicyManager.aidl
+++ b/core/java/android/net/INetworkPolicyManager.aidl
@@ -38,8 +38,6 @@
boolean isUidForeground(int uid);
- int[] getPowerSaveAppIdWhitelist();
-
void registerListener(INetworkPolicyListener listener);
void unregisterListener(INetworkPolicyListener listener);
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index bc03637..b4c7b2b 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -129,14 +129,6 @@
}
}
- public int[] getPowerSaveAppIdWhitelist() {
- try {
- return mService.getPowerSaveAppIdWhitelist();
- } catch (RemoteException e) {
- return new int[0];
- }
- }
-
public void registerListener(INetworkPolicyListener listener) {
try {
mService.registerListener(listener);
diff --git a/core/java/android/os/IDeviceIdleController.aidl b/core/java/android/os/IDeviceIdleController.aidl
new file mode 100644
index 0000000..3cb29ff
--- /dev/null
+++ b/core/java/android/os/IDeviceIdleController.aidl
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 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.
+ */
+
+package android.os;
+
+/** @hide */
+interface IDeviceIdleController {
+ void addPowerSaveWhitelistApp(String name);
+ void removePowerSaveWhitelistApp(String name);
+ String[] getSystemPowerWhitelist();
+ String[] getFullPowerWhitelist();
+ int[] getAppIdWhitelist();
+}
diff --git a/core/java/android/os/IPermissionController.aidl b/core/java/android/os/IPermissionController.aidl
index 73a68f1..0cc1603 100644
--- a/core/java/android/os/IPermissionController.aidl
+++ b/core/java/android/os/IPermissionController.aidl
@@ -20,4 +20,5 @@
/** @hide */
interface IPermissionController {
boolean checkPermission(String permission, int pid, int uid);
+ String[] getPackagesForUid(int uid);
}
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 01c9a21..1d9d7d2 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -920,6 +920,14 @@
= "android.os.action.DEVICE_IDLE_MODE_CHANGED";
/**
+ * @hide Intent that is broadcast when the set of power save whitelist apps has changed.
+ * This broadcast is only sent to registered receivers.
+ */
+ @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String ACTION_POWER_SAVE_WHITELIST_CHANGED
+ = "android.os.action.POWER_SAVE_WHITELIST_CHANGED";
+
+ /**
* Intent that is broadcast when the state of {@link #isPowerSaveMode()} is about to change.
* This broadcast is only sent to registered receivers.
*
diff --git a/core/java/android/speech/RecognizerIntent.java b/core/java/android/speech/RecognizerIntent.java
index e991d84..ce94315c 100644
--- a/core/java/android/speech/RecognizerIntent.java
+++ b/core/java/android/speech/RecognizerIntent.java
@@ -403,4 +403,12 @@
*/
public static final String EXTRA_SUPPORTED_LANGUAGES =
"android.speech.extra.SUPPORTED_LANGUAGES";
+
+ /**
+ * Optional boolean, to be used with {@link #ACTION_RECOGNIZE_SPEECH},
+ * {@link #ACTION_VOICE_SEARCH_HANDS_FREE}, {@link #ACTION_WEB_SEARCH} to indicate whether to
+ * only use an offline speech recognition engine. The default is false, meaning that either
+ * network or offline recognition engines may be used.
+ */
+ public static final String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE";
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index e8fc15e..b5b7f0f 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -15490,12 +15490,8 @@
if (drawingWithRenderNode) {
renderNode.setAlpha(alpha * getAlpha() * getTransitionAlpha());
} else if (layerType == LAYER_TYPE_NONE) {
- int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG;
- if ((parentFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0) {
- layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
- }
canvas.saveLayerAlpha(sx, sy, sx + getWidth(), sy + getHeight(),
- multipliedAlpha, layerFlags);
+ multipliedAlpha);
}
} else {
// Alpha is handled by the child directly, clobber the layer's alpha
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index f7c6b68..35e7389 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -3817,6 +3817,10 @@
startSelectionActionModeWithoutSelection();
}
}
+ } else {
+ if (mSelectionActionMode != null) {
+ mSelectionActionMode.invalidateContentRect();
+ }
}
hideAfterDelay();
break;
diff --git a/core/java/com/android/internal/content/PackageMonitor.java b/core/java/com/android/internal/content/PackageMonitor.java
index eff44bd..481ab0e 100644
--- a/core/java/com/android/internal/content/PackageMonitor.java
+++ b/core/java/com/android/internal/content/PackageMonitor.java
@@ -44,7 +44,6 @@
sPackageFilt.addAction(Intent.ACTION_PACKAGE_CHANGED);
sPackageFilt.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
sPackageFilt.addAction(Intent.ACTION_PACKAGE_RESTARTED);
- sPackageFilt.addAction(Intent.ACTION_UID_REMOVED);
sPackageFilt.addDataScheme("package");
sNonDataFilt.addAction(Intent.ACTION_UID_REMOVED);
sNonDataFilt.addAction(Intent.ACTION_USER_STOPPED);
diff --git a/core/java/com/android/internal/widget/FloatingToolbar.java b/core/java/com/android/internal/widget/FloatingToolbar.java
index 3a1e0ca..3f7696f 100644
--- a/core/java/com/android/internal/widget/FloatingToolbar.java
+++ b/core/java/com/android/internal/widget/FloatingToolbar.java
@@ -438,6 +438,9 @@
// Make sure a panel is set as the content.
if (mContentContainer.getChildCount() == 0) {
setMainPanelAsContent();
+ // If we're yet to show the popup, set the container visibility to zero.
+ // The "show" animation will make this visible.
+ mContentContainer.setAlpha(0);
}
preparePopupContent();
mPopupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, x, y);
@@ -478,7 +481,7 @@
* Returns {@code true} if this popup is currently showing. {@code false} otherwise.
*/
public boolean isShowing() {
- return mPopupWindow.isShowing() && !mDismissed && !mHidden;
+ return !mDismissed && !mHidden;
}
/**
@@ -494,7 +497,7 @@
* This is a no-op if this popup is not showing.
*/
public void updateCoordinates(int x, int y) {
- if (!isShowing()) {
+ if (!isShowing() || !mPopupWindow.isShowing()) {
return;
}
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index c384ef9..6afb226 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -26,6 +26,8 @@
#include <utils/Log.h>
#include <media/AudioRecord.h>
+#include <ScopedUtfChars.h>
+
#include "android_media_AudioFormat.h"
#include "android_media_AudioErrors.h"
@@ -146,7 +148,7 @@
static jint
android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
jobject jaa, jint sampleRateInHertz, jint channelMask, jint channelIndexMask,
- jint audioFormat, jint buffSizeInBytes, jintArray jSession)
+ jint audioFormat, jint buffSizeInBytes, jintArray jSession, jstring opPackageName)
{
//ALOGV(">> Entering android_media_AudioRecord_setup");
//ALOGV("sampleRate=%d, audioFormat=%d, channel mask=%x, buffSizeInBytes=%d",
@@ -208,8 +210,10 @@
env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
nSession = NULL;
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
// create an uninitialized AudioRecord object
- sp<AudioRecord> lpRecorder = new AudioRecord();
+ sp<AudioRecord> lpRecorder = new AudioRecord(String16(opPackageNameStr.c_str()));
audio_attributes_t *paa = NULL;
// read the AudioAttributes values
@@ -597,7 +601,7 @@
// name, signature, funcPtr
{"native_start", "(II)I", (void *)android_media_AudioRecord_start},
{"native_stop", "()V", (void *)android_media_AudioRecord_stop},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;IIIII[I)I",
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/Object;IIIII[ILjava/lang/String;)I",
(void *)android_media_AudioRecord_setup},
{"native_finalize", "()V", (void *)android_media_AudioRecord_finalize},
{"native_release", "()V", (void *)android_media_AudioRecord_release},
diff --git a/core/jni/android_media_RemoteDisplay.cpp b/core/jni/android_media_RemoteDisplay.cpp
index e2bba30..9bc223b 100644
--- a/core/jni/android_media_RemoteDisplay.cpp
+++ b/core/jni/android_media_RemoteDisplay.cpp
@@ -134,8 +134,10 @@
// ----------------------------------------------------------------------------
-static jlong nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
+static jlong nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr,
+ jstring opPackageNameStr) {
ScopedUtfChars iface(env, ifaceStr);
+ ScopedUtfChars opPackageName(env, opPackageNameStr);
sp<IServiceManager> sm = defaultServiceManager();
sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(
@@ -146,7 +148,7 @@
}
sp<NativeRemoteDisplayClient> client(new NativeRemoteDisplayClient(env, remoteDisplayObj));
- sp<IRemoteDisplay> display = service->listenForRemoteDisplay(
+ sp<IRemoteDisplay> display = service->listenForRemoteDisplay(String16(opPackageName.c_str()),
client, String8(iface.c_str()));
if (display == NULL) {
ALOGE("Media player service rejected request to listen for remote display '%s'.",
@@ -176,7 +178,7 @@
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
- {"nativeListen", "(Ljava/lang/String;)J",
+ {"nativeListen", "(Ljava/lang/String;Ljava/lang/String;)J",
(void*)nativeListen },
{"nativeDispose", "(J)V",
(void*)nativeDispose },
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 45c078d..942e6a6 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -79,6 +79,8 @@
<protected-broadcast android:name="android.os.action.POWER_SAVE_MODE_CHANGED" />
<protected-broadcast android:name="android.os.action.POWER_SAVE_MODE_CHANGING" />
+ <protected-broadcast android:name="android.os.action.DEVICE_IDLE_MODE_CHANGED" />
+ <protected-broadcast android:name="android.os.action.POWER_SAVE_WHITELIST_CHANGED" />
<protected-broadcast android:name="android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED" />
diff --git a/core/res/res/drawable/btn_check_material_anim.xml b/core/res/res/drawable/btn_check_material_anim.xml
index 41caa4e..7cb1b89 100644
--- a/core/res/res/drawable/btn_check_material_anim.xml
+++ b/core/res/res/drawable/btn_check_material_anim.xml
@@ -15,15 +15,24 @@
-->
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_checked="true" android:id="@+id/on"
+
+ <item
+ android:id="@+id/on"
+ android:state_checked="true"
android:drawable="@drawable/ic_checkbox_checked" />
- <item android:id="@+id/off"
+
+ <item
+ android:id="@+id/off"
android:drawable="@drawable/ic_checkbox_unchecked" />
- <transition android:fromId="@+id/off" android:toId="@+id/on"
+ <transition
+ android:fromId="@+id/off"
+ android:toId="@+id/on"
android:drawable="@drawable/ic_checkbox_unchecked_animation" />
- <transition android:fromId="@+id/on" android:toId="@+id/off"
+ <transition
+ android:fromId="@+id/on"
+ android:toId="@+id/off"
android:drawable="@drawable/ic_checkbox_checked_animation" />
-</animated-selector>
+</animated-selector>
diff --git a/core/res/res/drawable/ic_checkbox_checked.xml b/core/res/res/drawable/ic_checkbox_checked.xml
index 4764115..cc7b5df 100644
--- a/core/res/res/drawable/ic_checkbox_checked.xml
+++ b/core/res/res/drawable/ic_checkbox_checked.xml
@@ -22,7 +22,7 @@
android:viewportWidth="48"
android:height="32dp"
android:viewportHeight="48"
- android:tint="?attr/colorControlNormal" >
+ android:tint="?attr/colorControlActivated" >
<group
android:name="icon_null"
android:translateX="24"
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java
index 8c49ff0..5d863c2 100644
--- a/keystore/java/android/security/KeyStore.java
+++ b/keystore/java/android/security/KeyStore.java
@@ -53,6 +53,14 @@
public static final int UNDEFINED_ACTION = 9;
public static final int WRONG_PASSWORD = 10;
+ /**
+ * Per operation authentication is needed before this operation is valid.
+ * This is returned from {@link #begin} when begin succeeds but the operation uses
+ * per-operation authentication and must authenticate before calling {@link #update} or
+ * {@link #finish}.
+ */
+ public static final int OP_AUTH_NEEDED = 15;
+
// Used for UID field to indicate the calling UID.
public static final int UID_SELF = -1;
diff --git a/libs/hwui/FrameInfo.h b/libs/hwui/FrameInfo.h
index 65daf03..c8189b8 100644
--- a/libs/hwui/FrameInfo.h
+++ b/libs/hwui/FrameInfo.h
@@ -53,6 +53,7 @@
kWindowLayoutChanged = 1 << 0,
kRTAnimation = 1 << 1,
kSurfaceCanvas = 1 << 2,
+ kSkippedFrame = 1 << 3,
};
MAKE_FLAGS_ENUM(FrameInfoFlags)
@@ -101,6 +102,10 @@
set(FrameInfoIndex::kFrameCompleted) = systemTime(CLOCK_MONOTONIC);
}
+ void addFlag(FrameInfoFlags flag) {
+ set(FrameInfoIndex::kFlags) |= static_cast<uint64_t>(flag);
+ }
+
int64_t operator[](FrameInfoIndex index) const {
if (index == FrameInfoIndex::kNumIndexes) return 0;
return mFrameInfo[static_cast<int>(index)];
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 30935d5..f1ec8ae 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1262,7 +1262,7 @@
endTiling();
RenderBuffer* buffer = mCaches.renderBufferCache.get(
- Stencil::getSmallestStencilFormat(),
+ Stencil::getLayerStencilFormat(),
layer->getWidth(), layer->getHeight());
layer->setStencilRenderBuffer(buffer);
diff --git a/libs/hwui/renderstate/Stencil.cpp b/libs/hwui/renderstate/Stencil.cpp
index cedb233..92a057d 100644
--- a/libs/hwui/renderstate/Stencil.cpp
+++ b/libs/hwui/renderstate/Stencil.cpp
@@ -42,12 +42,17 @@
return STENCIL_BUFFER_SIZE;
}
-GLenum Stencil::getSmallestStencilFormat() {
+/**
+ * This method will return either GL_STENCIL_INDEX4_OES if supported,
+ * GL_STENCIL_INDEX8 if not.
+ *
+ * Layers can't use a single bit stencil because multi-rect ClipArea needs a high enough
+ * stencil resolution to represent the summation of multiple intersecting rect geometries.
+ */
+GLenum Stencil::getLayerStencilFormat() {
#if !DEBUG_STENCIL
const Extensions& extensions = Caches::getInstance().extensions();
- if (extensions.has1BitStencil()) {
- return GL_STENCIL_INDEX1_OES;
- } else if (extensions.has4BitStencil()) {
+ if (extensions.has4BitStencil()) {
return GL_STENCIL_INDEX4_OES;
}
#endif
diff --git a/libs/hwui/renderstate/Stencil.h b/libs/hwui/renderstate/Stencil.h
index e4f0f3f..3a8f8eb 100644
--- a/libs/hwui/renderstate/Stencil.h
+++ b/libs/hwui/renderstate/Stencil.h
@@ -42,10 +42,7 @@
*/
ANDROID_API static uint8_t getStencilSize();
- /**
- * Returns the smallest stencil format accepted by render buffers.
- */
- static GLenum getSmallestStencilFormat();
+ static GLenum getLayerStencilFormat();
/**
* Clears the stencil buffer.
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 9237151..3de3086 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -27,12 +27,25 @@
#include "../OpenGLRenderer.h"
#include <algorithm>
+#include <cutils/properties.h>
#include <private/hwui/DrawGlInfo.h>
#include <strings.h>
#define TRIM_MEMORY_COMPLETE 80
#define TRIM_MEMORY_UI_HIDDEN 20
+#define PROPERTY_SKIP_EMPTY_DAMAGE "debug.hwui.skip_empty_damage"
+
+static bool sInitialized = false;
+static bool sSkipEmptyDamage = true;
+
+static void initGlobals() {
+ if (sInitialized) return;
+ sInitialized = true;
+ sSkipEmptyDamage = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE,
+ sSkipEmptyDamage);
+}
+
namespace android {
namespace uirenderer {
namespace renderthread {
@@ -45,6 +58,9 @@
, mAnimationContext(contextFactory->createAnimationContext(mRenderThread.timeLord()))
, mRootRenderNode(rootRenderNode)
, mJankTracker(thread.timeLord().frameIntervalNanos()) {
+ // Done lazily at first draw instead of at library load to avoid
+ // running pre-zygote fork
+ initGlobals();
mRenderThread.renderState().registerCanvasContext(this);
mProfiler.setDensity(mRenderThread.mainDisplayInfo().density);
}
@@ -203,12 +219,17 @@
LOG_ALWAYS_FATAL_IF(!mCanvas || mEglSurface == EGL_NO_SURFACE,
"drawRenderNode called on a context with no canvas or surface!");
- profiler().markPlaybackStart();
- mCurrentFrameInfo->markIssueDrawCommandsStart();
-
SkRect dirty;
mDamageAccumulator.finish(&dirty);
+ if (dirty.isEmpty() && sSkipEmptyDamage) {
+ mCurrentFrameInfo->addFlag(FrameInfoFlags::kSkippedFrame);
+ return;
+ }
+
+ profiler().markPlaybackStart();
+ mCurrentFrameInfo->markIssueDrawCommandsStart();
+
EGLint width, height;
mEglManager.beginFrame(mEglSurface, &width, &height);
if (width != mCanvas->getViewportWidth() || height != mCanvas->getViewportHeight()) {
@@ -277,6 +298,8 @@
prepareTree(info, frameInfo);
if (info.out.canDrawThisFrame) {
draw();
+ } else {
+ mCurrentFrameInfo->addFlag(FrameInfoFlags::kSkippedFrame);
}
}
diff --git a/location/java/android/location/GpsMeasurement.java b/location/java/android/location/GpsMeasurement.java
index df128c9..f13a440 100644
--- a/location/java/android/location/GpsMeasurement.java
+++ b/location/java/android/location/GpsMeasurement.java
@@ -140,8 +140,6 @@
/**
* The state of the GPS receiver contains millisecond ambiguity.
- *
- * @hide
*/
public static final short STATE_MSEC_AMBIGUOUS = (1<<4);
@@ -399,8 +397,6 @@
*
* @return {@code true} if {@link #getPseudorangeRateInMetersPerSec()} contains a corrected
* value, {@code false} if it contains an uncorrected value.
- *
- * @hide
*/
public boolean isPseudorangeRateCorrected() {
return !isFlagSet(GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE);
diff --git a/location/java/android/location/GpsNavigationMessage.java b/location/java/android/location/GpsNavigationMessage.java
index 5b12a61..5c3c710 100644
--- a/location/java/android/location/GpsNavigationMessage.java
+++ b/location/java/android/location/GpsNavigationMessage.java
@@ -62,23 +62,17 @@
/**
* The Navigation Message Status is 'unknown'.
- *
- * @hide
*/
public static final short STATUS_UNKNOWN = 0;
/**
* The Navigation Message was received without any parity error in its navigation words.
- *
- * @hide
*/
public static final short STATUS_PARITY_PASSED = (1<<0);
/**
* The Navigation Message was received with words that failed parity check, but the receiver was
* able to correct those words.
- *
- * @hide
*/
public static final short STATUS_PARITY_REBUILT = (1<<1);
@@ -220,8 +214,6 @@
/**
* Gets the Status of the navigation message contained in the object.
- *
- * @hide
*/
public short getStatus() {
return mStatus;
@@ -229,8 +221,6 @@
/**
* Sets the status of the navigation message.
- *
- * @hide
*/
public void setStatus(short value) {
mStatus = value;
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index 201a796..d5e6b3e 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -26,6 +26,8 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.app.ActivityThread;
+import android.app.Application;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -378,7 +380,7 @@
int initResult = native_setup( new WeakReference<AudioRecord>(this),
mAudioAttributes, mSampleRate, mChannelMask, mChannelIndexMask,
mAudioFormat, mNativeBufferSizeInBytes,
- session);
+ session, getMyOpPackageName());
if (initResult != SUCCESS) {
loge("Error code "+initResult+" when initializing native AudioRecord object.");
return; // with mState == STATE_UNINITIALIZED
@@ -1321,7 +1323,6 @@
return native_set_pos_update_period(periodInFrames);
}
-
//--------------------------------------------------------------------------
// Explicit Routing
//--------------------
@@ -1451,7 +1452,7 @@
private native final int native_setup(Object audiorecord_this,
Object /*AudioAttributes*/ attributes,
int sampleRate, int channelMask, int channelIndexMask, int audioFormat,
- int buffSizeInBytes, int[] sessionId);
+ int buffSizeInBytes, int[] sessionId, String opPackageName);
// TODO remove: implementation calls directly into implementation of native_release()
private native final void native_finalize();
@@ -1500,4 +1501,14 @@
Log.e(TAG, msg);
}
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 78fd9f0..1b054cc 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -18,6 +18,7 @@
import android.annotation.SystemApi;
import android.app.ActivityThread;
+import android.app.Application;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Looper;
@@ -111,7 +112,7 @@
/* Native setup requires a weak reference to our object.
* It's easier to create it here than in C++.
*/
- native_setup(new WeakReference<MediaRecorder>(this), packageName);
+ native_setup(new WeakReference<MediaRecorder>(this), packageName, getMyOpPackageName());
}
/**
@@ -1080,7 +1081,7 @@
private static native final void native_init();
private native final void native_setup(Object mediarecorder_this,
- String clientName) throws IllegalStateException;
+ String clientName, String opPackageName) throws IllegalStateException;
private native final void native_finalize();
@@ -1088,4 +1089,15 @@
@Override
protected void finalize() { native_finalize(); }
+
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/java/android/media/RemoteDisplay.java b/media/java/android/media/RemoteDisplay.java
index 4e937a5..5add65a 100644
--- a/media/java/android/media/RemoteDisplay.java
+++ b/media/java/android/media/RemoteDisplay.java
@@ -37,17 +37,19 @@
private final CloseGuard mGuard = CloseGuard.get();
private final Listener mListener;
private final Handler mHandler;
+ private final String mOpPackageName;
private long mPtr;
- private native long nativeListen(String iface);
+ private native long nativeListen(String iface, String opPackageName);
private native void nativeDispose(long ptr);
private native void nativePause(long ptr);
private native void nativeResume(long ptr);
- private RemoteDisplay(Listener listener, Handler handler) {
+ private RemoteDisplay(Listener listener, Handler handler, String opPackageName) {
mListener = listener;
mHandler = handler;
+ mOpPackageName = opPackageName;
}
@Override
@@ -66,7 +68,8 @@
* @param listener The listener to invoke when displays are connected or disconnected.
* @param handler The handler on which to invoke the listener.
*/
- public static RemoteDisplay listen(String iface, Listener listener, Handler handler) {
+ public static RemoteDisplay listen(String iface, Listener listener, Handler handler,
+ String opPackageName) {
if (iface == null) {
throw new IllegalArgumentException("iface must not be null");
}
@@ -77,7 +80,7 @@
throw new IllegalArgumentException("handler must not be null");
}
- RemoteDisplay display = new RemoteDisplay(listener, handler);
+ RemoteDisplay display = new RemoteDisplay(listener, handler, opPackageName);
display.startListening(iface);
return display;
}
@@ -113,7 +116,7 @@
}
private void startListening(String iface) {
- mPtr = nativeListen(iface);
+ mPtr = nativeListen(iface, mOpPackageName);
if (mPtr == 0) {
throw new IllegalStateException("Could not start listening for "
+ "remote display connection on \"" + iface + "\"");
diff --git a/media/java/android/media/audiofx/AudioEffect.java b/media/java/android/media/audiofx/AudioEffect.java
index a8b9686e..9fc90df 100644
--- a/media/java/android/media/audiofx/AudioEffect.java
+++ b/media/java/android/media/audiofx/AudioEffect.java
@@ -18,6 +18,8 @@
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.app.ActivityThread;
+import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -395,7 +397,7 @@
// native initialization
int initResult = native_setup(new WeakReference<AudioEffect>(this),
type.toString(), uuid.toString(), priority, audioSession, id,
- desc);
+ desc, getMyOpPackageName());
if (initResult != SUCCESS && initResult != ALREADY_EXISTS) {
Log.e(TAG, "Error code " + initResult
+ " when initializing AudioEffect.");
@@ -1217,7 +1219,8 @@
private static native final void native_init();
private native final int native_setup(Object audioeffect_this, String type,
- String uuid, int priority, int audioSession, int[] id, Object[] desc);
+ String uuid, int priority, int audioSession, int[] id, Object[] desc,
+ String opPackageName);
private native final void native_finalize();
@@ -1356,4 +1359,15 @@
}
return b;
}
+
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioEffect outside of an app");
+ }
}
diff --git a/media/java/android/media/audiofx/Visualizer.java b/media/java/android/media/audiofx/Visualizer.java
index 24c74ac..0c48063 100644
--- a/media/java/android/media/audiofx/Visualizer.java
+++ b/media/java/android/media/audiofx/Visualizer.java
@@ -16,6 +16,8 @@
package android.media.audiofx;
+import android.app.ActivityThread;
+import android.app.Application;
import android.util.Log;
import java.lang.ref.WeakReference;
import android.os.Handler;
@@ -206,7 +208,8 @@
synchronized (mStateLock) {
mState = STATE_UNINITIALIZED;
// native initialization
- int result = native_setup(new WeakReference<Visualizer>(this), audioSession, id);
+ int result = native_setup(new WeakReference<Visualizer>(this), audioSession, id,
+ getMyOpPackageName());
if (result != SUCCESS && result != ALREADY_EXISTS) {
Log.e(TAG, "Error code "+result+" when initializing Visualizer.");
switch (result) {
@@ -716,7 +719,8 @@
private native final int native_setup(Object audioeffect_this,
int audioSession,
- int[] id);
+ int[] id,
+ String opPackageName);
private native final void native_finalize();
@@ -766,5 +770,15 @@
}
+ private static String getMyOpPackageName() {
+ ActivityThread activityThread = ActivityThread.currentActivityThread();
+ if (activityThread != null) {
+ Application application = activityThread.getApplication();
+ if (application != null) {
+ return application.getOpPackageName();
+ }
+ }
+ throw new IllegalStateException("Cannot create AudioRecord outside of an app");
+ }
}
diff --git a/media/java/android/media/midi/MidiDeviceInfo.java b/media/java/android/media/midi/MidiDeviceInfo.java
index af108eb..35374ed 100644
--- a/media/java/android/media/midi/MidiDeviceInfo.java
+++ b/media/java/android/media/midi/MidiDeviceInfo.java
@@ -69,6 +69,13 @@
public static final String PROPERTY_PRODUCT = "product";
/**
+ * Bundle key for the device's version property.
+ * Used with the {@link android.os.Bundle} returned by {@link #getProperties}
+ * Matches the USB device version number for USB MIDI devices.
+ */
+ public static final String PROPERTY_VERSION = "version";
+
+ /**
* Bundle key for the device's serial number property.
* Used with the {@link android.os.Bundle} returned by {@link #getProperties}
* Matches the USB device serial number for USB MIDI devices.
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 8b7d40d..02297fc 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -31,6 +31,8 @@
#include <media/mediarecorder.h>
#include <utils/threads.h>
+#include <ScopedUtfChars.h>
+
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
@@ -444,11 +446,13 @@
static void
android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jstring packageName)
+ jstring packageName, jstring opPackageName)
{
ALOGV("setup");
- sp<MediaRecorder> mr = new MediaRecorder();
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
+ sp<MediaRecorder> mr = new MediaRecorder(String16(opPackageNameStr.c_str()));
if (mr == NULL) {
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
return;
@@ -506,7 +510,8 @@
{"native_reset", "()V", (void *)android_media_MediaRecorder_native_reset},
{"release", "()V", (void *)android_media_MediaRecorder_release},
{"native_init", "()V", (void *)android_media_MediaRecorder_native_init},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;)V", (void *)android_media_MediaRecorder_native_setup},
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V",
+ (void *)android_media_MediaRecorder_native_setup},
{"native_finalize", "()V", (void *)android_media_MediaRecorder_native_finalize},
};
diff --git a/media/jni/audioeffect/android_media_AudioEffect.cpp b/media/jni/audioeffect/android_media_AudioEffect.cpp
index c364d469..96b72a2 100644
--- a/media/jni/audioeffect/android_media_AudioEffect.cpp
+++ b/media/jni/audioeffect/android_media_AudioEffect.cpp
@@ -25,6 +25,8 @@
#include <android_runtime/AndroidRuntime.h>
#include "media/AudioEffect.h"
+#include <ScopedUtfChars.h>
+
using namespace android;
#define AUDIOEFFECT_SUCCESS 0
@@ -249,7 +251,8 @@
static jint
android_media_AudioEffect_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId, jobjectArray javadesc)
+ jstring type, jstring uuid, jint priority, jint sessionId, jintArray jId,
+ jobjectArray javadesc, jstring opPackageName)
{
ALOGV("android_media_AudioEffect_native_setup");
AudioEffectJniStorage* lpJniStorage = NULL;
@@ -267,6 +270,8 @@
jstring jdescName;
jstring jdescImplementor;
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
if (type != NULL) {
typeStr = env->GetStringUTFChars(type, NULL);
if (typeStr == NULL) { // Out of memory
@@ -312,6 +317,7 @@
// create the native AudioEffect object
lpAudioEffect = new AudioEffect(typeStr,
+ String16(opPackageNameStr.c_str()),
uuidStr,
priority,
effectCallback,
@@ -868,7 +874,7 @@
// Dalvik VM type signatures
static JNINativeMethod gMethods[] = {
{"native_init", "()V", (void *)android_media_AudioEffect_native_init},
- {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;)I",
+ {"native_setup", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;II[I[Ljava/lang/Object;Ljava/lang/String;)I",
(void *)android_media_AudioEffect_native_setup},
{"native_finalize", "()V", (void *)android_media_AudioEffect_native_finalize},
{"native_release", "()V", (void *)android_media_AudioEffect_native_release},
diff --git a/media/jni/audioeffect/android_media_Visualizer.cpp b/media/jni/audioeffect/android_media_Visualizer.cpp
index 460277f..abc681e 100644
--- a/media/jni/audioeffect/android_media_Visualizer.cpp
+++ b/media/jni/audioeffect/android_media_Visualizer.cpp
@@ -26,6 +26,8 @@
#include <utils/threads.h>
#include "media/Visualizer.h"
+#include <ScopedUtfChars.h>
+
using namespace android;
#define VISUALIZER_SUCCESS 0
@@ -331,7 +333,7 @@
static jint
android_media_visualizer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
- jint sessionId, jintArray jId)
+ jint sessionId, jintArray jId, jstring opPackageName)
{
ALOGV("android_media_visualizer_native_setup");
visualizerJniStorage* lpJniStorage = NULL;
@@ -339,6 +341,8 @@
Visualizer* lpVisualizer = NULL;
jint* nId = NULL;
+ ScopedUtfChars opPackageNameStr(env, opPackageName);
+
lpJniStorage = new visualizerJniStorage();
if (lpJniStorage == NULL) {
ALOGE("setup: Error creating JNI Storage");
@@ -362,7 +366,8 @@
}
// create the native Visualizer object
- lpVisualizer = new Visualizer(0,
+ lpVisualizer = new Visualizer(String16(opPackageNameStr.c_str()),
+ 0,
android_media_visualizer_effect_callback,
lpJniStorage,
sessionId);
@@ -662,7 +667,7 @@
// Dalvik VM type signatures
static JNINativeMethod gMethods[] = {
{"native_init", "()V", (void *)android_media_visualizer_native_init},
- {"native_setup", "(Ljava/lang/Object;I[I)I",
+ {"native_setup", "(Ljava/lang/Object;I[ILjava/lang/String;)I",
(void *)android_media_visualizer_native_setup},
{"native_finalize", "()V", (void *)android_media_visualizer_native_finalize},
{"native_release", "()V", (void *)android_media_visualizer_native_release},
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index 0e3867d..745c190 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -461,7 +461,7 @@
// to run during this time are placed in mPendingWhileIdleAlarms
Alarm mPendingIdleUntil = null;
Alarm mNextWakeFromIdle = null;
- final ArrayList<Alarm> mPendingWhileIdleAlarms = new ArrayList<>();
+ ArrayList<Alarm> mPendingWhileIdleAlarms = new ArrayList<>();
public AlarmManagerService(Context context) {
super(context);
@@ -567,10 +567,14 @@
void restorePendingWhileIdleAlarmsLocked() {
// Bring pending alarms back into the main list.
- final long nowElapsed = SystemClock.elapsedRealtime();
- for (int i=mPendingWhileIdleAlarms.size() - 1; i >= 0 && mPendingIdleUntil == null; i--) {
- Alarm a = mPendingWhileIdleAlarms.remove(i);
- reAddAlarmLocked(a, nowElapsed, false);
+ if (mPendingWhileIdleAlarms.size() > 0) {
+ ArrayList<Alarm> alarms = mPendingWhileIdleAlarms;
+ mPendingWhileIdleAlarms = new ArrayList<>();
+ final long nowElapsed = SystemClock.elapsedRealtime();
+ for (int i=alarms.size() - 1; i >= 0; i--) {
+ Alarm a = alarms.get(i);
+ reAddAlarmLocked(a, nowElapsed, false);
+ }
}
// Reschedule everything.
@@ -1053,11 +1057,16 @@
dumpAlarmList(pw, b.alarms, " ", nowELAPSED, nowRTC, sdf);
}
}
- if (mPendingIdleUntil != null) {
+ if (mPendingIdleUntil != null || mPendingWhileIdleAlarms.size() > 0) {
pw.println();
pw.println("Idle mode state:");
- pw.print(" Idling until: "); pw.println(mPendingIdleUntil);
- mPendingIdleUntil.dump(pw, " ", nowRTC, nowELAPSED, sdf);
+ pw.print(" Idling until: ");
+ if (mPendingIdleUntil != null) {
+ pw.println(mPendingIdleUntil);
+ mPendingIdleUntil.dump(pw, " ", nowRTC, nowELAPSED, sdf);
+ } else {
+ pw.println("null");
+ }
pw.println(" Pending alarms:");
dumpAlarmList(pw, mPendingWhileIdleAlarms, " ", nowELAPSED, nowRTC, sdf);
}
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
new file mode 100644
index 0000000..b7bc0f0
--- /dev/null
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -0,0 +1,879 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package com.android.server;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.hardware.TriggerEvent;
+import android.hardware.TriggerEventListener;
+import android.hardware.display.DisplayManager;
+import android.net.INetworkPolicyManager;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.IDeviceIdleController;
+import android.os.Looper;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.PowerManagerInternal;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Slog;
+import android.util.SparseBooleanArray;
+import android.util.TimeUtils;
+import android.util.Xml;
+import android.view.Display;
+import com.android.internal.app.IBatteryStats;
+import com.android.internal.os.AtomicFile;
+import com.android.internal.os.BackgroundThread;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+import com.android.server.am.BatteryStatsService;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * Keeps track of device idleness and drives low power mode based on that.
+ */
+public class DeviceIdleController extends SystemService {
+ private static final String TAG = "DeviceIdleController";
+
+ public static final String SERVICE_NAME = "deviceidle";
+
+ private static final String ACTION_STEP_IDLE_STATE =
+ "com.android.server.device_idle.STEP_IDLE_STATE";
+
+ // TODO: These need to be moved to system settings.
+
+ /**
+ * This is the time, after becoming inactive, at which we start looking at the
+ * motion sensor to determine if the device is being left alone. We don't do this
+ * immediately after going inactive just because we don't want to be continually running
+ * the significant motion sensor whenever the screen is off.
+ */
+ private static final long DEFAULT_INACTIVE_TIMEOUT = 30*60*1000L;
+ /**
+ * This is the time, after seeing motion, that we wait after becoming inactive from
+ * that until we start looking for motion again.
+ */
+ private static final long DEFAULT_MOTION_INACTIVE_TIMEOUT = 10*60*1000L;
+ /**
+ * This is the time, after the inactive timeout elapses, that we will wait looking
+ * for significant motion until we truly consider the device to be idle.
+ */
+ private static final long DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT = 30*60*1000L;
+ /**
+ * This is the initial time, after being idle, that we will allow ourself to be back
+ * in the IDLE_PENDING state allowing the system to run normally until we return to idle.
+ */
+ private static final long DEFAULT_IDLE_PENDING_TIMEOUT = 5*60*1000L;
+ /**
+ * Maximum pending idle timeout (time spent running) we will be allowed to use.
+ */
+ private static final long DEFAULT_MAX_IDLE_PENDING_TIMEOUT = 10*60*1000L;
+ /**
+ * Scaling factor to apply to current pending idle timeout each time we cycle through
+ * that state.
+ */
+ private static final float DEFAULT_IDLE_PENDING_FACTOR = 2f;
+ /**
+ * This is the initial time that we want to sit in the idle state before waking up
+ * again to return to pending idle and allowing normal work to run.
+ */
+ private static final long DEFAULT_IDLE_TIMEOUT = 60*60*1000L;
+ /**
+ * Maximum idle duration we will be allowed to use.
+ */
+ private static final long DEFAULT_MAX_IDLE_TIMEOUT = 6*60*60*1000L;
+ /**
+ * Scaling factor to apply to current idle timeout each time we cycle through that state.
+ */
+ private static final float DEFAULT_IDLE_FACTOR = 2f;
+ /**
+ * This is the minimum time we will allow until the next upcoming alarm for us to
+ * actually go in to idle mode.
+ */
+ private static final long DEFAULT_MIN_TIME_TO_ALARM = 60*60*1000L;
+
+ private AlarmManager mAlarmManager;
+ private IBatteryStats mBatteryStats;
+ private PowerManagerInternal mLocalPowerManager;
+ private INetworkPolicyManager mNetworkPolicyManager;
+ private DisplayManager mDisplayManager;
+ private SensorManager mSensorManager;
+ private Sensor mSigMotionSensor;
+ private PendingIntent mAlarmIntent;
+ private Intent mIdleIntent;
+ private Display mCurDisplay;
+ private boolean mScreenOn;
+ private boolean mCharging;
+ private boolean mSigMotionActive;
+
+ /** Device is currently active. */
+ private static final int STATE_ACTIVE = 0;
+ /** Device is inactve (screen off, no motion) and we are waiting to for idle. */
+ private static final int STATE_INACTIVE = 1;
+ /** Device is past the initial inactive period, and waiting for the next idle period. */
+ private static final int STATE_IDLE_PENDING = 2;
+ /** Device is in the idle state, trying to stay asleep as much as possible. */
+ private static final int STATE_IDLE = 3;
+ /** Device is in the idle state, but temporarily out of idle to do regular maintenance. */
+ private static final int STATE_IDLE_MAINTENANCE = 4;
+ private static String stateToString(int state) {
+ switch (state) {
+ case STATE_ACTIVE: return "ACTIVE";
+ case STATE_INACTIVE: return "INACTIVE";
+ case STATE_IDLE_PENDING: return "IDLE_PENDING";
+ case STATE_IDLE: return "IDLE";
+ case STATE_IDLE_MAINTENANCE: return "IDLE_MAINTENANCE";
+ default: return Integer.toString(state);
+ }
+ }
+
+ private int mState;
+
+ private long mInactiveTimeout;
+ private long mNextAlarmTime;
+ private long mNextIdlePendingDelay;
+ private long mNextIdleDelay;
+
+ public final AtomicFile mConfigFile;
+
+ /**
+ * Package names the system has white-listed to opt out of power save restrictions.
+ */
+ private final ArrayMap<String, Integer> mPowerSaveWhitelistApps = new ArrayMap<>();
+
+ /**
+ * Package names the user has white-listed to opt out of power save restrictions.
+ */
+ private final ArrayMap<String, Integer> mPowerSaveWhitelistUserApps = new ArrayMap<>();
+
+ /**
+ * UIDs that have been white-listed to opt out of power save restrictions.
+ */
+ private final SparseBooleanArray mPowerSaveWhitelistAppIds = new SparseBooleanArray();
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
+ int plugged = intent.getIntExtra("plugged", 0);
+ updateChargingLocked(plugged != 0);
+ } else if (ACTION_STEP_IDLE_STATE.equals(intent.getAction())) {
+ synchronized (DeviceIdleController.this) {
+ stepIdleStateLocked();
+ }
+ }
+ }
+ };
+
+ private final DisplayManager.DisplayListener mDisplayListener
+ = new DisplayManager.DisplayListener() {
+ @Override public void onDisplayAdded(int displayId) {
+ }
+
+ @Override public void onDisplayRemoved(int displayId) {
+ }
+
+ @Override public void onDisplayChanged(int displayId) {
+ if (displayId == Display.DEFAULT_DISPLAY) {
+ synchronized (DeviceIdleController.this) {
+ updateDisplayLocked();
+ }
+ }
+ }
+ };
+
+ private final TriggerEventListener mSigMotionListener = new TriggerEventListener() {
+ @Override public void onTrigger(TriggerEvent event) {
+ synchronized (DeviceIdleController.this) {
+ significantMotionLocked();
+ }
+ }
+ };
+
+ static final int MSG_WRITE_CONFIG = 1;
+ static final int MSG_REPORT_IDLE_ON = 2;
+ static final int MSG_REPORT_IDLE_OFF = 3;
+ static final int MSG_REPORT_ACTIVE = 4;
+
+ final class MyHandler extends Handler {
+ MyHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_WRITE_CONFIG: {
+ handleWriteConfigFile();
+ } break;
+ case MSG_REPORT_IDLE_ON: {
+ mLocalPowerManager.setDeviceIdleMode(true);
+ try {
+ mNetworkPolicyManager.setDeviceIdleMode(true);
+ mBatteryStats.noteDeviceIdleMode(true, false, false);
+ } catch (RemoteException e) {
+ }
+ getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
+ } break;
+ case MSG_REPORT_IDLE_OFF: {
+ mLocalPowerManager.setDeviceIdleMode(false);
+ try {
+ mNetworkPolicyManager.setDeviceIdleMode(false);
+ mBatteryStats.noteDeviceIdleMode(false, false, false);
+ } catch (RemoteException e) {
+ }
+ getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
+ } break;
+ case MSG_REPORT_ACTIVE: {
+ boolean fromMotion = msg.arg1 != 0;
+ boolean needBroadcast = msg.arg2 != 0;
+ mLocalPowerManager.setDeviceIdleMode(false);
+ try {
+ mNetworkPolicyManager.setDeviceIdleMode(false);
+ mBatteryStats.noteDeviceIdleMode(false, !fromMotion, fromMotion);
+ } catch (RemoteException e) {
+ }
+ if (needBroadcast) {
+ getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
+ }
+ } break;
+ }
+ }
+ }
+
+ final MyHandler mHandler;
+
+ private final class BinderService extends IDeviceIdleController.Stub {
+ @Override public void addPowerSaveWhitelistApp(String name) {
+ getContext().enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER,
+ null);
+ addPowerSaveWhitelistAppInternal(name);
+ }
+
+ @Override public void removePowerSaveWhitelistApp(String name) {
+ getContext().enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER,
+ null);
+ removePowerSaveWhitelistAppInternal(name);
+ }
+
+ @Override public String[] getSystemPowerWhitelist() {
+ return getSystemPowerWhitelistInternal();
+ }
+
+ @Override public String[] getFullPowerWhitelist() {
+ return getFullPowerWhitelistInternal();
+ }
+
+ @Override public int[] getAppIdWhitelist() {
+ return getAppIdWhitelistInternal();
+ }
+
+ @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ DeviceIdleController.this.dump(fd, pw, args);
+ }
+ }
+
+ public DeviceIdleController(Context context) {
+ super(context);
+ mConfigFile = new AtomicFile(new File(getSystemDir(), "deviceidle.xml"));
+ mHandler = new MyHandler(BackgroundThread.getHandler().getLooper());
+ }
+
+ private static File getSystemDir() {
+ return new File(Environment.getDataDirectory(), "system");
+ }
+
+ @Override
+ public void onStart() {
+ final PackageManager pm = getContext().getPackageManager();
+
+ synchronized (this) {
+ SystemConfig sysConfig = SystemConfig.getInstance();
+ ArraySet<String> allowPower = sysConfig.getAllowInPowerSave();
+ for (int i=0; i<allowPower.size(); i++) {
+ String pkg = allowPower.valueAt(i);
+ try {
+ ApplicationInfo ai = pm.getApplicationInfo(pkg, 0);
+ if ((ai.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
+ mPowerSaveWhitelistApps.put(ai.packageName,
+ UserHandle.getAppId(ai.uid));
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ }
+
+ readConfigFileLocked();
+ updateWhitelistAppIdsLocked();
+
+ mScreenOn = true;
+ // Start out assuming we are charging. If we aren't, we will at least get
+ // a battery update the next time the level drops.
+ mCharging = true;
+ mState = STATE_ACTIVE;
+ mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT;
+ }
+
+ publishBinderService(SERVICE_NAME, new BinderService());
+ }
+
+ @Override
+ public void onBootPhase(int phase) {
+ if (phase == PHASE_SYSTEM_SERVICES_READY) {
+ synchronized (this) {
+ mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
+ mBatteryStats = BatteryStatsService.getService();
+ mLocalPowerManager = getLocalService(PowerManagerInternal.class);
+ mNetworkPolicyManager = INetworkPolicyManager.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
+ mDisplayManager = (DisplayManager) getContext().getSystemService(
+ Context.DISPLAY_SERVICE);
+ mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
+ mSigMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
+
+ Intent intent = new Intent(ACTION_STEP_IDLE_STATE)
+ .setPackage("android")
+ .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+ mAlarmIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
+
+ mIdleIntent = new Intent(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
+ mIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ filter.addAction(ACTION_STEP_IDLE_STATE);
+ getContext().registerReceiver(mReceiver, filter);
+
+ mDisplayManager.registerDisplayListener(mDisplayListener, null);
+ updateDisplayLocked();
+ }
+ }
+ }
+
+ public boolean addPowerSaveWhitelistAppInternal(String name) {
+ synchronized (this) {
+ try {
+ ApplicationInfo ai = getContext().getPackageManager().getApplicationInfo(name, 0);
+ if (mPowerSaveWhitelistUserApps.put(name, UserHandle.getAppId(ai.uid)) == null) {
+ reportPowerSaveWhitelistChangedLocked();
+ updateWhitelistAppIdsLocked();
+ writeConfigFileLocked();
+ }
+ return true;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+ }
+
+ public boolean removePowerSaveWhitelistAppInternal(String name) {
+ synchronized (this) {
+ if (mPowerSaveWhitelistUserApps.remove(name) != null) {
+ reportPowerSaveWhitelistChangedLocked();
+ updateWhitelistAppIdsLocked();
+ writeConfigFileLocked();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String[] getSystemPowerWhitelistInternal() {
+ synchronized (this) {
+ int size = mPowerSaveWhitelistApps.size();
+ String[] apps = new String[size];
+ for (int i = 0; i < mPowerSaveWhitelistApps.size(); i++) {
+ apps[i] = mPowerSaveWhitelistApps.keyAt(i);
+ }
+ return apps;
+ }
+ }
+
+ public String[] getFullPowerWhitelistInternal() {
+ synchronized (this) {
+ int size = mPowerSaveWhitelistApps.size() + mPowerSaveWhitelistUserApps.size();
+ String[] apps = new String[size];
+ int cur = 0;
+ for (int i = 0; i < mPowerSaveWhitelistApps.size(); i++) {
+ apps[cur] = mPowerSaveWhitelistApps.keyAt(i);
+ cur++;
+ }
+ for (int i = 0; i < mPowerSaveWhitelistUserApps.size(); i++) {
+ apps[cur] = mPowerSaveWhitelistUserApps.keyAt(i);
+ cur++;
+ }
+ return apps;
+ }
+ }
+
+ public int[] getAppIdWhitelistInternal() {
+ synchronized (this) {
+ int size = mPowerSaveWhitelistAppIds.size();
+ int[] appids = new int[size];
+ for (int i = 0; i < size; i++) {
+ appids[i] = mPowerSaveWhitelistAppIds.keyAt(i);
+ }
+ return appids;
+ }
+ }
+
+ void updateDisplayLocked() {
+ mCurDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
+ // We consider any situation where the display is showing something to be it on,
+ // because if there is anything shown we are going to be updating it at some
+ // frequency so can't be allowed to go into deep sleeps.
+ boolean screenOn = mCurDisplay.getState() != Display.STATE_OFF;;
+ if (!screenOn && mScreenOn) {
+ mScreenOn = false;
+ becomeInactiveIfAppropriateLocked();
+ } else if (screenOn) {
+ mScreenOn = true;
+ becomeActiveLocked("screen");
+ }
+ }
+
+ void updateChargingLocked(boolean charging) {
+ if (!charging && mCharging) {
+ mCharging = false;
+ becomeInactiveIfAppropriateLocked();
+ } else if (charging) {
+ mCharging = charging;
+ becomeActiveLocked("charging");
+ }
+ }
+
+ void scheduleReportActiveLocked(boolean fromMotion) {
+ Message msg = mHandler.obtainMessage(MSG_REPORT_ACTIVE, fromMotion ? 1 : 0,
+ mState == STATE_IDLE ? 1 : 0);
+ mHandler.sendMessage(msg);
+ }
+
+ void becomeActiveLocked(String reason) {
+ if (mState != STATE_ACTIVE) {
+ EventLogTags.writeDeviceIdle(STATE_ACTIVE, reason);
+ scheduleReportActiveLocked(false);
+ mState = STATE_ACTIVE;
+ mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT;
+ mNextIdlePendingDelay = 0;
+ mNextIdleDelay = 0;
+ cancelAlarmLocked();
+ stopMonitoringSignificantMotion();
+ }
+ }
+
+ void becomeInactiveIfAppropriateLocked() {
+ if (!mScreenOn && !mCharging && mState == STATE_ACTIVE) {
+ // Screen has turned off; we are now going to become inactive and start
+ // waiting to see if we will ultimately go idle.
+ mState = STATE_INACTIVE;
+ mNextIdlePendingDelay = 0;
+ mNextIdleDelay = 0;
+ scheduleAlarmLocked(mInactiveTimeout, false);
+ EventLogTags.writeDeviceIdle(mState, "no activity");
+ }
+ }
+
+ void stepIdleStateLocked() {
+ EventLogTags.writeDeviceIdleStep();
+
+ final long now = SystemClock.elapsedRealtime();
+ if ((now+DEFAULT_MIN_TIME_TO_ALARM) > mAlarmManager.getNextWakeFromIdleTime()) {
+ // Whoops, there is an upcoming alarm. We don't actually want to go idle.
+ if (mState != STATE_ACTIVE) {
+ becomeActiveLocked("alarm");
+ }
+ return;
+ }
+
+ switch (mState) {
+ case STATE_INACTIVE:
+ // We have now been inactive long enough, it is time to start looking
+ // for significant motion and sleep some more while doing so.
+ startMonitoringSignificantMotion();
+ scheduleAlarmLocked(DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT, false);
+ // Reset the upcoming idle delays.
+ mNextIdlePendingDelay = DEFAULT_IDLE_PENDING_TIMEOUT;
+ mNextIdleDelay = DEFAULT_IDLE_TIMEOUT;
+ mState = STATE_IDLE_PENDING;
+ EventLogTags.writeDeviceIdle(mState, "step");
+ break;
+ case STATE_IDLE_PENDING:
+ case STATE_IDLE_MAINTENANCE:
+ // We have been waiting to become idle, and now it is time! This is the
+ // only case where we want to use a wakeup alarm, because we do want to
+ // drag the device out of its sleep state in this case to do the next
+ // scheduled work.
+ scheduleAlarmLocked(mNextIdleDelay, true);
+ mNextIdleDelay = (long)(mNextIdleDelay*DEFAULT_IDLE_FACTOR);
+ if (mNextIdleDelay > DEFAULT_MAX_IDLE_TIMEOUT) {
+ mNextIdleDelay = DEFAULT_MAX_IDLE_TIMEOUT;
+ }
+ mState = STATE_IDLE;
+ EventLogTags.writeDeviceIdle(mState, "step");
+ mHandler.sendEmptyMessage(MSG_REPORT_IDLE_ON);
+ break;
+ case STATE_IDLE:
+ // We have been idling long enough, now it is time to do some work.
+ scheduleAlarmLocked(mNextIdlePendingDelay, false);
+ mNextIdlePendingDelay = (long)(mNextIdlePendingDelay*DEFAULT_IDLE_PENDING_FACTOR);
+ if (mNextIdlePendingDelay > DEFAULT_MAX_IDLE_PENDING_TIMEOUT) {
+ mNextIdlePendingDelay = DEFAULT_MAX_IDLE_PENDING_TIMEOUT;
+ }
+ mState = STATE_IDLE_MAINTENANCE;
+ EventLogTags.writeDeviceIdle(mState, "step");
+ mHandler.sendEmptyMessage(MSG_REPORT_IDLE_OFF);
+ break;
+ }
+ }
+
+ void significantMotionLocked() {
+ // When the sensor goes off, its trigger is automatically removed.
+ mSigMotionActive = false;
+ // The device is not yet active, so we want to go back to the pending idle
+ // state to wait again for no motion. Note that we only monitor for significant
+ // motion after moving out of the inactive state, so no need to worry about that.
+ if (mState != STATE_ACTIVE) {
+ scheduleReportActiveLocked(true);
+ mState = STATE_ACTIVE;
+ mInactiveTimeout = DEFAULT_MOTION_INACTIVE_TIMEOUT;
+ EventLogTags.writeDeviceIdle(mState, "motion");
+ becomeInactiveIfAppropriateLocked();
+ }
+ }
+
+ void startMonitoringSignificantMotion() {
+ if (mSigMotionSensor != null && !mSigMotionActive) {
+ mSensorManager.requestTriggerSensor(mSigMotionListener, mSigMotionSensor);
+ mSigMotionActive = true;
+ }
+ }
+
+ void stopMonitoringSignificantMotion() {
+ if (mSigMotionActive) {
+ mSensorManager.cancelTriggerSensor(mSigMotionListener, mSigMotionSensor);
+ mSigMotionActive = false;
+ }
+ }
+
+ void cancelAlarmLocked() {
+ if (mNextAlarmTime != 0) {
+ mNextAlarmTime = 0;
+ mAlarmManager.cancel(mAlarmIntent);
+ }
+ }
+
+ void scheduleAlarmLocked(long delay, boolean idleUntil) {
+ if (mSigMotionSensor == null) {
+ // If there is no significant motion sensor on this device, then we won't schedule
+ // alarms, because we can't determine if the device is not moving. This effectively
+ // turns off normal exeuction of device idling, although it is still possible to
+ // manually poke it by pretending like the alarm is going off.
+ return;
+ }
+ mNextAlarmTime = SystemClock.elapsedRealtime() + delay;
+ if (idleUntil) {
+ mAlarmManager.setIdleUntil(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+ mNextAlarmTime, mAlarmIntent);
+ } else {
+ mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+ mNextAlarmTime, mAlarmIntent);
+ }
+ }
+
+ private void updateWhitelistAppIdsLocked() {
+ mPowerSaveWhitelistAppIds.clear();
+ for (int i=0; i<mPowerSaveWhitelistApps.size(); i++) {
+ mPowerSaveWhitelistAppIds.put(mPowerSaveWhitelistApps.valueAt(i), true);
+ }
+ for (int i=0; i<mPowerSaveWhitelistUserApps.size(); i++) {
+ mPowerSaveWhitelistAppIds.put(mPowerSaveWhitelistUserApps.valueAt(i), true);
+ }
+ }
+
+ private void reportPowerSaveWhitelistChangedLocked() {
+ Intent intent = new Intent(PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+ getContext().sendBroadcast(intent);
+ }
+
+ void readConfigFileLocked() {
+ Slog.d(TAG, "Reading config from " + mConfigFile.getBaseFile());
+ mPowerSaveWhitelistUserApps.clear();
+ FileInputStream stream;
+ try {
+ stream = mConfigFile.openRead();
+ } catch (FileNotFoundException e) {
+ return;
+ }
+ try {
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(stream, null);
+ readConfigFileLocked(parser);
+ } catch (XmlPullParserException e) {
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ }
+ }
+
+ }
+
+ private void readConfigFileLocked(XmlPullParser parser) {
+ final PackageManager pm = getContext().getPackageManager();
+
+ try {
+ int type;
+ while ((type = parser.next()) != XmlPullParser.START_TAG
+ && type != XmlPullParser.END_DOCUMENT) {
+ ;
+ }
+
+ if (type != XmlPullParser.START_TAG) {
+ throw new IllegalStateException("no start tag found");
+ }
+
+ int outerDepth = parser.getDepth();
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+ if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+ continue;
+ }
+
+ String tagName = parser.getName();
+ if (tagName.equals("wl")) {
+ String name = parser.getAttributeValue(null, "n");
+ if (name != null) {
+ try {
+ ApplicationInfo ai = pm.getApplicationInfo(name, 0);
+ mPowerSaveWhitelistUserApps.put(ai.packageName,
+ UserHandle.getAppId(ai.uid));
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ }
+ } else {
+ Slog.w(TAG, "Unknown element under <config>: "
+ + parser.getName());
+ XmlUtils.skipCurrentTag(parser);
+ }
+ }
+
+ } catch (IllegalStateException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ } catch (NullPointerException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ } catch (NumberFormatException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ } catch (XmlPullParserException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ } catch (IOException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ } catch (IndexOutOfBoundsException e) {
+ Slog.w(TAG, "Failed parsing config " + e);
+ }
+ }
+
+ void writeConfigFileLocked() {
+ mHandler.removeMessages(MSG_WRITE_CONFIG);
+ mHandler.sendEmptyMessageDelayed(MSG_WRITE_CONFIG, 5000);
+ }
+
+ void handleWriteConfigFile() {
+ final ByteArrayOutputStream memStream = new ByteArrayOutputStream();
+
+ try {
+ synchronized (this) {
+ XmlSerializer out = new FastXmlSerializer();
+ out.setOutput(memStream, "utf-8");
+ writeConfigFileLocked(out);
+ }
+ } catch (IOException e) {
+ }
+
+ synchronized (mConfigFile) {
+ FileOutputStream stream = null;
+ try {
+ stream = mConfigFile.startWrite();
+ memStream.writeTo(stream);
+ stream.flush();
+ FileUtils.sync(stream);
+ stream.close();
+ mConfigFile.finishWrite(stream);
+ } catch (IOException e) {
+ Slog.w(TAG, "Error writing config file", e);
+ mConfigFile.failWrite(stream);
+ }
+ }
+ }
+
+ void writeConfigFileLocked(XmlSerializer out) throws IOException {
+ out.startDocument(null, true);
+ out.startTag(null, "config");
+ for (int i=0; i<mPowerSaveWhitelistUserApps.size(); i++) {
+ String name = mPowerSaveWhitelistUserApps.keyAt(i);
+ out.startTag(null, "wl");
+ out.attribute(null, "n", name);
+ out.endTag(null, "wl");
+ }
+ out.endTag(null, "config");
+ out.endDocument();
+ }
+
+ private void dumpHelp(PrintWriter pw) {
+ pw.println("Device idle controller (deviceidle) dump options:");
+ pw.println(" [-h] [CMD]");
+ pw.println(" -h: print this help text.");
+ pw.println("Commands:");
+ pw.println(" step");
+ pw.println(" Immediately step to next state, without waiting for alarm.");
+ pw.println(" whitelist");
+ pw.println(" Add (prefix with +) or remove (prefix with -) packages.");
+ }
+
+ void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+ != PackageManager.PERMISSION_GRANTED) {
+ pw.println("Permission Denial: can't dump DeviceIdleController from from pid="
+ + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+ + " without permission " + android.Manifest.permission.DUMP);
+ return;
+ }
+
+ if (args != null) {
+ for (int i=0; i<args.length; i++) {
+ String arg = args[i];
+ if ("-h".equals(arg)) {
+ dumpHelp(pw);
+ return;
+ } else if ("step".equals(arg)) {
+ synchronized (this) {
+ stepIdleStateLocked();
+ pw.print("Stepped to: "); pw.println(stateToString(mState));
+ }
+ return;
+ } else if ("whitelist".equals(arg)) {
+ i++;
+ while (i < args.length) {
+ arg = args[i];
+ i++;
+ if (arg.length() < 1 || (arg.charAt(0) != '-'
+ && arg.charAt(0) != '+')) {
+ pw.println("Package must be prefixed with + or -: " + arg);
+ return;
+ }
+ char op = arg.charAt(0);
+ String pkg = arg.substring(1);
+ if (op == '+') {
+ if (addPowerSaveWhitelistAppInternal(pkg)) {
+ pw.println("Added: " + pkg);
+ } else {
+ pw.println("Unknown package: " + pkg);
+ }
+ } else {
+ if (removePowerSaveWhitelistAppInternal(pkg)) {
+ pw.println("Removed: " + pkg);
+ }
+ }
+ }
+ return;
+ } else if (arg.length() > 0 && arg.charAt(0) == '-'){
+ pw.println("Unknown option: " + arg);
+ return;
+ } else {
+ pw.println("Unknown command: " + arg);
+ return;
+ }
+ }
+ }
+
+ synchronized (this) {
+ int size = mPowerSaveWhitelistApps.size();
+ if (size > 0) {
+ pw.println(" Whitelist system apps:");
+ for (int i = 0; i < size; i++) {
+ pw.print(" ");
+ pw.println(mPowerSaveWhitelistApps.keyAt(i));
+ }
+ }
+ size = mPowerSaveWhitelistUserApps.size();
+ if (size > 0) {
+ pw.println(" Whitelist user apps:");
+ for (int i = 0; i < size; i++) {
+ pw.print(" ");
+ pw.println(mPowerSaveWhitelistUserApps.keyAt(i));
+ }
+ }
+ size = mPowerSaveWhitelistAppIds.size();
+ if (size > 0) {
+ pw.println(" Whitelist app uids:");
+ for (int i = 0; i < size; i++) {
+ pw.print(" UID=");
+ pw.print(mPowerSaveWhitelistAppIds.keyAt(i));
+ pw.print(": ");
+ pw.print(mPowerSaveWhitelistAppIds.valueAt(i));
+ pw.println();
+ }
+ }
+ pw.print(" mSigMotionSensor="); pw.println(mSigMotionSensor);
+ pw.print(" mCurDisplay="); pw.println(mCurDisplay);
+ pw.print(" mScreenOn="); pw.println(mScreenOn);
+ pw.print(" mCharging="); pw.println(mCharging);
+ pw.print(" mSigMotionActive="); pw.println(mSigMotionActive);
+ pw.print(" mState="); pw.println(stateToString(mState));
+ pw.print(" mInactiveTimeout="); TimeUtils.formatDuration(mInactiveTimeout, pw);
+ pw.println();
+ if (mNextAlarmTime != 0) {
+ pw.print(" mNextAlarmTime=");
+ TimeUtils.formatDuration(mNextAlarmTime, SystemClock.elapsedRealtime(), pw);
+ pw.println();
+ }
+ if (mNextIdlePendingDelay != 0) {
+ pw.print(" mNextIdlePendingDelay=");
+ TimeUtils.formatDuration(mNextIdlePendingDelay, pw);
+ pw.println();
+ }
+ if (mNextIdleDelay != 0) {
+ pw.print(" mNextIdleDelay=");
+ TimeUtils.formatDuration(mNextIdleDelay, pw);
+ pw.println();
+ }
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 15d7367..25a98c0 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -699,12 +699,10 @@
private final StringBuilder mStrictModeBuffer = new StringBuilder();
/**
- * Keeps track of all IIntentReceivers that have been registered for
- * broadcasts. Hash keys are the receiver IBinder, hash value is
- * a ReceiverList.
+ * Keeps track of all IIntentReceivers that have been registered for broadcasts.
+ * Hash keys are the receiver IBinder, hash value is a ReceiverList.
*/
- final HashMap<IBinder, ReceiverList> mRegisteredReceivers =
- new HashMap<IBinder, ReceiverList>();
+ final HashMap<IBinder, ReceiverList> mRegisteredReceivers = new HashMap<>();
/**
* Resolver for broadcast intents to registered receivers.
@@ -716,7 +714,7 @@
protected boolean allowFilterResult(
BroadcastFilter filter, List<BroadcastFilter> dest) {
IBinder target = filter.receiverList.receiver.asBinder();
- for (int i=dest.size()-1; i>=0; i--) {
+ for (int i = dest.size() - 1; i >= 0; i--) {
if (dest.get(i).receiverList.receiver.asBinder() == target) {
return false;
}
@@ -6603,6 +6601,12 @@
return mActivityManagerService.checkPermission(permission, pid,
uid) == PackageManager.PERMISSION_GRANTED;
}
+
+ @Override
+ public String[] getPackagesForUid(int uid) {
+ return mActivityManagerService.mContext.getPackageManager()
+ .getPackagesForUid(uid);
+ }
}
class IntentFirewallInterface implements IntentFirewall.AMSInterface {
@@ -15656,8 +15660,7 @@
// Original caller already died
return null;
}
- ReceiverList rl
- = (ReceiverList)mRegisteredReceivers.get(receiver.asBinder());
+ ReceiverList rl = mRegisteredReceivers.get(receiver.asBinder());
if (rl == null) {
rl = new ReceiverList(this, callerApp, callingPid, callingUid,
userId, receiver);
@@ -15689,7 +15692,7 @@
permission, callingUid, userId);
rl.add(bf);
if (!bf.debugCheck()) {
- Slog.w(TAG, "==> For Dynamic broadast");
+ Slog.w(TAG, "==> For Dynamic broadcast");
}
mReceiverResolver.addFilter(bf);
@@ -15699,9 +15702,9 @@
ArrayList receivers = new ArrayList();
receivers.add(bf);
- int N = allSticky.size();
- for (int i=0; i<N; i++) {
- Intent intent = (Intent)allSticky.get(i);
+ final int stickyCount = allSticky.size();
+ for (int i = 0; i < stickyCount; i++) {
+ Intent intent = allSticky.get(i);
BroadcastQueue queue = broadcastQueueForIntent(intent);
BroadcastRecord r = new BroadcastRecord(queue, intent, null,
null, -1, -1, null, null, AppOpsManager.OP_NONE, receivers, null, 0,
@@ -15761,8 +15764,7 @@
void removeReceiverLocked(ReceiverList rl) {
mRegisteredReceivers.remove(rl.receiver.asBinder());
- int N = rl.size();
- for (int i=0; i<N; i++) {
+ for (int i = rl.size() - 1; i >= 0; i--) {
mReceiverResolver.removeFilter(rl.get(i));
}
}
@@ -16133,24 +16135,24 @@
}
ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
if (stickies == null) {
- stickies = new ArrayMap<String, ArrayList<Intent>>();
+ stickies = new ArrayMap<>();
mStickyBroadcasts.put(userId, stickies);
}
ArrayList<Intent> list = stickies.get(intent.getAction());
if (list == null) {
- list = new ArrayList<Intent>();
+ list = new ArrayList<>();
stickies.put(intent.getAction(), list);
}
- int N = list.size();
+ final int stickiesCount = list.size();
int i;
- for (i=0; i<N; i++) {
+ for (i = 0; i < stickiesCount; i++) {
if (intent.filterEquals(list.get(i))) {
// This sticky already exists, replace it.
list.set(i, new Intent(intent));
break;
}
}
- if (i >= N) {
+ if (i >= stickiesCount) {
list.add(new Intent(intent));
}
}
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index a91a7ca..e5c5dff 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -309,7 +309,6 @@
}
public void skipCurrentReceiverLocked(ProcessRecord app) {
- boolean reschedule = false;
BroadcastRecord r = app.curReceiver;
if (r != null && r.queue == this) {
// The current broadcast is waiting for this app's receiver
@@ -318,7 +317,6 @@
logBroadcastReceiverDiscardLocked(r);
finishReceiverLocked(r, r.resultCode, r.resultData,
r.resultExtras, r.resultAbort, false);
- reschedule = true;
}
if (r == null && mPendingBroadcast != null && mPendingBroadcast.curApp == app) {
if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST,
diff --git a/services/core/java/com/android/server/display/WifiDisplayController.java b/services/core/java/com/android/server/display/WifiDisplayController.java
index 31c1eea..8932ca0 100644
--- a/services/core/java/com/android/server/display/WifiDisplayController.java
+++ b/services/core/java/com/android/server/display/WifiDisplayController.java
@@ -775,7 +775,7 @@
handleConnectionFailure(false);
}
}
- }, mHandler);
+ }, mHandler, mContext.getOpPackageName());
// Use extended timeout value for certification, as some tests require user inputs
int rtspTimeout = mWifiDisplayCertMode ?
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 818f0aa..e45092c 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -110,13 +110,16 @@
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
+import android.os.IDeviceIdleController;
import android.os.INetworkManagementService;
import android.os.IPowerManager;
import android.os.Message;
import android.os.MessageQueue.IdleHandler;
+import android.os.PowerManager;
import android.os.PowerManagerInternal;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -138,6 +141,7 @@
import android.util.Xml;
import com.android.server.AppOpsService;
+import com.android.server.DeviceIdleController;
import libcore.io.IoUtils;
import com.android.internal.R;
@@ -245,6 +249,7 @@
private IConnectivityManager mConnManager;
private INotificationManager mNotifManager;
private PowerManagerInternal mPowerManagerInternal;
+ private IDeviceIdleController mDeviceIdleController;
final Object mRulesLock = new Object();
@@ -321,6 +326,8 @@
mPowerManager = checkNotNull(powerManager, "missing powerManager");
mNetworkStats = checkNotNull(networkStats, "missing networkStats");
mNetworkManager = checkNotNull(networkManagement, "missing networkManagement");
+ mDeviceIdleController = IDeviceIdleController.Stub.asInterface(ServiceManager.getService(
+ DeviceIdleController.SERVICE_NAME));
mTime = checkNotNull(time, "missing TrustedTime");
HandlerThread thread = new HandlerThread(TAG);
@@ -342,28 +349,27 @@
mNotifManager = checkNotNull(notifManager, "missing INotificationManager");
}
+ void updatePowerSaveWhitelistLocked() {
+ try {
+ final int[] whitelist = mDeviceIdleController.getAppIdWhitelist();
+ mPowerSaveWhitelistAppIds.clear();
+ if (whitelist != null) {
+ for (int uid : whitelist) {
+ mPowerSaveWhitelistAppIds.put(uid, true);
+ }
+ }
+ } catch (RemoteException e) {
+ }
+ }
+
public void systemReady() {
if (!isBandwidthControlEnabled()) {
Slog.w(TAG, "bandwidth controls disabled, unable to enforce policy");
return;
}
- final PackageManager pm = mContext.getPackageManager();
-
synchronized (mRulesLock) {
- SystemConfig sysConfig = SystemConfig.getInstance();
- ArraySet<String> allowPower = sysConfig.getAllowInPowerSave();
- for (int i=0; i<allowPower.size(); i++) {
- String pkg = allowPower.valueAt(i);
- try {
- ApplicationInfo ai = pm.getApplicationInfo(pkg, 0);
- if ((ai.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
- mPowerSaveWhitelistAppIds.put(UserHandle.getAppId(ai.uid), true);
- }
- } catch (PackageManager.NameNotFoundException e) {
- }
- }
-
+ updatePowerSaveWhitelistLocked();
mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
mPowerManagerInternal.registerLowPowerModeObserver(
new PowerManagerInternal.LowPowerModeListener() {
@@ -406,6 +412,11 @@
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
mContext.registerReceiver(mScreenReceiver, screenFilter);
+ // listen for changes to power save whitelist
+ final IntentFilter whitelistFilter = new IntentFilter(
+ PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED);
+ mContext.registerReceiver(mPowerSaveWhitelistReceiver, whitelistFilter, null, mHandler);
+
// watch for network interfaces to be claimed
final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
@@ -489,6 +500,17 @@
}
};
+ private BroadcastReceiver mPowerSaveWhitelistReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // on background handler thread, and POWER_SAVE_WHITELIST_CHANGED is protected
+ synchronized (mRulesLock) {
+ updatePowerSaveWhitelistLocked();
+ updateRulesForGlobalChangeLocked(false);
+ }
+ }
+ };
+
private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -1528,20 +1550,6 @@
return uids;
}
- @Override
- public int[] getPowerSaveAppIdWhitelist() {
- mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
- synchronized (mRulesLock) {
- int size = mPowerSaveWhitelistAppIds.size();
- int[] appids = new int[size];
- for (int i = 0; i < size; i++) {
- appids[i] = mPowerSaveWhitelistAppIds.keyAt(i);
- }
- return appids;
- }
- }
-
/**
* Remove any policies associated with given {@link UserHandle}, persisting
* if any changes are made.
diff --git a/services/core/java/com/android/server/power/DeviceIdleController.java b/services/core/java/com/android/server/power/DeviceIdleController.java
deleted file mode 100644
index 6b29b9a..0000000
--- a/services/core/java/com/android/server/power/DeviceIdleController.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright (C) 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.
- */
-
-package com.android.server.power;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
-import android.hardware.TriggerEvent;
-import android.hardware.TriggerEventListener;
-import android.hardware.display.DisplayManager;
-import android.net.INetworkPolicyManager;
-import android.os.Binder;
-import android.os.PowerManager;
-import android.os.PowerManagerInternal;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.util.TimeUtils;
-import android.view.Display;
-import com.android.internal.app.IBatteryStats;
-import com.android.server.SystemService;
-import com.android.server.am.BatteryStatsService;
-import com.android.server.EventLogTags;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-/**
- * Keeps track of device idleness and drives low power mode based on that.
- */
-public class DeviceIdleController extends SystemService {
- private static final String TAG = "DeviceIdleController";
-
- private static final String ACTION_STEP_IDLE_STATE =
- "com.android.server.device_idle.STEP_IDLE_STATE";
-
- // TODO: These need to be moved to system settings.
-
- /**
- * This is the time, after becoming inactive, at which we start looking at the
- * motion sensor to determine if the device is being left alone. We don't do this
- * immediately after going inactive just because we don't want to be continually running
- * the significant motion sensor whenever the screen is off.
- */
- private static final long DEFAULT_INACTIVE_TIMEOUT = 30*60*1000L;
- /**
- * This is the time, after seeing motion, that we wait after becoming inactive from
- * that until we start looking for motion again.
- */
- private static final long DEFAULT_MOTION_INACTIVE_TIMEOUT = 10*60*1000L;
- /**
- * This is the time, after the inactive timeout elapses, that we will wait looking
- * for significant motion until we truly consider the device to be idle.
- */
- private static final long DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT = 30*60*1000L;
- /**
- * This is the initial time, after being idle, that we will allow ourself to be back
- * in the IDLE_PENDING state allowing the system to run normally until we return to idle.
- */
- private static final long DEFAULT_IDLE_PENDING_TIMEOUT = 5*60*1000L;
- /**
- * Maximum pending idle timeout (time spent running) we will be allowed to use.
- */
- private static final long DEFAULT_MAX_IDLE_PENDING_TIMEOUT = 10*60*1000L;
- /**
- * Scaling factor to apply to current pending idle timeout each time we cycle through
- * that state.
- */
- private static final float DEFAULT_IDLE_PENDING_FACTOR = 2f;
- /**
- * This is the initial time that we want to sit in the idle state before waking up
- * again to return to pending idle and allowing normal work to run.
- */
- private static final long DEFAULT_IDLE_TIMEOUT = 60*60*1000L;
- /**
- * Maximum idle duration we will be allowed to use.
- */
- private static final long DEFAULT_MAX_IDLE_TIMEOUT = 6*60*60*1000L;
- /**
- * Scaling factor to apply to current idle timeout each time we cycle through that state.
- */
- private static final float DEFAULT_IDLE_FACTOR = 2f;
- /**
- * This is the minimum time we will allow until the next upcoming alarm for us to
- * actually go in to idle mode.
- */
- private static final long DEFAULT_MIN_TIME_TO_ALARM = 60*60*1000L;
-
- private AlarmManager mAlarmManager;
- private IBatteryStats mBatteryStats;
- private PowerManagerInternal mLocalPowerManager;
- private INetworkPolicyManager mNetworkPolicyManager;
- private DisplayManager mDisplayManager;
- private SensorManager mSensorManager;
- private Sensor mSigMotionSensor;
- private PendingIntent mAlarmIntent;
- private Intent mIdleIntent;
- private Display mCurDisplay;
- private boolean mScreenOn;
- private boolean mCharging;
- private boolean mSigMotionActive;
-
- /** Device is currently active. */
- private static final int STATE_ACTIVE = 0;
- /** Device is inactve (screen off, no motion) and we are waiting to for idle. */
- private static final int STATE_INACTIVE = 1;
- /** Device is past the initial inactive period, and waiting for the next idle period. */
- private static final int STATE_IDLE_PENDING = 2;
- /** Device is in the idle state, trying to stay asleep as much as possible. */
- private static final int STATE_IDLE = 3;
- private static String stateToString(int state) {
- switch (state) {
- case STATE_ACTIVE: return "ACTIVE";
- case STATE_INACTIVE: return "INACTIVE";
- case STATE_IDLE_PENDING: return "IDLE_PENDING";
- case STATE_IDLE: return "IDLE";
- default: return Integer.toString(state);
- }
- }
-
- private int mState;
-
- private long mInactiveTimeout;
- private long mNextAlarmTime;
- private long mNextIdlePendingDelay;
- private long mNextIdleDelay;
-
- private final Binder mBinder = new Binder() {
- @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- DeviceIdleController.this.dump(fd, pw, args);
- }
- };
-
- private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
- @Override public void onReceive(Context context, Intent intent) {
- if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
- int plugged = intent.getIntExtra("plugged", 0);
- updateChargingLocked(plugged != 0);
- } else if (ACTION_STEP_IDLE_STATE.equals(intent.getAction())) {
- synchronized (DeviceIdleController.this) {
- stepIdleStateLocked();
- }
- }
- }
- };
-
- private final DisplayManager.DisplayListener mDisplayListener
- = new DisplayManager.DisplayListener() {
- @Override public void onDisplayAdded(int displayId) {
- }
-
- @Override public void onDisplayRemoved(int displayId) {
- }
-
- @Override public void onDisplayChanged(int displayId) {
- if (displayId == Display.DEFAULT_DISPLAY) {
- synchronized (DeviceIdleController.this) {
- updateDisplayLocked();
- }
- }
- }
- };
-
- private final TriggerEventListener mSigMotionListener = new TriggerEventListener() {
- @Override public void onTrigger(TriggerEvent event) {
- synchronized (DeviceIdleController.this) {
- significantMotionLocked();
- }
- }
- };
-
- public DeviceIdleController(Context context) {
- super(context);
- }
-
- @Override
- public void onStart() {
- synchronized (this) {
- mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
- mBatteryStats = BatteryStatsService.getService();
- mLocalPowerManager = getLocalService(PowerManagerInternal.class);
- mNetworkPolicyManager = INetworkPolicyManager.Stub.asInterface(
- ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
- mDisplayManager = (DisplayManager) getContext().getSystemService(
- Context.DISPLAY_SERVICE);
- mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
- mSigMotionSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
-
- Intent intent = new Intent(ACTION_STEP_IDLE_STATE)
- .setPackage("android")
- .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
- mAlarmIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
-
- mIdleIntent = new Intent(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
- mIdleIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_BATTERY_CHANGED);
- filter.addAction(ACTION_STEP_IDLE_STATE);
- getContext().registerReceiver(mReceiver, filter);
-
- mDisplayManager.registerDisplayListener(mDisplayListener, null);
-
- mScreenOn = true;
- // Start out assuming we are charging. If we aren't, we will at least get
- // a battery update the next time the level drops.
- mCharging = true;
- mState = STATE_ACTIVE;
- mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT;
- updateDisplayLocked();
- }
-
- publishBinderService("deviceidle", mBinder);
- }
-
- void updateDisplayLocked() {
- mCurDisplay = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
- // We consider any situation where the display is showing something to be it on,
- // because if there is anything shown we are going to be updating it at some
- // frequency so can't be allowed to go into deep sleeps.
- boolean screenOn = mCurDisplay.getState() != Display.STATE_OFF;;
- if (!screenOn && mScreenOn) {
- mScreenOn = false;
- becomeInactiveIfAppropriateLocked();
- } else if (screenOn) {
- mScreenOn = true;
- becomeActiveLocked("screen");
- }
- }
-
- void updateChargingLocked(boolean charging) {
- if (!charging && mCharging) {
- mCharging = false;
- becomeInactiveIfAppropriateLocked();
- } else if (charging) {
- mCharging = charging;
- becomeActiveLocked("charging");
- }
- }
-
- void becomeActiveLocked(String reason) {
- if (mState != STATE_ACTIVE) {
- EventLogTags.writeDeviceIdle(STATE_ACTIVE, reason);
- mLocalPowerManager.setDeviceIdleMode(false);
- try {
- mNetworkPolicyManager.setDeviceIdleMode(false);
- mBatteryStats.noteDeviceIdleMode(false, true, false);
- } catch (RemoteException e) {
- }
- if (mState == STATE_IDLE) {
- getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
- }
- mState = STATE_ACTIVE;
- mInactiveTimeout = DEFAULT_INACTIVE_TIMEOUT;
- mNextIdlePendingDelay = 0;
- mNextIdleDelay = 0;
- cancelAlarmLocked();
- stopMonitoringSignificantMotion();
- }
- }
-
- void becomeInactiveIfAppropriateLocked() {
- if (!mScreenOn && !mCharging && mState == STATE_ACTIVE) {
- // Screen has turned off; we are now going to become inactive and start
- // waiting to see if we will ultimately go idle.
- mState = STATE_INACTIVE;
- mNextIdlePendingDelay = 0;
- mNextIdleDelay = 0;
- scheduleAlarmLocked(mInactiveTimeout, false);
- EventLogTags.writeDeviceIdle(mState, "no activity");
- }
- }
-
- void stepIdleStateLocked() {
- EventLogTags.writeDeviceIdleStep();
-
- final long now = SystemClock.elapsedRealtime();
- if ((now+DEFAULT_MIN_TIME_TO_ALARM) > mAlarmManager.getNextWakeFromIdleTime()) {
- // Whoops, there is an upcoming alarm. We don't actually want to go idle.
- if (mState != STATE_ACTIVE) {
- becomeActiveLocked("alarm");
- }
- return;
- }
-
- switch (mState) {
- case STATE_INACTIVE:
- // We have now been inactive long enough, it is time to start looking
- // for significant motion and sleep some more while doing so.
- startMonitoringSignificantMotion();
- scheduleAlarmLocked(DEFAULT_IDLE_AFTER_INACTIVE_TIMEOUT, false);
- // Reset the upcoming idle delays.
- mNextIdlePendingDelay = DEFAULT_IDLE_PENDING_TIMEOUT;
- mNextIdleDelay = DEFAULT_IDLE_TIMEOUT;
- mState = STATE_IDLE_PENDING;
- EventLogTags.writeDeviceIdle(mState, "step");
- break;
- case STATE_IDLE_PENDING:
- // We have been waiting to become idle, and now it is time! This is the
- // only case where we want to use a wakeup alarm, because we do want to
- // drag the device out of its sleep state in this case to do the next
- // scheduled work.
- scheduleAlarmLocked(mNextIdleDelay, true);
- mNextIdleDelay = (long)(mNextIdleDelay*DEFAULT_IDLE_FACTOR);
- if (mNextIdleDelay > DEFAULT_MAX_IDLE_TIMEOUT) {
- mNextIdleDelay = DEFAULT_MAX_IDLE_TIMEOUT;
- }
- mState = STATE_IDLE;
- EventLogTags.writeDeviceIdle(mState, "step");
- mLocalPowerManager.setDeviceIdleMode(true);
- try {
- mNetworkPolicyManager.setDeviceIdleMode(true);
- mBatteryStats.noteDeviceIdleMode(true, false, false);
- } catch (RemoteException e) {
- }
- getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
- break;
- case STATE_IDLE:
- // We have been idling long enough, now it is time to do some work.
- scheduleAlarmLocked(mNextIdlePendingDelay, false);
- mNextIdlePendingDelay = (long)(mNextIdlePendingDelay*DEFAULT_IDLE_PENDING_FACTOR);
- if (mNextIdlePendingDelay > DEFAULT_MAX_IDLE_PENDING_TIMEOUT) {
- mNextIdlePendingDelay = DEFAULT_MAX_IDLE_PENDING_TIMEOUT;
- }
- mState = STATE_IDLE_PENDING;
- EventLogTags.writeDeviceIdle(mState, "step");
- mLocalPowerManager.setDeviceIdleMode(false);
- try {
- mNetworkPolicyManager.setDeviceIdleMode(false);
- mBatteryStats.noteDeviceIdleMode(false, false, false);
- } catch (RemoteException e) {
- }
- getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
- break;
- }
- }
-
- void significantMotionLocked() {
- // When the sensor goes off, its trigger is automatically removed.
- mSigMotionActive = false;
- // The device is not yet active, so we want to go back to the pending idle
- // state to wait again for no motion. Note that we only monitor for significant
- // motion after moving out of the inactive state, so no need to worry about that.
- if (mState != STATE_ACTIVE) {
- mLocalPowerManager.setDeviceIdleMode(false);
- try {
- mNetworkPolicyManager.setDeviceIdleMode(false);
- mBatteryStats.noteDeviceIdleMode(false, false, true);
- } catch (RemoteException e) {
- }
- if (mState == STATE_IDLE) {
- getContext().sendBroadcastAsUser(mIdleIntent, UserHandle.ALL);
- }
- mState = STATE_ACTIVE;
- mInactiveTimeout = DEFAULT_MOTION_INACTIVE_TIMEOUT;
- EventLogTags.writeDeviceIdle(mState, "motion");
- becomeInactiveIfAppropriateLocked();
- }
- }
-
- void startMonitoringSignificantMotion() {
- if (mSigMotionSensor != null && !mSigMotionActive) {
- mSensorManager.requestTriggerSensor(mSigMotionListener, mSigMotionSensor);
- mSigMotionActive = true;
- }
- }
-
- void stopMonitoringSignificantMotion() {
- if (mSigMotionActive) {
- mSensorManager.cancelTriggerSensor(mSigMotionListener, mSigMotionSensor);
- mSigMotionActive = false;
- }
- }
-
- void cancelAlarmLocked() {
- if (mNextAlarmTime != 0) {
- mNextAlarmTime = 0;
- mAlarmManager.cancel(mAlarmIntent);
- }
- }
-
- void scheduleAlarmLocked(long delay, boolean idleUntil) {
- if (mSigMotionSensor == null) {
- // If there is no significant motion sensor on this device, then we won't schedule
- // alarms, because we can't determine if the device is not moving. This effectively
- // turns off normal exeuction of device idling, although it is still possible to
- // manually poke it by pretending like the alarm is going off.
- return;
- }
- mNextAlarmTime = SystemClock.elapsedRealtime() + delay;
- if (idleUntil) {
- mAlarmManager.setIdleUntil(AlarmManager.ELAPSED_REALTIME_WAKEUP,
- mNextAlarmTime, mAlarmIntent);
- } else {
- mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
- mNextAlarmTime, mAlarmIntent);
- }
- }
-
- private void dumpHelp(PrintWriter pw) {
- pw.println("Device idle controller (deviceidle) dump options:");
- pw.println(" [-h] [CMD]");
- pw.println(" -h: print this help text.");
- pw.println("Commands:");
- pw.println(" step");
- pw.println(" Immediately step to next state, without waiting for alarm.");
- }
-
- void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
- != PackageManager.PERMISSION_GRANTED) {
- pw.println("Permission Denial: can't dump DeviceIdleController from from pid="
- + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
- + " without permission " + android.Manifest.permission.DUMP);
- return;
- }
-
- if (args != null) {
- for (int i=0; i<args.length; i++) {
- String arg = args[i];
- if ("-h".equals(arg)) {
- dumpHelp(pw);
- return;
- } else if ("step".equals(arg)) {
- synchronized (this) {
- stepIdleStateLocked();
- pw.print("Stepped to: "); pw.println(stateToString(mState));
- }
- return;
- } else if (arg.length() > 0 && arg.charAt(0) == '-'){
- pw.println("Unknown option: " + arg);
- dumpHelp(pw);
- return;
- } else {
- pw.println("Unknown command: " + arg);
- dumpHelp(pw);
- return;
- }
- }
- }
-
- synchronized (this) {
- pw.print(" mSigMotionSensor="); pw.println(mSigMotionSensor);
- pw.print(" mCurDisplay="); pw.println(mCurDisplay);
- pw.print(" mScreenOn="); pw.println(mScreenOn);
- pw.print(" mCharging="); pw.println(mCharging);
- pw.print(" mSigMotionActive="); pw.println(mSigMotionActive);
- pw.print(" mState="); pw.println(stateToString(mState));
- pw.print(" mInactiveTimeout="); TimeUtils.formatDuration(mInactiveTimeout, pw);
- pw.println();
- if (mNextAlarmTime != 0) {
- pw.print(" mNextAlarmTime=");
- TimeUtils.formatDuration(mNextAlarmTime, SystemClock.elapsedRealtime(), pw);
- pw.println();
- }
- if (mNextIdlePendingDelay != 0) {
- pw.print(" mNextIdlePendingDelay=");
- TimeUtils.formatDuration(mNextIdlePendingDelay, pw);
- pw.println();
- }
- if (mNextIdleDelay != 0) {
- pw.print(" mNextIdleDelay=");
- TimeUtils.formatDuration(mNextIdleDelay, pw);
- pw.println();
- }
- }
- }
-}
diff --git a/services/core/jni/com_android_server_UsbHostManager.cpp b/services/core/jni/com_android_server_UsbHostManager.cpp
index ee50ff9..d8c172f 100644
--- a/services/core/jni/com_android_server_UsbHostManager.cpp
+++ b/services/core/jni/com_android_server_UsbHostManager.cpp
@@ -71,6 +71,7 @@
char *manufacturer = usb_device_get_manufacturer_name(device);
char *product = usb_device_get_product_name(device);
+ int version = usb_device_get_version(device);
char *serial = usb_device_get_serial(device);
jstring deviceName = env->NewStringUTF(devname);
@@ -81,7 +82,7 @@
jboolean result = env->CallBooleanMethod(thiz, method_beginUsbDeviceAdded,
deviceName, usb_device_get_vendor_id(device), usb_device_get_product_id(device),
deviceDesc->bDeviceClass, deviceDesc->bDeviceSubClass, deviceDesc->bDeviceProtocol,
- manufacturerName, productName, serialNumber);
+ manufacturerName, productName, version, serialNumber);
env->DeleteLocalRef(serialNumber);
env->DeleteLocalRef(productName);
@@ -199,7 +200,7 @@
return -1;
}
method_beginUsbDeviceAdded = env->GetMethodID(clazz, "beginUsbDeviceAdded",
- "(Ljava/lang/String;IIIIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z");
+ "(Ljava/lang/String;IIIIILjava/lang/String;Ljava/lang/String;ILjava/lang/String;)Z");
if (method_beginUsbDeviceAdded == NULL) {
ALOGE("Can't find beginUsbDeviceAdded");
return -1;
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 593853c..2922130 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -76,7 +76,6 @@
import com.android.server.pm.LauncherAppsService;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.UserManagerService;
-import com.android.server.power.DeviceIdleController;
import com.android.server.power.PowerManagerService;
import com.android.server.power.ShutdownThread;
import com.android.server.restrictions.RestrictionsManagerService;
@@ -599,6 +598,8 @@
mSystemServiceManager.startService(PersistentDataBlockService.class);
}
+ mSystemServiceManager.startService(DeviceIdleController.class);
+
// Always start the Device Policy Manager, so that the API is compatible with
// API8.
mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class);
@@ -965,7 +966,6 @@
if (!disableNonCoreServices) {
mSystemServiceManager.startService(MediaProjectionManagerService.class);
- mSystemServiceManager.startService(DeviceIdleController.class);
}
// Before things start rolling, be sure we have decided whether
diff --git a/services/usb/java/com/android/server/usb/UsbAlsaManager.java b/services/usb/java/com/android/server/usb/UsbAlsaManager.java
index daccf95..27c97d0 100644
--- a/services/usb/java/com/android/server/usb/UsbAlsaManager.java
+++ b/services/usb/java/com/android/server/usb/UsbAlsaManager.java
@@ -401,6 +401,7 @@
Bundle properties = new Bundle();
String manufacturer = usbDevice.getManufacturerName();
String product = usbDevice.getProductName();
+ String version = usbDevice.getVersion();
String name;
if (manufacturer == null || manufacturer.isEmpty()) {
name = product;
@@ -412,6 +413,7 @@
properties.putString(MidiDeviceInfo.PROPERTY_NAME, name);
properties.putString(MidiDeviceInfo.PROPERTY_MANUFACTURER, manufacturer);
properties.putString(MidiDeviceInfo.PROPERTY_PRODUCT, product);
+ properties.putString(MidiDeviceInfo.PROPERTY_VERSION, version);
properties.putString(MidiDeviceInfo.PROPERTY_SERIAL_NUMBER,
usbDevice.getSerialNumber());
properties.putInt(MidiDeviceInfo.PROPERTY_ALSA_CARD, alsaDevice.mCard);
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 5b58051..f5f2b07 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -112,7 +112,7 @@
*/
private boolean beginUsbDeviceAdded(String deviceName, int vendorID, int productID,
int deviceClass, int deviceSubclass, int deviceProtocol,
- String manufacturerName, String productName, String serialNumber) {
+ String manufacturerName, String productName, int version, String serialNumber) {
if (DEBUG) {
Slog.d(TAG, "usb:UsbHostManager.beginUsbDeviceAdded(" + deviceName + ")");
@@ -149,9 +149,12 @@
return false;
}
+ // Create version string in "%.%" format
+ String versionString = Integer.toString(version >> 8) + "." + (version & 0xFF);
+
mNewDevice = new UsbDevice(deviceName, vendorID, productID,
deviceClass, deviceSubclass, deviceProtocol,
- manufacturerName, productName, serialNumber);
+ manufacturerName, productName, versionString, serialNumber);
mNewConfigurations = new ArrayList<UsbConfiguration>();
mNewInterfaces = new ArrayList<UsbInterface>();
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 831a194..299c7c4 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -48,34 +48,148 @@
ACTION_CARRIER_CONFIG_CHANGED = "android.telephony.action.CARRIER_CONFIG_CHANGED";
/**
+ * Flag indicating whether the Phone app should ignore EVENT_SIM_NETWORK_LOCKED
+ * events from the Sim.
+ * If true, this will prevent the IccNetworkDepersonalizationPanel from being shown, and
+ * effectively disable the "Sim network lock" feature.
+ */
+ public static final String
+ BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS = "bool_ignore_sim_network_locked_events";
+
+ /**
+ * Flag indicating whether the Phone app should provide a "Dismiss" button on the SIM network
+ * unlock screen. The default value is true. If set to false, there will be *no way* to dismiss
+ * the SIM network unlock screen if you don't enter the correct unlock code. (One important
+ * consequence: there will be no way to make an Emergency Call if your SIM is network-locked and
+ * you don't know the PIN.)
+ */
+ public static final String
+ BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS = "bool_sim_network_unlock_allow_dismiss";
+
+ /** Flag indicating if the phone is a world phone */
+ public static final String BOOL_WORLD_PHONE = "bool_world_phone";
+
+ /**
+ * If true, enable vibration (haptic feedback) for key presses in the EmergencyDialer activity.
+ * The pattern is set on a per-platform basis using config_virtualKeyVibePattern. To be
+ * consistent with the regular Dialer, this value should agree with the corresponding values
+ * from config.xml under apps/Contacts.
+ */
+ public static final String
+ BOOL_ENABLE_DIALER_KEY_VIBRATION = "bool_enable_dialer_key_vibration";
+
+ /** Flag indicating if dtmf tone type is enabled */
+ public static final String BOOL_DTMF_TYPE_ENABLED = "bool_dtmf_type_enabled";
+
+ /** Flag indicating if auto retry is enabled */
+ public static final String BOOL_AUTO_RETRY_ENABLED = "bool_auto_retry_enabled";
+
+ /**
+ * Determine whether we want to play local DTMF tones in a call, or just let the radio/BP handle
+ * playing of the tones.
+ */
+ public static final String BOOL_ALLOW_LOCAL_DTMF_TONES = "bool_allow_local_dtmf_tones";
+
+ /**
+ * If true, show an onscreen "Dial" button in the dialer. In practice this is used on all
+ * platforms, even the ones with hard SEND/END keys, but for maximum flexibility it's controlled
+ * by a flag here (which can be overridden on a per-product basis.)
+ */
+ public static final String BOOL_SHOW_ONSCREEN_DIAL_BUTTON = "bool_show_onscreen_dial_button";
+
+ /** Determines if device implements a noise suppression device for in call audio. */
+ public static final String
+ BOOL_HAS_IN_CALL_NOISE_SUPPRESSION = "bool_has_in_call_noise_suppression";
+
+ /**
+ * Determines if the current device should allow emergency numbers to be logged in the Call Log.
+ * (Some carriers require that emergency calls *not* be logged, presumably to avoid the risk of
+ * accidental redialing from the call log UI. This is a good idea, so the default here is
+ * false.)
+ * <p>
+ * TODO: on the other hand, it might still be useful to have some record of the emergency calls
+ * you've made, or to be able to look up the exact date/time of an emergency call. So perhaps we
+ * <b>should</b> log those calls, but instead fix the call log to disable the "call" button for
+ * emergency numbers.
+ */
+ public static final String
+ BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG = "bool_allow_emergency_numbers_in_call_log";
+
+ /** If true, removes the Voice Privacy option from Call Settings */
+ public static final String BOOL_VOICE_PRIVACY_DISABLE = "bool_voice_privacy_disable";
+
+ /** Control whether users can reach the carrier portions of Cellular Network Settings. */
+ public static final String
+ BOOL_HIDE_CARRIER_NETWORK_SETTINGS = "bool_hide_carrier_network_settings";
+
+ /** Control whether users can edit APNs in Settings. */
+ public static final String BOOL_APN_EXPAND = "bool_apn_expand";
+
+ /** Control whether users can choose a network operator. */
+ public static final String BOOL_OPERATOR_SELECTION_EXPAND = "bool_operator_selection_expand";
+
+ /** Used in Cellular Network Settings for preferred network type. */
+ public static final String BOOL_PREFER_2G = "bool_prefer_2g";
+
+ /** Show cdma auto network mode in (glabal) roaming */
+ public static final String BOOL_SHOW_CDMA = "bool_show_cdma";
+
+ /** CDMA activation goes through HFA */
+ public static final String BOOL_USE_HFA_FOR_PROVISIONING = "bool_use_hfa_for_provisioning";
+
+ /**
+ * CDMA activation goes through OTASP.
+ * <p>
+ * TODO: This should be combined with config_use_hfa_for_provisioning and implemented as an enum
+ * (NONE, HFA, OTASP).
+ */
+ public static final String BOOL_USE_OTASP_FOR_PROVISIONING = "bool_use_otasp_for_provisioning";
+
+ /** Display carrier settings menu if true */
+ public static final String BOOL_CARRIER_SETTINGS_ENABLE = "bool_carrier_settings_enable";
+
+ /** Does not display additional call seting for IMS phone based on GSM Phone */
+ public static final String BOOL_ADDITIONAL_CALL_SETTING = "bool_additional_call_setting";
+
+ /** Show APN Settings for some CDMA carriers */
+ public static final String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
+
+ /** After a CDMA conference call is merged, the swap button should be displayed. */
+ public static final String BOOL_SUPPORT_SWAP_AFTER_MERGE = "bool_support_swap_after_merge";
+
+ /**
+ * Determine whether the voicemail notification is persistent in the notification bar. If true,
+ * the voicemail notifications cannot be dismissed from the notification bar.
+ */
+ public static final String
+ BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT = "bool_voicemail_notification_persistent";
+
+ /** For IMS video over LTE calls, determines whether video pause signalling is supported. */
+ public static final String
+ BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS = "bool_support_pause_ims_video_calls";
+
+ /**
+ * Disables dialing "*228" (OTASP provisioning) on CDMA carriers where it is not supported or is
+ * potentially harmful by locking the SIM to 3G.
+ */
+ public static final String
+ BOOL_DISABLE_CDMA_ACTIVATION_CODE = "bool_disable_cdma_activation_code";
+
+ /**
* Flag specifying whether VoLTE should be available for carrier, independent of carrier
* provisioning. If false: hard disabled. If true: then depends on carrier provisioning,
* availability, etc.
*/
public static final String BOOL_CARRIER_VOLTE_AVAILABLE = "bool_carrier_volte_available";
- /**
- * Flag specifying whether VoLTE availability is based on provisioning.
- */
+ /** Flag specifying whether VoLTE availability is based on provisioning. */
public static final String BOOL_CARRIER_VOLTE_PROVISIONED = "bool_carrier_volte_provisioned";
- /**
- * Flag specifying whether VoLTE TTY is supported.
- */
+ /** Flag specifying whether VoLTE TTY is supported. */
public static final String BOOL_CARRIER_VOLTE_TTY_SUPPORTED
= "bool_carrier_volte_tty_supported";
/**
- * Show APN Settings for some CDMA carriers.
- */
- public static final String BOOL_SHOW_APN_SETTING_CDMA = "bool_show_apn_setting_cdma";
-
- /**
- * Control whether users can edit APNs in Settings.
- */
- public static final String BOOL_APN_EXPAND = "bool_apn_expand";
-
- /**
* If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or RIL_RADIO_TECHNOLOGY_UNKNOWN:0
* this is the value that should be used instead. A configuration value of
* RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means there is no replacement value and that the default
@@ -86,9 +200,9 @@
/* The following 3 fields are related to carrier visual voicemail. */
/**
- * The carrier number MO sms messages are sent to.
+ * The carrier number MO sms messages are sent to.
*
- * @hide
+ * @hide
*/
public static final String STRING_VVM_DESTINATION_NUMBER = "string_vvm_destination_number";
@@ -122,17 +236,38 @@
static {
sDefaults = new Bundle();
+ sDefaults.putBoolean(BOOL_ADDITIONAL_CALL_SETTING, true);
+ sDefaults.putBoolean(BOOL_ALLOW_EMERGENCY_NUMBERS_IN_CALL_LOG, false);
+ sDefaults.putBoolean(BOOL_ALLOW_LOCAL_DTMF_TONES, true);
+ sDefaults.putBoolean(BOOL_APN_EXPAND, true);
+ sDefaults.putBoolean(BOOL_AUTO_RETRY_ENABLED, false);
+ sDefaults.putBoolean(BOOL_CARRIER_SETTINGS_ENABLE, false);
sDefaults.putBoolean(BOOL_CARRIER_VOLTE_AVAILABLE, false);
sDefaults.putBoolean(BOOL_CARRIER_VOLTE_PROVISIONED, false);
sDefaults.putBoolean(BOOL_CARRIER_VOLTE_TTY_SUPPORTED, true);
+ sDefaults.putBoolean(BOOL_DISABLE_CDMA_ACTIVATION_CODE, false);
+ sDefaults.putBoolean(BOOL_DTMF_TYPE_ENABLED, false);
+ sDefaults.putBoolean(BOOL_ENABLE_DIALER_KEY_VIBRATION, true);
+ sDefaults.putBoolean(BOOL_HAS_IN_CALL_NOISE_SUPPRESSION, false);
+ sDefaults.putBoolean(BOOL_HIDE_CARRIER_NETWORK_SETTINGS, false);
+ sDefaults.putBoolean(BOOL_IGNORE_SIM_NETWORK_LOCKED_EVENTS, false);
+ sDefaults.putBoolean(BOOL_OPERATOR_SELECTION_EXPAND, true);
+ sDefaults.putBoolean(BOOL_PREFER_2G, true);
sDefaults.putBoolean(BOOL_SHOW_APN_SETTING_CDMA, false);
- sDefaults.putBoolean(BOOL_APN_EXPAND, true);
-
+ sDefaults.putBoolean(BOOL_SHOW_CDMA, false);
+ sDefaults.putBoolean(BOOL_SHOW_ONSCREEN_DIAL_BUTTON, true);
+ sDefaults.putBoolean(BOOL_SIM_NETWORK_UNLOCK_ALLOW_DISMISS, true);
+ sDefaults.putBoolean(BOOL_SUPPORT_PAUSE_IMS_VIDEO_CALLS, true);
+ sDefaults.putBoolean(BOOL_SUPPORT_SWAP_AFTER_MERGE, true);
+ sDefaults.putBoolean(BOOL_USE_HFA_FOR_PROVISIONING, false);
+ sDefaults.putBoolean(BOOL_USE_OTASP_FOR_PROVISIONING, false);
+ sDefaults.putBoolean(BOOL_VOICEMAIL_NOTIFICATION_PERSISTENT, false);
+ sDefaults.putBoolean(BOOL_VOICE_PRIVACY_DISABLE, false);
+ sDefaults.putBoolean(BOOL_WORLD_PHONE, false);
sDefaults.putInt(INT_VOLTE_REPLACEMENT_RAT, 0);
-
+ sDefaults.putInt(INT_VVM_PORT_NUMBER, 0);
sDefaults.putString(STRING_VVM_DESTINATION_NUMBER, "");
sDefaults.putString(STRING_VVM_TYPE, "");
- sDefaults.putInt(INT_VVM_PORT_NUMBER, 0);
}
/**
@@ -190,10 +325,11 @@
/**
* Request the carrier config loader to update the cofig for phoneId.
- *
- * Depending on simState, the config may be cleared or loaded from config app.
- * This is only used by SubscriptionInfoUpdater.
- *
+ * <p>
+ * Depending on simState, the config may be cleared or loaded from config app. This is only used
+ * by SubscriptionInfoUpdater.
+ * </p>
+ *
* @hide
*/
@SystemApi
diff --git a/tests/permission/src/com/android/framework/permission/tests/ServiceManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/ServiceManagerPermissionTests.java
index 322b853..30d204f 100644
--- a/tests/permission/src/com/android/framework/permission/tests/ServiceManagerPermissionTests.java
+++ b/tests/permission/src/com/android/framework/permission/tests/ServiceManagerPermissionTests.java
@@ -52,6 +52,11 @@
public boolean checkPermission(java.lang.String permission, int pid, int uid) {
return true;
}
+
+ @Override
+ public String[] getPackagesForUid(int uid) {
+ return new String[0];
+ }
};
ServiceManagerNative.asInterface(BinderInternal.getContextObject())
.setPermissionController(pc);