Replace the isWorkProfile method from the SettingsLib
Replace the isWorkProfile() in the Settings with the common method defined in the SettingsLib to avoid duplicate code Bug: 306329984 Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge" Change-Id: Ic9b18e6b80c23f9d4fc200080224daa27cbf4a4d
This commit is contained in:
@@ -63,7 +63,7 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
Log.d(TAG, "onReceive:" + action);
|
Log.d(TAG, "onReceive:" + action);
|
||||||
if (DatabaseUtils.isWorkProfile(context)) {
|
if (com.android.settingslib.fuelgauge.BatteryUtils.isWorkProfile(context)) {
|
||||||
Log.w(TAG, "do nothing for work profile action=" + action);
|
Log.w(TAG, "do nothing for work profile action=" + action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,7 @@ import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDao;
|
|||||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
|
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
|
||||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotDao;
|
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotDao;
|
||||||
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotEntity;
|
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotEntity;
|
||||||
|
import com.android.settingslib.fuelgauge.BatteryUtils;
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -109,7 +110,7 @@ public class BatteryUsageContentProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
if (DatabaseUtils.isWorkProfile(getContext())) {
|
if (BatteryUtils.isWorkProfile(getContext())) {
|
||||||
Log.w(TAG, "do not create provider for work profile");
|
Log.w(TAG, "do not create provider for work profile");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ import com.android.settings.core.instrumentation.ElapsedTimeUtils;
|
|||||||
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
|
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
|
||||||
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
|
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.fuelgauge.BatteryUtils;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ public final class BootBroadcastReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent == null ? "" : intent.getAction();
|
final String action = intent == null ? "" : intent.getAction();
|
||||||
if (DatabaseUtils.isWorkProfile(context)) {
|
if (BatteryUtils.isWorkProfile(context)) {
|
||||||
Log.w(TAG, "do not start job for work profile action=" + action);
|
Log.w(TAG, "do not start job for work profile action=" + action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -159,12 +159,6 @@ public final class DatabaseUtils {
|
|||||||
|
|
||||||
private DatabaseUtils() {}
|
private DatabaseUtils() {}
|
||||||
|
|
||||||
/** Returns true if current user is a work profile user. */
|
|
||||||
public static boolean isWorkProfile(Context context) {
|
|
||||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
|
||||||
return userManager.isManagedProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the latest timestamp current user data in app usage event table. */
|
/** Returns the latest timestamp current user data in app usage event table. */
|
||||||
public static long getAppUsageStartTimestampOfUser(
|
public static long getAppUsageStartTimestampOfUser(
|
||||||
Context context, final long userId, final long earliestTimestamp) {
|
Context context, final long userId, final long earliestTimestamp) {
|
||||||
@@ -502,7 +496,7 @@ public final class DatabaseUtils {
|
|||||||
|
|
||||||
/** Returns the context with profile parent identity when current user is work profile. */
|
/** Returns the context with profile parent identity when current user is work profile. */
|
||||||
public static Context getParentContext(Context context) {
|
public static Context getParentContext(Context context) {
|
||||||
if (isWorkProfile(context)) {
|
if (com.android.settingslib.fuelgauge.BatteryUtils.isWorkProfile(context)) {
|
||||||
try {
|
try {
|
||||||
return context.createPackageContextAsUser(
|
return context.createPackageContextAsUser(
|
||||||
/* packageName= */ context.getPackageName(),
|
/* packageName= */ context.getPackageName(),
|
||||||
|
@@ -24,6 +24,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
|
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
|
||||||
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
|
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
|
||||||
|
import com.android.settingslib.fuelgauge.BatteryUtils;
|
||||||
|
|
||||||
/** Receives the periodic alarm {@link PendingIntent} callback. */
|
/** Receives the periodic alarm {@link PendingIntent} callback. */
|
||||||
public final class PeriodicJobReceiver extends BroadcastReceiver {
|
public final class PeriodicJobReceiver extends BroadcastReceiver {
|
||||||
@@ -49,7 +50,7 @@ public final class PeriodicJobReceiver extends BroadcastReceiver {
|
|||||||
Log.w(TAG, "receive unexpected action=" + action);
|
Log.w(TAG, "receive unexpected action=" + action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DatabaseUtils.isWorkProfile(context)) {
|
if (BatteryUtils.isWorkProfile(context)) {
|
||||||
BatteryUsageLogUtils.writeLog(
|
BatteryUsageLogUtils.writeLog(
|
||||||
context, Action.SCHEDULE_JOB, "do not refresh job for work profile");
|
context, Action.SCHEDULE_JOB, "do not refresh job for work profile");
|
||||||
Log.w(TAG, "do not refresh job for work profile action=" + action);
|
Log.w(TAG, "do not refresh job for work profile action=" + action);
|
||||||
|
@@ -23,7 +23,7 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batteryusage.DatabaseUtils;
|
import com.android.settingslib.fuelgauge.BatteryUtils;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -49,7 +49,7 @@ public final class BugReportContentProvider extends ContentProvider {
|
|||||||
Log.w(TAG, "failed to dump BatteryUsage state: null application context");
|
Log.w(TAG, "failed to dump BatteryUsage state: null application context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DatabaseUtils.isWorkProfile(context)) {
|
if (BatteryUtils.isWorkProfile(context)) {
|
||||||
Log.w(TAG, "ignore battery usage states dump in the work profile");
|
Log.w(TAG, "ignore battery usage states dump in the work profile");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -91,17 +91,6 @@ public final class DatabaseUtilsTest {
|
|||||||
DataProcessor.sUsageStatsManager = mUsageStatsManager;
|
DataProcessor.sUsageStatsManager = mUsageStatsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isWorkProfile_defaultValue_returnFalse() {
|
|
||||||
assertThat(DatabaseUtils.isWorkProfile(mContext)).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isWorkProfile_withManagedUser_returnTrue() {
|
|
||||||
BatteryTestUtils.setWorkProfile(mContext);
|
|
||||||
assertThat(DatabaseUtils.isWorkProfile(mContext)).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendAppUsageEventData_returnsExpectedList() {
|
public void sendAppUsageEventData_returnsExpectedList() {
|
||||||
// Configures the testing AppUsageEvent data.
|
// Configures the testing AppUsageEvent data.
|
||||||
|
Reference in New Issue
Block a user