效果图 需求:给基带版本添加点击事件 代码路径: packages/apps/Settings/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionSettings.java packages/apps/Settings/res/xml/firmware_version.xml 1、在/firmware_version.xml布局文件中,下面就是基带版本处理
<Preference
android:key="base_band"
android:title="@string/baseband_version"
android:summary="@string/summary_placeholder"
settings:enableCopying="true"
settings:controller="com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController"/>
2、给基带版本添加点击事件
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.SystemProperties;
import androidx.preference.Preference;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.deviceinfo.SupportCPVersion;
public class BasebandVersionPreferenceController extends BasePreferenceController {
@VisibleForTesting
static final String BASEBAND_PROPERTY = "gsm.version.baseband";
private static final String KEY_BASEBAND_VERSION = "baseband_version";
public BasebandVersionPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return !Utils.isWifiOnly(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public CharSequence getSummary() {
String basebandInfo = "";
if (mContext.getResources().getBoolean(R.bool.config_support_showCp2Info)){
basebandInfo = SupportCPVersion.getInstance().getBasedSummary(mContext,
BASEBAND_PROPERTY);
} else {
basebandInfo = SystemProperties.get(BASEBAND_PROPERTY,
mContext.getString(R.string.device_info_default));
}
return basebandInfo;
}
private int mEngHitCountdown = 4;
@Override
public String getPreferenceKey() {
return KEY_BASEBAND_VERSION;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), KEY_BASEBAND_VERSION)) {
return false;
}
if (Utils.isMonkeyRunning()) {
return false;
}
if (mEngHitCountdown > 0) {
mEngHitCountdown--;
if (mEngHitCountdown == 0) {
launchEngineerMode();
mEngHitCountdown = 4;
}
}
return true;
}
private void launchEngineerMode() {
String packageName = "com.sprd.engineermode";
String activity = "com.sprd.engineermode.EngineerModeActivity";
ComponentName component = new ComponentName(packageName, activity);
Intent intent = new Intent();
intent.setComponent(component);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
|