Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c20ef789 authored by Yi Kong's avatar Yi Kong Committed by Gerrit Code Review
Browse files

Merge "profcollect: check if ADB is active when the service starts." into main

parents 5e796fe9 bd3c95be
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.profcollect;

import android.Manifest;
import android.annotation.RequiresPermission;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
@@ -88,10 +90,11 @@ public final class ProfcollectForwardingService extends SystemService {
                createAndUploadReport(sSelfService);
            }
            if (UsbManager.ACTION_USB_STATE.equals(intent.getAction())) {
                boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
                boolean isADB = intent.getBooleanExtra(UsbManager.USB_FUNCTION_ADB, false);
                if (isADB) {
                    Log.d(LOG_TAG, "Received broadcast that ADB became " + connected);
                    boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
                    Log.d(LOG_TAG, "Received broadcast that ADB became " + connected
                            + ", was " + mAdbActive);
                    mAdbActive = connected;
                }
            }
@@ -117,9 +120,6 @@ public final class ProfcollectForwardingService extends SystemService {
        mUploadEnabled =
            context.getResources().getBoolean(R.bool.config_profcollectReportUploaderEnabled);

        // TODO: ADB might already be active when our service started.
        mAdbActive = false;

        final IntentFilter filter = new IntentFilter();
        filter.addAction(INTENT_UPLOAD_PROFILES);
        filter.addAction(UsbManager.ACTION_USB_STATE);
@@ -140,7 +140,13 @@ public final class ProfcollectForwardingService extends SystemService {
    }

    @Override
    @RequiresPermission(Manifest.permission.MANAGE_USB)
    public void onBootPhase(int phase) {
        if (phase == PHASE_SYSTEM_SERVICES_READY) {
            UsbManager usbManager = getContext().getSystemService(UsbManager.class);
            mAdbActive = ((usbManager.getCurrentFunctions() & UsbManager.FUNCTION_ADB) == 1);
            Log.d(LOG_TAG, "ADB is " + mAdbActive + " on system startup");
        }
        if (phase == PHASE_BOOT_COMPLETED) {
            if (mIProfcollect == null) {
                return;