Add a new feature provider for Battery info page
This feature provider contains the APIs to query certain battery info. Bug: 276399056 Test: robotests Change-Id: I8f8503f42a6ad1460b4601e44e8b720b91dd13d1
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.deviceinfo.batteryinfo;
|
||||
|
||||
/**
|
||||
* Feature Provider used for getting battery information.
|
||||
*/
|
||||
public interface BatteryInfoFeatureProvider {
|
||||
|
||||
/** Returns true if Manufacture date should be shown */
|
||||
boolean isManufactureDateAvailable();
|
||||
|
||||
/** Returns true if First use date should be shown */
|
||||
boolean isFirstUseDateAvailable();
|
||||
|
||||
/** Returns the summary of battery manufacture date */
|
||||
CharSequence getManufactureDateSummary();
|
||||
|
||||
/** Returns the summary of battery first use date */
|
||||
CharSequence getFirstUseDateSummary();
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.deviceinfo.batteryinfo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.BatteryManager;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/** Implementation of {@code BatteryInfoFeatureProvider} */
|
||||
public class BatteryInfoFeatureProviderImpl implements BatteryInfoFeatureProvider {
|
||||
|
||||
private BatteryManager mBatteryManager;
|
||||
private Context mContext;
|
||||
private long mManufactureDateInSec;
|
||||
private long mFirstUseDateInSec;
|
||||
|
||||
public BatteryInfoFeatureProviderImpl(Context context) {
|
||||
mContext = context;
|
||||
mBatteryManager = mContext.getSystemService(BatteryManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isManufactureDateAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirstUseDateAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getManufactureDateSummary() {
|
||||
if (!isManufactureDateAvailable()) {
|
||||
return null;
|
||||
}
|
||||
final long manufactureDateInSec = getManufactureDate();
|
||||
|
||||
return getFormattedDate(manufactureDateInSec * 1000L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getFirstUseDateSummary() {
|
||||
if (!isFirstUseDateAvailable()) {
|
||||
return null;
|
||||
}
|
||||
final long firstUseDateInSec = getFirstUseDate();
|
||||
|
||||
return getFormattedDate(firstUseDateInSec * 1000L);
|
||||
}
|
||||
|
||||
protected long getManufactureDate() {
|
||||
if (mManufactureDateInSec == 0L) {
|
||||
mManufactureDateInSec = mBatteryManager.getLongProperty(
|
||||
BatteryManager.BATTERY_PROPERTY_MANUFACTURING_DATE);
|
||||
}
|
||||
return mManufactureDateInSec;
|
||||
}
|
||||
|
||||
protected long getFirstUseDate() {
|
||||
if (mFirstUseDateInSec == 0L) {
|
||||
mFirstUseDateInSec = mBatteryManager.getLongProperty(
|
||||
BatteryManager.BATTERY_PROPERTY_FIRST_USAGE_DATE);
|
||||
}
|
||||
return mFirstUseDateInSec;
|
||||
}
|
||||
|
||||
private CharSequence getFormattedDate(long dateInMs) {
|
||||
final Date date = new Date(dateInMs);
|
||||
final CharSequence formattedDate =
|
||||
DateFormat.getDateInstance(DateFormat.LONG).format(date.getTime());
|
||||
|
||||
return formattedDate;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import com.android.settings.biometrics2.factory.BiometricsRepositoryProvider;
|
||||
import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.deviceinfo.batteryinfo.BatteryInfoFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
||||
import com.android.settings.fuelgauge.BatteryStatusFeatureProvider;
|
||||
@@ -204,6 +205,11 @@ public abstract class FeatureFactory {
|
||||
*/
|
||||
public abstract KeyboardSettingsFeatureProvider getKeyboardSettingsFeatureProvider();
|
||||
|
||||
/**
|
||||
* Retrieves implementation for Battery information feature.
|
||||
*/
|
||||
public abstract BatteryInfoFeatureProvider getBatteryInfoFeatureProvider();
|
||||
|
||||
public static final class FactoryNotFoundException extends RuntimeException {
|
||||
public FactoryNotFoundException(Throwable throwable) {
|
||||
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
|
||||
|
||||
@@ -47,6 +47,8 @@ import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
|
||||
import com.android.settings.deviceinfo.batteryinfo.BatteryInfoFeatureProvider;
|
||||
import com.android.settings.deviceinfo.batteryinfo.BatteryInfoFeatureProviderImpl;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
|
||||
import com.android.settings.fuelgauge.BatterySettingsFeatureProvider;
|
||||
@@ -117,6 +119,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
private AdvancedVpnFeatureProvider mAdvancedVpnFeatureProvider;
|
||||
private WifiFeatureProvider mWifiFeatureProvider;
|
||||
private KeyboardSettingsFeatureProvider mKeyboardSettingsFeatureProvider;
|
||||
private BatteryInfoFeatureProvider mBatteryInfoFeatureProvider;
|
||||
|
||||
@Override
|
||||
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
|
||||
@@ -376,4 +379,12 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
}
|
||||
return mKeyboardSettingsFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryInfoFeatureProvider getBatteryInfoFeatureProvider() {
|
||||
if (mBatteryInfoFeatureProvider == null) {
|
||||
mBatteryInfoFeatureProvider = new BatteryInfoFeatureProviderImpl(getAppContext());
|
||||
}
|
||||
return mBatteryInfoFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user