Skip to content

Commit

Permalink
Update maps, rework MCS
Browse files Browse the repository at this point in the history
MCS rework related to microg#23 and microg#24
  • Loading branch information
mar-v-in committed Aug 4, 2015
1 parent 61ede98 commit 331813c
Show file tree
Hide file tree
Showing 17 changed files with 829 additions and 243 deletions.
2 changes: 1 addition & 1 deletion extern/GmsApi
Submodule GmsApi updated 55 files
+2 −0 play-services-api/src/main/aidl/com/google/android/gms/maps/internal/IMapViewDelegate.aidl
+7 −0 play-services-api/src/main/aidl/com/google/android/gms/maps/internal/IOnMapReadyCallback.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/AddListenerRequest.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/DeleteDataItemsResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetConfigResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetConfigsResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetConnectedNodesResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetDataItemResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetFdForAssetResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/GetLocalNodeResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/PutDataRequest.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/PutDataResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/RemoveListenerRequest.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/SendMessageResponse.aidl
+0 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/StorageInfoResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/AddListenerRequest.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/CapabilityInfoParcelable.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/ChannelEventParcelable.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/DeleteDataItemsResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetConfigResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetConfigsResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetConnectedNodesResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetDataItemResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetFdForAssetResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/GetLocalNodeResponse.aidl
+10 −10 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/IWearableCallbacks.aidl
+13 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/IWearableListener.aidl
+5 −3 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/IWearableService.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/MessageEventParcelable.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/NodeParcelable.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/PutDataRequest.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/PutDataResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/RemoveListenerRequest.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/SendMessageResponse.aidl
+3 −0 play-services-api/src/main/aidl/com/google/android/gms/wearable/internal/StorageInfoResponse.aidl
+70 −5 play-services-api/src/main/java/com/google/android/gms/wearable/Asset.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/AddListenerRequest.java
+23 −0 play-services-api/src/main/java/com/google/android/gms/wearable/internal/CapabilityInfoParcelable.java
+3 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/ChannelEventParcelable.java
+40 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/DataItemAssetParcelable.java
+6 −6 play-services-api/src/main/java/com/google/android/gms/wearable/internal/DataItemParcelable.java
+40 −0 play-services-api/src/main/java/com/google/android/gms/wearable/internal/DeleteDataItemsResponse.java
+3 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetConfigResponse.java
+3 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetConfigsResponse.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetConnectedNodesResponse.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetDataItemResponse.java
+1 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetFdForAssetResponse.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/GetLocalNodeResponse.java
+23 −0 play-services-api/src/main/java/com/google/android/gms/wearable/internal/MessageEventParcelable.java
+6 −5 play-services-api/src/main/java/com/google/android/gms/wearable/internal/PutDataRequest.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/PutDataResponse.java
+1 −3 play-services-api/src/main/java/com/google/android/gms/wearable/internal/RemoveListenerRequest.java
+1 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/SendMessageResponse.java
+1 −1 play-services-api/src/main/java/com/google/android/gms/wearable/internal/StorageInfoResponse.java
+1 −1 play-services-api/src/main/java/org/microg/gms/common/Constants.java
5 changes: 3 additions & 2 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<uses-permission android:name="org.microg.gms.STATUS_BROADCAST" />
Expand Down Expand Up @@ -174,8 +175,8 @@
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data
android:scheme="package"
android:path="com.google.android.gms" />
android:path="com.google.android.gms"
android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,58 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;

import com.google.android.gms.dynamic.IObjectWrapper;
import com.google.android.gms.dynamic.ObjectWrapper;
import com.google.android.gms.maps.GoogleMapOptions;
import org.microg.gms.maps.bitmap.BitmapDescriptorFactoryImpl;
import com.google.android.gms.maps.model.internal.IBitmapDescriptorFactoryDelegate;
import org.microg.gms.maps.camera.CameraUpdateFactoryImpl;

import org.microg.gms.maps.MapFragmentImpl;
import org.microg.gms.maps.MapViewImpl;
import org.microg.gms.maps.ResourcesContainer;
import org.microg.gms.maps.bitmap.BitmapDescriptorFactoryImpl;
import org.microg.gms.maps.camera.CameraUpdateFactoryImpl;

