文章目录
前言
前面一篇文章在Android12 基础上已经分析了开机向导定制方案,这里再以实际案例在Android13 上面从另外一个思路来实现需求
需求-场景
去掉开机向导里面的SIM模块,Tel相关的全部去掉:比如 SIM 检测界面、紧急呼叫入口和界面
备注:在上一篇笔记中已经提到了思路,其实是无法去掉SIM界面和Tel 相关的,限制太多了。
下面我们从另外的角度来解决这个问题,换一个方向思考并解决问题。 去feature
第三方资料说明
高通C6490 android13 GMS 认证之CtsCarrierApiTestCases
附件WIFI——Only图片:MTK提供的WIFI Only方案
附件:FiseSetupWizard 自定义的一个开机向导源码
附件:CusSetupWizard 自定义的一个完整的开机向导原码
附件下载地址
备注:
- 附件 两个开机向导可以直接放到系统里面进行编译,去掉平台自带的开机向导,然后在已有开机向导源码基础上更改。【比较早的开机向导,UI不咋样】
- 在开机向导源码的基础上,分析已有部分的逻辑,针对性再定制自己需求,反推思考逻辑和业务,看能否实现自己定制的需求。
- WIFI-Only图片,为平台提供的WIFI Only部分修改点,可以借鉴。
- 特别提醒,不同平台和不同版本,以及
手机和平板方案区别是很大的。所以,参考即可。【这里重点提一下,如果您的方案是手机方案,是无法实现更改为WIFI Only方案的】
需求思路
按照平台 思路 从配置上去 feature
下面自己在MTKAndroid13 中 去feature的一些流程,可参考
去tel 相关
frameworks/native/data/etc/Android.bp
//prebuilt_etc {
// name: "android.hardware.telephony.gsm.prebuilt.xml",
// src: "android.hardware.telephony.gsm.xml",
// defaults: ["frameworks_native_data_etc_defaults"],
//}
//prebuilt_etc {
// name: "android.hardware.telephony.ims.prebuilt.xml",
// src: "android.hardware.telephony.ims.xml",
// defaults: ["frameworks_native_data_etc_defaults"],
//}
//prebuilt_etc {
// name: "android.hardware.telephony.cdma.prebuilt.xml",
// src: "android.hardware.telephony.cdma.xml",
// defaults: ["frameworks_native_data_etc_defaults"],
//}
屏蔽tel 和 修改sim 个数
device/mediatek/vendor/mgvi_64_armv9/device.mk
device/mediatek/vendor/mgvi_64_nfc_armv82/device.mk
device/mediatek/vendor/mgvi_64_tee_armv82/device.mk
device/mediatek/vendor/mgvi_64_teei_armv82/device.mk
device/mediatek/vendor/mgvi_64_teei_armv82/device.mk
device/mediatek/vendor/mgvi_32_armv82/device.mk
device/mediatek/vendor/mgvi_64_armv82/device.mk
device/mediatek/vendor/mgvi_32_armv82_ago/device.mk
device/mediatek/vendor/mgvi_64_ww_armv82/device.mk
#PRODUCT_COPY_FILES += $(LOCAL_PATH)/android.hardware.telephony.gsm.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.gsm.xml
# set Telephony property - SIM count 默认是2 我们改为0
SIM_COUNT := 0
屏蔽tel 相关
device/google_car/common/pre_google_car.mk
#$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony_system_ext.mk)
#$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony_vendor.mk)
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/car_core_hardware.xml:system/etc/permissions/car_core_hardware.xml \
frameworks/native/data/etc/android.hardware.type.automotive.xml:system/etc/permissions/android.hardware.type.automotive.xml \
# frameworks/native/data/etc/android.hardware.telephony.gsm.xml:system/etc/permissions/android.hardware.telephony.gsm.xml \
#frameworks/native/data/etc/android.hardware.telephony.cdma.xml:system/etc/permissions/android.hardware.telephony.cdma.xml \
device/google/coral/device.mk
#frameworks/native/data/etc/android.hardware.telephony.gsm.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.gsm.xml \
#frameworks/native/data/etc/android.hardware.telephony.cdma.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.cdma.xml \
#frameworks/native/data/etc/android.hardware.telephony.ims.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.ims.xml \
#frameworks/native/data/etc/android.hardware.telephony.carrierlock.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.carrierlock.xml \
device/google/cuttlefish/shared/phone/device_vendor.mk
device/google/cuttlefish/shared/slim/device_vendor.mk
device/google/cuttlefish/shared/wear/device_vendor.mk
#ifneq ($(LOCAL_PREFER_VENDOR_APEX),true)
#PRODUCT_COPY_FILES += \
# frameworks/native/data/etc/android.hardware.biometrics.face.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.biometrics.face.xml \
# frameworks/native/data/etc/android.hardware.faketouch.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.faketouch.xml \
# frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml \
# frameworks/native/data/etc/android.hardware.telephony.gsm.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.gsm.xml \
# frameworks/native/data/etc/android.hardware.telephony.ims.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.ims.xml
#endif
device/mediatek/common/device.mk
# For C2K CDMA feature file
#ifeq ($(strip $(RAT_CONFIG_C2K_SUPPORT)),yes)
#PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.telephony.cdma.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.cdma.xml
#endif
# Telephony
#PRODUCT_COPY_FILES += device/mediatek/config/apns-conf.xml:system/etc/apns-conf.xml:mtk
#PRODUCT_COPY_FILES += vendor/mediatek/proprietary/hardware/ril/fusion/mtk-ril/mdcomm/data/vendor-apns-conf.xml:$(TARGET_COPY_OUT_VENDOR)/etc/vendor-apns-conf.xml:mtk
#PRODUCT_COPY_FILES += device/mediatek/common/spn-conf.xml:$(TARGET_COPY_OUT_SYSTEM_EXT)/etc/spn-conf.xml:mtk
#PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.telephony.ims.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.ims.xml
屏蔽所有 PRODUCT_PROPERTY_OVERRIDES += ro.telephony.sim.count=? 选项
device/mediatek/vendor/mgvi_64_armv9/VendorConfig.mk
device/mediatek/vendor/mgvi_64_nfc_armv82/VendorConfig.mk
device/mediatek/vendor/mgvi_64_tee_armv82/VendorConfig.mk
device/mediatek/vendor/mgvi_64_teei_armv82/VendorConfig.mk
device/mediatek/vendor/mgvi_32_armv82/VendorConfig.mk
device/mediatek/vendor/mgvi_64_armv82/VendorConfig.mk
device/mediatek/vendor/mgvi_32_armv82_ago/VendorConfig.mk
device/mediatek/vendor/mgvi_64_ww_armv82/VendorConfig.mk
多卡 SIM 配置为no
MTK_MULTI_SIM_SUPPORT=no
换个思路,去feature。
上面方案一去系统的feature ,经验上看,对于平板方案按照这个思路来更改是没有问题的,但是对于手机方案来做的平板产品来讲,是无法去除成功的,所以如果你是手机方案的大屏产品。无论怎么去就是去不掉。 如果从驱动层来去除feature+moden,将4G全部去掉又会发现各种报错。
还是先参考下 两套开机向导的源码吧,这里我们举例其中一个开机向导Sim界面的源码来参考 系统开机向导 可能存在的判断逻辑。
SimMissingActivity 判断跳过逻辑
if (!SetupWizardUtils.simMissing(this) || !SetupWizardUtils.hasTelephony(this))
public class SimMissingActivity extends BaseSetupWizardActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!SetupWizardUtils.simMissing(this) || !SetupWizardUtils.hasTelephony(this)) {
// NetworkSetupActivity comes before us. DateTimeActivity comes after.
// If the user presses the back button on DateTimeActivity, we can only pass along
// that information to NetworkSetupActivity if we are still around. But if we finish
// here, we're gone, and NetworkSetupActivity will get whatever result we give here.
// We can't predict the future, but we can reasonably assume that the only way for
// NetworkSetupActivity to be reached later is if the user went backwards. So, we
// finish this activity faking that the user pressed the back button, which is required
// for subactivities like NetworkSetupActivity to work properly on backward navigation.
// TODO: Resolve all this.
finishAction(RESULT_SKIP, new Intent().putExtra("onBackPressed", true));
return;
}
getGlifLayout().setDescriptionText(getString(R.string.sim_missing_summary));
setNextAllowed(true);
}
重点代码: if (!SetupWizardUtils.simMissing(this) || !SetupWizardUtils.hasTelephony(this)) {
如果当前 不支持SIM 或者 没有Tel模块,那么就下一页
SetupWizardUtils 判断SIM 、 hasSystemFeature FEATURE_TELEPHONY
SIM 判断:
public static boolean simMissing(Context context) {
TelephonyManager tm = context.getSystemService(TelephonyManager.class);
SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
if (tm == null || sm == null) {
return false;
}
List<SubscriptionInfo> subs = sm.getActiveSubscriptionInfoList();
if (subs != null) {
for (SubscriptionInfo sub : subs) {
int simState = tm.getSimState(sub.getSimSlotIndex());
if (LOGV) {
Log.v(TAG, "getSimState(" + sub.getSubscriptionId() + ") == " + simState);
}
if (simState != -1) {
final int subId = sub.getSubscriptionId();
final TelephonyManager subTm = tm.createForSubscriptionId(subId);
if (isGSM(subTm) || isLteOnCdma(subTm, subId)) {
return false;
}
}
}
}
return true;
}
Tel的判断
public static boolean hasTelephony(Context context) {
PackageManager packageManager = context.getPackageManager();
return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}
PackageManager.FEATURE_TELEPHONY
packageManager 是一个抽象类,最终走到ApplicationPackageManager.java 实现类里面的 hasSystemFeature 方法,具体源码跟踪可以自行跟踪一下。
ApplicationPackageManager hasSystemFeature
@Override
public boolean hasSystemFeature(String name) {
return hasSystemFeature(name, 0);
}
@Override
public boolean hasSystemFeature(String name, int version) {
//wangfangchen add
if(name.contains("android.hardware.telephony")
){
Log.d("wangfangchen","hasSystemFeature name:"+name+" return false");
return false;
}
//wangfangchen end
.....
return mHasSystemFeatureCache.query(new HasSystemFeatureQuery(name, version));
}
所以,最终对于 android.hardware.telephony 相关的全部返回false
总结
- 编译源码,SIM界面 真的跳过了,实现了需求;紧急呼叫也没有了,实现了需求。
- 这种方法区别于上一篇官网方法,其实是从底层触发来解决问题,这个并不是谷歌提倡的,但是能够解决实际问题,且解决方便。
- 再次强调,不同平台不同安卓版本不同产品方案实现方法可能不一样,但是思路一样。