Add trigger for Mcs *#*#gcmstart#*#* and various fixes

This commit is contained in:
mar-v-in 2015-04-02 23:46:47 +02:00
parent 8669ab2bf4
commit 0e0309df85
11 changed files with 161 additions and 63 deletions

View File

@ -12,56 +12,69 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms"
android:versionName="1.0"
android:versionCode="6772000">
android:versionCode="6772000"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="22" />
<permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.google.android.c2dm.permission.RECEIVE"
android:protectionLevel="dangerous"
android:permissionGroup="android.permission-group.NETWORK"
android:label="@string/perm_c2dm_receive_label" />
<permission
android:name="com.google.android.c2dm.permission.SEND"
android:protectionLevel="dangerous" />
android:protectionLevel="dangerous"
android:label="@string/perm_c2dm_send_label" />
<permission-tree android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<permission-tree
android:icon="@drawable/proprietary_auth_ic_scope_icon_default"
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.local"
android:label="@string/permission_service_local_label"
android:description="@string/permission_service_local_description" />
android:protectionLevel="dangerous"
android:description="@string/permission_service_local_description"
android:label="@string/permission_service_local_label" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.mail"
android:label="@string/permission_service_mail_label"
android:description="@string/permission_service_mail_description" />
android:protectionLevel="dangerous"
android:description="@string/permission_service_mail_description"
android:label="@string/permission_service_mail_label" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.writely"
android:label="@string/permission_service_writely_label"
android:description="@string/permission_service_writely_description" />
android:protectionLevel="dangerous"
android:description="@string/permission_service_writely_description"
android:label="@string/permission_service_writely_label" />
<permission
android:name="org.microg.gms.STATUS_BROADCAST"
android:protectionLevel="dangerous"
android:label="@string/perm_status_broadcast_label" />
<uses-permission android:name="android.permission.FAKE_PACKAGE_SIGNATURE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<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="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" />
<application
android:label="@string/gms_app_name"
android:icon="@drawable/ic_microg_app">
android:icon="@drawable/ic_microg_app"
android:label="@string/gms_app_name">
<meta-data
android:name="fake-signature"
android:value="@string/fake_signature" />
@ -76,10 +89,6 @@
</intent-filter>
</service>
<!--
~ TODO: maybe this should go in UnifiedNlp?
~ Only if fake signature is not required
-->
<service android:name="org.microg.gms.location.ReportingAndroidService">
<intent-filter>
<action android:name="com.google.android.location.reporting.service.START" />
@ -93,13 +102,13 @@
<provider
android:name="org.microg.gms.gservices.GServicesProvider"
android:exported="true"
android:authorities="com.google.android.gsf.gservices" />
android:authorities="com.google.android.gsf.gservices"
android:exported="true" />
<provider
android:name="org.microg.gms.settings.GoogleSettingsProvider"
android:exported="true"
android:authorities="com.google.settings" />
android:authorities="com.google.settings"
android:exported="true" />
<provider
android:name="org.microg.gms.feeds.SubscribedFeedsProvider"
@ -119,10 +128,12 @@
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="android.server.checkin.CHECKIN" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data
android:host="2432546"
android:scheme="android_secret_code" />
@ -136,29 +147,38 @@
android:permission="com.google.android.c2dm.permission.RECEIVE">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.UNREGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.gcm.mcs.McsService"
android:name="org.microg.gms.gcm.McsService"
android:exported="true" />
<service
android:name="com.google.android.gms.gcm.http.GoogleHttpService"
android:exported="true" />
<receiver android:name="org.microg.gms.gcm.TriggerReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data
android:host="42678278"
android:scheme="android_secret_code" />
</intent-filter>
</receiver>
<!-- DroidGuard -->
<service
android:exported="true"
android:name="org.microg.gms.droidguard.DroidGuardService">
android:name="org.microg.gms.droidguard.DroidGuardService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.droidguard.service.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
@ -170,6 +190,7 @@
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.people.service.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
@ -206,36 +227,39 @@
<activity
android:name="org.microg.tools.AccountPickerActivity"
android:exported="true"
android:excludeFromRecents="true">
android:excludeFromRecents="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.common.account.CHOOSE_ACCOUNT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="org.microg.gms.auth.login.LoginActivity"
android:theme="@style/LoginBlueTheme"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true">
android:exported="true"
android:theme="@style/LoginBlueTheme">
<intent-filter>
<action android:name="com.google.android.gms.auth.login.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="org.microg.gms.auth.AskPermissionActivity"
android:theme="@style/Theme.AppCompat.Light.Dialog"
android:excludeFromRecents="true"
android:exported="true"
android:excludeFromRecents="true" />
android:theme="@style/Theme.AppCompat.Light.Dialog" />
<service
android:name="com.google.android.gms.auth.GetToken"
android:name=".auth.GetToken"
android:exported="true" />
<activity
android:name="com.google.android.gms.auth.TokenActivity"
android:name=".auth.TokenActivity"
android:exported="true" />
<!-- Other -->
@ -245,6 +269,7 @@
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.mdm.services.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
@ -280,5 +305,10 @@
<action android:name="com.google.android.gms.playlog.service.START" />
</intent-filter>
</service>
<service
android:name=".gcm.http.GoogleHttpService"
android:exported="true" />
</application>
</manifest>