public class CreatorImpl extends ICreator.Stub {
@Override
public void init(IObjectWrapper resources) throws RemoteException {
initV2(resources, 0);
}

@Override
public IMapFragmentDelegate newMapFragmentDelegate(IObjectWrapper activity) throws RemoteException {
return new MapFragmentImpl((Activity)ObjectWrapper.unwrap(activity));
}

@Override
public IMapViewDelegate newMapViewDelegate(IObjectWrapper context, GoogleMapOptions options) throws RemoteException {
return new MapViewImpl((Context)ObjectWrapper.unwrap(context), options);
}

@Override
public ICameraUpdateFactoryDelegate newCameraUpdateFactoryDelegate() throws RemoteException {
return new CameraUpdateFactoryImpl();
}

@Override
public IBitmapDescriptorFactoryDelegate newBitmapDescriptorFactoryDelegate() throws RemoteException {
return new BitmapDescriptorFactoryImpl();
}

@Override
public void initV2(IObjectWrapper resources, int flags) throws RemoteException {
ResourcesContainer.set((Resources) ObjectWrapper.unwrap(resources));
}
private static final String TAG = "GmsMapCreator";

@Override
public void init(IObjectWrapper resources) throws RemoteException {
initV2(resources, 0);
}

@Override
public IMapFragmentDelegate newMapFragmentDelegate(IObjectWrapper activity) throws RemoteException {
return new MapFragmentImpl((Activity) ObjectWrapper.unwrap(activity));
}

@Override
public IMapViewDelegate newMapViewDelegate(IObjectWrapper context, GoogleMapOptions options) throws RemoteException {
return new MapViewImpl((Context) ObjectWrapper.unwrap(context), options);
}

@Override
public ICameraUpdateFactoryDelegate newCameraUpdateFactoryDelegate() throws RemoteException {
return new CameraUpdateFactoryImpl();
}

@Override
public IBitmapDescriptorFactoryDelegate newBitmapDescriptorFactoryDelegate() throws RemoteException {
return new BitmapDescriptorFactoryImpl();
}

@Override
public void initV2(IObjectWrapper resources, int flags) throws RemoteException {
ResourcesContainer.set((Resources) ObjectWrapper.unwrap(resources));
}

@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
if (super.onTransact(code, data, reply, flags)) return true;
Log.d(TAG, "onTransact [unknown]: " + code + ", " + data + ", " + flags);
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ public class Constants {
public static final int MCS_DATA_MESSAGE_STANZA_TAG = 8;

public static final int MCS_VERSION_CODE = 41;

public static final int MSG_INPUT = 10;
public static final int MSG_INPUT_ERROR = 11;
public static final int MSG_OUTPUT = 20;
public static final int MSG_OUTPUT_ERROR = 21;
public static final int MSG_OUTPUT_READY = 22;
public static final int MSG_TEARDOWN = 30;
public static final int MSG_CONNECT = 40;
public static final int MSG_HEARTBEAT = 41;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.microg.gms.gcm;

import android.os.Handler;
import android.util.Log;

import com.squareup.wire.Message;
Expand All @@ -39,30 +40,63 @@
import static org.microg.gms.gcm.Constants.MCS_IQ_STANZA_TAG;
import static org.microg.gms.gcm.Constants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.Constants.MCS_LOGIN_RESPONSE_TAG;
import static org.microg.gms.gcm.Constants.MSG_INPUT;
import static org.microg.gms.gcm.Constants.MSG_INPUT_ERROR;

public class McsInputStream {
public class McsInputStream extends Thread {
private static final String TAG = "GmsGcmMcsInput";

private final InputStream is;
private boolean initialized;
private int version = -1;
private int lastStreamIdReported = -1;
private int streamId = 0;
private long lastMsgTime = 0;
private Handler mainHandler;

public McsInputStream(InputStream is) {
this(is, false);
public McsInputStream(InputStream is, Handler mainHandler) {
this(is, mainHandler, false);
}

public McsInputStream(InputStream is, boolean initialized) {
public McsInputStream(InputStream is, Handler mainHandler, boolean initialized) {
this.is = is;
this.mainHandler = mainHandler;
this.initialized = initialized;
setName("McsInputStream");
}

@Override
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
Message message = read();
if (message != null) {
lastMsgTime = System.currentTimeMillis();
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, message));
}
}
} catch (IOException e) {
try {
is.close();
} catch (IOException ignored) {
}
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT_ERROR, e));
}
}

public void close() {
interrupt();
}

public int getStreamId() {
lastStreamIdReported = streamId;
return streamId;
}

public long getLastMsgTime() {
return lastMsgTime;
}

