o que é o Google Play services MeasurementBrokerService e como pará-lo?

Criei um serviço que ouve uma base de fogo.

Este é um serviço simples com baixo uso de memória. Infelizmente, estou a ver um serviço do Google play services chamado MeasurementBrokerService a juntar-se ao meu serviço e não a libertar memória.

Ao contrário de uma questão relacionada : "Service MeasurementBrokerService is in use" está a mostrar no meu processo de candidatura

a pergunta acima não tem resposta aceite, por isso, por favor, não marque isto como um duplicate

não estou a usar firebase-appindexing.

a seguir está o meu ficheiro de gradle do nível do app:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }    
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.example.project.recommendedapp"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.github.clans:fab:1.6.4'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.0@aar') {
        transitive = true;
    }
    compile 'com.facebook.fresco:fresco:1.0.0'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.squareup.okhttp3:okhttp:3.5.0'

}
apply plugin: 'com.google.gms.google-services'
Alguém pode, por favor, guiar-me sobre como impedir que o serviço se junte ao meu processo?

o serviço é o seguinte:

public class SubscriptionListenerService extends Service {

DatabaseReference userNodeSubscriptionRef;

ChildEventListener subscribedTopicsListener;

SharedPreferences sessionPref,subscribedTopicsPreference;

SharedPreferences.Editor subscribedtopicsprefeditor;

String userid;

boolean stoppedInternally = false;

SharedPreferences.OnSharedPreferenceChangeListener sessionPrefChangeListener;

@Nullable
@Override
public IBinder onBind(Intent intent) {
    //do not need a binder over here
    return null;
}

@Override
public void onCreate(){
    super.onCreate();

    Log.d("FragmentCreate","onCreate called inside service");

    sessionPref = getSharedPreferences("SessionPref",0);

    subscribedTopicsPreference=getSharedPreferences("subscribedTopicsPreference",0);

    subscribedtopicsprefeditor=subscribedTopicsPreference.edit();

    userid = sessionPref.getString("userid",null);

    sessionPrefChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            Log.d("FragmentCreate","The shared preference changed "+key);
            stoppedInternally=true;
            sessionPref.unregisterOnSharedPreferenceChangeListener(this);
            if(userNodeSubscriptionRef!=null && subscribedTopicsListener!=null){
                userNodeSubscriptionRef.removeEventListener(subscribedTopicsListener);
            }
            stopSelf();
        }
    };

    sessionPref.registerOnSharedPreferenceChangeListener(sessionPrefChangeListener);

    subscribedTopicsListener = new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            if(!(dataSnapshot.getValue() instanceof Boolean)){
                Log.d("FragmentCreate","Please test subscriptions with a boolean value");
            }else {
                if ((Boolean) dataSnapshot.getValue()) {
                    //here we subscribe to the topic as the topic has a true value
                    Log.d("FragmentCreate", "Subscribing to topic " + dataSnapshot.getKey()+" "+this.getClass().getName());
                    subscribedtopicsprefeditor.putBoolean(dataSnapshot.getKey(), true);
                    FirebaseMessaging.getInstance().subscribeToTopic(dataSnapshot.getKey());
                } else {
                    //here we unsubscribed from the topic as the topic has a false value
                    Log.d("FragmentCreate", "Unsubscribing from topic " + dataSnapshot.getKey()+" "+this.getClass().getName());
                    subscribedtopicsprefeditor.remove(dataSnapshot.getKey());
                    FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
                }

                subscribedtopicsprefeditor.commit();
            }
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
            //either an unsubscription will trigger this, or a re-subscription after an unsubscription

            if(!(dataSnapshot.getValue() instanceof Boolean)){
                Log.d("FragmentCreate","Please test subscriptions with a boolean value");
            }else{

                if((Boolean)dataSnapshot.getValue()){
                    Log.d("FragmentCreate","Subscribing to topic "+dataSnapshot.getKey()+" "+this.getClass().getName());
                    subscribedtopicsprefeditor.putBoolean(dataSnapshot.getKey(),true);
                    FirebaseMessaging.getInstance().subscribeToTopic(dataSnapshot.getKey());
                }else{
                    Log.d("FragmentCreate","Unsubscribing from topic "+dataSnapshot.getKey()+" "+this.getClass().getName());
                    subscribedtopicsprefeditor.remove(dataSnapshot.getKey());
                    FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
                }

                subscribedtopicsprefeditor.commit();
            }

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
            //Log.d("FragmentCreate","Unubscribing from topic "+dataSnapshot.getKey());
            //FirebaseMessaging.getInstance().unsubscribeFromTopic(dataSnapshot.getKey());
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            //do nothing, this won't happen --- rather this isnt important
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d("FragmentCreate","Failed to listen to subscriptions node");
        }
    };

    if(userid!=null){

        Log.d("FragmentCreate","Found user id in service "+userid);

        userNodeSubscriptionRef = FirebaseDatabase.getInstance().getReference().child("Users").child(userid).child("subscriptions");

        userNodeSubscriptionRef.addChildEventListener(subscribedTopicsListener);

        userNodeSubscriptionRef.keepSynced(true);

    }else{
        Log.d("FragmentCreate","Couldn't find user id");
        stoppedInternally=true;
        stopSelf();
    }

}

