mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-01-24 09:57:31 +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,16 +54,18 @@ public class CheckinService extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
try {
|
try {
|
||||||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
|
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(TriggerReceiver.PREF_ENABLE_CHECKIN, false)) {
|
||||||
if (info != null) {
|
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
|
||||||
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
if (info != null) {
|
||||||
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
|
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
||||||
for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
|
String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
|
||||||
PeopleManager.loadUserInfo(this, account);
|
for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
|
||||||
}
|
PeopleManager.loadUserInfo(this, account);
|
||||||
McsService.scheduleReconnect(this);
|
}
|
||||||
if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
|
McsService.scheduleReconnect(this);
|
||||||
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
|
if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
|
||||||
|
startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -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,24 +101,29 @@ 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 (LastCheckinInfo.read(this).lastCheckin > 0) {
|
if (GcmPrefs.get(this).isGcmEnabled()) {
|
||||||
try {
|
if (LastCheckinInfo.read(this).lastCheckin > 0) {
|
||||||
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
try {
|
||||||
(ACTION_C2DM_REGISTER.equals(intent.getAction()) && "1".equals(intent.getStringExtra(EXTRA_DELETE)))) {
|
if (ACTION_C2DM_UNREGISTER.equals(intent.getAction()) ||
|
||||||
unregister(intent);
|
(ACTION_C2DM_REGISTER.equals(intent.getAction()) && "1".equals(intent.getStringExtra(EXTRA_DELETE)))) {
|
||||||
} else if (ACTION_C2DM_REGISTER.equals(intent.getAction())) {
|
unregister(intent);
|
||||||
register(intent);
|
} else if (ACTION_C2DM_REGISTER.equals(intent.getAction())) {
|
||||||
|
register(intent);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} else if (!intent.getBooleanExtra(EXTRA_SKIP_TRY_CHECKIN, false)) {
|
||||||
Log.w(TAG, e);
|
Log.d(TAG, "No checkin yet, trying to checkin");
|
||||||
|
intent.putExtra(EXTRA_SKIP_TRY_CHECKIN, true);
|
||||||
|
Intent subIntent = new Intent(this, CheckinService.class);
|
||||||
|
subIntent.putExtra(CheckinService.EXTRA_FORCE_CHECKIN, true);
|
||||||
|
subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
|
||||||
|
startService(subIntent);
|
||||||
}
|
}
|
||||||
} else if (!intent.getBooleanExtra(EXTRA_SKIP_TRY_CHECKIN, false)) {
|
} else {
|
||||||
Log.d(TAG, "No checkin yet, trying to checkin");
|
// GCM is disabled, deny registration
|
||||||
intent.putExtra(EXTRA_SKIP_TRY_CHECKIN, true);
|
replyNotAvailable(this, intent);
|
||||||
Intent subIntent = new Intent(this, CheckinService.class);
|
|
||||||
subIntent.putExtra(CheckinService.EXTRA_FORCE_CHECKIN, true);
|
|
||||||
subIntent.putExtra(CheckinService.EXTRA_CALLBACK_INTENT, intent);
|
|
||||||
startService(subIntent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,34 +156,7 @@ 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) {
|
||||||
new AlertDialog.Builder(getContext())
|
showUnregisterConfirm(registrations, getString(R.string.gcm_unregister_confirm_message));
|
||||||
.setTitle(String.format(getString(R.string.gcm_unregister_confirm_title), appName))
|
|
||||||
.setMessage(R.string.gcm_unregister_confirm_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();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -227,6 +174,37 @@ public class GcmAppFragment extends ResourceSettingsFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showUnregisterConfirm(final List<GcmDatabase.Registration> registrations, String unregisterConfirmDesc) {
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setTitle(getString(R.string.gcm_unregister_confirm_title, appName))
|
||||||
|
.setMessage(unregisterConfirmDesc)
|
||||||
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
public static class AsActivity extends AbstractSettingsActivity {
|
public static class AsActivity extends AbstractSettingsActivity {
|
||||||
public AsActivity() {
|
public AsActivity() {
|
||||||
showHomeAsUp = true;
|
showHomeAsUp = true;
|
||||||
|
@ -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