public boolean newStreamIdAvailable() {
return lastStreamIdReported != streamId;
}
Expand All @@ -88,14 +122,12 @@ public synchronized Message read() throws IOException {
ensureVersionRead();
int mcsTag = is.read();
int mcsSize = readVarint();
Log.d(TAG, "Reading from MCS tag=" + mcsTag + " size=" + mcsSize);
byte[] bytes = new byte[mcsSize];
int len = 0;
while (len < mcsSize) {
len += is.read(bytes, len, mcsSize - len);
}
Message read = read(mcsTag, bytes, len);
Log.d(TAG, "Read from MCS: " + read);
streamId++;
return read;
}
Expand All @@ -118,6 +150,7 @@ private static Message read(int mcsTag, byte[] bytes, int len) throws IOExceptio
case MCS_DATA_MESSAGE_STANZA_TAG:
return wire.parseFrom(bytes, 0, len, DataMessageStanza.class);
default:
Log.w(TAG, "Unknown tag: " + mcsTag);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.microg.gms.gcm;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.squareup.wire.Message;
Expand All @@ -28,52 +30,91 @@
import java.io.IOException;
import java.io.OutputStream;

import static org.microg.gms.gcm.Constants.*;

public class McsOutputStream {
import static org.microg.gms.gcm.Constants.MCS_DATA_MESSAGE_STANZA_TAG;
import static org.microg.gms.gcm.Constants.MCS_HEARTBEAT_ACK_TAG;
import static org.microg.gms.gcm.Constants.MCS_HEARTBEAT_PING_TAG;
import static org.microg.gms.gcm.Constants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.Constants.MCS_VERSION_CODE;
import static org.microg.gms.gcm.Constants.MSG_OUTPUT;
import static org.microg.gms.gcm.Constants.MSG_OUTPUT_ERROR;
import static org.microg.gms.gcm.Constants.MSG_OUTPUT_READY;
import static org.microg.gms.gcm.Constants.MSG_TEARDOWN;

public class McsOutputStream extends Thread implements Handler.Callback {
private static final String TAG = "GmsGcmMcsOutput";

private final OutputStream os;
private boolean initialized;
private int version = MCS_VERSION_CODE;
private int streamId = 0;

public McsOutputStream(OutputStream os) {
this(os, false);
private Handler mainHandler;
private Handler myHandler;

public McsOutputStream(OutputStream os, Handler mainHandler) {
this(os, mainHandler, false);
}

public McsOutputStream(OutputStream os, boolean initialized) {
public McsOutputStream(OutputStream os, Handler mainHandler, boolean initialized) {
this.os = os;
this.mainHandler = mainHandler;
this.initialized = initialized;
setName("McsOutputStream");
}

public int getStreamId() {
return streamId;
}

public void write(DataMessageStanza message) throws IOException {
write(message, MCS_DATA_MESSAGE_STANZA_TAG);
@Override
public void run() {
Looper.prepare();
myHandler = new Handler(this);
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_OUTPUT_READY));
Looper.loop();
}

public void write(LoginRequest loginRequest) throws IOException {
write(loginRequest, MCS_LOGIN_REQUEST_TAG);
}

public void write(HeartbeatAck ack) throws IOException {
write(ack, MCS_HEARTBEAT_ACK_TAG);
}

public void write(HeartbeatPing ping) throws IOException{
write(ping, MCS_HEARTBEAT_PING_TAG);
@Override
public boolean handleMessage(android.os.Message msg) {
switch (msg.what) {
case MSG_OUTPUT:
try {
Message message = (Message) msg.obj;
if (msg.obj instanceof DataMessageStanza) {
writeInternal(message, MCS_DATA_MESSAGE_STANZA_TAG);
} else if (msg.obj instanceof LoginRequest) {
writeInternal(message, MCS_LOGIN_REQUEST_TAG);
} else if (msg.obj instanceof HeartbeatAck) {
writeInternal(message, MCS_HEARTBEAT_ACK_TAG);
} else if (msg.obj instanceof HeartbeatPing) {
writeInternal(message, MCS_HEARTBEAT_PING_TAG);
} else {
Log.w(TAG, "Unknown message: " + msg.obj);
}
} catch (IOException e) {
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_OUTPUT_ERROR, e));
}
return true;
case MSG_TEARDOWN:
try {
os.close();
} catch (IOException ignored) {
}
try {
Looper.myLooper().quit();
} catch (Exception ignored) {
}
return true;
}
return false;
}

public synchronized void write(Message message, int tag) throws IOException {
private synchronized void writeInternal(Message message, int tag) throws IOException {
if (!initialized) {
Log.d(TAG, "Write MCS version code: " + version);
os.write(version);
initialized = true;
}
Log.d(TAG, "Write to MCS: " + message);
os.write(tag);
writeVarint(os, message.getSerializedSize());
os.write(message.toByteArray());
Expand All @@ -92,4 +133,8 @@ private void writeVarint(OutputStream os, int value) throws IOException {
}
}
}

public Handler getHandler() {
return myHandler;
}
}
Loading

0 comments on commit 331813c

Please sign in to comment.