Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wakelock - Tag name should use a unique prefix followed by a colon

Tags:

java

android

Screenshot of code in Android Studio

Tag name should use a unique prefix followed by a colon (found tag). For instance myapp:mywakelocktag. This will help with debugging less... (Ctrl+F1)

Wake Lock tags must follow the naming conventions defined in thePowerManager documentation. Issue id: InvalidWakeLockTag

    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {
        float distance = sensorEvent.values[0];
        if (!isVideo && !isSpeaker) {
            PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
            if (distance < 4) {
                if (wlOn != null && wlOn.isHeld()) {
                    wlOn.release();
                }
                if (pm != null) {
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                        if (wlOff == null)
                            wlOff = pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
                        if (!wlOff.isHeld()) wlOff.acquire();
                    }
                }
            } else {
                if (wlOff != null && wlOff.isHeld()) {
                    wlOff.release();
                }
                if (pm != null) {
                    if (wlOn == null)
                        wlOn = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
                    if (!wlOn.isHeld()) wlOn.acquire();
                }
            }
        }
    }
like image 521
ardi akbar Wijaya Avatar asked Jan 02 '19 10:01

ardi akbar Wijaya


2 Answers

Change "tag" to "AppName:tag"

It's searching for a colon ":" inside the string. It's not a very clear message, I thought it was asking me to make a string variable and reference that variable.

like image 145
Marlon Avatar answered Oct 26 '22 23:10

Marlon


From documentation, at https://developer.android.com/reference/android/os/PowerManager#newWakeLock(int,%20java.lang.String) a tag should follow the below guidelines. Please make sure your's does.

Recommended naming conventions for tags to make debugging easier:

  • use a unique prefix delimited by a colon for your app/library (e.g. gmail:mytag) to make it easier to understand where the wake locks comes from. This namespace will also avoid collision for tags inside your app coming from different libraries which will make debugging easier.
  • use constants (e.g. do not include timestamps in the tag) to make it easier for tools to aggregate similar wake locks. When collecting debugging data, the platform only monitors a finite number of tags, using constants will help tools to provide better debugging data.
  • avoid using Class#getName() or similar method since this class name can be transformed by java optimizer and obfuscator tools.
  • avoid wrapping the tag or a prefix to avoid collision with wake lock tags from the platform (e.g. alarm).
  • never include personnally identifiable information for privacy reasons.

Solution

Your tag is "tag", change it to something like myapp:tagforclassxyz

like image 33
Rohit5k2 Avatar answered Oct 27 '22 00:10

Rohit5k2