Android9.0 SystemUI 网络信号栏定制修改

简介: Android9.0 SystemUI 网络信号栏定制修改

前情提要


Android 8.1平台SystemUI 导航栏加载流程解析


9.0 改动点简要说明


1、新增 StatusBarMobileView 替代 SignalClusterView,用以控制信号栏显示

同时增加的还有 StatusBarIconViewStatusBarWifiView

2、整体流程和 8.1 类似


效果图


aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzExLzEzL01HT3pQVS5wbmc.png

整体流程图


2019111418465858.png


上代码


aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzExLzEzL01HalVrNi5wbmc.png


先来看初始赋值的地方 MobileSignalController.java,在 notifyListeners() 方法中进行我们对应的定制,


最后通过 callback.setMobileDataIndicators() 将状态值传递到 StatusBarSignalPolicy.java 解析显示


vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\policy\MobileSignalController.java

@Override
    public void notifyListeners(SignalCallback callback) {
        MobileIconGroup icons = getIcons();
        String contentDescription = getStringIfExists(getContentDescription());
        String dataContentDescription = getStringIfExists(icons.mDataContentDescription);
        if (mCurrentState.inetCondition == 0) {
            dataContentDescription = mContext.getString(R.string.data_connection_no_internet);
        }
        final boolean dataDisabled = mCurrentState.iconGroup == TelephonyIcons.DATA_DISABLED
                && mCurrentState.userSetup;
        /// M: Customize the signal strength icon id. @ {
        int iconId = getCurrentIconId();
        iconId = mStatusBarExt.getCustomizeSignalStrengthIcon(
                    mSubscriptionInfo.getSubscriptionId(),
                    iconId,
                    mSignalStrength,
                    mDataNetType,
                    mServiceState);
        /// @ }
        if (mSignalStrength != null) {
            /*int dbm = mSignalStrength.getDbm();
            int asu = mSignalStrength.getAsuLevel();
            Log.i("ccz","dbm="+dbm + " asu="+asu);*/
            Log.e("ccz", "isGSM=="+mSignalStrength.isGsm() 
                + " connected=="+mCurrentState.connected+" dataConnected=="+mCurrentState.dataConnected);
        }
        if (mCurrentState.connected) {
            //cczheng add get signal icon  [S]
      //通过 getSignalStrengthIcon 方法,根据自定义规则,返回要显示对应资源id
            iconId = TelephonyIcons.getSignalStrengthIcon(mSignalStrength != null ? mSignalStrength.getDbm() : -120,
                mSignalStrength != null ? mSignalStrength.getAsuLevel() : 0);
            //iconId = TelephonyIcons.getSignalStrengthIcon(mCurrentState.level);
            //cczheng add get signal icon  [E]
        }else{//未连接成功时显示 X
            iconId = R.drawable.stat_sys_signal_disable;
        }
        // Show icon in QS when we are connected or data is disabled.
        boolean showDataIcon = mCurrentState.dataConnected || dataDisabled;
        Log.i("ccz","dataDisabled="+dataDisabled + " showDataIcon="+showDataIcon);
        IconState statusIcon = new IconState(mCurrentState.enabled && !mCurrentState.airplaneMode,
                iconId, contentDescription);
        int qsTypeIcon = 0;
        IconState qsIcon = null;
        String description = null;
        // Only send data sim callbacks to QS.
        if (mCurrentState.dataSim) {
            qsTypeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.mQsDataType : 0;
            qsIcon = new IconState(mCurrentState.enabled
                    && !mCurrentState.isEmergency, getQsCurrentIconId(), contentDescription);
            description = mCurrentState.isEmergency ? null : mCurrentState.networkName;
        }
        boolean activityIn = mCurrentState.dataConnected
                && !mCurrentState.carrierNetworkChangeMode
                && mCurrentState.activityIn;
        boolean activityOut = mCurrentState.dataConnected
                && !mCurrentState.carrierNetworkChangeMode
                && mCurrentState.activityOut;
        showDataIcon &= mCurrentState.isDefault || dataDisabled;
        int typeIcon = (showDataIcon || mConfig.alwaysShowDataRatIcon) ? icons.mDataType : 0;
        /// M: Add for lwa.
        typeIcon = mCurrentState.lwaRegState == NetworkTypeUtils.LWA_STATE_CONNCTED
                && showDataIcon ? NetworkTypeUtils.LWA_ICON : typeIcon;
        /** M: Support [Network Type on StatusBar], change the implement methods.
          * Get the network icon base on service state.
          * Add one more parameter for network type.
          * @ { **/
        int networkIcon = mCurrentState.networkIcon;
        /// M: Support volte icon.Bug fix when airplane mode is on go to hide volte icon
        int volteIcon = mCurrentState.airplaneMode && !isImsOverWfc()
                ? 0 : mCurrentState.volteIcon;
        /// M: when data disabled, common show data icon as x, but op do not need show it @ {
        mStatusBarExt.isDataDisabled(mSubscriptionInfo.getSubscriptionId(), dataDisabled);
        /// @ }
        /// M: Customize the data type icon id. @ {
        typeIcon = mStatusBarExt.getDataTypeIcon(
                        mSubscriptionInfo.getSubscriptionId(),
                        typeIcon,
                        mDataNetType,
                        mCurrentState.dataConnected ? TelephonyManager.DATA_CONNECTED :
                            TelephonyManager.DATA_DISCONNECTED,
                        mServiceState);
        /// @ }
        /// M: Customize the network type icon id. @ {
        networkIcon = mStatusBarExt.getNetworkTypeIcon(
                        mSubscriptionInfo.getSubscriptionId(),
                        networkIcon,
                        mDataNetType,
                        mServiceState);
        /// for operator
    //通过 description 传递运营商信息
        description = mCurrentState.operator;
        // for qsdatetype
        qsTypeIcon = mCurrentState.mQsDataType;
        /// @ }
        //cczheng add  for when datadisable set mMobileDataActivity GONE [S]
    //数据网络关闭时,id 置为0,不显示上下行小箭头
        if (isDataDisabled()) {
            typeIcon = 0;
        }
        Log.d("ccz", "qsTypeIcon="+qsTypeIcon);
        //cczheng add  for when datadisable set mMobileDataActivity GONE [E]
        Log.e("ccz", " showDataIcon="+showDataIcon+" activityIn="+activityIn
            +" activityOut="+activityOut);
        Log.i("ccz", "networkName="+mCurrentState.networkName + "  description="+description);
        callback.setMobileDataIndicators(statusIcon, qsIcon, typeIcon, networkIcon, volteIcon,
                qsTypeIcon,activityIn, activityOut, dataContentDescription, description,
                 icons.mIsWide, mSubscriptionInfo.getSubscriptionId(), mCurrentState.roaming,
                 mCurrentState.isDefaultData, mCurrentState.customizedState);
        /// M: update plmn label @{
        mNetworkController.refreshPlmnCarrierLabel();
        /// @}
    }
  private final void updateTelephony() {
    .....
    /// M: For network type big icon.
        mCurrentState.networkIcon =
            NetworkTypeUtils.getNetworkTypeIcon(mServiceState, mConfig, hasService());
    /// M: For volte type icon.
      mCurrentState.volteIcon = getVolteIcon();
    //cczheng add for qsdatetype
      mCurrentState.mQsDataType = ((MobileIconGroup)mCurrentState.iconGroup).mQsDataType; 
      //cczheng add for operator
      mCurrentState.operator = getOperatorType();
      notifyListenersIfNecessary();
   }
  private String getOperatorType(){
        if (!hasService()) {
            // Not in service, don't show operator 
            return "0";
        }
       int operatorType = NetworkTypeUtils.getOperatorType(mPhone);
       if (operatorType == 0) 
           return "0";
       else
           return mContext.getResources().getString(operatorType); 
    }

