Database restructure: use protobuf to save battery information fields.

This patch only updates the existing fields.
There will be 2 following patches to:
1. Expose the new fields (foreground / foreground service / background x
   usage time / power consumption) to UI.
2. Get the full charge cycle start time from Database and remove the
   SharedPreference.

Test: make RunSettingsRoboTests + manual
Bug: 253553141
Change-Id: Iee02dc7e671f97899cb1495323acfa0173e31df2
This commit is contained in:
Kuan Wang
2022-11-09 16:24:23 +08:00
parent 45c9b11655
commit 1493fa2fea
19 changed files with 528 additions and 513 deletions

View File

@@ -32,6 +32,7 @@ import android.os.Process;
import android.os.SystemClock;
import android.os.UidBatteryConsumer;
import android.os.UserHandle;
import android.util.Base64;
import android.util.Log;
import androidx.annotation.IntDef;
@@ -52,6 +53,9 @@ import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
import com.android.settingslib.utils.PowerUtil;
import com.android.settingslib.utils.ThreadUtils;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.time.Duration;
@@ -316,6 +320,28 @@ public class BatteryUtils {
}
}
/**
* Parses proto object from string.
*
* @param serializedProto the serialized proto string
* @param protoClass class of the proto
* @return instance of the proto class parsed from the string
*/
@SuppressWarnings("unchecked")
public static <T extends MessageLite> T parseProtoFromString(
String serializedProto, T protoClass) {
if (serializedProto.isEmpty()) {
return (T) protoClass.getDefaultInstanceForType();
}
try {
return (T) protoClass.getParserForType()
.parseFrom(Base64.decode(serializedProto, Base64.DEFAULT));
} catch (InvalidProtocolBufferException e) {
Log.e(TAG, "Failed to deserialize proto class", e);
return (T) protoClass.getDefaultInstanceForType();
}
}
public void setForceAppStandby(int uid, String packageName,
int mode) {
final boolean isPreOApp = isPreOApp(packageName);