diff options
12 files changed, 176 insertions, 41 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 7f35d4a47adf..7d88149abb28 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -30910,6 +30910,8 @@ package android.os { field public static final int BATTERY_STATUS_NOT_CHARGING = 4; // 0x4 field public static final int BATTERY_STATUS_UNKNOWN = 1; // 0x1 field public static final String EXTRA_BATTERY_LOW = "battery_low"; + field public static final String EXTRA_CHARGING_STATUS = "android.os.extra.CHARGING_STATUS"; + field public static final String EXTRA_CYCLE_COUNT = "android.os.extra.CYCLE_COUNT"; field public static final String EXTRA_HEALTH = "health"; field public static final String EXTRA_ICON_SMALL = "icon-small"; field public static final String EXTRA_LEVEL = "level"; diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 1d3993106a8f..909a3dca3829 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -9152,6 +9152,14 @@ package android.os { public class BatteryManager { method @RequiresPermission(android.Manifest.permission.POWER_SAVER) public boolean setChargingStateUpdateDelayMillis(int); + field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_CHARGING_POLICY = 9; // 0x9 + field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_FIRST_USAGE_DATE = 8; // 0x8 + field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_MANUFACTURING_DATE = 7; // 0x7 + field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_STATE_OF_HEALTH = 10; // 0xa + field public static final int CHARGING_POLICY_ADAPTIVE_AC = 3; // 0x3 + field public static final int CHARGING_POLICY_ADAPTIVE_AON = 2; // 0x2 + field public static final int CHARGING_POLICY_ADAPTIVE_LONGLIFE = 4; // 0x4 + field public static final int CHARGING_POLICY_DEFAULT = 1; // 0x1 field public static final String EXTRA_EVENTS = "android.os.extra.EVENTS"; field public static final String EXTRA_EVENT_TIMESTAMP = "android.os.extra.EVENT_TIMESTAMP"; } diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index 6dc80cf4c374..611df0a4ea90 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -26,8 +26,6 @@ import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.UserIdInt; import android.app.Activity; -import android.app.ActivityThread; -import android.app.OnActivityPausedListener; import android.app.PendingIntent; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -1570,17 +1568,11 @@ public final class NfcAdapter { if (activity == null || intent == null) { throw new NullPointerException(); } - if (!activity.isResumed()) { - throw new IllegalStateException("Foreground dispatch can only be enabled " + - "when your activity is resumed"); - } try { TechListParcel parcel = null; if (techLists != null && techLists.length > 0) { parcel = new TechListParcel(techLists); } - ActivityThread.currentActivityThread().registerOnActivityPausedListener(activity, - mForegroundDispatchListener); sService.setForegroundDispatch(intent, filters, parcel); } catch (RemoteException e) { attemptDeadServiceRecovery(e); @@ -1608,25 +1600,8 @@ public final class NfcAdapter { throw new UnsupportedOperationException(); } } - ActivityThread.currentActivityThread().unregisterOnActivityPausedListener(activity, - mForegroundDispatchListener); - disableForegroundDispatchInternal(activity, false); - } - - OnActivityPausedListener mForegroundDispatchListener = new OnActivityPausedListener() { - @Override - public void onPaused(Activity activity) { - disableForegroundDispatchInternal(activity, true); - } - }; - - void disableForegroundDispatchInternal(Activity activity, boolean force) { try { sService.setForegroundDispatch(null, null, null); - if (!force && !activity.isResumed()) { - throw new IllegalStateException("You must disable foreground dispatching " + - "while your activity is still resumed"); - } } catch (RemoteException e) { attemptDeadServiceRecovery(e); } diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java index 76f857bd91b7..6bc0f6ea947c 100644 --- a/core/java/android/os/BatteryManager.java +++ b/core/java/android/os/BatteryManager.java @@ -147,6 +147,18 @@ public class BatteryManager { public static final String EXTRA_SEQUENCE = "seq"; /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * Int value representing the battery charging cycle count. + */ + public static final String EXTRA_CYCLE_COUNT = "android.os.extra.CYCLE_COUNT"; + + /** + * Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}: + * Int value representing the battery charging status. + */ + public static final String EXTRA_CHARGING_STATUS = "android.os.extra.CHARGING_STATUS"; + + /** * Extra for {@link android.content.Intent#ACTION_BATTERY_LEVEL_CHANGED}: * Contains list of Bundles representing battery events * @hide @@ -190,6 +202,35 @@ public class BatteryManager { /** Power source is dock. */ public static final int BATTERY_PLUGGED_DOCK = OsProtoEnums.BATTERY_PLUGGED_DOCK; // = 8 + // values for "charge policy" property + /** + * Default policy (e.g. normal). + * @hide + */ + @SystemApi + public static final int CHARGING_POLICY_DEFAULT = OsProtoEnums.CHARGING_POLICY_DEFAULT; // = 1 + /** + * Optimized for battery health using static thresholds (e.g stop at 80%). + * @hide + */ + @SystemApi + public static final int CHARGING_POLICY_ADAPTIVE_AON = + OsProtoEnums.CHARGING_POLICY_ADAPTIVE_AON; // = 2 + /** + * Optimized for battery health using adaptive thresholds. + * @hide + */ + @SystemApi + public static final int CHARGING_POLICY_ADAPTIVE_AC = + OsProtoEnums.CHARGING_POLICY_ADAPTIVE_AC; // = 3 + /** + * Optimized for battery health, devices always connected to power. + * @hide + */ + @SystemApi + public static final int CHARGING_POLICY_ADAPTIVE_LONGLIFE = + OsProtoEnums.CHARGING_POLICY_ADAPTIVE_LONGLIFE; // = 4 + /** @hide */ public static final int BATTERY_PLUGGED_ANY = BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS @@ -254,6 +295,76 @@ public class BatteryManager { */ public static final int BATTERY_PROPERTY_STATUS = 6; + /** + * Battery manufacturing date is reported in epoch. The 0 timepoint + * begins at midnight Coordinated Universal Time (UTC) on January 1, 1970. + * It is a long integer in seconds. + * + * <p class="note"> + * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission. + * + * Example: <code> + * // The value returned from the API can be used to create a Date, used + * // to set the time on a calendar and coverted to a string. + * import java.util.Date; + * + * mBatteryManager = mContext.getSystemService(BatteryManager.class); + * final long manufacturingDate = + * mBatteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_MANUFACTURING_DATE); + * Date date = new Date(manufacturingDate); + * Calendar calendar = Calendar.getInstance(); + * calendar.setTime(date); + * // Convert to yyyy-MM-dd HH:mm:ss format string + * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + * String dateString = sdf.format(date); + * </code> + * @hide + */ + @RequiresPermission(permission.BATTERY_STATS) + @SystemApi + public static final int BATTERY_PROPERTY_MANUFACTURING_DATE = 7; + + /** + * The date of first usage is reported in epoch. The 0 timepoint + * begins at midnight Coordinated Universal Time (UTC) on January 1, 1970. + * It is a long integer in seconds. + * + * <p class="note"> + * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission. + * + * {@link BATTERY_PROPERTY_MANUFACTURING_DATE for sample code} + * @hide + */ + @RequiresPermission(permission.BATTERY_STATS) + @SystemApi + public static final int BATTERY_PROPERTY_FIRST_USAGE_DATE = 8; + + /** + * Battery charging policy from a CHARGING_POLICY_* value.. + * + * <p class="note"> + * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission. + * + * @hide + */ + @RequiresPermission(permission.BATTERY_STATS) + @SystemApi + public static final int BATTERY_PROPERTY_CHARGING_POLICY = 9; + + /** + * + * Percentage representing the measured battery state of health (remaining + * estimated full charge capacity relative to the rated capacity in %). + * + * <p class="note"> + * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission. + * + * @hide + */ + @RequiresPermission(permission.BATTERY_STATS) + @SystemApi + public static final int BATTERY_PROPERTY_STATE_OF_HEALTH = 10; + private final Context mContext; private final IBatteryStats mBatteryStats; private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar; @@ -307,7 +418,6 @@ public class BatteryManager { try { BatteryProperty prop = new BatteryProperty(); - if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) ret = prop.getLong(); else diff --git a/core/jni/android_media_MicrophoneInfo.cpp b/core/jni/android_media_MicrophoneInfo.cpp index 65e30d8b1ea3..18f81254af7d 100644 --- a/core/jni/android_media_MicrophoneInfo.cpp +++ b/core/jni/android_media_MicrophoneInfo.cpp @@ -92,6 +92,7 @@ jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo, env->DeleteLocalRef(jFrequencyResponse); } // Create a list of Pair for channel mapping. + jChannelMappings = env->NewObject(gArrayListClass, gArrayListCstor); const auto &channelMapping = micInfo.channel_mapping; for (size_t i = 0; i < std::size(channelMapping); i++) { int channelMappingType = channelMapping[i]; diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index 27db41cb9f4e..171349a26569 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -841,7 +841,7 @@ public class RingtoneManager { if (ringtoneUri != null) { final Uri cacheUri = getCacheForType(type, context.getUserId()); try (InputStream in = openRingtone(context, ringtoneUri); - OutputStream out = resolver.openOutputStream(cacheUri)) { + OutputStream out = resolver.openOutputStream(cacheUri, "wt")) { FileUtils.copy(in, out); } catch (IOException e) { Log.w(TAG, "Failed to cache ringtone: " + e); diff --git a/packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java b/packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java index 2db0a8f4f911..33fc37ea0e6d 100644 --- a/packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java +++ b/packages/SettingsLib/ActivityEmbedding/src/com/android/settingslib/activityembedding/ActivityEmbeddingUtils.java @@ -25,7 +25,7 @@ import android.text.TextUtils; import android.util.Log; import androidx.core.os.BuildCompat; -import androidx.window.embedding.SplitController; +import androidx.window.embedding.ActivityEmbeddingController; import com.android.settingslib.utils.BuildCompatUtils; @@ -86,7 +86,7 @@ public final class ActivityEmbeddingUtils { * @param activity Activity that needs the check */ public static boolean isActivityEmbedded(Activity activity) { - return SplitController.getInstance().isActivityEmbedded(activity); + return ActivityEmbeddingController.getInstance(activity).isActivityEmbedded(activity); } /** diff --git a/packages/SettingsLib/res/values/arrays.xml b/packages/SettingsLib/res/values/arrays.xml index 9108449bd8d8..4de23bae2a15 100644 --- a/packages/SettingsLib/res/values/arrays.xml +++ b/packages/SettingsLib/res/values/arrays.xml @@ -118,9 +118,9 @@ <!-- Titles for Bluetooth HCI Snoop Filtered Logging --> <string-array name="bt_hci_snoop_log_filters_entries"> - <item>Headers Filtered</item> - <item>A2DP Media Packets Filtered</item> - <item>RFCOMM Channel Filtered</item> + <item>Leave only ACL headers</item> + <item>Filter A2DP media packets</item> + <item>Filter RFCOMM channel</item> </string-array> <!-- Values for Bluetooth HCI Snoop Filtered Logging --> @@ -132,10 +132,10 @@ <!-- Titles for Bluetooth HCI Snoop Filtered Logging --> <string-array name="bt_hci_snoop_log_profile_filter_entries"> - <item>Disabled</item> - <item>Magic</item> - <item>Header</item> - <item>Full Filter</item> + <item>Disable</item> + <item>Fill with string of characters</item> + <item>Leave only header</item> + <item>Fully remove</item> </string-array> <!-- Values for Bluetooth HCI Snoop Filtered Logging --> diff --git a/packages/SettingsLib/res/values/styles.xml b/packages/SettingsLib/res/values/styles.xml index 5237b4fa1c3d..172aff76d481 100644 --- a/packages/SettingsLib/res/values/styles.xml +++ b/packages/SettingsLib/res/values/styles.xml @@ -14,7 +14,7 @@ ~ limitations under the License --> -<resources> +<resources xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"> <style name="TextAppearanceSmall"> <item name="android:textAppearance">?android:attr/textAppearanceSmall</item> </style> @@ -73,7 +73,7 @@ </style> <style name="TextAppearanceBroadcastDialogButton" parent="@android:TextAppearance.DeviceDefault.Headline"> - <item name="android:textColor">?android:attr/textColorPrimary</item> + <item name="android:textColor">?androidprv:attr/textColorOnAccent</item> <item name="android:textSize">@dimen/broadcast_dialog_btn_text_size</item> </style> diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java index 379fe2ae713b..7634c58fd74d 100644 --- a/services/core/java/com/android/server/BatteryService.java +++ b/services/core/java/com/android/server/BatteryService.java @@ -149,6 +149,8 @@ public final class BatteryService extends SystemService { private int mLastMaxChargingCurrent; private int mLastMaxChargingVoltage; private int mLastChargeCounter; + private int mLastBatteryCycleCount; + private int mLastCharingState; private int mSequence = 1; @@ -503,7 +505,9 @@ public final class BatteryService extends SystemService { || mHealthInfo.maxChargingCurrentMicroamps != mLastMaxChargingCurrent || mHealthInfo.maxChargingVoltageMicrovolts != mLastMaxChargingVoltage || mHealthInfo.batteryChargeCounterUah != mLastChargeCounter - || mInvalidCharger != mLastInvalidCharger)) { + || mInvalidCharger != mLastInvalidCharger + || mHealthInfo.batteryCycleCount != mLastBatteryCycleCount + || mHealthInfo.chargingState != mLastCharingState)) { if (mPlugType != mLastPlugType) { if (mLastPlugType == BATTERY_PLUGGED_NONE) { @@ -677,6 +681,8 @@ public final class BatteryService extends SystemService { mLastChargeCounter = mHealthInfo.batteryChargeCounterUah; mLastBatteryLevelCritical = mBatteryLevelCritical; mLastInvalidCharger = mInvalidCharger; + mLastBatteryCycleCount = mHealthInfo.batteryCycleCount; + mLastCharingState = mHealthInfo.chargingState; } } @@ -708,6 +714,8 @@ public final class BatteryService extends SystemService { BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE, mHealthInfo.maxChargingVoltageMicrovolts); intent.putExtra(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounterUah); + intent.putExtra(BatteryManager.EXTRA_CYCLE_COUNT, mHealthInfo.batteryCycleCount); + intent.putExtra(BatteryManager.EXTRA_CHARGING_STATUS, mHealthInfo.chargingState); if (DEBUG) { Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. scale:" + BATTERY_SCALE + ", info:" + mHealthInfo.toString()); @@ -731,6 +739,8 @@ public final class BatteryService extends SystemService { event.putInt(BatteryManager.EXTRA_TEMPERATURE, mHealthInfo.batteryTemperatureTenthsCelsius); event.putInt(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounterUah); event.putLong(BatteryManager.EXTRA_EVENT_TIMESTAMP, now); + event.putInt(BatteryManager.EXTRA_CYCLE_COUNT, mHealthInfo.batteryCycleCount); + event.putInt(BatteryManager.EXTRA_CHARGING_STATUS, mHealthInfo.chargingState); boolean queueWasEmpty = mBatteryLevelsEventQueue.isEmpty(); mBatteryLevelsEventQueue.add(event); @@ -1241,11 +1251,20 @@ public final class BatteryService extends SystemService { } } - // Reduced IBatteryPropertiesRegistrar that only implements getProperty for usage - // in BatteryManager. + // Reduced IBatteryPropertiesRegistrar that implements getProperty for usage + // in BatteryManager and enforce permissions. private final class BatteryPropertiesRegistrar extends IBatteryPropertiesRegistrar.Stub { @Override public int getProperty(int id, final BatteryProperty prop) throws RemoteException { + switch (id) { + case BatteryManager.BATTERY_PROPERTY_MANUFACTURING_DATE: + case BatteryManager.BATTERY_PROPERTY_FIRST_USAGE_DATE: + case BatteryManager.BATTERY_PROPERTY_CHARGING_POLICY: + case BatteryManager.BATTERY_PROPERTY_STATE_OF_HEALTH: + mContext.enforceCallingPermission( + android.Manifest.permission.BATTERY_STATS, null); + break; + } return mHealthServiceWrapper.getProperty(id, prop); } @Override diff --git a/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java b/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java index c4113198ae1d..1153cc37e3da 100644 --- a/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java +++ b/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java @@ -18,6 +18,7 @@ package com.android.server.health; import android.annotation.NonNull; import android.annotation.Nullable; +import android.hardware.health.BatteryHealthData; import android.hardware.health.HealthInfo; import android.hardware.health.IHealth; import android.os.BatteryManager; @@ -113,6 +114,7 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper { private int getPropertyInternal(int id, BatteryProperty prop) throws RemoteException { IHealth service = mLastService.get(); if (service == null) throw new RemoteException("no health service"); + BatteryHealthData healthData; try { switch (id) { case BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER: @@ -133,6 +135,21 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper { case BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER: prop.setLong(service.getEnergyCounterNwh()); break; + case BatteryManager.BATTERY_PROPERTY_MANUFACTURING_DATE: + healthData = service.getBatteryHealthData(); + prop.setLong(healthData.batteryManufacturingDateSeconds); + break; + case BatteryManager.BATTERY_PROPERTY_FIRST_USAGE_DATE: + healthData = service.getBatteryHealthData(); + prop.setLong(healthData.batteryFirstUsageSeconds); + break; + case BatteryManager.BATTERY_PROPERTY_CHARGING_POLICY: + prop.setLong(service.getChargingPolicy()); + break; + case BatteryManager.BATTERY_PROPERTY_STATE_OF_HEALTH: + healthData = service.getBatteryHealthData(); + prop.setLong(healthData.batteryStateOfHealth); + break; } } catch (UnsupportedOperationException e) { // Leave prop untouched. diff --git a/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java b/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java index 90ddb6ffb34a..d2a6bf288be4 100644 --- a/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java +++ b/tests/BackgroundDexOptServiceIntegrationTests/src/com/android/server/pm/BackgroundDexOptServiceIntegrationTests.java @@ -31,6 +31,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -299,6 +300,8 @@ public final class BackgroundDexOptServiceIntegrationTests { // Test that background dexopt under low storage conditions downgrades unused packages. @Test + @Ignore("b/251438180: This test has been failing for a long time; temporarily disable it while" + + " we investigate this issue.") public void testBackgroundDexOptDowngradeSuccessful() throws IOException { // Should be more than DOWNGRADE_AFTER_DAYS. long deltaDays = DOWNGRADE_AFTER_DAYS + 1; |