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

Commit 7a8a0d41 authored by mxyyiyi's avatar mxyyiyi
Browse files

Create a method to check if current user is an additional profile user.

Bug: 354828134
Test: atest BatteryUtilsTest
Flag: EXEMPT bug fix
Change-Id: I010e753132195a16723f768425965ac925c9d4c7
parent 72eb4a3f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.Settings;
import android.util.ArraySet;
import android.util.Log;
import android.view.accessibility.AccessibilityManager;

import androidx.annotation.Nullable;
@@ -33,6 +34,7 @@ import androidx.annotation.VisibleForTesting;
import java.util.List;

public final class BatteryUtils {
    private static final String TAG = "BatteryUtils";

    /** The key to get the time to full from Settings.Global */
    public static final String GLOBAL_TIME_TO_FULL_MILLIS = "time_to_full_millis";
@@ -89,6 +91,18 @@ public final class BatteryUtils {
        return userManager.isPrivateProfile();
    }

    /** Returns true if current user is an additional profile user. */
    public static boolean isAdditionalProfile(Context context) {
        if (isWorkProfile(context)) {
            Log.d(TAG, "Current user is a work profile user.");
            return true;
        } else if (isPrivateProfile(context)) {
            Log.d(TAG, "Current user is a private profile user.");
            return true;
        }
        return false;
    }

    private static Boolean sChargingStringV2Enabled = null;

    /** Returns {@code true} if the charging string v2 is enabled. */
+19 −0
Original line number Diff line number Diff line
@@ -127,6 +127,25 @@ public class BatteryUtilsTest {
        assertThat(BatteryUtils.isPrivateProfile(mContext)).isTrue();
    }

    @Test
    public void isAdditionalProfile_defaultValue_returnFalse() {
        assertThat(BatteryUtils.isAdditionalProfile(mContext)).isFalse();
    }

    @Test
    public void isAdditionalProfile_workProfileMode_returnTrue() {
        doReturn(true).when(mUserManager).isManagedProfile();

        assertThat(BatteryUtils.isAdditionalProfile(mContext)).isTrue();
    }

    @Test
    public void isAdditionalProfile_privateProfileMode_returnTrue() {
        doReturn(true).when(mUserManager).isPrivateProfile();

        assertThat(BatteryUtils.isAdditionalProfile(mContext)).isTrue();
    }

    private void setTtsPackageName(String defaultTtsPackageName) {
        Settings.Secure.putString(mContext.getContentResolver(),
                Settings.Secure.TTS_DEFAULT_SYNTH, defaultTtsPackageName);