You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
Try to start all external Services over DBus
No need to hardcode this only for Cloud Messaging
This commit is contained in:
@@ -176,9 +176,10 @@ JNIEXPORT void JNICALL Java_android_content_Context_nativeRegisterUnifiedPush(JN
|
|||||||
(*env)->ReleaseStringUTFChars(env, application_jstr, application);
|
(*env)->ReleaseStringUTFChars(env, application_jstr, application);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_android_content_Context_nativeStartExternalService(JNIEnv *env, jclass this, jstring package_jstr, jobject intent)
|
JNIEXPORT void JNICALL Java_android_content_Context_nativeStartExternalService(JNIEnv *env, jclass this, jobject intent)
|
||||||
{
|
{
|
||||||
GVariant *variant = intent_serialize(env, intent);
|
GVariant *variant = intent_serialize(env, intent);
|
||||||
|
jstring package_jstr = _GET_OBJ_FIELD(intent, "packageName", "Ljava/lang/String;");
|
||||||
const char *package = (*env)->GetStringUTFChars(env, package_jstr, NULL);
|
const char *package = (*env)->GetStringUTFChars(env, package_jstr, NULL);
|
||||||
char *object_path = g_strdup_printf("/%s", package);
|
char *object_path = g_strdup_printf("/%s", package);
|
||||||
g_strdelimit(object_path, ".", '/');
|
g_strdelimit(object_path, ".", '/');
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ JNIEXPORT void JNICALL Java_android_content_Context_nativeRegisterUnifiedPush
|
|||||||
/*
|
/*
|
||||||
* Class: android_content_Context
|
* Class: android_content_Context
|
||||||
* Method: nativeStartExternalService
|
* Method: nativeStartExternalService
|
||||||
* Signature: (Ljava/lang/String;Landroid/content/Intent;)V
|
* Signature: (Landroid/content/Intent;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_android_content_Context_nativeStartExternalService
|
JNIEXPORT void JNICALL Java_android_content_Context_nativeStartExternalService
|
||||||
(JNIEnv *, jclass, jstring, jobject);
|
(JNIEnv *, jclass, jobject);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class Context extends Object {
|
|||||||
private static native void nativeOpenFile(int fd);
|
private static native void nativeOpenFile(int fd);
|
||||||
private static native void nativeExportUnifiedPush(String packageName);
|
private static native void nativeExportUnifiedPush(String packageName);
|
||||||
private static native void nativeRegisterUnifiedPush(String token, String application);
|
private static native void nativeRegisterUnifiedPush(String token, String application);
|
||||||
private static native void nativeStartExternalService(String packageName, Intent service);
|
private static native void nativeStartExternalService(Intent service);
|
||||||
|
|
||||||
static Application createApplication(long native_window) throws Exception {
|
static Application createApplication(long native_window) throws Exception {
|
||||||
Application application;
|
Application application;
|
||||||
@@ -482,23 +482,24 @@ public class Context extends Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (intent.getAction() != null && intent.getAction().startsWith("com.google.android.c2dm")) {
|
// Newer applications use a Messenger instead of a BroadcastReceiver for the GCM token return Intent.
|
||||||
nativeStartExternalService("com.google.android.c2dm", intent);
|
// To support new and old apps with a common interface, we wrap the Messenger in a BroadcastReceiver
|
||||||
// Newer applications use a Messenger instead of a BroadcastReceiver for the return Intent.
|
if ("com.google.android.c2dm.intent.REGISTER".equals(intent.getAction()) && intent.getParcelableExtra("google.messenger") instanceof Messenger) {
|
||||||
// To support new and old apps with a common interface, we wrap the Messenger in a BroadcastReceiver
|
|
||||||
final Messenger messenger = (Messenger)intent.getParcelableExtra("google.messenger");
|
final Messenger messenger = (Messenger)intent.getParcelableExtra("google.messenger");
|
||||||
if (messenger != null) {
|
receiverMap.put(new IntentFilter("com.google.android.c2dm.intent.REGISTRATION"), new BroadcastReceiver() {
|
||||||
receiverMap.put(new IntentFilter("com.google.android.c2dm.intent.REGISTRATION"), new BroadcastReceiver() {
|
@Override
|
||||||
@Override
|
public void onReceive(Context context, Intent resultIntent) {
|
||||||
public void onReceive(Context context, Intent resultIntent) {
|
try {
|
||||||
try {
|
messenger.send(Message.obtain(null, 0, resultIntent));
|
||||||
messenger.send(Message.obtain(null, 0, resultIntent));
|
} catch (RemoteException e) {
|
||||||
} catch (RemoteException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
if (intent.getPackage() != null && !intent.getPackage().equals(getPackageName())) {
|
||||||
|
// External package. Try to start using DBus Action
|
||||||
|
nativeStartExternalService(intent);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class Intent implements Parcelable {
|
|||||||
private Uri data;
|
private Uri data;
|
||||||
private int flags;
|
private int flags;
|
||||||
private String type;
|
private String type;
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
public Intent() {}
|
public Intent() {}
|
||||||
public Intent(Intent o) {
|
public Intent(Intent o) {
|
||||||
@@ -63,7 +64,8 @@ public class Intent implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Intent setPackage(String packageName) {
|
public Intent setPackage(String packageName) {
|
||||||
return this; //??
|
this.packageName = packageName;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent setType(String type) {
|
public Intent setType(String type) {
|
||||||
@@ -328,7 +330,7 @@ public class Intent implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPackage() {
|
public String getPackage() {
|
||||||
return component == null ? null : component.getPackageName();
|
return packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getScheme() {
|
public String getScheme() {
|
||||||
|
|||||||
Reference in New Issue
Block a user