根据通用标准自定义显示规则


dbm >= -107 4格


-107 > dbm >= -111 3格


-111 > dbm >= -114 2格


-114 > dbm >= -117 1格


vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\policy\TelephonyIcons.java

  static final int[] TELEPHONY_SIGNAL_STRENGTH_FULL = {
            R.drawable.stat_sys_signal_0_fully,
            R.drawable.stat_sys_signal_1_fully,
            R.drawable.stat_sys_signal_2_fully,
            R.drawable.stat_sys_signal_3_fully,
            R.drawable.stat_sys_signal_4_fully,
    };
    /**
     * Customize Signal strength icon.
     * @param level telephony signal strength leve.
     * @return Signal strength icon id.
     */
    static final int getSignalStrengthIcon(int level) {
        android.util.Log.e("ccz", "getSignalStrengthIcon() level=="+level);
        if (level >= 0 && level < TELEPHONY_SIGNAL_STRENGTH_FULL.length) {
            return TELEPHONY_SIGNAL_STRENGTH_FULL[level];
        }
        return 0;
    }
    static final int getSignalStrengthIcon(int dbm, int asu) {
        int level = 0;
        if(dbm >= -107) level = 4;
        else if (dbm >= -111) level = 3; 
        else if (dbm >= -114) level = 2; 
        else if (dbm >= -117) level = 1; 
        android.util.Log.e("ccz", "getSignalStrengthIcon() dbm=="+dbm + " asu=="+asu + " level=="+level);
        return TELEPHONY_SIGNAL_STRENGTH_FULL[level];
    }


