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

Commit d2d9cb28 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add WorkProfilePager to SpaPrivilegedLib

With privileged api to query all the user profiles.

Bug: 235727273
Test: Manual with Test App
Change-Id: I00fe0cab7946059128c685e5744a1c4b5eb75ca4
parent 14a8ead4
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -29,5 +29,4 @@ android_library {
        "androidx.compose.runtime_runtime",
    ],
    kotlincflags: ["-Xjvm-default=all"],
    min_sdk_version: "31",
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.settingslib.spaprivileged.framework.enterprise

import android.app.admin.DevicePolicyManager
import android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER
import android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER
import android.content.Context
import com.android.settingslib.spaprivileged.R

class EnterpriseRepository(private val context: Context) {
    private val resources by lazy {
        checkNotNull(context.getSystemService(DevicePolicyManager::class.java)).resources
    }

    fun getEnterpriseString(updatableStringId: String, resId: Int): String =
        resources.getString(updatableStringId) { context.getString(resId) }

    fun getProfileTitle(isManagedProfile: Boolean): String = if (isManagedProfile) {
        getEnterpriseString(WORK_CATEGORY_HEADER, R.string.category_work)
    } else {
        getEnterpriseString(PERSONAL_CATEGORY_HEADER, R.string.category_personal)
    }
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.settingslib.spaprivileged.template.scaffold

import android.content.pm.UserInfo
import android.os.UserHandle
import android.os.UserManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import com.android.settingslib.spa.widget.scaffold.SettingsPager
import com.android.settingslib.spaprivileged.framework.enterprise.EnterpriseRepository

@Composable
fun WorkProfilePager(content: @Composable (userInfo: UserInfo) -> Unit) {
    val context = LocalContext.current
    val profiles = remember {
        val userManager = checkNotNull(context.getSystemService(UserManager::class.java))
        userManager.getProfiles(UserHandle.myUserId())
    }
    val titles = remember {
        val enterpriseRepository = EnterpriseRepository(context)
        profiles.map {
            enterpriseRepository.getProfileTitle(isManagedProfile = it.isManagedProfile)
        }
    }

    SettingsPager(titles) { page ->
        content(profiles[page])
    }
}