Merge 24Q3 (ab/AP3A.240905.001) to aosp-main-future
Bug: 347831320 Merged-In: I2489a64804f068a957f9be3f87847d6911b24447 Change-Id: I1885ef34f69ac4eb6e76ac903fcacdebe4139ae1
This commit is contained in:
@@ -356,6 +356,11 @@ public class FingerprintSettings extends SubSettings {
|
||||
*/
|
||||
protected void handleError(int errMsgId, CharSequence msg) {
|
||||
switch (errMsgId) {
|
||||
case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
|
||||
case FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED:
|
||||
// Only happens if we get preempted by another activity, or canceled by the
|
||||
// user (e.g. swipe up to home). Ignored.
|
||||
return;
|
||||
case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
|
||||
mInFingerprintLockout = true;
|
||||
// We've been locked out. Reset after 30s.
|
||||
|
@@ -19,13 +19,16 @@ package com.android.settings.bluetooth;
|
||||
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
@@ -37,9 +40,14 @@ import androidx.preference.TwoStatePreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
@@ -53,22 +61,27 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
private static final String KEY_SPATIAL_AUDIO = "spatial_audio";
|
||||
private static final String KEY_HEAD_TRACKING = "head_tracking";
|
||||
|
||||
private final AudioManager mAudioManager;
|
||||
private final Spatializer mSpatializer;
|
||||
|
||||
@VisibleForTesting
|
||||
PreferenceCategory mProfilesContainer;
|
||||
@VisibleForTesting
|
||||
AudioDeviceAttributes mAudioDevice = null;
|
||||
@VisibleForTesting @Nullable AudioDeviceAttributes mAudioDevice = null;
|
||||
|
||||
AtomicBoolean mHasHeadTracker = new AtomicBoolean(false);
|
||||
AtomicBoolean mInitialRefresh = new AtomicBoolean(true);
|
||||
|
||||
public static final Set<Integer> SA_PROFILES =
|
||||
ImmutableSet.of(
|
||||
BluetoothProfile.A2DP, BluetoothProfile.LE_AUDIO, BluetoothProfile.HEARING_AID);
|
||||
|
||||
public BluetoothDetailsSpatialAudioController(
|
||||
Context context,
|
||||
PreferenceFragmentCompat fragment,
|
||||
CachedBluetoothDevice device,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, fragment, device, lifecycle);
|
||||
mAudioManager = context.getSystemService(AudioManager.class);
|
||||
mSpatializer = FeatureFactory.getFeatureFactory().getBluetoothFeatureProvider()
|
||||
.getSpatializer(context);
|
||||
}
|
||||
@@ -142,8 +155,12 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
if (mAudioDevice == null) {
|
||||
getAvailableDevice();
|
||||
if (Flags.enableDeterminingSpatialAudioAttributesByProfile()) {
|
||||
getAvailableDeviceByProfileState();
|
||||
} else {
|
||||
if (mAudioDevice == null) {
|
||||
getAvailableDevice();
|
||||
}
|
||||
}
|
||||
ThreadUtils.postOnBackgroundThread(
|
||||
() -> {
|
||||
@@ -274,6 +291,77 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
+ ", type : " + (mAudioDevice == null ? "no type" : mAudioDevice.getType()));
|
||||
}
|
||||
|
||||
private void getAvailableDeviceByProfileState() {
|
||||
Log.i(
|
||||
TAG,
|
||||
"getAvailableDevice() mCachedDevice: "
|
||||
+ mCachedDevice
|
||||
+ " profiles: "
|
||||
+ mCachedDevice.getProfiles());
|
||||
|
||||
AudioDeviceAttributes saDevice = null;
|
||||
for (LocalBluetoothProfile profile : mCachedDevice.getProfiles()) {
|
||||
// pick first enabled profile that is compatible with spatial audio
|
||||
if (SA_PROFILES.contains(profile.getProfileId())
|
||||
&& profile.isEnabled(mCachedDevice.getDevice())) {
|
||||
switch (profile.getProfileId()) {
|
||||
case BluetoothProfile.A2DP:
|
||||
saDevice =
|
||||
new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT,
|
||||
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP,
|
||||
mCachedDevice.getAddress());
|
||||
break;
|
||||
case BluetoothProfile.LE_AUDIO:
|
||||
if (mAudioManager.getBluetoothAudioDeviceCategory(
|
||||
mCachedDevice.getAddress())
|
||||
== AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER) {
|
||||
saDevice =
|
||||
new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT,
|
||||
AudioDeviceInfo.TYPE_BLE_SPEAKER,
|
||||
mCachedDevice.getAddress());
|
||||
} else {
|
||||
saDevice =
|
||||
new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT,
|
||||
AudioDeviceInfo.TYPE_BLE_HEADSET,
|
||||
mCachedDevice.getAddress());
|
||||
}
|
||||
|
||||
break;
|
||||
case BluetoothProfile.HEARING_AID:
|
||||
saDevice =
|
||||
new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT,
|
||||
AudioDeviceInfo.TYPE_HEARING_AID,
|
||||
mCachedDevice.getAddress());
|
||||
break;
|
||||
default:
|
||||
Log.i(
|
||||
TAG,
|
||||
"unrecognized profile for spatial audio: "
|
||||
+ profile.getProfileId());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
mAudioDevice = null;
|
||||
if (saDevice != null && mSpatializer.isAvailableForDevice(saDevice)) {
|
||||
mAudioDevice = saDevice;
|
||||
}
|
||||
|
||||
Log.d(
|
||||
TAG,
|
||||
"getAvailableDevice() device : "
|
||||
+ mCachedDevice.getDevice().getAnonymizedAddress()
|
||||
+ ", is available : "
|
||||
+ (mAudioDevice != null)
|
||||
+ ", type : "
|
||||
+ (mAudioDevice == null ? "no type" : mAudioDevice.getType()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setAvailableDevice(AudioDeviceAttributes audioDevice) {
|
||||
mAudioDevice = audioDevice;
|
||||
|
@@ -23,11 +23,16 @@ import android.os.Bundle;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryEvent;
|
||||
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
||||
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Feature Provider used in power usage */
|
||||
@@ -154,4 +159,14 @@ public interface PowerUsageFeatureProvider {
|
||||
|
||||
/** Whether the device is under the battery defender mode */
|
||||
boolean isBatteryDefend(BatteryInfo info);
|
||||
|
||||
/** Whether the battery usage reattribute is eabled or not. */
|
||||
boolean isBatteryUsageReattributeEnabled();
|
||||
|
||||
/** Collect and process battery reattribute data if needed. */
|
||||
boolean processBatteryReattributeData(
|
||||
@NonNull Context context,
|
||||
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
|
||||
@NonNull List<BatteryEvent> batteryEventList,
|
||||
final boolean isFromPeriodJob);
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.Utils.SYSTEMUI_PACKAGE_NAME;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -27,13 +26,19 @@ import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryDiffData;
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryEvent;
|
||||
import com.android.settings.fuelgauge.batteryusage.DetectRequestSourceType;
|
||||
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Implementation of {@code PowerUsageFeatureProvider} */
|
||||
@@ -240,4 +245,18 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
public boolean isBatteryDefend(BatteryInfo info) {
|
||||
return info.isBatteryDefender && !isExtraDefend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryUsageReattributeEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processBatteryReattributeData(
|
||||
@NonNull Context context,
|
||||
@NonNull Map<Long, BatteryDiffData> batteryDiffDataMap,
|
||||
@NonNull List<BatteryEvent> batteryEventList,
|
||||
final boolean isFromPeriodJob) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -77,11 +77,13 @@ public class BatteryDiffData {
|
||||
processAndSortEntries(mSystemEntries);
|
||||
}
|
||||
|
||||
long getStartTimestamp() {
|
||||
/** Gets the start timestamp. */
|
||||
public long getStartTimestamp() {
|
||||
return mStartTimestamp;
|
||||
}
|
||||
|
||||
long getEndTimestamp() {
|
||||
/** Gets the end timestamp. */
|
||||
public long getEndTimestamp() {
|
||||
return mEndTimestamp;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,8 @@ public class BatteryDiffData {
|
||||
return mScreenOnTime;
|
||||
}
|
||||
|
||||
List<BatteryDiffEntry> getAppDiffEntryList() {
|
||||
/** Gets the {@link BatteryDiffEntry} list for apps. */
|
||||
public List<BatteryDiffEntry> getAppDiffEntryList() {
|
||||
return mAppEntries;
|
||||
}
|
||||
|
||||
@@ -296,8 +299,7 @@ public class BatteryDiffData {
|
||||
* Sets total consume power, and adjusts the percentages to ensure the total round percentage
|
||||
* could be 100%, and then sorts entries based on the sorting key.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static void processAndSortEntries(final List<BatteryDiffEntry> batteryDiffEntries) {
|
||||
public static void processAndSortEntries(final List<BatteryDiffEntry> batteryDiffEntries) {
|
||||
if (batteryDiffEntries.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -201,6 +201,20 @@ public final class ConvertUtils {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
/** Gets the encoded string from {@link BatteryReattribute} instance. */
|
||||
@NonNull
|
||||
public static String encodeBatteryReattribute(
|
||||
@NonNull BatteryReattribute batteryReattribute) {
|
||||
return Base64.encodeToString(batteryReattribute.toByteArray(), Base64.DEFAULT);
|
||||
}
|
||||
|
||||
/** Gets the decoded {@link BatteryReattribute} instance from string. */
|
||||
@NonNull
|
||||
public static BatteryReattribute decodeBatteryReattribute(@NonNull String content) {
|
||||
return BatteryUtils.parseProtoFromString(
|
||||
content, BatteryReattribute.getDefaultInstance());
|
||||
}
|
||||
|
||||
/** Converts to {@link BatteryHistEntry} */
|
||||
public static BatteryHistEntry convertToBatteryHistEntry(
|
||||
BatteryEntry entry, BatteryUsageStats batteryUsageStats) {
|
||||
|
@@ -28,6 +28,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@@ -78,6 +80,7 @@ public class DataProcessManager {
|
||||
// Raw start timestamp with round to the nearest hour.
|
||||
private final long mRawStartTimestamp;
|
||||
private final long mLastFullChargeTimestamp;
|
||||
private final boolean mIsFromPeriodJob;
|
||||
private final Context mContext;
|
||||
private final Handler mHandler;
|
||||
private final UserIdsSeries mUserIdsSeries;
|
||||
@@ -122,6 +125,7 @@ public class DataProcessManager {
|
||||
Context context,
|
||||
Handler handler,
|
||||
final UserIdsSeries userIdsSeries,
|
||||
final boolean isFromPeriodJob,
|
||||
final long rawStartTimestamp,
|
||||
final long lastFullChargeTimestamp,
|
||||
@NonNull final OnBatteryDiffDataMapLoadedListener callbackFunction,
|
||||
@@ -130,6 +134,7 @@ public class DataProcessManager {
|
||||
mContext = context.getApplicationContext();
|
||||
mHandler = handler;
|
||||
mUserIdsSeries = userIdsSeries;
|
||||
mIsFromPeriodJob = isFromPeriodJob;
|
||||
mRawStartTimestamp = rawStartTimestamp;
|
||||
mLastFullChargeTimestamp = lastFullChargeTimestamp;
|
||||
mCallbackFunction = callbackFunction;
|
||||
@@ -147,6 +152,7 @@ public class DataProcessManager {
|
||||
mHandler = handler;
|
||||
mUserIdsSeries = userIdsSeries;
|
||||
mCallbackFunction = callbackFunction;
|
||||
mIsFromPeriodJob = false;
|
||||
mRawStartTimestamp = 0L;
|
||||
mLastFullChargeTimestamp = 0L;
|
||||
mHourlyBatteryLevelsPerDay = null;
|
||||
@@ -158,14 +164,9 @@ public class DataProcessManager {
|
||||
|
||||
/** Starts the async tasks to load battery history data and app usage data. */
|
||||
public void start() {
|
||||
start(/* isFromPeriodJob= */ false);
|
||||
}
|
||||
|
||||
/** Starts the async tasks to load battery history data and app usage data. */
|
||||
public void start(boolean isFromPeriodJob) {
|
||||
// If we have battery level data, load the battery history map and app usage simultaneously.
|
||||
if (mHourlyBatteryLevelsPerDay != null) {
|
||||
if (isFromPeriodJob) {
|
||||
if (mIsFromPeriodJob) {
|
||||
mIsCurrentBatteryHistoryLoaded = true;
|
||||
mIsCurrentAppUsageLoaded = true;
|
||||
mIsBatteryUsageSlotLoaded = true;
|
||||
@@ -514,6 +515,14 @@ public class DataProcessManager {
|
||||
mAppUsagePeriodMap,
|
||||
getSystemAppsPackageNames(),
|
||||
getSystemAppsUids()));
|
||||
// Process the reattributate data for the following two cases:
|
||||
// 1) the latest slot for the timestamp "until now"
|
||||
// 2) walkthrough all BatteryDiffData again to handle "re-compute" case
|
||||
final PowerUsageFeatureProvider featureProvider =
|
||||
FeatureFactory.getFeatureFactory()
|
||||
.getPowerUsageFeatureProvider();
|
||||
featureProvider.processBatteryReattributeData(
|
||||
mContext, batteryDiffDataMap, mBatteryEventList, mIsFromPeriodJob);
|
||||
|
||||
Log.d(
|
||||
TAG,
|
||||
@@ -683,12 +692,13 @@ public class DataProcessManager {
|
||||
context,
|
||||
handler,
|
||||
userIdsSeries,
|
||||
isFromPeriodJob,
|
||||
startTimestamp,
|
||||
lastFullChargeTime,
|
||||
onBatteryDiffDataMapLoadedListener,
|
||||
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
||||
processedBatteryHistoryMap)
|
||||
.start(isFromPeriodJob);
|
||||
.start();
|
||||
|
||||
return batteryLevelData;
|
||||
}
|
||||
|
@@ -429,6 +429,7 @@ public final class DatabaseUtils {
|
||||
database.batteryEventDao().clearAll();
|
||||
database.batteryStateDao().clearAll();
|
||||
database.batteryUsageSlotDao().clearAll();
|
||||
database.batteryReattributeDao().clearAll();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "clearAll() failed", e);
|
||||
}
|
||||
@@ -466,6 +467,7 @@ public final class DatabaseUtils {
|
||||
database.batteryEventDao().clearAllBefore(earliestTimestamp);
|
||||
database.batteryStateDao().clearAllBefore(earliestTimestamp);
|
||||
database.batteryUsageSlotDao().clearAllBefore(earliestTimestamp);
|
||||
database.batteryReattributeDao().clearAllBefore(earliestTimestamp);
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "clearAllBefore() failed", e);
|
||||
}
|
||||
|
@@ -55,6 +55,7 @@ public final class BugReportContentProvider extends ContentProvider {
|
||||
}
|
||||
writer.println("dump BatteryUsage and AppUsage states:");
|
||||
LogUtils.dumpAppOptimizationModeEventHist(context, writer);
|
||||
LogUtils.dumpBatteryReattributeDatabaseHist(context, writer);
|
||||
LogUtils.dumpBatteryUsageDatabaseHist(context, writer);
|
||||
LogUtils.dumpAppUsageDatabaseHist(context, writer);
|
||||
LogUtils.dumpBatteryUsageSlotDatabaseHist(context, writer);
|
||||
|
@@ -19,6 +19,8 @@ package com.android.settings.fuelgauge.batteryusage.bugreport;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batteryusage.AppOptModeSharedPreferencesUtils;
|
||||
import com.android.settings.fuelgauge.batteryusage.AppOptimizationModeEvent;
|
||||
@@ -29,11 +31,14 @@ import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventDao;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryEventDao;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryEventEntity;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryReattributeDao;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryReattributeEntity;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryState;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDao;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotDao;
|
||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotEntity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.time.Clock;
|
||||
@@ -127,6 +132,33 @@ public final class LogUtils {
|
||||
dumpListItems(writer, entities, entity -> entity);
|
||||
}
|
||||
|
||||
static void dumpBatteryReattributeDatabaseHist(Context context, PrintWriter writer) {
|
||||
try {
|
||||
dumpBatteryReattributeDatabaseHist(
|
||||
BatteryStateDatabase.getInstance(context).batteryReattributeDao(),
|
||||
writer);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "failed to run dumpBatteryReattributeDatabaseHist()", e);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void dumpBatteryReattributeDatabaseHist(
|
||||
BatteryReattributeDao batteryReattributeDao, PrintWriter writer) {
|
||||
if (!FeatureFactory.getFeatureFactory().getPowerUsageFeatureProvider()
|
||||
.isBatteryUsageReattributeEnabled()) {
|
||||
writer.println("\n\tBatteryReattribute is disabled!");
|
||||
return;
|
||||
}
|
||||
writer.println("\n\tBatteryReattribute DatabaseHistory:");
|
||||
final List<BatteryReattributeEntity> entities =
|
||||
batteryReattributeDao.getAllAfter(
|
||||
Clock.systemUTC().millis() - DUMP_TIME_OFFSET.toMillis());
|
||||
if (entities != null && !entities.isEmpty()) {
|
||||
dumpListItems(writer, entities, entity -> entity);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T, S> void dumpListItems(
|
||||
PrintWriter writer, List<T> itemList, Function<T, S> itemConverter) {
|
||||
final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.settings.fuelgauge.batteryusage.db;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** DAO for accessing {@link BatteryReattributeEntity} in the database. */
|
||||
@Dao
|
||||
public interface BatteryReattributeDao {
|
||||
|
||||
/** Inserts a {@link BatteryReattributeEntity} data into the database. */
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(event: BatteryReattributeEntity)
|
||||
|
||||
/** Gets all recorded data after a specific timestamp. */
|
||||
@Query(
|
||||
"SELECT * FROM BatteryReattributeEntity WHERE "
|
||||
+ "timestampStart >= :timestampStart ORDER BY timestampStart DESC")
|
||||
fun getAllAfter(timestampStart: Long): List<BatteryReattributeEntity>
|
||||
|
||||
/** Deletes all recorded data before a specific timestamp. */
|
||||
@Query("DELETE FROM BatteryReattributeEntity WHERE timestampStart <= :timestampStart")
|
||||
fun clearAllBefore(timestampStart: Long)
|
||||
|
||||
/** Deletes all recorded data after a specific timestamp. */
|
||||
@Query("DELETE FROM BatteryReattributeEntity WHERE timestampStart >= :timestampStart")
|
||||
fun clearAllAfter(timestampStart: Long)
|
||||
|
||||
/** Clears all recorded data in the database. */
|
||||
@Query("DELETE FROM BatteryReattributeEntity") fun clearAll()
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.settings.fuelgauge.batteryusage.db;
|
||||
|
||||
import static com.android.settings.fuelgauge.batteryusage.ConvertUtils.utcToLocalTimeForLogging;
|
||||
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryReattribute;
|
||||
import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
/** A {@link Entity} for battery usage reattribution data in the database. */
|
||||
@Entity
|
||||
public class BatteryReattributeEntity {
|
||||
|
||||
/** The start timestamp of this record data. */
|
||||
@PrimaryKey
|
||||
public final long timestampStart;
|
||||
|
||||
/** The end timestamp of this record data. */
|
||||
public final long timestampEnd;
|
||||
|
||||
/** The battery usage reattribution data for corresponding uids. */
|
||||
public final String reattributeData;
|
||||
|
||||
public BatteryReattributeEntity(@NonNull BatteryReattribute batteryReattribute) {
|
||||
this(
|
||||
batteryReattribute.getTimestampStart(),
|
||||
batteryReattribute.getTimestampEnd(),
|
||||
ConvertUtils.encodeBatteryReattribute(batteryReattribute));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryReattributeEntity(
|
||||
long timestampStart, long timestampEnd, @NonNull String reattributeData) {
|
||||
this.timestampStart = timestampStart;
|
||||
this.timestampEnd = timestampEnd;
|
||||
this.reattributeData = reattributeData;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
final BatteryReattribute batteryReattribute =
|
||||
ConvertUtils.decodeBatteryReattribute(reattributeData);
|
||||
final StringBuilder builder = new StringBuilder()
|
||||
.append("\nBatteryReattributeEntity{")
|
||||
.append("\n\t" + utcToLocalTimeForLogging(timestampStart))
|
||||
.append("\n\t" + utcToLocalTimeForLogging(timestampEnd))
|
||||
.append("\n\t" + batteryReattribute);
|
||||
if (batteryReattribute != null) {
|
||||
builder.append("\n\t" + batteryReattribute.getReattributeDataMap());
|
||||
}
|
||||
return builder.append("\n}").toString();
|
||||
}
|
||||
}
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge.batteryusage.db;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
@@ -29,11 +30,13 @@ import androidx.room.RoomDatabase;
|
||||
AppUsageEventEntity.class,
|
||||
BatteryEventEntity.class,
|
||||
BatteryState.class,
|
||||
BatteryUsageSlotEntity.class
|
||||
BatteryUsageSlotEntity.class,
|
||||
BatteryReattributeEntity.class
|
||||
},
|
||||
version = 1)
|
||||
version = 2)
|
||||
public abstract class BatteryStateDatabase extends RoomDatabase {
|
||||
private static final String TAG = "BatteryStateDatabase";
|
||||
private static final String DB_FILE_NAME = "battery-usage-db-v10";
|
||||
|
||||
private static BatteryStateDatabase sBatteryStateDatabase;
|
||||
|
||||
@@ -49,11 +52,15 @@ public abstract class BatteryStateDatabase extends RoomDatabase {
|
||||
/** Provides DAO for battery usage slot table. */
|
||||
public abstract BatteryUsageSlotDao batteryUsageSlotDao();
|
||||
|
||||
/** Provides DAO for battery reattribution table. */
|
||||
@NonNull
|
||||
public abstract BatteryReattributeDao batteryReattributeDao();
|
||||
|
||||
/** Gets or creates an instance of {@link RoomDatabase}. */
|
||||
public static BatteryStateDatabase getInstance(Context context) {
|
||||
if (sBatteryStateDatabase == null) {
|
||||
sBatteryStateDatabase =
|
||||
Room.databaseBuilder(context, BatteryStateDatabase.class, "battery-usage-db-v9")
|
||||
Room.databaseBuilder(context, BatteryStateDatabase.class, DB_FILE_NAME)
|
||||
// Allows accessing data in the main thread for dumping bugreport.
|
||||
.allowMainThreadQueries()
|
||||
.fallbackToDestructiveMigration()
|
||||
|
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_package = "com.android.settings.fuelgauge.batteryusage";
|
||||
option java_outer_classname = "BatteryReaatributeProto";
|
||||
|
||||
// Battery usage reattribute data for a specific timestamp slot.
|
||||
message BatteryReattribute {
|
||||
optional int64 timestamp_start = 1;
|
||||
optional int64 timestamp_end = 2;
|
||||
// Battery reattribute data for uid and its corresponding ratio.
|
||||
map<int32, float> reattribute_data = 3;
|
||||
}
|
@@ -44,6 +44,16 @@ class DisplayOverOtherAppsListModel(context: Context) : AppOpPermissionListModel
|
||||
logPermissionChange(newAllowed)
|
||||
}
|
||||
|
||||
// TODO (b/349195999)
|
||||
override fun isChangeable(record: AppOpPermissionRecord): Boolean {
|
||||
if (record.app.packageName in
|
||||
context.resources.getStringArray(R.array.display_over_apps_permission_change_exempt)
|
||||
&& record.app.isSystemApp()) {
|
||||
return false
|
||||
}
|
||||
return super.isChangeable(record)
|
||||
}
|
||||
|
||||
private fun logPermissionChange(newAllowed: Boolean) {
|
||||
val category = when {
|
||||
newAllowed -> SettingsEnums.APP_SPECIAL_PERMISSION_APPDRAW_ALLOW
|
||||
|
@@ -26,7 +26,7 @@ import com.android.settings.R
|
||||
import com.android.settings.core.BasePreferenceController
|
||||
import com.android.settings.flags.Flags
|
||||
|
||||
class DeviceDiagnosticsPreferenceController(context: Context, preferenceKey: String) :
|
||||
open class DeviceDiagnosticsPreferenceController(context: Context, preferenceKey: String) :
|
||||
BasePreferenceController(context, preferenceKey) {
|
||||
|
||||
override fun getAvailabilityStatus(): Int {
|
||||
@@ -59,6 +59,12 @@ class DeviceDiagnosticsPreferenceController(context: Context, preferenceKey: Str
|
||||
val packageName = mContext.getResources().getString(
|
||||
R.string.config_device_diagnostics_package_name)
|
||||
intent.setPackage(packageName)
|
||||
|
||||
val info = mContext.getPackageManager().resolveActivity(intent, 0)
|
||||
if (info == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return intent
|
||||
}
|
||||
|
Reference in New Issue
Block a user