舍弃原来的网络大图标,新增网络小图标,这样可以在下方显示网络数据图标


vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\mediatek\systemui\statusbar\networktype\NetworkTypeUtils.java

//cczheng add show small networkType
static final Map<Integer, Integer> sNetworkTypeSmallIcons = new HashMap<Integer, Integer>() {
  {
            // For CDMA 3G
            put(TelephonyManager.NETWORK_TYPE_EVDO_0, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_EVDO_A, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_EVDO_B, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_EHRPD, R.drawable.stat_sys_data_fully_connected_3g);
            // For CDMA 1x
            put(TelephonyManager.NETWORK_TYPE_CDMA, R.drawable.stat_sys_data_fully_connected_1x);
            put(TelephonyManager.NETWORK_TYPE_1xRTT, R.drawable.stat_sys_data_fully_connected_1x);
            // Edge
            put(TelephonyManager.NETWORK_TYPE_EDGE, R.drawable.stat_sys_data_fully_connected_e);
            // 3G
            put(TelephonyManager.NETWORK_TYPE_UMTS, R.drawable.stat_sys_data_fully_connected_3g);
            // For 4G
            put(TelephonyManager.NETWORK_TYPE_LTE, R.drawable.stat_sys_data_fully_connected_4g);
            // 3G
            put(TelephonyManager.NETWORK_TYPE_HSDPA, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_HSUPA, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_HSPA, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_HSPAP, R.drawable.stat_sys_data_fully_connected_3g);
            put(TelephonyManager.NETWORK_TYPE_IWLAN, 0);
        }
    };
public static int getNetworkTypeIcon(ServiceState serviceState, Config config,
            boolean hasService) {
        if (!hasService) {
            // Not in service, no network type.
            return 0;
        }
        int tempNetworkType = getNetworkType(serviceState);
        //cczheng change  sNetworkTypeIcons to sNetworkTypeSmallIcons, show small networkType
        //Integer iconId = sNetworkTypeIcons.get(tempNetworkType);
        Integer iconId = sNetworkTypeSmallIcons.get(tempNetworkType);//add
        if (iconId == null) {
            iconId = tempNetworkType == TelephonyManager.NETWORK_TYPE_UNKNOWN ? 0 :
                     config.showAtLeast3G ? R.drawable.stat_sys_network_type_3g :
                                            R.drawable.stat_sys_network_type_g;
        }
        Log.i("ccz", "Operator=="+ serviceState.getOperatorAlphaLong());
        return iconId.intValue();
    }
