Add settings and Fix small MCS problems

This commit is contained in:
mar-v-in 2015-04-03 23:54:41 +02:00
parent 0e0309df85
commit 7b3e490d55
9 changed files with 153 additions and 50 deletions

View File

@ -24,38 +24,37 @@
<permission
android:name="com.google.android.c2dm.permission.RECEIVE"
android:protectionLevel="dangerous"
android:label="@string/perm_c2dm_receive_label"
android:permissionGroup="android.permission-group.NETWORK"
android:label="@string/perm_c2dm_receive_label" />
android:protectionLevel="dangerous" />
<permission
android:name="com.google.android.c2dm.permission.SEND"
android:protectionLevel="dangerous"
android:label="@string/perm_c2dm_send_label" />
android:label="@string/perm_c2dm_send_label"
android:protectionLevel="dangerous" />
<permission-tree
android:icon="@drawable/proprietary_auth_ic_scope_icon_default"
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH"
android:icon="@drawable/proprietary_auth_ic_scope_icon_default" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.local"
android:protectionLevel="dangerous"
android:description="@string/permission_service_local_description"
android:label="@string/permission_service_local_label" />
android:label="@string/permission_service_local_label"
android:protectionLevel="dangerous" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.mail"
android:protectionLevel="dangerous"
android:description="@string/permission_service_mail_description"
android:label="@string/permission_service_mail_label" />
android:label="@string/permission_service_mail_label"
android:protectionLevel="dangerous" />
<permission
android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.writely"
android:protectionLevel="dangerous"
android:description="@string/permission_service_writely_description"
android:label="@string/permission_service_writely_label" />
android:label="@string/permission_service_writely_label"
android:protectionLevel="dangerous" />
<permission
android:name="org.microg.gms.STATUS_BROADCAST"
android:protectionLevel="dangerous"
android:label="@string/perm_status_broadcast_label" />
android:label="@string/perm_status_broadcast_label"
android:protectionLevel="dangerous" />
<uses-permission android:name="android.permission.FAKE_PACKAGE_SIGNATURE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ -71,7 +70,6 @@
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<uses-permission android:name="org.microg.gms.STATUS_BROADCAST" />
<application
android:icon="@drawable/ic_microg_app"
android:label="@string/gms_app_name">
@ -88,7 +86,6 @@
<action android:name="com.google.android.location.internal.GoogleLocationManagerService.START" />
</intent-filter>
</service>
<service android:name="org.microg.gms.location.ReportingAndroidService">
<intent-filter>
<action android:name="com.google.android.location.reporting.service.START" />
@ -104,12 +101,10 @@
android:name="org.microg.gms.gservices.GServicesProvider"
android:authorities="com.google.android.gsf.gservices"
android:exported="true" />
<provider
android:name="org.microg.gms.settings.GoogleSettingsProvider"
android:authorities="com.google.settings"
android:exported="true" />
<provider
android:name="org.microg.gms.feeds.SubscribedFeedsProvider"
android:authorities="subscribedfeeds"
@ -156,12 +151,14 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.gcm.McsService"
android:exported="true" />
<receiver android:name="org.microg.gms.gcm.TriggerReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
@ -235,7 +232,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="org.microg.gms.auth.login.LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -247,7 +243,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="org.microg.gms.auth.AskPermissionActivity"
android:excludeFromRecents="true"
@ -273,7 +268,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.icing.LightweightIndexService"
android:exported="true">
@ -281,7 +275,6 @@
<action android:name="com.google.android.gms.icing.LIGHTWEIGHT_INDEX_SERVICE" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.icing.IndexService"
android:exported="true">
@ -289,7 +282,6 @@
<action android:name="com.google.android.gms.icing.INDEX_SERVICE" />
</intent-filter>
</service>
<service
android:name=".analytics.service.AnalyticsService"
android:exported="true">
@ -297,7 +289,6 @@
<action android:name="com.google.android.gms.analytics.service.START" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.playlog.PlayLogService"
android:exported="true">
@ -305,10 +296,20 @@
<action android:name="com.google.android.gms.playlog.service.START" />
</intent-filter>
</service>
<service
android:name=".gcm.http.GoogleHttpService"
android:exported="true" />
<activity
android:name="org.microg.gms.ui.SettingsActivity"
android:icon="@drawable/ic_microg_app"
android:label="@string/gms_settings_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -36,7 +36,7 @@ public class AuthManager {
private static final String TAG = "GmsAuthManager";
public static final String PERMISSION_TREE_BASE = "com.google.android.googleapps.permission.GOOGLE_AUTH.";
private static final String PREF_KEY_TRUST_GOOGLE = "auth_manager_trust_google";
private static final String PREF_AUTH_TRUST_GOOGLE = "auth_manager_trust_google";
private final Context context;
private final String accountName;
@ -165,7 +165,7 @@ public class AuthManager {
}
public static boolean isTrustGooglePermitted(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_KEY_TRUST_GOOGLE, true);
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_AUTH_TRUST_GOOGLE, true);
}
private boolean isSystemApp() {

View File

@ -16,7 +16,6 @@
package org.microg.gms.gcm;
import android.util.Base64;
import android.util.Log;
import com.squareup.wire.Message;
@ -92,8 +91,9 @@ public class McsInputStream {
Log.d(TAG, "Reading from MCS tag=" + mcsTag + " size=" + mcsSize);
byte[] bytes = new byte[mcsSize];
int len = 0;
while ((len += is.read(bytes, len, mcsSize - len)) < mcsSize) ;
Log.d(TAG, "Reading from MCS: " + Base64.encodeToString(bytes, 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++;

View File

@ -58,13 +58,14 @@ public class McsService extends IntentService {
public static final String FROM_FIELD = "gcm@android.com";
public static final int HEARTBEAT_MS = 60000;
private static AtomicBoolean connected = new AtomicBoolean(false);
public static final int HEARTBEAT_ALLOWED_OFFSET_MS = 2000;
private static final AtomicBoolean connecting = new AtomicBoolean(false);
private static Thread connectionThread;
private static Thread heartbeatThread;
private Socket sslSocket;
private McsInputStream inputStream;
private McsOutputStream outputStream;
private Thread connectionThread;
private Thread heartbeatThread;
private long lastMsgTime;
public McsService() {
@ -73,7 +74,7 @@ public class McsService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
if (connected.compareAndSet(false, true)) {
if (!isConnected()) {
connectionThread = new Thread(new Runnable() {
@Override
public void run() {
@ -87,7 +88,7 @@ public class McsService extends IntentService {
}
public static boolean isConnected() {
return connected.get();
return connecting.get() || (connectionThread != null && connectionThread.isAlive());
}
private void heartbeatLoop() {
@ -95,7 +96,7 @@ public class McsService extends IntentService {
while (!Thread.interrupted()) {
try {
long waitTime;
while ((waitTime = lastMsgTime + HEARTBEAT_MS - System.currentTimeMillis()) > 0) {
while ((waitTime = lastMsgTime + HEARTBEAT_MS - System.currentTimeMillis()) > HEARTBEAT_ALLOWED_OFFSET_MS) {
synchronized (heartbeatThread) {
Log.d(TAG, "Waiting for " + waitTime + "ms");
heartbeatThread.wait(waitTime);
@ -123,6 +124,7 @@ public class McsService extends IntentService {
}
private void connect() {
connecting.set(false);
try {
Log.d(TAG, "Starting MCS connection...");
LastCheckinInfo info = LastCheckinInfo.read(this);
@ -160,7 +162,6 @@ public class McsService extends IntentService {
heartbeatThread.interrupt();
heartbeatThread = null;
}
connected.set(false);
Log.d(TAG, "Connection closed");
}

View File

@ -19,6 +19,8 @@ package org.microg.gms.gcm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
public class TriggerReceiver extends BroadcastReceiver {
@ -27,9 +29,15 @@ public class TriggerReceiver extends BroadcastReceiver {
@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));
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected() || force) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREF_ENABLE_GCM, false) || force) {
if (!McsService.isConnected() || force) {
context.startService(new Intent(context, McsService.class));
}
}
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.ui;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.preference.PreferenceFragment;
import com.google.android.gms.R;
public class SettingsActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_wrapper, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.gms_preferences);
}
}
}

View File

@ -29,4 +29,10 @@
<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>
<string name="pref_auth_trust_google">auth_manager_trust_google</string>
<string name="pref_auth_trust_google_title">Trust Google for app permissions</string>
<string name="pref_auth_trust_google_summary">When disabled, the user is asked before an apps authorization request is sent to Google. Some applications will fail to use the Google account if this is disabled.</string>
<string name="gms_settings_name">µg Settings</string>
</resources>

View File

@ -1,9 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<!--
<PreferenceCategory android:title="@string/google_settings_header_title" />
<PreferenceScreen android:title="@string/maps_settings_title" android:key="key1">
<intent android:action="com.google.android.apps.maps.LOCATION_SETTINGS" />
</PreferenceScreen> -->
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/account_manager_title">
<CheckBoxPreference
android:key="@string/pref_auth_trust_google"
android:defaultValue="true"
android:title="@string/pref_auth_trust_google_title"
android:summary="@string/pref_auth_trust_google_summary" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Background services">
<CheckBoxPreference
android:key="checkin_enable_service"
android:defaultValue="false"
android:title="Enable regular checkin" />
<CheckBoxPreference
android:key="gcm_enable_mcs_service"
android:defaultValue="false"
android:dependency="checkin_enable_service"
android:title="Enable Google Cloud Messaging" />
</PreferenceCategory>
</PreferenceScreen>