android8.0适配

1.logo适配

logo适配
悬浮框适配

https://blog.csdn.net/saberhao/article/details/53909841
java.lang.RuntimeException: Unable to create application cn.com.xiyun.canteen.base.application.BaseApplication: java.lang.SecurityException: Not allowed to change Do Not Disturb state
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5743)
at android.app.ActivityThread.-wrap1(Unknown Source:0)

 Caused by: java.lang.SecurityException: Not allowed to change Do Not Disturb state
    at android.os.Parcel.readException(Parcel.java:2013)
    at android.os.Parcel.readException(Parcel.java:1959)
    at android.media.IAudioService$Stub$Proxy.setStreamVolume(IAudioService.java:943)

广播适配

系统应用广播适配
普通应用广播
针对8.0的普通广播,动态注册即可。
太空桥作为系统应用广播限制就比较多了:
太空桥包含主进程、iot进程,两个进程之间通信有很多使用的是广播,可查看源码
ActivityManagerService 会对系统广播进行安全校验:

 private void checkBroadcastFromSystem(Intent intent, ProcessRecord callerApp,
        String callerPackage, int callingUid, boolean isProtectedBroadcast, List receivers) {
    if ((intent.getFlags() & Intent.FLAG_RECEIVER_FROM_SHELL) != 0) {
        // Don't yell about broadcasts sent via shell
        return;
    }

    final String action = intent.getAction();
    if (isProtectedBroadcast
            || Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
            || Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS.equals(action)
            || Intent.ACTION_MEDIA_BUTTON.equals(action)
            || Intent.ACTION_MEDIA_SCANNER_SCAN_FILE.equals(action)
            || Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS.equals(action)
            || Intent.ACTION_MASTER_CLEAR.equals(action)
            || Intent.ACTION_FACTORY_RESET.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_CONFIGURE.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION.equals(action)
            || TelephonyIntents.ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE.equals(action)
            || SuggestionSpan.ACTION_SUGGESTION_PICKED.equals(action)
            || AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION.equals(action)
            || AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION.equals(action)) {
        // Broadcast is either protected, or it's a public action that
        // we've relaxed, so it's fine for system internals to send.
        return;
    }

    // This broadcast may be a problem...  but there are often system components that
    // want to send an internal broadcast to themselves, which is annoying to have to
    // explicitly list each action as a protected broadcast, so we will check for that
    // one safe case and allow it: an explicit broadcast, only being received by something
    // that has protected itself.
    if (receivers != null && receivers.size() > 0
            && (intent.getPackage() != null || intent.getComponent() != null)) {
        boolean allProtected = true;
        for (int i = receivers.size()-1; i >= 0; i--) {
            Object target = receivers.get(i);
            if (target instanceof ResolveInfo) {
                ResolveInfo ri = (ResolveInfo)target;
                if (ri.activityInfo.exported && ri.activityInfo.permission == null) {
                    allProtected = false;
                    break;
                }
            } else {
                BroadcastFilter bf = (BroadcastFilter)target;
                if (bf.requiredPermission == null) {
                    allProtected = false;
                    break;
                }
            }
        }
        if (allProtected) {
            // All safe!
            return;
        }
    }

    // The vast majority of broadcasts sent from system internals
    // should be protected to avoid security holes, so yell loudly
    // to ensure we examine these cases.
    if (callerApp != null) {
        Log.wtf(TAG, "Sending non-protected broadcast " + action
                        + " from system " + callerApp.toShortString() + " pkg " + callerPackage,
                new Throwable());
    } else {
        Log.wtf(TAG, "Sending non-protected broadcast " + action
                        + " from system uid " + UserHandle.formatUid(callingUid)
                        + " pkg " + callerPackage,
                new Throwable());
    }
}

  ####异常警告::
  system_process E/ActivityManager: Sending non-protected broadcast com.xiyun.spacebridge.iot.service.amqUpdateTopic from system 1637:com.yunzong.spacebridge/1000 pkg com.yunzong.spacebridge
java.lang.Throwable
    at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19126)
    at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19731)
    at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:19873)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:240)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2922)
    at android.os.Binder.execTransact(Binder.java:697)

针对这种情况通过注册一个静态广播的空壳,来绕过系统的检测 ,

MQTT动态注册:

  IntentFilter filter = new IntentFilter(ACTION);
    registerReceiver(receiver, filter,BrocastPermissions.BROCAST_PERMISSION_MQTT,null);//需要添加权限

发送广播:

    Intent intent = new Intent();
    intent.setPackage(context.getPackageName());
    intent.setAction(MQTTService.ACTION);
    intent.putExtra("type", Key.KEY_HEART_CHECK);
    intent.putExtra(PreferenceKeys.BIND_PACAGE_NAME, context.getPackageName());
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    context.sendBroadcast(intent, BrocastPermissions.BROCAST_PERMISSION_MQTT);//添加权限

空壳Reciver

                  /**
                 * 由于在mqttservice中动态注册的广播,在在发送广播得时候回出现                                                                Sending non-protected broadcast
           *   这个reciver主要是作为空壳,绕过系统检查
           * Created by zhangxiaoping on 2019/3/29 17:31
           */
        public class EmptyIotReciver extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
              Log.e("TestIotReciver","TestIotReciver..........");
                }
        }

  
        
            
        
    

系统应用针对静态注册的需添加权限,方可解除警告:

        
        
            
        
    

太空桥项目主要用两个空壳Reciver:

    1.EmptySpaceReciver :主要用于主进程  android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST"  
    主要用于接收iot进程发过来的广播,可将对应的action添加到清单文件。
    2.EmptyIotReciver:主要用于iot进程,android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST"
    主要用于接收主进程发的广播,可将对应的action添加到清单文件。
     
        
            
        
    

    
        
            
            
            
            
        
    

你可能感兴趣的:(android8.0适配)