Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b30f6a2 authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Replace the isWorkProfile method from the SettingsLib" into main

parents ba6a19ea 7007b112
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public final class BatteryUsageBroadcastReceiver extends BroadcastReceiver {
        }
        final String action = intent.getAction();
        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);
            return;
        }
+2 −1
Original line number Diff line number Diff line
@@ -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.BatteryUsageSlotDao;
import com.android.settings.fuelgauge.batteryusage.db.BatteryUsageSlotEntity;
import com.android.settingslib.fuelgauge.BatteryUtils;

import java.time.Clock;
import java.time.Duration;
@@ -109,7 +110,7 @@ public class BatteryUsageContentProvider extends ContentProvider {

    @Override
    public boolean onCreate() {
        if (DatabaseUtils.isWorkProfile(getContext())) {
        if (BatteryUtils.isWorkProfile(getContext())) {
            Log.w(TAG, "do not create provider for work profile");
            return false;
        }
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.settings.core.instrumentation.ElapsedTimeUtils;
import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.BatteryUtils;

import java.time.Duration;

@@ -56,7 +57,7 @@ public final class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        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);
            return;
        }
+1 −7
Original line number Diff line number Diff line
@@ -159,12 +159,6 @@ public final class 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. */
    public static long getAppUsageStartTimestampOfUser(
            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. */
    public static Context getParentContext(Context context) {
        if (isWorkProfile(context)) {
        if (com.android.settingslib.fuelgauge.BatteryUtils.isWorkProfile(context)) {
            try {
                return context.createPackageContextAsUser(
                        /* packageName= */ context.getPackageName(),
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.Log;

import com.android.settings.fuelgauge.BatteryUsageHistoricalLogEntry.Action;
import com.android.settings.fuelgauge.batteryusage.bugreport.BatteryUsageLogUtils;
import com.android.settingslib.fuelgauge.BatteryUtils;

/** Receives the periodic alarm {@link PendingIntent} callback. */
public final class PeriodicJobReceiver extends BroadcastReceiver {
@@ -49,7 +50,7 @@ public final class PeriodicJobReceiver extends BroadcastReceiver {
            Log.w(TAG, "receive unexpected action=" + action);
            return;
        }
        if (DatabaseUtils.isWorkProfile(context)) {
        if (BatteryUtils.isWorkProfile(context)) {
            BatteryUsageLogUtils.writeLog(
                    context, Action.SCHEDULE_JOB, "do not refresh job for work profile");
            Log.w(TAG, "do not refresh job for work profile action=" + action);
Loading