mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-01-24 18:07:32 +01:00
GCM: fix display of uninstalled apps, do not allow registration if GCM is disabled (it won't succeed anyway)
This commit is contained in:
parent
83725f43cd
commit
ef9e9b0921
@ -22,6 +22,7 @@ import android.app.IntentService;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ public class CheckinService extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
try {
|
try {
|
||||||
|
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(TriggerReceiver.PREF_ENABLE_CHECKIN, false)) {
|
||||||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
|
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
||||||
@ -65,6 +67,7 @@ public class CheckinService extends IntentService {
|
|||||||
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
|
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -26,7 +26,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class TriggerReceiver extends WakefulBroadcastReceiver {
|
public class TriggerReceiver extends WakefulBroadcastReceiver {
|
||||||
private static final String TAG = "GmsCheckinTrigger";
|
private static final String TAG = "GmsCheckinTrigger";
|
||||||
private static final String PREF_ENABLE_CHECKIN = "checkin_enable_service";
|
public static final String PREF_ENABLE_CHECKIN = "checkin_enable_service";
|
||||||
private static final long REGULAR_CHECKIN_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
|
private static final long REGULAR_CHECKIN_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -99,6 +99,7 @@ public class PackageUtils {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static String packageFromPendingIntent(PendingIntent pi) {
|
public static String packageFromPendingIntent(PendingIntent pi) {
|
||||||
|
if (pi == null) return null;
|
||||||
if (SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
if (SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
return pi.getTargetPackage();
|
return pi.getTargetPackage();
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,6 +101,7 @@ public class PushRegisterService extends IntentService {
|
|||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
Log.d(TAG, "onHandleIntent: " + intent);
|
Log.d(TAG, "onHandleIntent: " + intent);
|
||||||
Log.d(TAG, "onHandleIntent: " + intent.getExtras());
|
Log.d(TAG, "onHandleIntent: " + intent.getExtras());
|
||||||
|
if (GcmPrefs.get(this).isGcmEnabled()) {
|
||||||
if (LastCheckinInfo.read(this).lastCheckin > 0) {
|
if (LastCheckinInfo.read(this).lastCheckin > 0) {
|
||||||
try {
|
try {
|
||||||
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
||||||
@ -120,6 +121,10 @@ public class PushRegisterService extends IntentService {
|
|||||||
subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
|
subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
|
||||||
startService(subIntent);
|
startService(subIntent);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// GCM is disabled, deny registration
|
||||||
|
replyNotAvailable(this, intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(final Intent intent) {
|
private void register(final Intent intent) {
|
||||||
@ -146,7 +151,19 @@ public class PushRegisterService extends IntentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void replyNotAvailable(Context context, Intent intent) {
|
||||||
|
replyNotAvailable(context, intent, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void replyNotAvailable(Context context, Intent intent, String packageName) {
|
public static void replyNotAvailable(Context context, Intent intent, String packageName) {
|
||||||
|
if (packageName == null) {
|
||||||
|
PendingIntent pendingIntent = intent.getParcelableExtra(EXTRA_APP);
|
||||||
|
packageName = PackageUtils.packageFromPendingIntent(pendingIntent);
|
||||||
|
}
|
||||||
|
if (packageName == null) {
|
||||||
|
// skip reply
|
||||||
|
return;
|
||||||
|
}
|
||||||
Intent outIntent = new Intent(ACTION_C2DM_REGISTRATION);
|
Intent outIntent = new Intent(ACTION_C2DM_REGISTRATION);
|
||||||
outIntent.putExtra(EXTRA_ERROR, ERROR_SERVICE_NOT_AVAILABLE);
|
outIntent.putExtra(EXTRA_ERROR, ERROR_SERVICE_NOT_AVAILABLE);
|
||||||
Log.d(TAG, "registration not allowed");
|
Log.d(TAG, "registration not allowed");
|
||||||
|
@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
@ -123,34 +124,7 @@ public class GcmAppFragment extends ResourceSettingsFragment {
|
|||||||
if (!(boolean) newValue) {
|
if (!(boolean) newValue) {
|
||||||
final List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(packageName);
|
final List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(packageName);
|
||||||
if (!registrations.isEmpty()) {
|
if (!registrations.isEmpty()) {
|
||||||
new AlertDialog.Builder(getContext())
|
showUnregisterConfirm(registrations, getString(R.string.gcm_unregister_after_deny_message));
|
||||||
.setTitle(String.format(getString(R.string.gcm_unregister_confirm_title), appName))
|
|
||||||
.setMessage(R.string.gcm_unregister_after_deny_message)
|
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (GcmDatabase.Registration registration : registrations) {
|
|
||||||
PushRegisterService.unregister(getContext(), registration.packageName, registration.signature, null, null);
|
|
||||||
}
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateAppDetails();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
database.setAppAllowRegister(packageName, (Boolean) newValue);
|
database.setAppAllowRegister(packageName, (Boolean) newValue);
|
||||||
@ -182,9 +156,28 @@ public class GcmAppFragment extends ResourceSettingsFragment {
|
|||||||
registerDetails.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
registerDetails.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
showUnregisterConfirm(registrations, getString(R.string.gcm_unregister_confirm_message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Preference messageDetails = root.findPreference(PREF_MESSAGE_DETAILS);
|
||||||
|
if (app.totalMessageCount == 0) {
|
||||||
|
messageDetails.setSummary(R.string.gcm_no_message_yet);
|
||||||
|
} else {
|
||||||
|
String s = getString(R.string.gcm_messages_counter, app.totalMessageCount, app.totalMessageBytes);
|
||||||
|
if (app.lastMessageTimestamp != 0) {
|
||||||
|
s += "\n" + getString(R.string.gcm_last_message_at, DateUtils.getRelativeDateTimeString(getContext(), app.lastMessageTimestamp, MINUTE_IN_MILLIS, WEEK_IN_MILLIS, FORMAT_SHOW_TIME));
|
||||||
|
}
|
||||||
|
messageDetails.setSummary(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showUnregisterConfirm(final List<GcmDatabase.Registration> registrations, String unregisterConfirmDesc) {
|
||||||
new AlertDialog.Builder(getContext())
|
new AlertDialog.Builder(getContext())
|
||||||
.setTitle(String.format(getString(R.string.gcm_unregister_confirm_title), appName))
|
.setTitle(getString(R.string.gcm_unregister_confirm_title, appName))
|
||||||
.setMessage(R.string.gcm_unregister_confirm_message)
|
.setMessage(unregisterConfirmDesc)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
@ -210,21 +203,6 @@ public class GcmAppFragment extends ResourceSettingsFragment {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Preference messageDetails = root.findPreference(PREF_MESSAGE_DETAILS);
|
|
||||||
if (app.totalMessageCount == 0) {
|
|
||||||
messageDetails.setSummary(R.string.gcm_no_message_yet);
|
|
||||||
} else {
|
|
||||||
String s = getString(R.string.gcm_messages_counter, app.totalMessageCount, app.totalMessageBytes);
|
|
||||||
if (app.lastMessageTimestamp != 0) {
|
|
||||||
s += "\n" + getString(R.string.gcm_last_message_at, DateUtils.getRelativeDateTimeString(getContext(), app.lastMessageTimestamp, MINUTE_IN_MILLIS, WEEK_IN_MILLIS, FORMAT_SHOW_TIME));
|
|
||||||
}
|
|
||||||
messageDetails.setSummary(s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AsActivity extends AbstractSettingsActivity {
|
public static class AsActivity extends AbstractSettingsActivity {
|
||||||
|
@ -213,6 +213,7 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
|
|||||||
setIcon(packageManager.getApplicationIcon(applicationInfo));
|
setIcon(packageManager.getApplicationIcon(applicationInfo));
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
setTitle(app.packageName);
|
setTitle(app.packageName);
|
||||||
|
setIcon(android.R.drawable.sym_def_app_icon);
|
||||||
}
|
}
|
||||||
setOnPreferenceClickListener(this);
|
setOnPreferenceClickListener(this);
|
||||||
updateViewDetails();
|
updateViewDetails();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user