//cczheng add for operatortype
static final int[] OPERATOR_TYPE = {
        R.string.operator_cmcc,//CHINA_MOBILE
        R.string.operator_cucc,//CHINA_UNICOM
        R.string.operator_ctcc//CHINA_TELECOM
};
public static int getOperatorType(TelephonyManager telephonyManager) {
    int type = 0;
    String operator = telephonyManager.getSimOperator();
    switch (operator) {
        case "46000":
        case "46002":
        case "46007":
        case "41004": 
            type = OPERATOR_TYPE[0];
            break;
        case "46001":
        case "46006":
            type = OPERATOR_TYPE[1];
            break;
        case "46003":
        case "46011":
            type = OPERATOR_TYPE[2];
            break;
        default:
            break;
    }
    return type;
}

StatusBarSignalPolicy 通过 description 传递运营商类型


vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\phone\StatusBarSignalPolicy.java

@Override
    public void setMobileDataIndicators(IconState statusIcon, IconState qsIcon, int statusType,
            int networkType, int volteIcon, int qsType, boolean activityIn, boolean activityOut,
            String typeContentDescription, String description, boolean isWide, int subId,
            boolean roaming, boolean isDefaultData, int customizedState) {
        Log.i("ccz","StatusBarSignalPolicy setMobileDataIndicators()");
        MobileIconState state = getState(subId);
        if (state == null) {
            return;
        }
    .....
    //cczheng add for operator because description is unless
        state.mOperator = description;
        Log.e("ccz","mMobileStrengthId="+statusIcon.icon);
        // Always send a copy to maintain value type semantics
        mIconController.setMobileIcons(mSlotMobile, MobileIconState.copyStates(mMobileStates));
}

StatusBarMobileView 获取传递的资源id值显示对应的图标


vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\StatusBarMobileView.java


