Android 多用户问题

记录一个开发过程中遇见的多用户问题

Android

java 复制代码
        List<MediaController> mediaControllers = mediaSessionManager.getActiveSessions(null);

List<MediaController> 在普通应用中可以获取到,但是在systemUI中获取不到

看了一下是 user组别问题导致的

应该使用

java 复制代码
 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @SuppressLint("UserHandle")
    public @NonNull List<MediaController> getActiveSessionsForUser(
            @Nullable ComponentName notificationListener, @NonNull UserHandle userHandle) {
        Objects.requireNonNull(userHandle, "userHandle shouldn't be null");
        return getActiveSessionsForUser(notificationListener, userHandle.getIdentifier());
    }

这个api解决 那为什么systemUI在 0这个组别?

java 复制代码
    private static void startSystemUi(Context context, WindowManagerService windowManager) {
        PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        Intent intent = new Intent();
        intent.setComponent(pm.getSystemUiServiceComponent());
        intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
        //Slog.d(TAG, "Starting service: " + intent);
        context.startServiceAsUser(intent, UserHandle.SYSTEM);
        windowManager.onSystemUiStarted();
    }

在systemserver 里启动的组别就是这个

音频mediassion相关是区分用户的

那么还有没有什么是区别用户的

当然有 PMS也是这样

在工程模式下,可以使用 getInstalledPackages 或 getInstalledPackagesAsUser 方法获取全部已安装的应用程序,并展示给用户

java 复制代码
public List<PackageInfo> getAllInstalledApps(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return packageManager.getInstalledPackages(PackageManager.GET_META_DATA);
}
相关推荐
EngZegNgi2 小时前
安卓应用启动崩溃的问题排查记录
android·crash·启动崩溃
火柴就是我2 小时前
每日见闻之Container Decoration
android·flutter
天枢破军2 小时前
【AOSP】解决repo拉取提示无法连接android.googlesource.com
android
whysqwhw2 小时前
OkHttp之AndroidPlatform类分析
android
XiaolongTu3 小时前
Kotlin Flow详述:从一个“卡顿”问题到线程切换的本质
android·面试
Kapaseker3 小时前
全网最详细的Compose Stable讲解,你一定要看
android
solo_993 小时前
使用Android Studio 聊微信
android
whysqwhw3 小时前
OkHttp PublicSuffix包的平台化设计分析
android
whysqwhw3 小时前
Conscrypt 源码分析全图解(附精要讲解)
android
一只柠檬新3 小时前
Kotlin object单例到底是懒汉式还是饿汉式
android·kotlin