@Override
public int onStartCommand(Intent intent,int flags,int startId){
    //don't need anything done over here
    //The intent can have the following extras

    //If the intent was started by the alarm manager ..... it will contain android.intent.extra.ALARM_COUNT
    //If the intent was sent by the broadcast receiver listening for boot/update ... it will contain wakelockid
    //If it was started from within the app .... it will contain no extras in the intent

    //The following will not throw an exception if the intent does not have an wakelockid in extra
    //As per android doc... the following method releases the wakelock if any specified inside the extra and returns true
    //If no wakelockid is specified, it will return false;

    if(intent!=null){
        if(BootEventReceiver.completeWakefulIntent(intent)){
            Log.d("FragmentCreate","Wakelock released");
        }else{
            Log.d("FragmentCreate","Wakelock not acquired in the first place");
        }
    }else{
        Log.d("FragmentCreate","Intent started by regular app usage");
    }

    return START_STICKY;
}

@Override
public void onDestroy(){

    if(userNodeSubscriptionRef!=null){
        userNodeSubscriptionRef.keepSynced(false);
    }

    userNodeSubscriptionRef = null;

    subscribedTopicsListener = null;

    sessionPref = null;
    subscribedTopicsPreference = null;

    subscribedtopicsprefeditor = null;

    userid = null;

    sessionPrefChangeListener = null;

    if(stoppedInternally){
        Log.d("FragmentCreate","Service getting stopped due to no userid or due to logout or data clearance...do not restart auto.. it will launch when user logs in or signs up");
    }else{

        Log.d("FragmentCreate","Service getting killed by user explicitly from running services or by force stop ... attempt restart");

        //well basically restart the service using an alarm manager ... restart after one minute

        AlarmManager alarmManager = (AlarmManager) this.getSystemService(ALARM_SERVICE);

        Intent restartServiceIntent = new Intent(this,SubscriptionListenerService.class);
        restartServiceIntent.setPackage(this.getPackageName());

        //context , uniqueid to identify the intent , actual intent , type of pending intent
        PendingIntent pendingIntentToBeFired = PendingIntent.getService(this,1,restartServiceIntent,PendingIntent.FLAG_ONE_SHOT);

        if(Build.VERSION.SDK_INT>=23){
            alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+600000,pendingIntentToBeFired);
        }else{
            alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+600000,pendingIntentToBeFired);
        }


    }

    super.onDestroy();

}


}
Author: Community, 2017-02-10

1 answers

Verifiquei que, de alguma forma, o serviço de medição do google estava a funcionar no meu dispositivo.

Recorri à seguinte abordagem:

As seguintes paragens na recolha de dados por base firebase.

Https://firebase.google.com/support/guides/disable-analytics diz - nos a seguinte abordagem

<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />
Isto por si só ainda não pode impedir a medição de inicialização.

O segundo passo que se resolveu é adicionar o seguinte à aplicação ficheiro de gradle de Nível:

configurations {
    all*.exclude group: 'com.google.firebase', module: 'firebase-core'
}

Isto basicamente remove todo o código que a análise da base firebase usa.

No caso de ainda não funcionar, certifique-se de que o gradle não inclui a dependência do serviço de jogo largo

Eg: compile ' com.o.androide.gms: play-services-location: 10.0.1 '

Em vez de "com".o.androide.gms: serviços de jogo: 10.0.1 '

O pior caso e eu não testei isto como o acima resolvido para mim riz:

Https://developers.google.com/analytics/devguides/collection/android/v4/advanced

O Google deve realmente parar de colocar coisas indesejadas sem a permissão do dev IMHO. Espero que isto ajude alguém.

 1
Author: Kushan, 2017-02-10 14:46:14