public class StatusBarMobileView extends FrameLayout implements DarkReceiver,
        StatusIconDisplayable {
    private static final String TAG = "StatusBarMobileView";
  ....
    //cczheng add
    private ImageView mMobileDataActivity;
    private TextView mOperatorType;
   private void init() {
    ....
        mNetworkType    = findViewById(R.id.network_type);
        mVolteType      = findViewById(R.id.volte_indicator_ext);
        /// @}
        mMobileDataActivity = findViewById(R.id.data_inout);
        mOperatorType = findViewById(R.id.tv_operator);
        mMobileDrawable = new SignalDrawable(getContext());
        //cczheng annotaion don't use system full style
        //mMobile.setImageDrawable(mMobileDrawable);
        initDotView();
        mIsWfcEnable = SystemProperties.get("persist.vendor.mtk_wfc_support").equals("1");
        /// M: Add for Plugin feature @ {
        mStatusBarExt = OpSystemUICustomizationFactoryBase.getOpFactory(mContext)
                                     .makeSystemUIStatusBar(mContext);
        /// @ }
    }
    private void initViewState() {
        setContentDescription(mState.contentDescription);
        if (!mState.visible) {
            mMobileGroup.setVisibility(View.GONE);
        } else {
            mMobileGroup.setVisibility(View.VISIBLE);
        }
        //cczheng don't use system style change empty line style 注释原来的实心信号格
        //mMobileDrawable.setLevel(mState.strengthId);
        mMobile.setImageResource(mState.strengthId);
        //show  date in out icon 数据流量小箭头
        mMobileDataActivity.setImageResource(getDataActivityIcon(mState.activityIn, mState.activityOut));
        if (mState.typeId > 0) {
            if (!mStatusBarExt.disableHostFunction()) {
                mMobileType.setContentDescription(mState.typeContentDescription);
                mMobileType.setImageResource(mState.typeId);
            }
            //cczheng hide small datatype icon x or 4G
            mMobileType.setVisibility(View.GONE /*View.VISIBLE*/);
        } else {
            mMobileType.setVisibility(View.GONE);
        }
        mMobileRoaming.setVisibility(mState.roaming ? View.VISIBLE : View.GONE);
        mIn.setVisibility(mState.activityIn ? View.VISIBLE : View.GONE);
        mOut.setVisibility(mState.activityIn ? View.VISIBLE : View.GONE);
        //mInoutContainer.setVisibility((mState.activityIn || mState.activityOut)
        //        ? View.VISIBLE : View.GONE);
        mMobileDataActivity.setVisibility(mState.typeId != 0 ? View.VISIBLE : View.GONE);
        /// M: Add for [Network Type and volte on Statusbar] @{
        setCustomizeViewProperty();
        /// @}
        showWfcIfAirplaneMode();
        /// M: Add data group for plugin feature. @ {
        mStatusBarExt.addCustomizedView(mState.subId, mContext, mMobileGroup);
        setCustomizedOpViews();
        /// @ }
    }
    private void updateState(MobileIconState state) {
        setContentDescription(state.contentDescription);
        if (mState.visible != state.visible) {
            mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE);
            // To avoid StatusBarMobileView will not show in extreme case,
            // force request layout once if visible state changed.
            requestLayout();
        }
        if (mState.strengthId != state.strengthId) {
            //cczheng don't use system style change empty line style
            //mMobileDrawable.setLevel(state.strengthId);
            mMobile.setImageResource(state.strengthId);
        }
        //show  date in out icon 
        mMobileDataActivity.setImageResource(getDataActivityIcon(state.activityIn, state.activityOut));
        if (mState.typeId != state.typeId) {
            if (state.typeId != 0) {
                if (!mStatusBarExt.disableHostFunction()) {
                    mMobileType.setContentDescription(state.typeContentDescription);
                    mMobileType.setImageResource(state.typeId);
                }
                //cczheng hide small datatype icon x or 4G
        //数据流量标识 mMobileDataActivity 替代 mMobileType
                mMobileType.setVisibility(View.GONE /*View.VISIBLE*/);
            } else {
                mMobileType.setVisibility(View.GONE);
            }
        }
        mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE);
        mIn.setVisibility(state.activityIn ? View.VISIBLE : View.GONE);
        mOut.setVisibility(state.activityIn ? View.VISIBLE : View.GONE);
        //mInoutContainer.setVisibility((state.activityIn || state.activityOut)
        //        ? View.VISIBLE : View.GONE);
        mMobileDataActivity.setVisibility(state.typeId != 0 ? View.VISIBLE : View.GONE);
        /// M: Add for [Network Type and volte on Statusbar] @{
        if (mState.networkIcon != state.networkIcon) {
            setNetworkIcon(state.networkIcon);
        }
        if (mState.volteIcon != state.volteIcon) {
            setVolteIcon(state.volteIcon);
        }
        if (mState.mOperator != state.mOperator) {
            setOperatorText(state.mOperator);
        }
        if (mState.mCustomizedState != state.mCustomizedState
                || mState.networkIcon != state.networkIcon) {
            // if cs reg state has changed or network icon change to LTE,need to update.
            mStatusBarExt.setDisVolteView(mState.subId, state.volteIcon, mVolteType);
        }
        /// @}
        mState = state;
        // should added after set mState
        showWfcIfAirplaneMode();
        setCustomizedOpViews();
    }
    //cczheng add for data in out icon [S]  
     final int DATA_ACTIVITY_NONE = R.drawable.ct_stat_sys_signal_not_inout;
     final int DATA_ACTIVITY_IN = R.drawable.ct_stat_sys_signal_in;
     final int DATA_ACTIVITY_OUT = R.drawable.ct_stat_sys_signal_out;
     final int DATA_ACTIVITY_INOUT = R.drawable.ct_stat_sys_signal_inout;
    /**
     * M: getDataActivityIcon: Get DataActivity icon by dataActivity type.
     * @param activityIn : dataActivity Type
     * @param activityOut : dataActivity Type
     * @return  dataActivity icon ID
     */
     public int getDataActivityIcon(boolean activityIn, boolean activityOut) {
        Log.i("ccz", "mActivityIn="+activityIn+" mActivityOut="+activityOut);  
        int icon = DATA_ACTIVITY_NONE;
        if (activityIn && activityOut) {
            icon = DATA_ACTIVITY_INOUT;
        }else if (activityIn) {
            icon = DATA_ACTIVITY_IN;
        }else if (activityOut) {
            icon = DATA_ACTIVITY_OUT;
        }
        return icon;
    }
    //cczheng add for data in out icon [S]  
  private void setOperatorText(String mOperator){
        if ("0".equals(mOperator)) {
            mOperatorType.setVisibility(View.GONE);
        } else {
            mOperatorType.setText(mOperator);
            mOperatorType.setVisibility(View.VISIBLE);
        }
    }

