美文网首页
Android8.1 适配Android5.1 APP

Android8.1 适配Android5.1 APP

作者: 招金 | 来源:发表于2021-10-21 16:16 被阅读0次

    客户在Android5.1 ROM上开发的应用,想适配到定制的Android8.1版本上,由不想多改app代码,那只能在ROM端想办法解决了。以下就是碰到问题以及解决方法。

    1.连续点击某些页面跳转时候,页面各种乱跳。

    原因参考: windowIsTranslucent引发的血案
    找到原因就好办,由于app使用了windowIsTranslucent导致,framework把获取windowIsTranslucent配置地方处理掉。

    ALPS/frameworks/base/services/core/java/com/android/server/am/ActivityRecord.java 
    public final class ActivityRecord extends ConfigurationContainer implements
     
             Entry ent = AttributeCache.instance().get(packageName,
                     realTheme, com.android.internal.R.styleable.Window, userId);
    +        /*
             final boolean translucent = ent != null && (ent.array.getBoolean(
                     com.android.internal.R.styleable.Window_windowIsTranslucent, false)
                     || (!ent.array.hasValue(
                             com.android.internal.R.styleable.Window_windowIsTranslucent)
                             && ent.array.getBoolean(
                                     com.android.internal.R.styleable.Window_windowSwipeToDismiss,
    -                                        false)));
    +                                        false)));*/
    +        final boolean translucent = false;                                
    +
             fullscreen = ent != null && !ent.array.getBoolean(
                     com.android.internal.R.styleable.Window_windowIsFloating, false) && !translucent;
    

    2.app在其他平台使用的是ttyMFD1串口通信,固定了,库没法修改

    解决方法 在init.rc使用软链接(前提是我们平台没有ttyMFD1串口)

     symlink /dev/ttyMT1 /dev/ttyMFD1
    

    3.app后台服务被频繁杀死

    原因参考:Android8.0 启动后台Service问题
    ROM修改

     ALPS/frameworks/base/services/core/java/com/android/server/am/ActiveServices.java 
                 r.fgWaiting = false;
                 mAm.mHandler.removeMessages(
                         ActivityManagerService.SERVICE_FOREGROUND_TIMEOUT_MSG, r);
    +            /*
                 if (r.app != null) {
                     Message msg = mAm.mHandler.obtainMessage(
                             ActivityManagerService.SERVICE_FOREGROUND_CRASH_MSG);
                     msg.obj = r.app;
                     mAm.mHandler.sendMessage(msg);
                 }
    +            */
             }
     
             if (DEBUG_SERVICE) {
    
     ALPS/frameworks/base/services/core/java/com/android/server/am/ActiveServices.java 
    index 184a7a8..f9c9841 100755
    @@ -106,7 +106,7 @@ public final class ActiveServices {
     
         // How long the startForegroundService() grace period is to get around to
         // calling startForeground() before we ANR + stop it.
    -    static final int SERVICE_START_FOREGROUND_TIMEOUT = 5*1000;
    +    static final int SERVICE_START_FOREGROUND_TIMEOUT = 10*1000;
     
         final ActivityManagerService mAm;
     
    @@ -3421,11 +3421,14 @@ public final class ActiveServices {
             if (r.app.executingServices.size() == 0 || r.app.thread == null) {
                 return;
             }
    +
    +        /*
             Message msg = mAm.mHandler.obtainMessage(
                     ActivityManagerService.SERVICE_FOREGROUND_TIMEOUT_MSG);
             msg.obj = r;
             r.fgWaiting = true;
             mAm.mHandler.sendMessageDelayed(msg, SERVICE_START_FOREGROUND_TIMEOUT);
    +        */
         }
     
         final class ServiceDumper {
    
    

    4.App悬浮上层,权限报错

     ALPS/frameworks/base/core/java/android/app/AppOpsManager.java
    @@ -915,7 +915,7 @@ public class AppOpsManager {
                 AppOpsManager.MODE_ALLOWED,
                 AppOpsManager.MODE_ALLOWED,
                 AppOpsManager.MODE_DEFAULT, // OP_WRITE_SETTINGS
    -            AppOpsManager.MODE_DEFAULT, // OP_SYSTEM_ALERT_WINDOW
    +            AppOpsManager.MODE_ALLOWED, // OP_SYSTEM_ALERT_WINDOW
                 AppOpsManager.MODE_ALLOWED,
                 AppOpsManager.MODE_ALLOWED,
                 AppOpsManager.MODE_ALLOWED,
    

    5.句柄泄漏

    进程默认的句柄上线是1024,可以调整延缓出错崩溃,当然更需要找到原因。
    延缓方法init.rc

    setrlimit 7 4096 4096
    

    监控句柄方法

    #!/system/bin/sh
    array=(
    com.xxx.xxx.xxx.settings
    com.xxx.xxx.xxx.settings:remote
    )
    
    #超过上限值报警
    fdcritical=800
    
    #2秒检测一次
    sleeptime=2
    
    function check_fd()
    {
        process=$1
        pid=$(pidof $1)
        fdnum=""
        if [ ! -n "$pid" ]; then
            pid="null"
        else
            fdnum=$(ls /proc/$pid/fd/ | wc -w)
            if [ $fdnum -ge $fdcritical ];then
                echo "warning!" $process $pid $fdnum
            fi
        fi
    }
    while [ "1" = "1" ]
    do
    for element in ${array[@]}
    do
    check_fd $element
    done
    sleep $sleeptime
    done
    

    6.USB TP插拔会界面会闪烁

    --- ALPS/frameworks/base/core/java/android/content/res/Configuration.java ----
    old mode 100644
    new mode 100755
    index f7cccd5..f7cd2b7
    @@ -388,9 +388,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration
             if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
                 list.add("CONFIG_LOCALE");
             }
    +        /*
             if ((diff & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) {
                 list.add("CONFIG_TOUCHSCREEN");
             }
    +        */
             if ((diff & ActivityInfo.CONFIG_KEYBOARD) != 0) {
                 list.add("CONFIG_KEYBOARD");
             }
    @@ -1148,11 +1150,15 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                 changed |= ActivityInfo.CONFIG_LOCALE;
                 userSetLocale = true;
             }
    +
    +        /*
             if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
                     && touchscreen != delta.touchscreen) {
                 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
                 touchscreen = delta.touchscreen;
             }
    +        */
    +
             if (delta.keyboard != KEYBOARD_UNDEFINED
                     && keyboard != delta.keyboard) {
                 changed |= ActivityInfo.CONFIG_KEYBOARD;
    @@ -1361,10 +1367,12 @@ public final class Configuration implements Parcelable, Comparable<Configuration
                     && deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
                 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
             }
    +        /*
             if ((compareUndefined || delta.touchscreen != TOUCHSCREEN_UNDEFINED)
                     && touchscreen != delta.touchscreen) {
                 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
             }
    +        */
             if ((compareUndefined || delta.keyboard != KEYBOARD_UNDEFINED)
                     && keyboard != delta.keyboard) {
                 changed |= ActivityInfo.CONFIG_KEYBOARD;
    
    

    相关文章

      网友评论

          本文标题:Android8.1 适配Android5.1 APP

          本文链接:https://www.haomeiwen.com/subject/khztaltx.html