Only require C2D_MESSAGE permission when defined

This commit is contained in:
Marvin W 2018-08-28 14:10:52 +02:00
parent 9e0ee103a1
commit f94d140dea
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A

View File

@ -23,6 +23,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
import android.os.Build;
@ -468,6 +469,15 @@ public class McsService extends Service implements Handler.Callback {
intent.putExtra(appData.key, appData.value);
}
String receiverPermission;
try {
String name = msg.category + ".permission.C2D_MESSAGE";
getPackageManager().getPermissionInfo(name, 0);
receiverPermission = name;
} catch (PackageManager.NameNotFoundException e) {
receiverPermission = null;
}
List<ResolveInfo> infos = getPackageManager().queryBroadcastReceivers(intent, PackageManager.GET_RESOLVED_FILTER);
if (infos == null || infos.isEmpty()) {
logd("No target for message, wut?");
@ -476,7 +486,7 @@ public class McsService extends Service implements Handler.Callback {
logd("Target: " + resolveInfo);
Intent targetIntent = new Intent(intent);
targetIntent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
sendOrderedBroadcast(targetIntent, msg.category + ".permission.C2D_MESSAGE");
sendOrderedBroadcast(targetIntent, receiverPermission);
}
}
}