StatusBarMobileView 对应布局文件 status_bar_mobile_signal_group 修改


vendor\mediatek\proprietary\packages\apps\SystemUI\res\layout\status_bar_mobile_signal_group.xml

<com.android.systemui.statusbar.StatusBarMobileView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mobile_combo"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center_vertical" >
    <com.android.keyguard.AlphaOptimizedLinearLayout
        android:id="@+id/mobile_group"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="horizontal" >
        <ImageView
            android:id="@+id/volte_indicator_ext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:visibility="gone"
            />
        <!-- <ImageView
            android:id="@+id/network_type"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
            android:visibility="gone"
            /> -->
        <!-- cczheng  annotaion network_type and add data in out view-->
        <FrameLayout
            android:layout_height="17dp"
            android:layout_width="wrap_content">
            <ImageView
                android:id="@+id/network_type"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:paddingEnd="2dp"
                android:visibility="gone"/>
            <ImageView
                android:id="@+id/data_inout"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:paddingEnd="2dp"
                android:visibility="gone"/>
        </FrameLayout> 
        <!-- end -->
    .......
    <ImageView
            android:id="@+id/mobile_roaming"
            android:layout_width="wrap_content"
            android:layout_height="17dp"
            android:paddingStart="1dp"
            android:paddingTop="1.5dp"
            android:paddingBottom="3dp"
            android:paddingEnd="1dp"
            android:scaleType="fitCenter"
            android:src="@drawable/stat_sys_roaming_ext"
            android:contentDescription="@string/data_connection_roaming"
            android:visibility="gone" />
        <!-- cczheng add for sim operator  -->
        <TextView
            android:id="@+id/tv_operator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"/>
    </com.android.keyguard.AlphaOptimizedLinearLayout>
</com.android.systemui.statusbar.StatusBarMobileView>


