Skip to content

Commit

Permalink
fix(flying-peogin): key error
Browse files Browse the repository at this point in the history
  • Loading branch information
Justson committed Aug 18, 2020
1 parent 05c64b0 commit 8722fad
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// implementation project(path: ':library')
implementation project(path: ':library')
implementation 'com.google.code.gson:gson:2.8.6'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
implementation 'com.github.Justson:flying-pigeon:v1.0.3'
// implementation 'com.github.Justson:flying-pigeon:v1.0.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void run() {
@Override
public void onClick(View v) {
Pigeon flyPigeon = Pigeon.newBuilder(MainActivity.this).setAuthority("com.flyingpigeon.ipc_sample").build();
flyPigeon.route("/submit/bitmap", "submit-bitmap", new byte[1024]).resquestLarge().fly();
Bundle bundle = flyPigeon.route("/query/username").withString("userid", UUID.randomUUID().toString()).fly();
if (bundle != null) {
Log.e(TAG, "bundle:" + bundle.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.flyingpigeon.ipc_sample;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.flyingpigeon.library.Config;
import com.flyingpigeon.library.Pigeon;
import com.flyingpigeon.library.ServiceManager;
import com.flyingpigeon.library.annotations.RequestLarge;
import com.flyingpigeon.library.annotations.route;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

TextView ipcLabel;
public static final String TAG = Config.PREFIX + "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -46,6 +50,12 @@ public void run() {
out.putString("username", "ipc-sample");
}

@RequestLarge
@route("/submit/bitmap")
public void submitBitmap(String bitmapInfo, byte[] bitmap) {
Log.e(TAG, "bitmapInfo:" + bitmapInfo + " bitmap:" + bitmap.length);
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
3 changes: 0 additions & 3 deletions library/src/main/java/com/flyingpigeon/library/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.os.Parcel;
import android.os.Parcelable;
import com.flyingpigeon.library.log.FlyPigeonLog;

import java.io.Serializable;

Expand Down Expand Up @@ -394,7 +393,6 @@ public static class PairParcelable extends Pair {
public PairParcelable(String key, Parcelable value) {
super(key);
this.value = value;
FlyPigeonLog.e(TAG, "key:" + this.getKey());
}

protected PairParcelable(String key) {
Expand Down Expand Up @@ -447,7 +445,6 @@ public static class PairString extends Pair {
public PairString(String key, String value) {
super(key);
this.value = value;
FlyPigeonLog.e(TAG, "key:" + this.getKey());
}

protected PairString(String key) {
Expand Down
3 changes: 0 additions & 3 deletions library/src/main/java/com/flyingpigeon/library/RealCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import android.net.Uri;
import android.os.Bundle;

import com.flyingpigeon.library.log.FlyPigeonLog;

import java.lang.reflect.Method;

import static com.flyingpigeon.library.PigeonConstant.PIGEON_KEY_CLASS;
Expand Down Expand Up @@ -65,7 +63,6 @@ Bundle execute(String route, Bundle bundle) {
int flags = 0;
flags = ParametersSpec.setParamParcel(flags, false);
bundle.putInt(PIGEON_KEY_FLAGS, flags);
FlyPigeonLog.e(TAG, "uri:" + uri.toString() + " contentValues:" + bundle + " contentResolver:" + contentResolver);
Bundle result = contentResolver.call(uri, "", "", bundle);
return result;
} catch (Throwable throwable) {
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/java/com/flyingpigeon/library/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.flyingpigeon.library.boxing.ServerBoxmenImpl;
import com.flyingpigeon.library.invoker.MethodInvoker;
import com.flyingpigeon.library.invoker.RouteResponseLargeInvoker;
import com.flyingpigeon.library.log.FlyPigeonLog;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -128,7 +127,6 @@ Cursor dispatch(Uri uri, String[] arg, String route) {
BundleCursor bundleCursor = new BundleCursor(bundle, new String[]{PIGEON_KEY_RESULT});
bundle.putInt(PIGEON_KEY_RESPONSE_CODE, PIGEON_RESPONSE_RESULE_SUCCESS);
try {
FlyPigeonLog.e(TAG, "matchQuery:" + route);
int pLength = (arg.length - 2) / 2;
String[] params = new String[pLength];
String[] types = new String[pLength];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public Bundle call(@NonNull String method, @Nullable String arg, @Nullable Bundl
return null;
}
Bundle response = new Bundle();
in.setClassLoader(Pair.class.getClassLoader());
Parcelable returnResponse = in.getParcelable(PIGEON_KEY_RESPONSE);
response.putParcelable(PIGEON_KEY_RESPONSE, returnResponse);
try {
in.setClassLoader(Pair.class.getClassLoader());
String calling = getCallingPackage();
if (!TextUtils.isEmpty(calling)) {
in.putString(PIGEON_KEY_CALLING_PACKAGE, calling);
Expand Down
11 changes: 7 additions & 4 deletions library/src/main/java/com/flyingpigeon/library/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.util.Pair;

import com.flyingpigeon.library.ashmem.Ashmem;
import com.flyingpigeon.library.log.FlyPigeonLog;

import java.io.Serializable;
import java.lang.reflect.Type;
Expand All @@ -35,9 +36,9 @@
* @since 1.0.0
*/
public class Utils {
private static final String TAG = Utils.class.getSimpleName();


public static byte[] toPrimitives(Byte[] oBytes) {
public static byte[] toPrimitives(Byte[] oBytes) {
if (oBytes == null || oBytes.length <= 0) {
return new byte[0];
}
Expand Down Expand Up @@ -311,7 +312,7 @@ public static void convert(String key, Bundle bundle, Type type, Object arg) {
Parcelable parcelable = bundle.getParcelable(key);
} else {
ParameterHandler.ByteArrayHandler byteArrayHandler = (ParameterHandler.ByteArrayHandler) map.get(byte[].class);
byteArrayHandler.apply(array, byte[].class.getName(), bundle);
byteArrayHandler.apply(array, key, bundle);
}

} else if (Byte[].class.isAssignableFrom(typeClazz)) {
Expand All @@ -325,7 +326,7 @@ public static void convert(String key, Bundle bundle, Type type, Object arg) {
Parcelable parcelable = bundle.getParcelable(key);
} else {
ParameterHandler.ByteArrayHandler byteArrayHandler = (ParameterHandler.ByteArrayHandler) map.get(byte[].class);
byteArrayHandler.apply(array, byte[].class.getName(), bundle);
byteArrayHandler.apply(array, key, bundle);
}

} else if (String.class.isAssignableFrom(typeClazz)) {
Expand All @@ -342,6 +343,8 @@ public static void convert(String key, Bundle bundle, Type type, Object arg) {
assert handler != null;
handler.apply((Serializable) arg, key, bundle);
Parcelable parcelable = bundle.getParcelable(key);
} else {
FlyPigeonLog.e(TAG, "unkown class:" + typeClazz);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.os.Parcelable;

import com.flyingpigeon.library.ClassUtil;
import com.flyingpigeon.library.Config;
import com.flyingpigeon.library.Utils;

import java.lang.reflect.Type;
Expand All @@ -38,6 +39,8 @@
* @since 1.0.0
*/
public class RouteClientBoxmenImpl implements RouteClientBoxmen<Bundle, Object> {
private static final String TAG = Config.PREFIX + RouteClientBoxmenImpl.class.getSimpleName();

@Override
public Bundle boxing(String route, Object[] params) {
Type[] types = new Type[params.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import android.os.Parcelable;
import android.util.Pair;

import com.flyingpigeon.library.log.FlyPigeonLog;

import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -105,7 +103,6 @@ private android.util.Pair<Class<?>, Object> parcelableToClazz(Parcelable parcela
if (value instanceof ParcelFileDescriptor) {
String lengthKey = index + PIGEON_KEY_ARRAY_LENGTH;
int arrayLength = extras.getInt(lengthKey);
FlyPigeonLog.e(TAG, "keyLength:" + arrayLength + " lengthKey:" + lengthKey);
ParcelFileDescriptor parcelFileDescriptor = (ParcelFileDescriptor) value;
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
FileInputStream fileInputStream = new FileInputStream(fileDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.flyingpigeon.library.Config;
import com.flyingpigeon.library.Utils;
import com.flyingpigeon.library.log.FlyPigeonLog;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -60,6 +61,10 @@ public Object invoke(Object... args) throws IllegalAccessException, InvocationTa
System.arraycopy(args, 0, p, 0, Math.min(parametersLength, args.length));
args = p;
}

for (int i = 0; i < args.length; i++) {
FlyPigeonLog.e(TAG, "args:" + args[i]);
}
}

for (int i = 0; i < parametersLength; i++) {
Expand Down

0 comments on commit 8722fad

Please sign in to comment.