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 package com.android.car.settings.privacy; 18 19 import android.Manifest; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.icu.text.RelativeDateTimeFormatter; 23 24 import com.android.car.ui.preference.CarUiPreference; 25 import com.android.settingslib.applications.RecentAppOpsAccess; 26 import com.android.settingslib.utils.StringUtil; 27 28 /** 29 * Utilities related to camera recent access. 30 */ 31 public final class CameraRecentAccessUtil { CameraRecentAccessUtil()32 private CameraRecentAccessUtil() { 33 } 34 35 /** 36 * Create a {@link CarUiPreference} for an app with it's last access time and a link to its 37 * camera permission settings. 38 */ createAppPreference(Context prefContext, RecentAppOpsAccess.Access access)39 public static CarUiPreference createAppPreference(Context prefContext, 40 RecentAppOpsAccess.Access access) { 41 CarUiPreference pref = new CarUiPreference(prefContext); 42 pref.setIcon(access.icon); 43 pref.setTitle(access.label); 44 pref.setSummary(StringUtil.formatRelativeTime(prefContext, 45 System.currentTimeMillis() - access.accessFinishTime, false, 46 RelativeDateTimeFormatter.Style.SHORT)); 47 pref.setOnPreferenceClickListener(preference -> { 48 Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION); 49 intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, 50 Manifest.permission_group.CAMERA); 51 intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName); 52 intent.putExtra(Intent.EXTRA_USER, access.userHandle); 53 prefContext.startActivity(intent); 54 return true; 55 }); 56 return pref; 57 } 58 } 59