mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-12 11:14:20 +00:00
Make GCM re-registration failure notification based.
// FREEBIE
This commit is contained in:
parent
d42c4229fd
commit
bf19307916
@ -208,13 +208,14 @@
|
|||||||
android:clearTaskOnLaunch="true"
|
android:clearTaskOnLaunch="true"
|
||||||
android:finishOnTaskLaunch="true" />
|
android:finishOnTaskLaunch="true" />
|
||||||
|
|
||||||
<service android:enabled="true" android:name=".service.GcmRegistrationService"/>
|
<activity android:name=".PlayServicesProblemActivity"
|
||||||
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
|
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||||
|
|
||||||
<service android:enabled="true" android:name=".service.ApplicationMigrationService"/>
|
<service android:enabled="true" android:name=".service.ApplicationMigrationService"/>
|
||||||
<service android:enabled="true" android:name=".service.KeyCachingService"/>
|
<service android:enabled="true" android:name=".service.KeyCachingService"/>
|
||||||
<service android:enabled="true" android:name=".service.SendReceiveService"/>
|
|
||||||
<service android:enabled="true" android:name=".service.RegistrationService"/>
|
<service android:enabled="true" android:name=".service.RegistrationService"/>
|
||||||
<service android:enabled="true" android:name=".service.DirectoryRefreshService"/>
|
<service android:enabled="true" android:name=".service.DirectoryRefreshService"/>
|
||||||
<service android:enabled="true" android:name=".service.PreKeyService"/>
|
|
||||||
|
|
||||||
<service android:name=".service.QuickResponseService"
|
<service android:name=".service.QuickResponseService"
|
||||||
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
|
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
|
||||||
|
@ -149,6 +149,10 @@
|
|||||||
settings, and messages...
|
settings, and messages...
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
<!-- GcmRefreshJob -->
|
||||||
|
<string name="GcmRefreshJob_Permanent_TextSecure_communication_failure">Permanent TextSecure communication failure!</string>
|
||||||
|
<string name="GcmRefreshJob_TextSecure_was_unable_to_register_with_Google_Play_Services">TextSecure was unable to register with Google Play Services. Communication over the data channel has been disabled, please try re-registering from the TextSecure settings menu.</string>
|
||||||
|
|
||||||
<!-- GroupCreateActivity -->
|
<!-- GroupCreateActivity -->
|
||||||
<string name="GroupCreateActivity_actionbar_title">New group</string>
|
<string name="GroupCreateActivity_actionbar_title">New group</string>
|
||||||
<string name="GroupCreateActivity_actionbar_update_title">Update group</string>
|
<string name="GroupCreateActivity_actionbar_update_title">Update group</string>
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2014 Open Whisper Systems
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.thoughtcrime.securesms;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
|
public class PlayServicesProblemActivity extends FragmentActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
PlayServicesProblemFragment fragment = new PlayServicesProblemFragment();
|
||||||
|
fragment.show(getSupportFragmentManager(), "dialog");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2014 Open Whisper Systems
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.thoughtcrime.securesms;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||||
|
|
||||||
|
public class PlayServicesProblemFragment extends DialogFragment {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(@NonNull Bundle bundle) {
|
||||||
|
int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
|
||||||
|
return GooglePlayServicesUtil.getErrorDialog(code, getActivity(), 9111);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2014 Open Whisper Systems
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package org.thoughtcrime.securesms.jobs;
|
package org.thoughtcrime.securesms.jobs;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.PlayServicesProblemActivity;
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.whispersystems.jobqueue.JobParameters;
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
@ -31,22 +53,22 @@ public class GcmRefreshJob extends ContextJob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRun() throws Exception {
|
public void onRun() throws Exception {
|
||||||
String registrationId = TextSecurePreferences.getGcmRegistrationId(context);
|
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
|
||||||
|
String registrationId = TextSecurePreferences.getGcmRegistrationId(context);
|
||||||
|
|
||||||
if (registrationId == null) {
|
if (registrationId == null) {
|
||||||
Log.w(TAG, "GCM registrationId expired, reregistering...");
|
Log.w(TAG, "GCM registrationId expired, reregistering...");
|
||||||
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
|
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
|
||||||
|
|
||||||
if (result != ConnectionResult.SUCCESS) {
|
if (result != ConnectionResult.SUCCESS) {
|
||||||
Toast.makeText(context, "Unable to register with GCM!", Toast.LENGTH_LONG).show();
|
notifyGcmFailure();
|
||||||
|
accountManager.setGcmId(Optional.<String>absent());
|
||||||
|
TextSecurePreferences.setPushRegistered(context, false);
|
||||||
|
} else {
|
||||||
|
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
|
||||||
|
accountManager.setGcmId(Optional.of(gcmId));
|
||||||
|
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
|
|
||||||
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
|
|
||||||
|
|
||||||
accountManager.setGcmId(Optional.of(gcmId));
|
|
||||||
|
|
||||||
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,4 +83,21 @@ public class GcmRefreshJob extends ContextJob {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyGcmFailure() {
|
||||||
|
Intent intent = new Intent(context, PlayServicesProblemActivity.class);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1122, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
|
|
||||||
|
builder.setSmallIcon(R.drawable.icon_notification);
|
||||||
|
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
|
||||||
|
R.drawable.ic_action_warning_red));
|
||||||
|
builder.setContentTitle(context.getString(R.string.GcmRefreshJob_Permanent_TextSecure_communication_failure));
|
||||||
|
builder.setContentText(context.getString(R.string.GcmRefreshJob_TextSecure_was_unable_to_register_with_Google_Play_Services));
|
||||||
|
builder.setTicker(context.getString(R.string.GcmRefreshJob_Permanent_TextSecure_communication_failure));
|
||||||
|
builder.setContentIntent(pendingIntent);
|
||||||
|
|
||||||
|
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||||
|
.notify(12, builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user