1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.settings.enterprise; 16 17 import static android.app.admin.DevicePolicyResources.Strings.Settings.ADMIN_ACTION_NONE; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 import android.text.format.DateUtils; 22 23 import androidx.preference.Preference; 24 25 import com.android.settings.R; 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settingslib.core.AbstractPreferenceController; 29 30 import java.util.Date; 31 32 public abstract class AdminActionPreferenceControllerBase extends 33 AbstractPreferenceController implements PreferenceControllerMixin { 34 35 protected final EnterprisePrivacyFeatureProvider mFeatureProvider; 36 AdminActionPreferenceControllerBase(Context context)37 public AdminActionPreferenceControllerBase(Context context) { 38 super(context); 39 mFeatureProvider = FeatureFactory.getFeatureFactory() 40 .getEnterprisePrivacyFeatureProvider(); 41 } 42 getAdminActionTimestamp()43 protected abstract Date getAdminActionTimestamp(); 44 45 @Override updateState(Preference preference)46 public void updateState(Preference preference) { 47 final Date timestamp = getAdminActionTimestamp(); 48 preference.setSummary(timestamp == null ? 49 getEnterprisePrivacyNone() : 50 DateUtils.formatDateTime(mContext, timestamp.getTime(), 51 DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE)); 52 } 53 getEnterprisePrivacyNone()54 private String getEnterprisePrivacyNone() { 55 return ((DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)) 56 .getResources() 57 .getString(ADMIN_ACTION_NONE, 58 () -> mContext.getString(R.string.enterprise_privacy_none)); 59 } 60 61 @Override isAvailable()62 public boolean isAvailable() { 63 return true; 64 } 65 } 66