1.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)
廣播適配
系統(tǒng)應用廣播適配
普通應用廣播
針對8.0的普通廣播彤悔,動態(tài)注冊即可。
太空橋作為系統(tǒng)應用廣播限制就比較多了:
太空橋包含主進程吓肋、iot進程灾常,兩個進程之間通信有很多使用的是廣播,可查看源碼
ActivityManagerService 會對系統(tǒng)廣播進行安全校驗:
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)
針對這種情況通過注冊一個靜態(tài)廣播的空殼,來繞過系統(tǒng)的檢測 畦娄,
MQTT動態(tài)注冊:
IntentFilter filter = new IntentFilter(ACTION);
registerReceiver(receiver, filter,BrocastPermissions.BROCAST_PERMISSION_MQTT,null);//需要添加權限
發(fā)送廣播:
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中動態(tài)注冊的廣播,在在發(fā)送廣播得時候回出現(xiàn) Sending non-protected broadcast
* 這個reciver主要是作為空殼弊仪,繞過系統(tǒng)檢查
* 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..........");
}
}
<receiver
android:name=".receiver.EmptyIotReciver"
android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST">
<intent-filter>
<action android:name="com.xiyun.spacebridge.iot.service.amqUpdateTopic" />
</intent-filter>
</receiver>
系統(tǒng)應用針對靜態(tài)注冊的需添加權限熙卡,方可解除警告:
<receiver android:name=".receiver.MqServiceMsgBrocast"
android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST">
<intent-filter>
<action android:name="com.xiyun.spacebridge.iot.INFORM_AUTH" />
</intent-filter>
</receiver>
太空橋項目主要用兩個空殼Reciver:
1.EmptySpaceReciver :主要用于主進程 android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST"
主要用于接收iot進程發(fā)過來的廣播,可將對應的action添加到清單文件励饵。
2.EmptyIotReciver:主要用于iot進程驳癌,android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST"
主要用于接收主進程發(fā)的廣播,可將對應的action添加到清單文件役听。
<receiver
android:name=".receiver.EmptyIotReciver"
android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST">
<intent-filter>
<action android:name="com.xiyun.spacebridge.iot.service.amqUpdateTopic" />
</intent-filter>
</receiver>
<receiver
android:name=".receiver.EmptySpaceReciver"
android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST">
<intent-filter>
<action android:name="connet_success" />
<action android:name="connet_faile" />
<action android:name="task_progress" />
<action android:name="finish_sync_app" />
</intent-filter>
</receiver>