aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-android/app/src/main/kotlin/org/meshbay/client/phonesync/Profiles.kt
blob: 660cfaa9a5c5a52a4213e827d714bad726a72fa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.meshbay.client.phonesync

import android.content.Context
import android.os.Build
import android.os.UserManager

/**
 * Backups are of the personal profile only, never of a work profile: a copy
 * of the application installed inside a work profile offers none of them.
 *
 * In the personal profile, every source reads that profile alone: MediaStore,
 * ContactsContract, the SMS and calendar providers answer for the profile
 * they are asked from, and none of the cross-profile (`ENTERPRISE_*`) URIs
 * is used (`test_android_shell.py` checks for them).
 */
object Profiles {
    fun isPersonal(context: Context): Boolean {
        val users = context.getSystemService(UserManager::class.java)
        // Before Android 11 an application cannot ask whether its own profile
        // is managed; a work profile is never the system user, so that is
        // the test there (a secondary user on a shared tablet loses backups).
        return if (Build.VERSION.SDK_INT >= 30) !users.isManagedProfile else users.isSystemUser
    }
}