View File

@ -27,6 +27,7 @@ public class TriggerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Trigger checkin: " + intent);
Intent subIntent = new Intent(context, CheckinService.class);
if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
subIntent.putExtra("force", true);

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.microg.gms.gcm.mcs;
package org.microg.gms.gcm;
public class Constants {
public static final int MCS_HEARTBEAT_PING_TAG = 0;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.microg.gms.gcm.mcs;
package org.microg.gms.gcm;
import android.util.Base64;
import android.util.Log;
@ -22,16 +22,24 @@ import android.util.Log;
import com.squareup.wire.Message;
import com.squareup.wire.Wire;
import org.microg.gms.gcm.mcs.Close;
import org.microg.gms.gcm.mcs.DataMessageStanza;
import org.microg.gms.gcm.mcs.HeartbeatAck;
import org.microg.gms.gcm.mcs.HeartbeatPing;
import org.microg.gms.gcm.mcs.IqStanza;
import org.microg.gms.gcm.mcs.LoginRequest;
import org.microg.gms.gcm.mcs.LoginResponse;
import java.io.IOException;
import java.io.InputStream;
import static org.microg.gms.gcm.mcs.Constants.MCS_CLOSE_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_DATA_MESSAGE_STANZA_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_HEARTBEAT_ACK_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_HEARTBEAT_PING_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_IQ_STANZA_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.mcs.Constants.MCS_LOGIN_RESPONSE_TAG;
import static org.microg.gms.gcm.Constants.MCS_CLOSE_TAG;
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_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;
public class McsInputStream {
private static final String TAG = "GmsGcmMcsInput";

View File

@ -0,0 +1,4 @@
package org.microg.gms.gcm;
public class McsMessage {
}

View File

@ -14,16 +14,21 @@
* limitations under the License.
*/
package org.microg.gms.gcm.mcs;
package org.microg.gms.gcm;
import android.util.Log;
import com.squareup.wire.Message;
import org.microg.gms.gcm.mcs.DataMessageStanza;
import org.microg.gms.gcm.mcs.HeartbeatAck;
import org.microg.gms.gcm.mcs.HeartbeatPing;
import org.microg.gms.gcm.mcs.LoginRequest;
import java.io.IOException;
import java.io.OutputStream;
import static org.microg.gms.gcm.mcs.Constants.*;
import static org.microg.gms.gcm.Constants.*;
public class McsOutputStream {
private static final String TAG = "GmsGcmMcsOutput";

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.microg.gms.gcm.mcs;
package org.microg.gms.gcm;
import android.app.IntentService;
import android.content.Context;
@ -25,6 +25,14 @@ import android.util.Log;
import com.squareup.wire.Message;
import org.microg.gms.checkin.LastCheckinInfo;
import org.microg.gms.gcm.mcs.AppData;
import org.microg.gms.gcm.mcs.Close;
import org.microg.gms.gcm.mcs.DataMessageStanza;
import org.microg.gms.gcm.mcs.HeartbeatAck;
import org.microg.gms.gcm.mcs.HeartbeatPing;
import org.microg.gms.gcm.mcs.LoginRequest;
import org.microg.gms.gcm.mcs.LoginResponse;
import org.microg.gms.gcm.mcs.Setting;
import java.io.IOException;
import java.net.Socket;
@ -38,18 +46,20 @@ import static android.os.Build.VERSION.SDK_INT;
public class McsService extends IntentService {
private static final String TAG = "GmsGcmMcsSvc";
public static final String PREFERENCES_NAME = "mcs";
public static final String PREF_LAST_PERSISTENT_ID = "last_persistent_id";
public static final String SERVICE_HOST = "mtalk.google.com";
public static final int SERVICE_PORT = 5228;
public static final String PREF_LAST_PERSISTENT_ID = "last_persistent_id";
public static final String SELF_CATEGORY = "com.google.android.gsf.gtalkservice";
public static final String IDLE_NOTIFICATION = "IdleNotification";
public static final String FROM_FIELD = "gcm@android.com";
public static final int HEARTBEAT_MS = 60000;
private static AtomicBoolean connected = new AtomicBoolean(false);
private Socket socket;
private Socket sslSocket;
private McsInputStream inputStream;
private McsOutputStream outputStream;
@ -76,6 +86,10 @@ public class McsService extends IntentService {
}
}
public static boolean isConnected() {
return connected.get();
}
private void heartbeatLoop() {
try {
while (!Thread.interrupted()) {
@ -112,7 +126,7 @@ public class McsService extends IntentService {
try {
Log.d(TAG, "Starting MCS connection...");
LastCheckinInfo info = LastCheckinInfo.read(this);
socket = new Socket(SERVICE_HOST, SERVICE_PORT);
Socket socket = new Socket(SERVICE_HOST, SERVICE_PORT);
Log.d(TAG, "Connected to " + SERVICE_HOST + ":" + SERVICE_PORT);
sslSocket = SSLContext.getDefault().getSocketFactory().createSocket(socket, "mtalk.google.com", 5228, true);
Log.d(TAG, "Activated SSL with " + SERVICE_HOST + ":" + SERVICE_PORT);
@ -121,8 +135,7 @@ public class McsService extends IntentService {
LoginRequest loginRequest = buildLoginRequest(info);
Log.d(TAG, "Sending login request...");
outputStream.write(loginRequest);
boolean close = false;
while (!close) {
while (!Thread.interrupted()) {
Message o = inputStream.read();
lastMsgTime = System.currentTimeMillis();
if (o instanceof DataMessageStanza) {
@ -211,7 +224,7 @@ public class McsService extends IntentService {
.resource(Long.toString(info.androidId))
.user(Long.toString(info.androidId))
.use_rmq2(true)
.setting(Arrays.asList(new Setting("new_vc", "1")))
.setting(Collections.singletonList(new Setting("new_vc", "1")))
.received_persistent_id(Arrays.asList(getSharedPreferences().getString(PREF_LAST_PERSISTENT_ID, "").split("\\|")))
.build();
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2013-2015 µg Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.gms.gcm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
public class TriggerReceiver extends BroadcastReceiver {
private static final String PREF_ENABLE_GCM = "gcm_enable_mcs_service";
@Override
public void onReceive(Context context, Intent intent) {
boolean force = "android.provider.Telephony.SECRET_CODE".equals(intent.getAction());
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_ENABLE_GCM, false) || force) {
if (!McsService.isConnected() || force) {
context.startService(new Intent(context, McsService.class));
}
}
}
}

View File

@ -1,4 +0,0 @@
package org.microg.gms.gcm.mcs;
public class McsMessage {
}

View File

@ -133,6 +133,7 @@ public class InfoWindow {
*/
private class DefaultWindow extends FrameLayout {
@SuppressWarnings("deprecation")
public DefaultWindow(View view) {
super(context);
addView(view);

View File

@ -25,4 +25,8 @@
<string name="account_manager_title">µg Google Account Manager</string>
<string name="allow">Allow</string>
<string name="deny">Deny</string>
<string name="perm_status_broadcast_label">listen to internal status broadcasts</string>
<string name="perm_c2dm_receive_label">listen to C2DM messages</string>
<string name="perm_c2dm_send_label">send C2DM messages to other apps</string>
</resources>