其他分享
首页 > 其他分享> > Android 系统APK-Camera 开机时自动检测摄像头,有显示相机图标,无就隐藏

Android 系统APK-Camera 开机时自动检测摄像头,有显示相机图标,无就隐藏

作者:互联网

路径:frameworks/base/services/core/java/com/android/server/am/UserController.java

设置是否显示摄像头图标(由有无摄像头决定)

++    public void setCamera(boolean state){
++       PackageManager p = mInjector.getContext().getPackageManager();
++        if(state){
++            p.setApplicationEnabledSetting("com.android.camera2", PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
++        }else{
++            p.setApplicationEnabledSetting("com.android.camera2", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
++        }
++    }

检查是否有摄像头

    private void finishUserUnlockedCompleted(UserState uss) {
        final int userId = uss.mHandle.getIdentifier();
        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_UNLOCKED_COMPLETED, userId);

++        int n = android.hardware.Camera.getNumberOfCameras();
++        if (n==0){
++            setCamera(false);
++        }else if(n>0){
++            setCamera(true);
++        }
    }

标签:++,自动检测,ENABLED,APK,Camera,android,PackageManager,setCamera,摄像头
来源: https://blog.csdn.net/qq_27494201/article/details/121741464