Files
app_Settings/src/com/android/settings/accounts/EmergencyInfoPreferenceController.java
Fan Zhang 5c3301b0ab Add configs to display/hide a few tiles in device info page
- Displaying/hiding Emergency info, branded account, device header
  widget are now driven by config flags
- Also refactored controllers to use BasePreferenceController

Change-Id: Ie601ebf689e0744c6a05a2cca5513fa43ef355e0
Fixes: 119607340
Test: robotests
2019-01-28 14:44:02 -08:00

104 lines
3.8 KiB
Java

/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.accounts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.search.SearchIndexableRaw;
import java.util.List;
public class EmergencyInfoPreferenceController extends BasePreferenceController {
public static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENCY_INFO";
private static final String PACKAGE_NAME_EMERGENCY = "com.android.emergency";
public EmergencyInfoPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
if (isAvailable()) {
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
final Resources res = mContext.getResources();
data.title = res.getString(com.android.settings.R.string.emergency_info_title);
data.screenTitle = res.getString(com.android.settings.R.string.emergency_info_title);
rawData.add(data);
}
}
@Override
public void updateState(Preference preference) {
UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo(
UserHandle.myUserId());
preference.setSummary(mContext.getString(R.string.emergency_info_summary, info.name));
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
Intent intent = new Intent(getIntentAction(mContext));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(intent);
return true;
}
return false;
}
@Override
public int getAvailabilityStatus() {
if (!mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info)) {
return UNSUPPORTED_ON_DEVICE;
}
final Intent intent = new Intent(getIntentAction(mContext)).setPackage(
getPackageName(mContext));
final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent,
0);
return infos != null && !infos.isEmpty()
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
private static String getIntentAction(Context context) {
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
return context.getResources().getString(R.string.config_emergency_intent_action);
}
return ACTION_EDIT_EMERGENCY_INFO;
}
private static String getPackageName(Context context) {
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
return context.getResources().getString(R.string.config_emergency_package_name);
}
return PACKAGE_NAME_EMERGENCY;
}
}