1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 @file:JvmName("PrivacySourcesUtils") 18 19 package com.android.permissioncontroller.privacysources 20 21 import android.content.Context 22 import android.content.Intent 23 import android.os.Build 24 import android.os.UserManager 25 import android.safetycenter.SafetyCenterManager 26 import android.safetycenter.SafetyEvent 27 import androidx.annotation.RequiresApi 28 import com.android.permissioncontroller.permission.utils.Utils 29 import com.android.permissioncontroller.privacysources.SafetyCenterReceiver.RefreshEvent 30 31 @RequiresApi(Build.VERSION_CODES.TIRAMISU) getSafetyCenterEventnull32fun getSafetyCenterEvent(refreshEvent: RefreshEvent, intent: Intent): SafetyEvent { 33 return when (refreshEvent) { 34 RefreshEvent.UNKNOWN -> 35 SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build() 36 RefreshEvent.EVENT_DEVICE_REBOOTED -> 37 SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build() 38 RefreshEvent.EVENT_REFRESH_REQUESTED -> { 39 val refreshBroadcastId = 40 intent.getStringExtra(SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID) 41 SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED) 42 .setRefreshBroadcastId(refreshBroadcastId) 43 .build() 44 } 45 } 46 } 47 48 @RequiresApi(Build.VERSION_CODES.TIRAMISU) isProfilenull49fun isProfile(context: Context): Boolean { 50 val userManager = Utils.getSystemServiceSafe(context, UserManager::class.java) 51 return userManager.isProfile 52 } 53