目录
相关文章
|
5天前
|
缓存 网络协议 安全
Android网络面试题之Http基础和Http1.0的特点
**HTTP基础:GET和POST关键差异在于参数传递方式(GET在URL,POST在请求体),安全性(POST更安全),数据大小限制(POST无限制,GET有限制),速度(GET较快)及用途(GET用于获取,POST用于提交)。面试中常强调POST的安全性、数据量、数据类型支持及速度。HTTP 1.0引入了POST和HEAD方法,支持多种数据格式和缓存,但每个请求需新建TCP连接。**
20 5
|
3天前
|
安全 网络协议 算法
Android网络基础面试题之HTTPS的工作流程和原理
HTTPS简述 HTTPS基于TCP 443端口,通过CA证书确保服务器身份,使用DH算法协商对称密钥进行加密通信。流程包括TCP握手、证书验证(公钥解密,哈希对比)和数据加密传输(随机数加密,预主密钥,对称加密)。特点是安全但慢,易受特定攻击,且依赖可信的CA。每次请求可能复用Session ID以减少握手。
13 2
|
9天前
|
缓存 JSON 网络协议
Android面试题:App性能优化之电量优化和网络优化
这篇文章讨论了Android应用的电量和网络优化。电量优化涉及Doze和Standby模式,其中应用可能需要通过用户白名单或电池广播来适应限制。Battery Historian和Android Studio的Energy Profile是电量分析工具。建议减少不必要的操作,延迟非关键任务,合并网络请求。网络优化包括HTTPDNS减少DNS解析延迟,Keep-Alive复用连接,HTTP/2实现多路复用,以及使用protobuf和gzip压缩数据。其他策略如使用WebP图像格式,按网络质量提供不同分辨率的图片,以及启用HTTP缓存也是有效手段。
29 9
|
4天前
|
缓存 网络协议 Android开发
Android网络面试题之Http1.1和Http2.0
HTTP/1.1 引入持久连接和管道机制提升效率,支持分块传输编码和更多请求方式如PUT、PATCH。Host字段指定服务器域名,RANGE用于断点续传。HTTP/2变为二进制协议,实现多工处理,头信息压缩和服务器推送,减少延迟并优化资源加载。HTTP不断发展,从早期的简单传输到后来的高效交互。
14 0
Android网络面试题之Http1.1和Http2.0
|
9天前
|
JSON Java API
【Android】使用 Retrofit2 发送异步网络请求的简单案例
**摘要:** Retrofit是Android和Java的HTTP客户端库,简化了RESTful API交互。它通过Java接口定义HTTP请求,并提供注解管理参数、HTTP方法等。要使用Retrofit,首先在AndroidManifest.xml中添加`INTERNET`权限,然后在`build.gradle`中引入Retrofit和Gson依赖。创建服务器响应数据类和描述接口的接口,如`Result`和`Api`。通过Retrofit.Builder配置基础URL并构建实例,之后调用接口方法创建Call对象并发送异步请求。
42 1
|
13天前
|
缓存 网络协议 Java
Android面试题之Java网络通信基础知识
Socket是应用与TCP/IP通信的接口,封装了底层细节。网络通信涉及连接、读写数据。BIO是同步阻塞,NIO支持多路复用(如Selector),AIO在某些平台提供异步非阻塞服务。BIO示例中,服务端用固定线程池处理客户端请求,客户端发起连接并读写数据。NIO的关键是Selector监控多个通道的事件,减少线程消耗。书中推荐《Java网络编程》和《UNIX网络编程》。关注公众号AntDream了解更多。
20 2
|
14天前
|
XML JSON Java
Android面试题 之 网络通信基础面试题
序列化对比:Serializable码流大、性能低;XML人机可读但复杂;JSON轻量、兼容性好但空间消耗大;ProtoBuff高效紧凑。支持大量长连接涉及系统限制调整、缓冲区优化。select/poll/epoll是IO多路复用,epoll在高连接数下性能更优且支持边缘触发。水平触发持续通知数据,边缘触发仅通知新数据。直接内存减少一次拷贝,零拷贝技术如sendfile和MMAP提升效率。关注公众号&quot;AntDream&quot;了解更多技术细节。
16 1
|
3天前
|
机器学习/深度学习 网络协议 C语言
程序技术好文:网络编程中的SIGPIPE信号
程序技术好文:网络编程中的SIGPIPE信号
|
4天前
|
安全 Java API
Android获取Wi-Fi网络列表
【6月更文挑战第21天】
|
9天前
|
机器学习/深度学习 算法 语音技术
基于语音信号MFCC特征提取和GRNN神经网络的人员身份检测算法matlab仿真
**语音识别算法概览** MATLAB2022a中实现,结合MFCC与GRNN技术进行说话人身份检测。MFCC利用人耳感知特性提取语音频谱特征,GRNN作为非线性映射工具,擅长序列学习,确保高效识别。预加重、分帧、加窗、FFT、滤波器组、IDCT构成MFCC步骤,GRNN以其快速学习与鲁棒性处理不稳定数据。适用于多种领域。